1
0
Fork 0

Codechange: Use Map::Iterate() to iterate tiles

pull/13151/head
SamuXarick 2024-10-27 18:52:57 +00:00 committed by rubidium42
parent cfb995b6e9
commit 10e2d1ca36
15 changed files with 36 additions and 36 deletions

View File

@ -146,7 +146,7 @@ static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if ((int32_t)TileHeight(t) > new_value) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */

View File

@ -408,7 +408,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
static void DestructIndustry(Industry *i)
{
for (TileIndex tile = 0; tile != Map::Size(); tile++) {
for (const auto tile : Map::Iterate()) {
if (i->TileBelongsToIndustry(tile)) {
ResetIndustryConstructionStage(tile);
MarkTileDirtyByTile(tile);

View File

@ -626,7 +626,7 @@ public:
for (Industry *industry : Industry::Iterate()) delete industry;
/* Clear farmland. */
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
for (const auto tile : Map::Iterate()) {
if (IsTileType(tile, MP_CLEAR) && GetRawClearGround(tile) == CLEAR_FIELDS) {
MakeClear(tile, CLEAR_GRASS, 3);
}

View File

@ -1471,7 +1471,7 @@ static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
std::array<int, MAX_TILE_HEIGHT + 1> edge_histogram = {};
/* Build a histogram of the map height. */
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
for (const auto tile : Map::Iterate()) {
uint h = TileHeight(tile);
histogram[h]++;

View File

@ -367,7 +367,7 @@ uint GetClosestWaterDistance(TileIndex tile, bool water)
if (!water) {
/* no land found - is this a water-only map? */
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_VOID) && !IsTileType(t, MP_WATER)) return 0x1FF;
}
}

View File

@ -1928,7 +1928,7 @@ static void SetDefaultRailGui()
/* Find the most used rail type */
uint count[RAILTYPE_END];
memset(count, 0, sizeof(count));
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || HasStationTileRail(t) ||
(IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) {
count[GetRailType(t)]++;

View File

@ -1919,7 +1919,7 @@ void UpdateNearestTownForRoadTiles(bool invalidate)
{
assert(!invalidate || _generating_world);
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_ROAD) && !IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
TownID tid = INVALID_TOWN;
if (!invalidate) {

View File

@ -657,7 +657,7 @@ bool AfterLoadGame()
* (4.3) version, so I just check when versions are older, and then
* walk through the whole map.. */
if (IsSavegameVersionBefore(SLV_4, 3)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
SetTileOwner(t, OWNER_WATER);
}
@ -928,7 +928,7 @@ bool AfterLoadGame()
}
}
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
switch (GetTileType(t)) {
case MP_STATION: {
BaseStation *bst = BaseStation::GetByTile(t);
@ -1340,7 +1340,7 @@ bool AfterLoadGame()
}
/* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
switch (GetTileType(t)) {
case MP_RAILWAY:
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
@ -1469,7 +1469,7 @@ bool AfterLoadGame()
* To give this prettiness to old savegames, we remove all farmfields and
* plant new ones. */
if (IsSavegameVersionBefore(SLV_32)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
/* remove fields */
MakeClear(t, CLEAR_GRASS, 3);
@ -1691,7 +1691,7 @@ bool AfterLoadGame()
/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
Replace the owner for those by OWNER_NONE. */
if (IsSavegameVersionBefore(SLV_82)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_WATER) &&
GetWaterTileType(t) == WATER_TILE_CLEAR &&
GetTileOwner(t) == OWNER_WATER &&
@ -1861,7 +1861,7 @@ bool AfterLoadGame()
/* Update locks, depots, docks and buoys to have a water class based
* on its neighbouring tiles. Done after river and canal updates to
* ensure neighbours are correct. */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (!IsTileFlat(t)) continue;
if (IsTileType(t, MP_WATER) && IsLock(t)) SetWaterClassDependingOnSurroundings(t, false);
@ -1870,7 +1870,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_87)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
/* skip oil rigs at borders! */
if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
(TileX(t) == 0 || TileY(t) == 0 || TileX(t) == Map::MaxX() - 1 || TileY(t) == Map::MaxY() - 1)) {
@ -2409,7 +2409,7 @@ bool AfterLoadGame()
{119, 15}, // 14 unused tiles (radar)
{140, 4}, // APT_GRASS_FENCE_NE_FLAG_2
};
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsAirportTile(t)) {
StationGfx old_gfx = GetStationGfx(t);
uint8_t offset = 0;
@ -2448,7 +2448,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_141)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
/* Reset tropic zone for VOID tiles, they shall not have any. */
if (IsTileType(t, MP_VOID)) SetTropicZone(t, TROPICZONE_NORMAL);
}
@ -2528,7 +2528,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_149)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_STATION)) continue;
if (!IsBuoy(t) && !IsOilRig(t) && !(IsDock(t) && IsTileFlat(t))) {
SetWaterClass(t, WATER_CLASS_INVALID);
@ -2885,7 +2885,7 @@ bool AfterLoadGame()
/* The road owner of standard road stops was not properly accounted for. */
if (IsSavegameVersionBefore(SLV_172)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (!IsBayRoadStopTile(t)) continue;
Owner o = GetTileOwner(t);
SetRoadOwner(t, RTT_ROAD, o);
@ -2912,7 +2912,7 @@ bool AfterLoadGame()
{
/* Station blocked, wires and pylon flags need to be stored in the map. This is effectively cached data, so no
* version check is necessary. This is done here as the SLV_182 check below needs the blocked status. */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (HasStationTileRail(t)) SetRailStationTileFlags(t, GetStationSpec(t));
}
}
@ -2928,7 +2928,7 @@ bool AfterLoadGame()
/* Blocked tiles could be reserved due to a bug, which causes
* other places to assert upon e.g. station reconstruction. */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (HasStationTileRail(t) && IsStationTileBlocked(t)) {
SetRailStationReservation(t, false);
}
@ -3146,14 +3146,14 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_TREES_WATER_CLASS)) {
/* Update water class for trees. */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_TREES)) SetWaterClass(t, GetTreeGround(t) == TREE_GROUND_SHORE ? WATER_CLASS_SEA : WATER_CLASS_INVALID);
}
}
/* Update structures for multitile docks */
if (IsSavegameVersionBefore(SLV_MULTITILE_DOCKS)) {
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
/* Clear docking tile flag from relevant tiles as it
* was not previously cleared. */
if (IsTileType(t, MP_WATER) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE)) {
@ -3175,7 +3175,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBeforeOrAt(SLV_ENDING_YEAR)) {
/* Reset roadtype/streetcartype info for non-road bridges. */
for (auto t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
if (IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) != TRANSPORT_ROAD) {
SetRoadTypes(t, INVALID_ROADTYPE, INVALID_ROADTYPE);
}
@ -3266,7 +3266,7 @@ bool AfterLoadGame()
}
/* Refresh all level crossings to bar adjacent crossing tiles, if needed. */
for (auto tile : Map::Iterate()) {
for (const auto tile : Map::Iterate()) {
if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile, false);
}
}

