src/tree_cmd.cpp
changeset 5587 167d9a91ef02
parent 5584 1111b4d36e35
child 5668 36b39f4a9032
equal deleted inserted replaced
5586:2d4126d81ebb 5587:167d9a91ef02
    26 
    26 
    27 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    27 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    28 {
    28 {
    29 	switch (_opt.landscape) {
    29 	switch (_opt.landscape) {
    30 		case LT_NORMAL:
    30 		case LT_NORMAL:
    31 			return seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE;
    31 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
    32 
    32 
    33 		case LT_HILLY:
    33 		case LT_HILLY:
    34 			return seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC;
    34 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
    35 
    35 
    36 		case LT_DESERT:
    36 		case LT_DESERT:
    37 			switch (GetTropicZone(tile)) {
    37 			switch (GetTropicZone(tile)) {
    38 				case TROPICZONE_INVALID: return seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL;
    38 				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
    39 				case TROPICZONE_DESERT:  return (seed > 12) ? TREE_INVALID : TREE_CACTUS;
    39 				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
    40 				default:                 return seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST;
    40 				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
    41 			}
    41 			}
    42 
    42 
    43 		default:
    43 		default:
    44 			return seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND;
    44 			return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
    45 	}
    45 	}
    46 }
    46 }
    47 
    47 
    48 static void PlaceTree(TileIndex tile, uint32 r)
    48 static void PlaceTree(TileIndex tile, uint32 r)
    49 {
    49 {
    53 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    53 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    54 
    54 
    55 		// above snowline?
    55 		// above snowline?
    56 		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
    56 		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
    57 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    57 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    58 			SetTreeCounter(tile, GB(r, 24, 3));
    58 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    59 		} else {
    59 		} else {
    60 			SetTreeGroundDensity(tile, GB(r, 28, 1), 0);
    60 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    61 			SetTreeCounter(tile, GB(r, 24, 4));
    61 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
    62 		}
    62 		}
    63 	}
    63 	}
    64 }
    64 }
    65 
    65 
    66 static void DoPlaceMoreTrees(TileIndex tile)
    66 static void DoPlaceMoreTrees(TileIndex tile)
   114 				IsClearGround(cur_tile, CLEAR_FIELDS) ||
   114 				IsClearGround(cur_tile, CLEAR_FIELDS) ||
   115 				IsClearGround(cur_tile, CLEAR_ROCKS))
   115 				IsClearGround(cur_tile, CLEAR_ROCKS))
   116 			continue;
   116 			continue;
   117 
   117 
   118 		/* Not too much height difference */
   118 		/* Not too much height difference */
   119 		if (myabs(GetTileZ(cur_tile) - height) > 2) continue;
   119 		if (delta(GetTileZ(cur_tile), height) > 2) continue;
   120 
   120 
   121 		/* Place one tree and quit */
   121 		/* Place one tree and quit */
   122 		PlaceTree(cur_tile, r);
   122 		PlaceTree(cur_tile, r);
   123 		break;
   123 		break;
   124 	}
   124 	}
   276 							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   276 							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   277 							if (t != NULL)
   277 							if (t != NULL)
   278 								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
   278 								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
   279 						}
   279 						}
   280 
   280 
   281 						treetype = p1;
   281 						treetype = (TreeType)p1;
   282 						if (treetype == TREE_INVALID) {
   282 						if (treetype == TREE_INVALID) {
   283 							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
   283 							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
   284 							if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
   284 							if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
   285 						}
   285 						}
   286 
   286 
   406 
   406 
   407 
   407 
   408 static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y)
   408 static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y)
   409 {
   409 {
   410 	uint z;
   410 	uint z;
   411 	uint tileh = GetTileSlope(tile, &z);
   411 	Slope tileh = GetTileSlope(tile, &z);
   412 
   412 
   413 	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
   413 	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
   414 }
   414 }
   415 
   415 
   416 static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
   416 static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
   652 {
   652 {
   653 	_trees_tick_ctr = 0;
   653 	_trees_tick_ctr = 0;
   654 }
   654 }
   655 
   655 
   656 
   656 
   657 const TileTypeProcs _tile_type_trees_procs = {
   657 extern const TileTypeProcs _tile_type_trees_procs = {
   658 	DrawTile_Trees,           /* draw_tile_proc */
   658 	DrawTile_Trees,           /* draw_tile_proc */
   659 	GetSlopeZ_Trees,          /* get_slope_z_proc */
   659 	GetSlopeZ_Trees,          /* get_slope_z_proc */
   660 	ClearTile_Trees,          /* clear_tile_proc */
   660 	ClearTile_Trees,          /* clear_tile_proc */
   661 	GetAcceptedCargo_Trees,   /* get_accepted_cargo_proc */
   661 	GetAcceptedCargo_Trees,   /* get_accepted_cargo_proc */
   662 	GetTileDesc_Trees,        /* get_tile_desc_proc */
   662 	GetTileDesc_Trees,        /* get_tile_desc_proc */