/** * Place new trees. * * This function takes care of the selected tree placer algorithm and * place randomly the trees for a new game. */ void GenerateTrees() { uint i, total; if (_settings_game.game_creation.tree_placer == TP_NONE) return; switch (_settings_game.game_creation.tree_placer) { case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break; case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break; default: NOT_REACHED(); } total = ScaleByMapSize(DEFAULT_TREE_STEPS); if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(DEFAULT_RAINFOREST_TREE_STEPS); total *= i; uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? ScaleByMapSize(GB(Random(), 0, 5) + 25) : 0; total += num_groups * DEFAULT_TREE_STEPS; SetGeneratingWorldProgress(GWP_TREE, total); if (num_groups != 0) PlaceTreeGroups(num_groups); for (; i != 0; i--) { PlaceTreesRandomly(); } }
/** * Place some trees randomly * * This function just place some trees randomly on the map. */ void PlaceTreesRandomly() { uint i, j, ht; i = ScaleByMapSize(DEFAULT_TREE_STEPS); if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV; do { uint32 r = Random(); TileIndex tile = RandomTileSeed(r); IncreaseGeneratingWorldProgress(GWP_TREE); if (CanPlantTreesOnTile(tile, true)) { PlaceTree(tile, r); if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue; /* Place a number of trees based on the tile height. * This gives a cool effect of multiple trees close together. * It is almost real life ;) */ ht = GetTileZ(tile); /* The higher we get, the more trees we plant */ j = GetTileZ(tile) / TILE_HEIGHT * 2; /* Above snowline more trees! */ if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3; while (j--) { PlaceTreeAtSameHeight(tile, ht); } } } while (--i); /* place extra trees at rainforest area */ if (_settings_game.game_creation.landscape == LT_TROPIC) { i = ScaleByMapSize(DEFAULT_RAINFOREST_TREE_STEPS); if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV; do { uint32 r = Random(); TileIndex tile = RandomTileSeed(r); IncreaseGeneratingWorldProgress(GWP_TREE); if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) { PlaceTree(tile, r); } } while (--i); } }
void GenerateClearTile() { uint i, gi; TileIndex tile; /* add rough tiles */ i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i); do { IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); tile = RandomTile(); if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); } while (--i); /* add rocky tiles */ i = gi; do { uint32 r = Random(); tile = RandomTileSeed(r); IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY); if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) { uint j = GB(r, 16, 4) + 5; for (;;) { TileIndex tile_new; SetClearGroundDensity(tile, CLEAR_ROCKS, 3); do { if (--j == 0) goto get_out; tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2)); } while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT)); tile = tile_new; } get_out:; } } while (--i); }