diff options
author | glx22 <glx@openttd.org> | 2021-04-30 17:01:26 +0200 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-05-03 19:46:57 +0200 |
commit | 2feb801e56f5f36121bcc44d04cb46937987c490 (patch) | |
tree | 4ca88e9a3e2a917e489cb86cd80e230eb2bdafeb | |
parent | 983c7ade60f82a49d8c23c1f295add1fd9a913b0 (diff) | |
download | openttd-2feb801e56f5f36121bcc44d04cb46937987c490.tar.xz |
Codechange: Replace FOR_ALL_ROADTRAMTYPES with range-based for loops
-rw-r--r-- | src/road.h | 2 | ||||
-rw-r--r-- | src/road_cmd.cpp | 6 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 2 | ||||
-rw-r--r-- | src/saveload/company_sl.cpp | 6 | ||||
-rw-r--r-- | src/station_cmd.cpp | 6 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 2 |
6 files changed, 12 insertions, 12 deletions
diff --git a/src/road.h b/src/road.h index becbf4051..6a2af6698 100644 --- a/src/road.h +++ b/src/road.h @@ -32,7 +32,7 @@ enum RoadTramTypes : uint8 { }; DECLARE_ENUM_AS_BIT_SET(RoadTramTypes) -#define FOR_ALL_ROADTRAMTYPES(x) for (RoadTramType x : { RTT_ROAD, RTT_TRAM }) +static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM }; /** Roadtype flags. Starts with RO instead of R because R is used for rails */ enum RoadTypeFlags { diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 830f9dd4f..82e944f6e 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1238,7 +1238,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags) /* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */ if ((HasExactlyOneBit(b) && GetRoadBits(tile, RTT_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) { CommandCost ret(EXPENSES_CONSTRUCTION); - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue; CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true); @@ -2203,7 +2203,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne Company::Get(new_owner)->infrastructure.road[rt] += 2; SetTileOwner(tile, new_owner); - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { if (GetRoadOwner(tile, rtt) == old_owner) { SetRoadOwner(tile, rtt, new_owner); } @@ -2213,7 +2213,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne return; } - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { /* Update all roadtypes, no matter if they are present */ if (GetRoadOwner(tile, rtt) == old_owner) { RoadType rt = GetRoadType(tile, rtt); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 56680511c..7fd220494 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1855,7 +1855,7 @@ bool AfterLoadGame() } } else if (IsTileType(t, MP_ROAD)) { /* works for all RoadTileType */ - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { /* update even non-existing road types to update tile owner too */ Owner o = GetRoadOwner(t, rtt); if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE); diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index fb2742a18..5770f9791 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -128,7 +128,7 @@ void AfterLoadCompanyStats() } /* Iterate all present road types as each can have a different owner. */ - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { RoadType rt = GetRoadType(tile, rtt); if (rt == INVALID_ROADTYPE) continue; c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt)); @@ -151,7 +151,7 @@ void AfterLoadCompanyStats() case STATION_BUS: case STATION_TRUCK: { /* Iterate all present road types as each can have a different owner. */ - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { RoadType rt = GetRoadType(tile, rtt); if (rt == INVALID_ROADTYPE) continue; c = Company::GetIfValid(GetRoadOwner(tile, rtt)); @@ -209,7 +209,7 @@ void AfterLoadCompanyStats() case TRANSPORT_ROAD: { /* Iterate all present road types as each can have a different owner. */ - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { RoadType rt = GetRoadType(tile, rtt); if (rt == INVALID_ROADTYPE) continue; c = Company::GetIfValid(GetRoadOwner(tile, rtt)); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 451dedbad..39efb710e 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2029,7 +2029,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags) } /* Update company infrastructure counts. */ - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { RoadType rt = GetRoadType(tile, rtt); UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), -static_cast<int>(ROAD_STOP_TRACKBIT_FACTOR)); } @@ -2110,7 +2110,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui RoadType road_type[] = { INVALID_ROADTYPE, INVALID_ROADTYPE }; Owner road_owner[] = { OWNER_NONE, OWNER_NONE }; if (IsDriveThroughStopTile(cur_tile)) { - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { road_type[rtt] = GetRoadType(cur_tile, rtt); if (road_type[rtt] == INVALID_ROADTYPE) continue; road_owner[rtt] = GetRoadOwner(cur_tile, rtt); @@ -4178,7 +4178,7 @@ void DeleteOilRig(TileIndex tile) static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner) { if (IsRoadStopTile(tile)) { - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { /* Update all roadtypes, no matter if they are present */ if (GetRoadOwner(tile, rtt) == old_owner) { RoadType rt = GetRoadType(tile, rtt); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 2f76dbcef..dd8d731ee 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1811,7 +1811,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner * don't want to update the infrastructure counts twice. */ uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0; - FOR_ALL_ROADTRAMTYPES(rtt) { + for (RoadTramType rtt : _roadtramtypes) { /* Update all roadtypes, no matter if they are present */ if (GetRoadOwner(tile, rtt) == old_owner) { RoadType rt = GetRoadType(tile, rtt); |