src/tree_cmd.cpp
changeset 9358 2e1e4d2f71dd
parent 9354 845e07db4549
child 9413 7042a8ec3fa8
equal deleted inserted replaced
9357:f540f1fb6bd9 9358:2e1e4d2f71dd
   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 (_opt.landscape) {
   115 	switch (_settings.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);
   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 (_opt.landscape == LT_ARCTIC && ht > GetSnowLine()) {
   262 				if (_settings.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 (_opt.landscape == LT_TROPIC) {
   273 	if (_settings.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);
   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_creation.tree_placer == TP_NONE) return;
   300 
   300 
   301 	if (_opt.landscape != LT_TOYLAND) PlaceMoreTrees();
   301 	if (_settings.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees();
   302 
   302 
   303 	switch (_settings.game_creation.tree_placer) {
   303 	switch (_settings.game_creation.tree_placer) {
   304 		case TP_ORIGINAL: i = _opt.landscape == LT_ARCTIC ? 15 : 6; break;
   304 		case TP_ORIGINAL: i = _settings.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
   305 		case TP_IMPROVED: i = _opt.landscape == LT_ARCTIC ?  4 : 2; break;
   305 		case TP_IMPROVED: i = _settings.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 (_opt.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
   310 	if (_settings.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[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
   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;
   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);
   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 (_opt.landscape) {
   629 		switch (_settings.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 (_opt.landscape == LT_TROPIC &&
   655 			if (_settings.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, _opt.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile));
   707 						MakeClear(tile, _settings.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 (_opt.landscape == LT_TROPIC &&
   728 	if (_settings.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 	}