src/tree_cmd.cpp
branchgamebalance
changeset 9906 6f41b8713b65
parent 9903 dc85aaa556ae
child 9908 0fa543611bbe
equal deleted inserted replaced
9905:91eca6fdee8d 9906:6f41b8713b65
     7 #include "table/strings.h"
     7 #include "table/strings.h"
     8 #include "table/sprites.h"
     8 #include "table/sprites.h"
     9 #include "table/tree_land.h"
     9 #include "table/tree_land.h"
    10 #include "functions.h"
    10 #include "functions.h"
    11 #include "map.h"
    11 #include "map.h"
       
    12 #include "landscape.h"
    12 #include "tile.h"
    13 #include "tile.h"
    13 #include "tree_map.h"
    14 #include "tree_map.h"
    14 #include "viewport.h"
    15 #include "viewport.h"
    15 #include "command.h"
    16 #include "command.h"
    16 #include "town.h"
    17 #include "town.h"
    25 };
    26 };
    26 
    27 
    27 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    28 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    28 {
    29 {
    29 	switch (_opt.landscape) {
    30 	switch (_opt.landscape) {
    30 		case LT_NORMAL:
    31 		case LT_TEMPERATE:
    31 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
    32 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
    32 
    33 
    33 		case LT_HILLY:
    34 		case LT_ARCTIC:
    34 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
    35 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
    35 
    36 
    36 		case LT_DESERT:
    37 		case LT_TROPIC:
    37 			switch (GetTropicZone(tile)) {
    38 			switch (GetTropicZone(tile)) {
    38 				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
    39 				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
    39 				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
    40 				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
    40 				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
    41 				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
    41 			}
    42 			}
    51 
    52 
    52 	if (tree != TREE_INVALID) {
    53 	if (tree != TREE_INVALID) {
    53 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    54 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    54 
    55 
    55 		// above snowline?
    56 		// above snowline?
    56 		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
    57 		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
    57 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    58 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    58 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    59 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    59 		} else {
    60 		} else {
    60 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    61 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    61 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
    62 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
   148 			ht = GetTileZ(tile);
   149 			ht = GetTileZ(tile);
   149 			/* The higher we get, the more trees we plant */
   150 			/* The higher we get, the more trees we plant */
   150 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   151 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   151 			while (j--) {
   152 			while (j--) {
   152 				/* Above snowline more trees! */
   153 				/* Above snowline more trees! */
   153 				if (_opt.landscape == LT_HILLY && ht > _opt.snow_line) {
   154 				if (_opt.landscape == LT_ARCTIC && ht > GetSnowLine()) {
   154 					PlaceTreeAtSameHeight(tile, ht);
   155 					PlaceTreeAtSameHeight(tile, ht);
   155 					PlaceTreeAtSameHeight(tile, ht);
   156 					PlaceTreeAtSameHeight(tile, ht);
   156 				};
   157 				};
   157 
   158 
   158 				PlaceTreeAtSameHeight(tile, ht);
   159 				PlaceTreeAtSameHeight(tile, ht);
   159 			}
   160 			}
   160 		}
   161 		}
   161 	} while (--i);
   162 	} while (--i);
   162 
   163 
   163 	/* place extra trees at rainforest area */
   164 	/* place extra trees at rainforest area */
   164 	if (_opt.landscape == LT_DESERT) {
   165 	if (_opt.landscape == LT_TROPIC) {
   165 		i = ScaleByMapSize(15000);
   166 		i = ScaleByMapSize(15000);
   166 
   167 
   167 		do {
   168 		do {
   168 			uint32 r = Random();
   169 			uint32 r = Random();
   169 			TileIndex tile = RandomTileSeed(r);
   170 			TileIndex tile = RandomTileSeed(r);
   184 {
   185 {
   185 	uint i, total;
   186 	uint i, total;
   186 
   187 
   187 	if (_patches.tree_placer == TP_NONE) return;
   188 	if (_patches.tree_placer == TP_NONE) return;
   188 
   189 
   189 	if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
   190 	if (_opt.landscape != LT_TOYLAND) PlaceMoreTrees();
   190 
   191 
   191 	switch (_patches.tree_placer) {
   192 	switch (_patches.tree_placer) {
   192 		case TP_ORIGINAL: i = _opt.landscape == LT_HILLY ? 15 : 6; break;
   193 		case TP_ORIGINAL: i = _opt.landscape == LT_ARCTIC ? 15 : 6; break;
   193 		case TP_IMPROVED: i = _opt.landscape == LT_HILLY ?  4 : 2; break;
   194 		case TP_IMPROVED: i = _opt.landscape == LT_ARCTIC ?  4 : 2; break;
   194 		default: NOT_REACHED(); return;
   195 		default: NOT_REACHED(); return;
   195 	}
   196 	}
   196 
   197 
   197 	total = ScaleByMapSize(1000);
   198 	total = ScaleByMapSize(1000);
   198 	if (_opt.landscape == LT_DESERT) total += ScaleByMapSize(15000);
   199 	if (_opt.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
   199 	total *= i;
   200 	total *= i;
   200 	SetGeneratingWorldProgress(GWP_TREE, total);
   201 	SetGeneratingWorldProgress(GWP_TREE, total);
   201 
   202 
   202 	for (; i != 0; i--) {
   203 	for (; i != 0; i--) {
   203 		PlaceTreesRandomly();
   204 		PlaceTreesRandomly();
   494 	}
   495 	}
   495 }
   496 }
   496 
   497 
   497 static void TileLoopTreesAlps(TileIndex tile)
   498 static void TileLoopTreesAlps(TileIndex tile)
   498 {
   499 {
   499 	int k = GetTileZ(tile) - _opt.snow_line + TILE_HEIGHT;
   500 	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
   500 
   501 
   501 	if (k < 0) {
   502 	if (k < 0) {
   502 		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
   503 		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
   503 		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
   504 		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
   504 	} else {
   505 	} else {
   521 }
   522 }
   522 
   523 
   523 static void TileLoop_Trees(TileIndex tile)
   524 static void TileLoop_Trees(TileIndex tile)
   524 {
   525 {
   525 	switch (_opt.landscape) {
   526 	switch (_opt.landscape) {
   526 		case LT_DESERT: TileLoopTreesDesert(tile); break;
   527 		case LT_TROPIC: TileLoopTreesDesert(tile); break;
   527 		case LT_HILLY:  TileLoopTreesAlps(tile);   break;
   528 		case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
   528 	}
   529 	}
   529 
   530 
   530 	TileLoopClearHelper(tile);
   531 	TileLoopClearHelper(tile);
   531 
   532 
   532 	if (GetTreeCounter(tile) < 15) {
   533 	if (GetTreeCounter(tile) < 15) {
   535 	}
   536 	}
   536 	SetTreeCounter(tile, 0);
   537 	SetTreeCounter(tile, 0);
   537 
   538 
   538 	switch (GetTreeGrowth(tile)) {
   539 	switch (GetTreeGrowth(tile)) {
   539 		case 3: /* regular sized tree */
   540 		case 3: /* regular sized tree */
   540 			if (_opt.landscape == LT_DESERT &&
   541 			if (_opt.landscape == LT_TROPIC &&
   541 					GetTreeType(tile) != TREE_CACTUS &&
   542 					GetTreeType(tile) != TREE_CACTUS &&
   542 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   543 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   543 				AddTreeGrowth(tile, 1);
   544 				AddTreeGrowth(tile, 1);
   544 			} else {
   545 			} else {
   545 				switch (GB(Random(), 0, 3)) {
   546 				switch (GB(Random(), 0, 3)) {
   610 	TileIndex tile;
   611 	TileIndex tile;
   611 	ClearGround ct;
   612 	ClearGround ct;
   612 	TreeType tree;
   613 	TreeType tree;
   613 
   614 
   614 	/* place a tree at a random rainforest spot */
   615 	/* place a tree at a random rainforest spot */
   615 	if (_opt.landscape == LT_DESERT &&
   616 	if (_opt.landscape == LT_TROPIC &&
   616 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   617 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   617 			IsTileType(tile, MP_CLEAR) &&
   618 			IsTileType(tile, MP_CLEAR) &&
   618 			!IsBridgeAbove(tile) &&
   619 			!IsBridgeAbove(tile) &&
   619 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   620 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   620 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   621 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {