Codechange: replace INVALID_X with XID::Invalid() for PoolIDs
This commit is contained in:
@@ -125,14 +125,14 @@ CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID c
|
||||
if (IsTileType(tile_cur, MP_STATION)) {
|
||||
StationID t = GetStationIndex(tile_cur);
|
||||
if (!T::IsValidID(t) || T::Get(t)->owner != company || !filter(T::Get(t))) continue;
|
||||
if (closest_station == INVALID_STATION) {
|
||||
if (closest_station == StationID::Invalid()) {
|
||||
closest_station = t;
|
||||
} else if (closest_station != t) {
|
||||
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
*st = (closest_station == INVALID_STATION) ? nullptr : T::Get(closest_station);
|
||||
*st = (closest_station == StationID::Invalid()) ? nullptr : T::Get(closest_station);
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
@@ -900,14 +900,14 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
|
||||
}
|
||||
|
||||
/* if station is set, then we have special handling to allow building on top of already existing stations.
|
||||
* so station points to INVALID_STATION if we can build on any station.
|
||||
* so station points to StationID::Invalid() if we can build on any station.
|
||||
* Or it points to a station if we're only allowed to build on exactly that station. */
|
||||
if (station != nullptr && IsTileType(tile_cur, MP_STATION)) {
|
||||
if (!IsRailStation(tile_cur)) {
|
||||
return ClearTile_Station(tile_cur, DoCommandFlag::Auto); // get error message
|
||||
} else {
|
||||
StationID st = GetStationIndex(tile_cur);
|
||||
if (*station == INVALID_STATION) {
|
||||
if (*station == StationID::Invalid()) {
|
||||
*station = st;
|
||||
} else if (*station != st) {
|
||||
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
|
||||
@@ -972,7 +972,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
|
||||
cost.AddCost(ret);
|
||||
|
||||
/* If station is set, then we have special handling to allow building on top of already existing stations.
|
||||
* Station points to INVALID_STATION if we can build on any station.
|
||||
* Station points to StationID::Invalid() if we can build on any station.
|
||||
* Or it points to a station if we're only allowed to build on exactly that station. */
|
||||
if (station != nullptr && IsTileType(cur_tile, MP_STATION)) {
|
||||
if (!IsAnyRoadStop(cur_tile)) {
|
||||
@@ -987,7 +987,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
|
||||
return CommandCost(STR_ERROR_DRIVE_THROUGH_DIRECTION);
|
||||
}
|
||||
StationID st = GetStationIndex(cur_tile);
|
||||
if (*station == INVALID_STATION) {
|
||||
if (*station == StationID::Invalid()) {
|
||||
*station = st;
|
||||
} else if (*station != st) {
|
||||
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
|
||||
@@ -1163,7 +1163,7 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station
|
||||
assert(*st == nullptr);
|
||||
bool check_surrounding = true;
|
||||
|
||||
if (existing_station != INVALID_STATION) {
|
||||
if (existing_station != StationID::Invalid()) {
|
||||
if (adjacent && existing_station != station_to_join) {
|
||||
/* You can't build an adjacent station over the top of one that
|
||||
* already exists. */
|
||||
@@ -1188,7 +1188,7 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station
|
||||
}
|
||||
|
||||
/* Distant join */
|
||||
if (*st == nullptr && station_to_join != INVALID_STATION) *st = T::GetIfValid(station_to_join);
|
||||
if (*st == nullptr && station_to_join != StationID::Invalid()) *st = T::GetIfValid(station_to_join);
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
@@ -1364,8 +1364,8 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy
|
||||
}
|
||||
|
||||
bool reuse = (station_to_join != NEW_STATION);
|
||||
if (!reuse) station_to_join = INVALID_STATION;
|
||||
bool distant_join = (station_to_join != INVALID_STATION);
|
||||
if (!reuse) station_to_join = StationID::Invalid();
|
||||
bool distant_join = (station_to_join != StationID::Invalid());
|
||||
|
||||
if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
|
||||
|
||||
@@ -1375,7 +1375,7 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy
|
||||
TileArea new_location(tile_org, w_org, h_org);
|
||||
|
||||
/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
|
||||
StationID est = INVALID_STATION;
|
||||
StationID est = StationID::Invalid();
|
||||
std::vector<Train *> affected_vehicles;
|
||||
/* Add construction and clearing expenses. */
|
||||
CommandCost cost = CalculateRailStationCost(new_location, flags, axis, &est, rt, affected_vehicles, spec_class, spec_index, plat_len, numtracks);
|
||||
@@ -1964,8 +1964,8 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width
|
||||
{
|
||||
if (!ValParamRoadType(rt) || !IsValidDiagDirection(ddir) || stop_type >= RoadStopType::End) return CMD_ERROR;
|
||||
bool reuse = (station_to_join != NEW_STATION);
|
||||
if (!reuse) station_to_join = INVALID_STATION;
|
||||
bool distant_join = (station_to_join != INVALID_STATION);
|
||||
if (!reuse) station_to_join = StationID::Invalid();
|
||||
bool distant_join = (station_to_join != StationID::Invalid());
|
||||
|
||||
/* Check if the given station class is valid */
|
||||
if (static_cast<uint>(spec_class) >= RoadStopClass::GetClassCount()) return CMD_ERROR;
|
||||
@@ -2008,7 +2008,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width
|
||||
} else {
|
||||
unit_cost = _price[is_truck_stop ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS];
|
||||
}
|
||||
StationID est = INVALID_STATION;
|
||||
StationID est = StationID::Invalid();
|
||||
CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, is_drive_through, is_truck_stop ? StationType::Truck : StationType::Bus, axis, ddir, &est, rt, unit_cost);
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
@@ -2523,8 +2523,8 @@ void UpdateAirportsNoise()
|
||||
CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airport_type, uint8_t layout, StationID station_to_join, bool allow_adjacent)
|
||||
{
|
||||
bool reuse = (station_to_join != NEW_STATION);
|
||||
if (!reuse) station_to_join = INVALID_STATION;
|
||||
bool distant_join = (station_to_join != INVALID_STATION);
|
||||
if (!reuse) station_to_join = StationID::Invalid();
|
||||
bool distant_join = (station_to_join != StationID::Invalid());
|
||||
|
||||
if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
|
||||
|
||||
@@ -2584,7 +2584,7 @@ CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airpor
|
||||
}
|
||||
|
||||
Station *st = nullptr;
|
||||
ret = FindJoiningStation(INVALID_STATION, station_to_join, allow_adjacent, airport_area, &st);
|
||||
ret = FindJoiningStation(StationID::Invalid(), station_to_join, allow_adjacent, airport_area, &st);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* Distant join */
|
||||
@@ -2788,8 +2788,8 @@ static const uint8_t _dock_h_chk[4] = { 1, 2, 1, 2 };
|
||||
CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station_to_join, bool adjacent)
|
||||
{
|
||||
bool reuse = (station_to_join != NEW_STATION);
|
||||
if (!reuse) station_to_join = INVALID_STATION;
|
||||
bool distant_join = (station_to_join != INVALID_STATION);
|
||||
if (!reuse) station_to_join = StationID::Invalid();
|
||||
bool distant_join = (station_to_join != StationID::Invalid());
|
||||
|
||||
if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
|
||||
|
||||
@@ -2836,7 +2836,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station
|
||||
|
||||
/* middle */
|
||||
Station *st = nullptr;
|
||||
ret = FindJoiningStation(INVALID_STATION, station_to_join, adjacent, dock_area, &st);
|
||||
ret = FindJoiningStation(StationID::Invalid(), station_to_join, adjacent, dock_area, &st);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* Distant join */
|
||||
@@ -3861,7 +3861,7 @@ static void UpdateStationRating(Station *st)
|
||||
uint waiting = ge->HasData() ? ge->GetData().cargo.AvailableCount() : 0;
|
||||
|
||||
/* num_dests is at least 1 if there is any cargo as
|
||||
* INVALID_STATION is also a destination.
|
||||
* StationID::Invalid() is also a destination.
|
||||
*/
|
||||
uint num_dests = ge->HasData() ? static_cast<uint>(ge->GetData().cargo.Packets()->MapSize()) : 0;
|
||||
|
||||
@@ -3869,7 +3869,7 @@ static void UpdateStationRating(Station *st)
|
||||
* with only one or two next hops. They are allowed to have more
|
||||
* cargo waiting per next hop.
|
||||
* With manual cargo distribution waiting_avg = waiting / 2 as then
|
||||
* INVALID_STATION is the only destination.
|
||||
* StationID::Invalid() is the only destination.
|
||||
*/
|
||||
uint waiting_avg = waiting / (num_dests + 1);
|
||||
|
||||
@@ -4120,8 +4120,8 @@ void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint
|
||||
Station *st2 = Station::Get(next_station_id);
|
||||
GoodsEntry &ge2 = st2->goods[cargo];
|
||||
LinkGraph *lg = nullptr;
|
||||
if (ge1.link_graph == INVALID_LINK_GRAPH) {
|
||||
if (ge2.link_graph == INVALID_LINK_GRAPH) {
|
||||
if (ge1.link_graph == LinkGraphID::Invalid()) {
|
||||
if (ge2.link_graph == LinkGraphID::Invalid()) {
|
||||
if (LinkGraph::CanAllocateItem()) {
|
||||
lg = new LinkGraph(cargo);
|
||||
LinkGraphSchedule::instance.Queue(lg);
|
||||
@@ -4137,7 +4137,7 @@ void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint
|
||||
ge1.link_graph = lg->index;
|
||||
ge1.node = lg->AddNode(st);
|
||||
}
|
||||
} else if (ge2.link_graph == INVALID_LINK_GRAPH) {
|
||||
} else if (ge2.link_graph == LinkGraphID::Invalid()) {
|
||||
lg = LinkGraph::Get(ge1.link_graph);
|
||||
ge2.link_graph = lg->index;
|
||||
ge2.node = lg->AddNode(st2);
|
||||
@@ -4262,7 +4262,7 @@ static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Sourc
|
||||
StationID next = ge.GetVia(st->index);
|
||||
ge.GetOrCreateData().cargo.Append(new CargoPacket(st->index, amount, source), next);
|
||||
LinkGraph *lg = nullptr;
|
||||
if (ge.link_graph == INVALID_LINK_GRAPH) {
|
||||
if (ge.link_graph == LinkGraphID::Invalid()) {
|
||||
if (LinkGraph::CanAllocateItem()) {
|
||||
lg = new LinkGraph(type);
|
||||
LinkGraphSchedule::instance.Queue(lg);
|
||||
@@ -4797,7 +4797,7 @@ uint FlowStat::GetShare(StationID st) const
|
||||
*/
|
||||
StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||
{
|
||||
if (this->unrestricted == 0) return INVALID_STATION;
|
||||
if (this->unrestricted == 0) return StationID::Invalid();
|
||||
assert(!this->shares.empty());
|
||||
SharesMap::const_iterator it = this->shares.upper_bound(RandomRange(this->unrestricted));
|
||||
assert(it != this->shares.end() && it->first <= this->unrestricted);
|
||||
@@ -4809,7 +4809,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||
uint end = it->first;
|
||||
uint begin = (it == this->shares.begin() ? 0 : (--it)->first);
|
||||
uint interval = end - begin;
|
||||
if (interval >= this->unrestricted) return INVALID_STATION; // Only one station in the map.
|
||||
if (interval >= this->unrestricted) return StationID::Invalid(); // Only one station in the map.
|
||||
uint new_max = this->unrestricted - interval;
|
||||
uint rand = RandomRange(new_max);
|
||||
SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) :
|
||||
@@ -4823,7 +4823,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||
uint end2 = it2->first;
|
||||
uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first);
|
||||
uint interval2 = end2 - begin2;
|
||||
if (interval2 >= new_max) return INVALID_STATION; // Only the two excluded stations in the map.
|
||||
if (interval2 >= new_max) return StationID::Invalid(); // Only the two excluded stations in the map.
|
||||
new_max -= interval2;
|
||||
if (begin > begin2) {
|
||||
Swap(begin, begin2);
|
||||
@@ -5028,11 +5028,11 @@ void FlowStatMap::PassOnFlow(StationID origin, StationID via, uint flow)
|
||||
FlowStatMap::iterator prev_it = this->find(origin);
|
||||
if (prev_it == this->end()) {
|
||||
FlowStat fs(via, flow);
|
||||
fs.AppendShare(INVALID_STATION, flow);
|
||||
fs.AppendShare(StationID::Invalid(), flow);
|
||||
this->emplace(origin, fs);
|
||||
} else {
|
||||
prev_it->second.ChangeShare(via, flow);
|
||||
prev_it->second.ChangeShare(INVALID_STATION, flow);
|
||||
prev_it->second.ChangeShare(StationID::Invalid(), flow);
|
||||
assert(!prev_it->second.GetShares()->empty());
|
||||
}
|
||||
}
|
||||
@@ -5045,14 +5045,14 @@ void FlowStatMap::FinalizeLocalConsumption(StationID self)
|
||||
{
|
||||
for (auto &i : *this) {
|
||||
FlowStat &fs = i.second;
|
||||
uint local = fs.GetShare(INVALID_STATION);
|
||||
uint local = fs.GetShare(StationID::Invalid());
|
||||
if (local > INT_MAX) { // make sure it fits in an int
|
||||
fs.ChangeShare(self, -INT_MAX);
|
||||
fs.ChangeShare(INVALID_STATION, -INT_MAX);
|
||||
fs.ChangeShare(StationID::Invalid(), -INT_MAX);
|
||||
local -= INT_MAX;
|
||||
}
|
||||
fs.ChangeShare(self, -(int)local);
|
||||
fs.ChangeShare(INVALID_STATION, -(int)local);
|
||||
fs.ChangeShare(StationID::Invalid(), -(int)local);
|
||||
|
||||
/* If the local share is used up there must be a share for some
|
||||
* remote station. */
|
||||
|
||||
Reference in New Issue
Block a user