Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <queue>
- static void CreateDesertOrRainForest()
- {
- TileIndex update_freq = MapSize() / 8;
- uint max_desert_height = CeilDiv(_settings_game.construction.max_heightlevel, 4);
- std::queue<std::pair<TileIndex, TileIndex>> queue;
- for (TileIndex tile = 0; tile != MapSize(); ++tile) {
- if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
- if (!IsValidTile(tile)) continue;
- if ((TileHeight(tile) >= max_desert_height || IsTileType(tile, MP_WATER))) {
- SetTropicZone(tile, TROPICZONE_RAINFOREST);
- queue.push(std::make_pair(tile, tile));
- } else {
- SetTropicZone(tile, TROPICZONE_DESERT);
- }
- }
- static const TileIndexDiffC NEIGHBORS[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
- while (!queue.empty()) {
- auto p = queue.front();
- queue.pop();
- for (auto &d : NEIGHBORS) {
- auto t = AddTileIndexDiffCWrap(p.second, d);
- if (t == INVALID_TILE) continue;
- if (GetTropicZone(t) != TROPICZONE_DESERT) continue;
- auto dist = DistanceSquare(t, p.first);
- if (dist < 49) {
- queue.push(std::make_pair(p.first, t));
- SetTropicZone(t, dist < 4 ? TROPICZONE_RAINFOREST : TROPICZONE_NORMAL);
- }
- }
- }
- for (uint i = 0; i != 256; i++) {
- if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
- RunTileLoop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement