summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-01-08 10:16:18 +0000
committerGitHub <noreply@github.com>2021-01-08 11:16:18 +0100
commit9b800a96ed32720ff60b74e498a0e0a6351004f9 (patch)
tree3f287d339e15c4902ee415556475fd9b2918d33c /src/station_cmd.cpp
parentc1fddb9a6ae5c3af6865461a7295788a341011a2 (diff)
downloadopenttd-9b800a96ed32720ff60b74e498a0e0a6351004f9.tar.xz
Codechange: Remove min/max functions in favour of STL variants (#8502)
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 5a4d13c47..7bd124f06 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1069,10 +1069,10 @@ CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis a
TileArea cur_ta = st->train_station;
/* determine new size of train station region.. */
- int x = min(TileX(cur_ta.tile), TileX(new_ta.tile));
- int y = min(TileY(cur_ta.tile), TileY(new_ta.tile));
- new_ta.w = max(TileX(cur_ta.tile) + cur_ta.w, TileX(new_ta.tile) + new_ta.w) - x;
- new_ta.h = max(TileY(cur_ta.tile) + cur_ta.h, TileY(new_ta.tile) + new_ta.h) - y;
+ int x = std::min(TileX(cur_ta.tile), TileX(new_ta.tile));
+ int y = std::min(TileY(cur_ta.tile), TileY(new_ta.tile));
+ new_ta.w = std::max(TileX(cur_ta.tile) + cur_ta.w, TileX(new_ta.tile) + new_ta.w) - x;
+ new_ta.h = std::max(TileY(cur_ta.tile) + cur_ta.h, TileY(new_ta.tile) + new_ta.h) - y;
new_ta.tile = TileXY(x, y);
/* make sure the final size is not too big. */
@@ -1325,7 +1325,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
/* Perform NewStation checks */
/* Check if the station size is permitted */
- if (HasBit(statspec->disallowed_platforms, min(numtracks - 1, 7)) || HasBit(statspec->disallowed_lengths, min(plat_len - 1, 7))) {
+ if (HasBit(statspec->disallowed_platforms, std::min(numtracks - 1, 7)) || HasBit(statspec->disallowed_lengths, std::min(plat_len - 1, 7))) {
return CMD_ERROR;
}
@@ -3364,7 +3364,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
} else if (x < stop) {
v->vehstatus |= VS_TRAIN_SLOWING;
- uint16 spd = max(0, (stop - x) * 20 - 15);
+ uint16 spd = std::max(0, (stop - x) * 20 - 15);
if (spd < v->cur_speed) v->cur_speed = spd;
}
}
@@ -3456,7 +3456,7 @@ static void TruncateCargo(const CargoSpec *cs, GoodsEntry *ge, uint amount = UIN
if (source_station == nullptr) continue;
GoodsEntry &source_ge = source_station->goods[cs->Index()];
- source_ge.max_waiting_cargo = max(source_ge.max_waiting_cargo, i->second);
+ source_ge.max_waiting_cargo = std::max(source_ge.max_waiting_cargo, i->second);
}
}
@@ -3512,7 +3512,9 @@ static void UpdateStationRating(Station *st)
/* NewGRFs expect last speed to be 0xFF when no vehicle has arrived yet. */
uint last_speed = ge->HasVehicleEverTriedLoading() ? ge->last_speed : 0xFF;
- uint32 var18 = min(ge->time_since_pickup, 0xFF) | (min(ge->max_waiting_cargo, 0xFFFF) << 8) | (min(last_speed, 0xFF) << 24);
+ uint32 var18 = std::min<uint>(ge->time_since_pickup, 0xFFu)
+ | (std::min<uint>(ge->max_waiting_cargo, 0xFFFFu) << 8)
+ | (std::min<uint>(last_speed, 0xFFu) << 24);
/* Convert to the 'old' vehicle types */
uint32 var10 = (st->last_vehicle_type == VEH_INVALID) ? 0x0 : (st->last_vehicle_type + 0x10);
uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, cs);
@@ -3571,7 +3573,7 @@ static void UpdateStationRating(Station *st)
uint32 r = Random();
if (rating <= (int)GB(r, 0, 7)) {
/* Need to have int, otherwise it will just overflow etc. */
- waiting = max((int)waiting - (int)((GB(r, 8, 2) - 1) * num_dests), 0);
+ waiting = std::max((int)waiting - (int)((GB(r, 8, 2) - 1) * num_dests), 0);
waiting_changed = true;
}
}
@@ -3587,7 +3589,7 @@ static void UpdateStationRating(Station *st)
uint difference = waiting - WAITING_CARGO_THRESHOLD;
waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
- waiting = min(waiting, MAX_WAITING_CARGO);
+ waiting = std::min(waiting, MAX_WAITING_CARGO);
waiting_changed = true;
}
@@ -3801,7 +3803,7 @@ void IncreaseStats(Station *st, const Vehicle *front, StationID next_station_id)
* As usage is not such an important figure anyway we just
* ignore the additional cargo then.*/
IncreaseStats(st, v->cargo_type, next_station_id, v->refit_cap,
- min(v->refit_cap, v->cargo.StoredCount()), EUM_INCREASE);
+ std::min<uint>(v->refit_cap, v->cargo.StoredCount()), EUM_INCREASE);
}
}
}
@@ -4113,11 +4115,11 @@ void UpdateStationDockingTiles(Station *st)
/* Expand the area by a tile on each side while
* making sure that we remain inside the map. */
- int x2 = min(x + area->w + 1, MapSizeX());
- int x1 = max(x - 1, 0);
+ int x2 = std::min<int>(x + area->w + 1, MapSizeX());
+ int x1 = std::max<int>(x - 1, 0);
- int y2 = min(y + area->h + 1, MapSizeY());
- int y1 = max(y - 1, 0);
+ int y2 = std::min<int>(y + area->h + 1, MapSizeY());
+ int y1 = std::max<int>(y - 1, 0);
TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
TILE_AREA_LOOP(tile, ta) {
@@ -4586,7 +4588,7 @@ void FlowStat::ScaleToMonthly(uint runtime)
SharesMap new_shares;
uint share = 0;
for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
- share = max(share + 1, i->first * 30 / runtime);
+ share = std::max(share + 1, i->first * 30 / runtime);
new_shares[share] = i->second;
if (this->unrestricted == i->first) this->unrestricted = share;
}