src/tree_cmd.cpp
branchNewGRF_ports
changeset 10991 d8811e327d12
parent 10731 67db0d431d5e
equal deleted inserted replaced
10731:67db0d431d5e 10991:d8811e327d12
   110  * @param seed The seed for randomness, must be less or equal 256
   110  * @param seed The seed for randomness, must be less or equal 256
   111  * @return The random tree type
   111  * @return The random tree type
   112  */
   112  */
   113 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
   113 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
   114 {
   114 {
   115 	switch (_settings.game_creation.landscape) {
   115 	switch (_settings_game.game_creation.landscape) {
   116 		case LT_TEMPERATE:
   116 		case LT_TEMPERATE:
   117 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
   117 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
   118 
   118 
   119 		case LT_ARCTIC:
   119 		case LT_ARCTIC:
   120 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
   120 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
   247 
   247 
   248 		IncreaseGeneratingWorldProgress(GWP_TREE);
   248 		IncreaseGeneratingWorldProgress(GWP_TREE);
   249 
   249 
   250 		if (CanPlantTreesOnTile(tile, true)) {
   250 		if (CanPlantTreesOnTile(tile, true)) {
   251 			PlaceTree(tile, r);
   251 			PlaceTree(tile, r);
   252 			if (_settings.game_creation.tree_placer != TP_IMPROVED) continue;
   252 			if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue;
   253 
   253 
   254 			/* Place a number of trees based on the tile height.
   254 			/* Place a number of trees based on the tile height.
   255 			 *  This gives a cool effect of multiple trees close together.
   255 			 *  This gives a cool effect of multiple trees close together.
   256 			 *  It is almost real life ;) */
   256 			 *  It is almost real life ;) */
   257 			ht = GetTileZ(tile);
   257 			ht = GetTileZ(tile);
   258 			/* The higher we get, the more trees we plant */
   258 			/* The higher we get, the more trees we plant */
   259 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   259 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   260 			while (j--) {
   260 			while (j--) {
   261 				/* Above snowline more trees! */
   261 				/* Above snowline more trees! */
   262 				if (_settings.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) {
   262 				if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) {
   263 					PlaceTreeAtSameHeight(tile, ht);
   263 					PlaceTreeAtSameHeight(tile, ht);
   264 					PlaceTreeAtSameHeight(tile, ht);
   264 					PlaceTreeAtSameHeight(tile, ht);
   265 				};
   265 				};
   266 
   266 
   267 				PlaceTreeAtSameHeight(tile, ht);
   267 				PlaceTreeAtSameHeight(tile, ht);
   268 			}
   268 			}
   269 		}
   269 		}
   270 	} while (--i);
   270 	} while (--i);
   271 
   271 
   272 	/* place extra trees at rainforest area */
   272 	/* place extra trees at rainforest area */
   273 	if (_settings.game_creation.landscape == LT_TROPIC) {
   273 	if (_settings_game.game_creation.landscape == LT_TROPIC) {
   274 		i = ScaleByMapSize(15000);
   274 		i = ScaleByMapSize(15000);
   275 
   275 
   276 		do {
   276 		do {
   277 			uint32 r = Random();
   277 			uint32 r = Random();
   278 			TileIndex tile = RandomTileSeed(r);
   278 			TileIndex tile = RandomTileSeed(r);
   294  */
   294  */
   295 void GenerateTrees()
   295 void GenerateTrees()
   296 {
   296 {
   297 	uint i, total;
   297 	uint i, total;
   298 
   298 
   299 	if (_settings.game_creation.tree_placer == TP_NONE) return;
   299 	if (_settings_game.game_creation.tree_placer == TP_NONE) return;
   300 
   300 
   301 	if (_settings.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees();
   301 	if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees();
   302 
   302 
   303 	switch (_settings.game_creation.tree_placer) {
   303 	switch (_settings_game.game_creation.tree_placer) {
   304 		case TP_ORIGINAL: i = _settings.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
   304 		case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
   305 		case TP_IMPROVED: i = _settings.game_creation.landscape == LT_ARCTIC ?  4 : 2; break;
   305 		case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ?  4 : 2; break;
   306 		default: NOT_REACHED(); return;
   306 		default: NOT_REACHED(); return;
   307 	}
   307 	}
   308 
   308 
   309 	total = ScaleByMapSize(1000);
   309 	total = ScaleByMapSize(1000);
   310 	if (_settings.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
   310 	if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
   311 	total *= i;
   311 	total *= i;
   312 	SetGeneratingWorldProgress(GWP_TREE, total);
   312 	SetGeneratingWorldProgress(GWP_TREE, total);
   313 
   313 
   314 	for (; i != 0; i--) {
   314 	for (; i != 0; i--) {
   315 		PlaceTreesRandomly();
   315 		PlaceTreesRandomly();
   330 	int ey;
   330 	int ey;
   331 	int sx, sy, x, y;
   331 	int sx, sy, x, y;
   332 
   332 
   333 	if (p2 >= MapSize()) return CMD_ERROR;
   333 	if (p2 >= MapSize()) return CMD_ERROR;
   334 	/* Check the tree type. It can be random or some valid value within the current climate */
   334 	/* Check the tree type. It can be random or some valid value within the current climate */
   335 	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_settings.game_creation.landscape] >= _tree_count_by_landscape[_settings.game_creation.landscape]) return CMD_ERROR;
   335 	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_settings_game.game_creation.landscape] >= _tree_count_by_landscape[_settings_game.game_creation.landscape]) return CMD_ERROR;
   336 
   336 
   337 	// make sure sx,sy are smaller than ex,ey
   337 	// make sure sx,sy are smaller than ex,ey
   338 	ex = TileX(tile);
   338 	ex = TileX(tile);
   339 	ey = TileY(tile);
   339 	ey = TileY(tile);
   340 	sx = TileX(p2);
   340 	sx = TileX(p2);
   388 							default: break;
   388 							default: break;
   389 						}
   389 						}
   390 					}
   390 					}
   391 
   391 
   392 					if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
   392 					if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
   393 						Town *t = ClosestTownFromTile(tile, _settings.economy.dist_local_authority);
   393 						Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
   394 						if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
   394 						if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
   395 					}
   395 					}
   396 
   396 
   397 					if (flags & DC_EXEC) {
   397 					if (flags & DC_EXEC) {
   398 						TreeType treetype;
   398 						TreeType treetype;
   531 static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
   531 static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
   532 {
   532 {
   533 	uint num;
   533 	uint num;
   534 
   534 
   535 	if (IsValidPlayer(_current_player)) {
   535 	if (IsValidPlayer(_current_player)) {
   536 		Town *t = ClosestTownFromTile(tile, _settings.economy.dist_local_authority);
   536 		Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
   537 		if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
   537 		if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
   538 	}
   538 	}
   539 
   539 
   540 	num = GetTreeCount(tile) + 1;
   540 	num = GetTreeCount(tile) + 1;
   541 	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
   541 	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
   624 static void TileLoop_Trees(TileIndex tile)
   624 static void TileLoop_Trees(TileIndex tile)
   625 {
   625 {
   626 	if (GetTreeGround(tile) == TREE_GROUND_SHORE) {
   626 	if (GetTreeGround(tile) == TREE_GROUND_SHORE) {
   627 		TileLoop_Water(tile);
   627 		TileLoop_Water(tile);
   628 	} else {
   628 	} else {
   629 		switch (_settings.game_creation.landscape) {
   629 		switch (_settings_game.game_creation.landscape) {
   630 			case LT_TROPIC: TileLoopTreesDesert(tile); break;
   630 			case LT_TROPIC: TileLoopTreesDesert(tile); break;
   631 			case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
   631 			case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
   632 		}
   632 		}
   633 	}
   633 	}
   634 
   634 
   650 	}
   650 	}
   651 	SetTreeCounter(tile, 0);
   651 	SetTreeCounter(tile, 0);
   652 
   652 
   653 	switch (GetTreeGrowth(tile)) {
   653 	switch (GetTreeGrowth(tile)) {
   654 		case 3: /* regular sized tree */
   654 		case 3: /* regular sized tree */
   655 			if (_settings.game_creation.landscape == LT_TROPIC &&
   655 			if (_settings_game.game_creation.landscape == LT_TROPIC &&
   656 					GetTreeType(tile) != TREE_CACTUS &&
   656 					GetTreeType(tile) != TREE_CACTUS &&
   657 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   657 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   658 				AddTreeGrowth(tile, 1);
   658 				AddTreeGrowth(tile, 1);
   659 			} else {
   659 			} else {
   660 				switch (GB(Random(), 0, 3)) {
   660 				switch (GB(Random(), 0, 3)) {
   702 				switch (GetTreeGround(tile)) {
   702 				switch (GetTreeGround(tile)) {
   703 					case TREE_GROUND_SHORE: MakeShore(tile); break;
   703 					case TREE_GROUND_SHORE: MakeShore(tile); break;
   704 					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
   704 					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
   705 					case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
   705 					case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
   706 					default: // snow or desert
   706 					default: // snow or desert
   707 						MakeClear(tile, _settings.game_creation.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile));
   707 						MakeClear(tile, _settings_game.game_creation.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile));
   708 						break;
   708 						break;
   709 				}
   709 				}
   710 			}
   710 			}
   711 			break;
   711 			break;
   712 
   712 
   723 	uint32 r;
   723 	uint32 r;
   724 	TileIndex tile;
   724 	TileIndex tile;
   725 	TreeType tree;
   725 	TreeType tree;
   726 
   726 
   727 	/* place a tree at a random rainforest spot */
   727 	/* place a tree at a random rainforest spot */
   728 	if (_settings.game_creation.landscape == LT_TROPIC &&
   728 	if (_settings_game.game_creation.landscape == LT_TROPIC &&
   729 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   729 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   730 			CanPlantTreesOnTile(tile, false) &&
   730 			CanPlantTreesOnTile(tile, false) &&
   731 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   731 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   732 		PlantTreesOnTile(tile, tree, 0, 0);
   732 		PlantTreesOnTile(tile, tree, 0, 0);
   733 	}
   733 	}