Codechange: Replace FOR_ALL_ROADTRAMTYPES with range-based for loops

(cherry picked from commit 2feb801e56)
pull/259/head
glx22 3 years ago committed by Jonathan G Rennison
parent 72cfb991e5
commit 8333323090

@ -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 {

@ -1743,7 +1743,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);
@ -2756,7 +2756,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);
}
@ -2766,7 +2766,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);

@ -2160,7 +2160,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);

@ -133,7 +133,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));
@ -156,7 +156,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));

@ -2178,7 +2178,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));
}
@ -2262,7 +2262,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
Owner road_owner[] = { OWNER_NONE, OWNER_NONE };
DisallowedRoadDirections drd = DRD_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);
@ -4548,7 +4548,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);

@ -2616,7 +2616,7 @@ static void UpdateRoadTunnelBridgeInfrastructure(TileIndex begin, TileIndex end,
const uint middle_len = 2 * GetTunnelBridgeLength(begin, end) * TUNNELBRIDGE_TRACKBIT_FACTOR;
const uint len = middle_len + (4 * TUNNELBRIDGE_TRACKBIT_FACTOR);
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
RoadType rt = GetRoadType(begin, rtt);
if (rt == INVALID_ROADTYPE) continue;
Company * const c = Company::GetIfValid(GetRoadOwner(begin, rtt));
@ -2638,7 +2638,7 @@ static void UpdateRoadTunnelBridgeInfrastructure(TileIndex begin, TileIndex end,
}
}
}
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
RoadType rt = GetRoadType(end, rtt);
if (rt == INVALID_ROADTYPE) continue;
Company * const c = Company::GetIfValid(GetRoadOwner(end, rtt));
@ -2724,7 +2724,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
/* Only execute this for one of the two ends */
SubtractRoadTunnelBridgeInfrastructure(tile, other_end);
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
/* Update all roadtypes, no matter if they are present */
if (GetRoadOwner(tile, rtt) == old_owner) {
SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);

Loading…
Cancel
Save