View File

@ -106,7 +106,7 @@ void AfterLoadCompanyStats()
}
Company *c;
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
for (const auto tile : Map::Iterate()) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
c = Company::GetIfValid(GetTileOwner(tile));

View File

@ -52,7 +52,7 @@ static void ConvertRailTypes()
}
if (!needs_conversion) return;
for (TileIndex t : Map::Iterate()) {
for (const auto t : Map::Iterate()) {
switch (GetTileType(t)) {
case MP_RAILWAY:
SetRailType(t, railtype_conversion_map[GetRailType(t)]);

View File

@ -35,7 +35,7 @@ void RebuildTownCaches()
town->cache.num_houses = 0;
}
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetHouseType(t);
@ -63,7 +63,7 @@ void RebuildTownCaches()
*/
void UpdateHousesAndTowns()
{
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetCleanHouseType(t);
@ -76,7 +76,7 @@ void UpdateHousesAndTowns()
}
/* Check for cases when a NewGRF has set a wrong house substitute type. */
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_type = GetCleanHouseType(t);

View File

@ -819,7 +819,7 @@ bool MakeHeightmapScreenshot(const char *filename)
}
_heightmap_highest_peak = 0;
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
for (const auto tile : Map::Iterate()) {
uint h = TileHeight(tile);
_heightmap_highest_peak = std::max(h, _heightmap_highest_peak);
}

View File

@ -533,7 +533,7 @@ static bool CheckMaxHeightLevel(int32_t &new_value)
/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if ((int32_t)TileHeight(t) > new_value) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */

View File

@ -128,7 +128,7 @@ Town::~Town()
#endif /* WITH_ASSERT */
/* Check no tile is related to us. */
for (TileIndex tile = 0; tile < Map::Size(); ++tile) {
for (const auto tile : Map::Iterate()) {
switch (GetTileType(tile)) {
case MP_HOUSE:
assert(GetTownIndex(tile) != this->index);
@ -3248,7 +3248,7 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TownID town_id)
* these do not directly have an owner so we need to check adjacent
* tiles. This won't work correctly in the same loop if the adjacent
* tile was already deleted earlier in the loop. */
for (TileIndex current_tile = 0; current_tile < Map::Size(); ++current_tile) {
for (const auto current_tile : Map::Iterate()) {
if (IsTileType(current_tile, MP_TUNNELBRIDGE) && TestTownOwnsBridge(current_tile, t)) {
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
if (ret.Failed()) return ret;
@ -3256,7 +3256,7 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TownID town_id)
}
/* Check all remaining tiles for town ownership. */
for (TileIndex current_tile = 0; current_tile < Map::Size(); ++current_tile) {
for (const auto current_tile : Map::Iterate()) {
bool try_clear = false;
switch (GetTileType(current_tile)) {
case MP_ROAD:
@ -4071,7 +4071,7 @@ static IntervalTimer<TimerGameEconomy> _economy_towns_monthly({TimerGameEconomy:
static IntervalTimer<TimerGameEconomy> _economy_towns_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::TOWN}, [](auto)
{
/* Increment house ages */
for (TileIndex t = 0; t < Map::Size(); t++) {
for (const auto t : Map::Iterate()) {
if (!IsTileType(t, MP_HOUSE)) continue;
IncrementHouseAge(t);
}

View File

@ -1299,7 +1299,7 @@ void TileLoop_Water(TileIndex tile)
void ConvertGroundTilesIntoWaterTiles()
{
for (TileIndex tile = 0; tile < Map::Size(); ++tile) {
for (const auto tile : Map::Iterate()) {
auto [slope, z] = GetTileSlopeZ(tile);
if (IsTileType(tile, MP_CLEAR) && z == 0) {
/* Make both water for tiles at level 0