src/tree_cmd.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6683 7ec558346172
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file tree_cmd.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "bridge_map.h"
     7 #include "bridge_map.h"
     6 #include "clear_map.h"
     8 #include "clear_map.h"
    51 	TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
    53 	TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
    52 
    54 
    53 	if (tree != TREE_INVALID) {
    55 	if (tree != TREE_INVALID) {
    54 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    56 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    55 
    57 
    56 		// above snowline?
    58 		/* above snowline? */
    57 		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
    59 		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
    58 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    60 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    59 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    61 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    60 		} else {
    62 		} else {
    61 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    63 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
   205 	}
   207 	}
   206 }
   208 }
   207 
   209 
   208 /** Plant a tree.
   210 /** Plant a tree.
   209  * @param tile start tile of area-drag of tree plantation
   211  * @param tile start tile of area-drag of tree plantation
       
   212  * @param flags type of operation
   210  * @param p1 tree type, -1 means random.
   213  * @param p1 tree type, -1 means random.
   211  * @param p2 end tile of area-drag
   214  * @param p2 end tile of area-drag
   212  */
   215  */
   213 int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   216 int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   214 {
   217 {
   238 		for (y = sy; y <= ey; y++) {
   241 		for (y = sy; y <= ey; y++) {
   239 			TileIndex tile = TileXY(x, y);
   242 			TileIndex tile = TileXY(x, y);
   240 
   243 
   241 			switch (GetTileType(tile)) {
   244 			switch (GetTileType(tile)) {
   242 				case MP_TREES:
   245 				case MP_TREES:
   243 					// no more space for trees?
   246 					/* no more space for trees? */
   244 					if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
   247 					if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
   245 						msg = STR_2803_TREE_ALREADY_HERE;
   248 						msg = STR_2803_TREE_ALREADY_HERE;
   246 						continue;
   249 						continue;
   247 					}
   250 					}
   248 
   251 
   249 					if (flags & DC_EXEC) {
   252 					if (flags & DC_EXEC) {
   250 						AddTreeCount(tile, 1);
   253 						AddTreeCount(tile, 1);
   251 						MarkTileDirtyByTile(tile);
   254 						MarkTileDirtyByTile(tile);
   252 					}
   255 					}
   253 					// 2x as expensive to add more trees to an existing tile
   256 					/* 2x as expensive to add more trees to an existing tile */
   254 					cost += _price.build_trees * 2;
   257 					cost += _price.build_trees * 2;
   255 					break;
   258 					break;
   256 
   259 
   257 				case MP_CLEAR:
   260 				case MP_CLEAR:
   258 					if (!IsTileOwner(tile, OWNER_NONE) ||
   261 					if (!IsTileOwner(tile, OWNER_NONE) ||
   312 }
   315 }
   313 
   316 
   314 struct TreeListEnt {
   317 struct TreeListEnt {
   315 	SpriteID image;
   318 	SpriteID image;
   316 	SpriteID pal;
   319 	SpriteID pal;
   317 	byte x,y;
   320 	byte x, y;
   318 };
   321 };
   319 
   322 
   320 static void DrawTile_Trees(TileInfo *ti)
   323 static void DrawTile_Trees(TileInfo *ti)
   321 {
   324 {
   322 	const PalSpriteID *s;
   325 	const PalSpriteID *s;
   363 		s = _tree_layout_sprite[index];
   366 		s = _tree_layout_sprite[index];
   364 	}
   367 	}
   365 
   368 
   366 	StartSpriteCombine();
   369 	StartSpriteCombine();
   367 
   370 
   368 	if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) {
   371 	if (!HASBIT(_transparent_opt, TO_TREES) || !_patches.invisible_trees) {
   369 		TreeListEnt te[4];
   372 		TreeListEnt te[4];
   370 		uint i;
   373 		uint i;
   371 
   374 
   372 		/* put the trees to draw in a list */
   375 		/* put the trees to draw in a list */
   373 		i = GetTreeCount(ti->tile) + 1;
   376 		i = GetTreeCount(ti->tile) + 1;
   374 		do {
   377 		do {
   375 			SpriteID image = s[0].sprite + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
   378 			SpriteID image = s[0].sprite + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
   376 			SpriteID pal;
   379 			SpriteID pal;
   377 			if (_display_opt & DO_TRANS_BUILDINGS) {
   380 			if (HASBIT(_transparent_opt, TO_TREES)) {
   378 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
   381 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
   379 				pal = PALETTE_TO_TRANSPARENT;
   382 				pal = PALETTE_TO_TRANSPARENT;
   380 			} else {
   383 			} else {
   381 				pal = s[0].pal;
   384 				pal = s[0].pal;
   382 			}
   385 			}
   620 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   623 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   621 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   624 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   622 		MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0);
   625 		MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0);
   623 	}
   626 	}
   624 
   627 
   625 	// byte underflow
   628 	/* byte underflow */
   626 	if (--_trees_tick_ctr != 0) return;
   629 	if (--_trees_tick_ctr != 0) return;
   627 
   630 
   628 	/* place a tree at a random spot */
   631 	/* place a tree at a random spot */
   629 	r = Random();
   632 	r = Random();
   630 	tile = TILE_MASK(r);
   633 	tile = TILE_MASK(r);
   643 static void ClickTile_Trees(TileIndex tile)
   646 static void ClickTile_Trees(TileIndex tile)
   644 {
   647 {
   645 	/* not used */
   648 	/* not used */
   646 }
   649 }
   647 
   650 
   648 static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode)
   651 static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode)
   649 {
   652 {
   650 	return 0;
   653 	return 0;
   651 }
   654 }
   652 
   655 
   653 static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player)
   656 static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player)