-
-
Save SamuXarick/4d1226c201967f3beb1eee3f931a7c02 to your computer and use it in GitHub Desktop.
Two lists of tiles, I want to set rainforest on tiles that are 49 squared dist away from desert tiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void CreateDesertOrRainForest(uint desert_tropic_line) | |
{ | |
TileIndex update_freq = Map::Size() / 2; | |
std::vector<std::pair<TileIndex, TileIndex>> queue; | |
for (TileIndex tile = 0; tile != Map::Size(); ++tile) { | |
if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); | |
if (!IsValidTile(tile)) continue; | |
if (TileHeight(tile) >= desert_tropic_line || IsTileType(tile, MP_WATER)) { | |
SetTropicZone(tile, TROPICZONE_RAINFOREST); | |
queue.push_back(std::make_pair(tile, tile)); | |
} else { | |
SetTropicZone(tile, TROPICZONE_DESERT); | |
} | |
} | |
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); | |
std::vector<TileIndex> normal_tiles; | |
static const TileIndexDiffC neighbours[] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; | |
auto i = 0; | |
while (i != queue.size()) { | |
auto p = queue[i]; | |
for (auto &d : neighbours) { | |
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_back(std::make_pair(p.first, t)); | |
if (dist == 0) { | |
SetTropicZone(t, TROPICZONE_RAINFOREST); | |
} else { | |
if (IsValidTile(t)) normal_tiles.emplace_back(t); | |
SetTropicZone(t, TROPICZONE_NORMAL); | |
} | |
} | |
} | |
i++; | |
} | |
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); | |
TileIndex middle = TileXY(Map::SizeX() / 2, Map::SizeY() / 2); | |
TileArea ta(middle, 1, 1); | |
ta.Expand(6); | |
std::vector<TileIndexDiffC> diffs; | |
for (auto &tile : ta) { | |
if (DistanceSquare(tile, middle) <= 50) { | |
TileIndexDiffC diff = TileIndexToTileIndexDiffC(tile, middle); | |
diffs.emplace_back(diff); | |
} | |
} | |
update_freq = normal_tiles.size() / 4; | |
auto count = 0; | |
for (auto &tile : normal_tiles) { | |
count++; | |
if (count == update_freq) { | |
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); | |
count = 0; | |
} | |
bool make_rainforest = true; | |
for (auto &diff : diffs) { | |
auto t = AddTileIndexDiffCWrap(tile, diff); | |
if (IsValidTile(t) && GetTropicZone(t) == TROPICZONE_DESERT) { | |
make_rainforest = false; | |
break; | |
} | |
} | |
if (make_rainforest) { | |
SetTropicZone(tile, TROPICZONE_RAINFOREST); | |
} | |
} | |
for (uint i = 0; i != 256; i++) { | |
if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); | |
RunTileLoop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment