mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-20 19:02:41 +01:00
Codechange: Use EnumBitSet for StationFacility.
This commit is contained in:
committed by
Peter Nelson
parent
8d38308ebb
commit
75387b9e2b
@@ -444,7 +444,7 @@ void Station::UpdateVirtCoord()
|
||||
Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
|
||||
|
||||
pt.y -= 32 * ZOOM_BASE;
|
||||
if ((this->facilities & FACIL_AIRPORT) && this->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_BASE;
|
||||
if (this->facilities.Test(StationFacility::Airport) && this->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_BASE;
|
||||
|
||||
if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
||||
|
||||
@@ -637,8 +637,8 @@ void UpdateStationAcceptance(Station *st, bool show_msg)
|
||||
|
||||
/* Make sure the station can accept the goods type. */
|
||||
bool is_passengers = IsCargoInClass(i, CargoClass::Passengers);
|
||||
if ((!is_passengers && !(st->facilities & ~FACIL_BUS_STOP)) ||
|
||||
(is_passengers && !(st->facilities & ~FACIL_TRUCK_STOP))) {
|
||||
if ((!is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::TruckStop, StationFacility::Airport, StationFacility::Dock})) ||
|
||||
(is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::BusStop, StationFacility::Airport, StationFacility::Dock}))) {
|
||||
amt = 0;
|
||||
}
|
||||
|
||||
@@ -1414,7 +1414,7 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
st->train_station = new_location;
|
||||
st->AddFacility(FACIL_TRAIN, new_location.tile);
|
||||
st->AddFacility(StationFacility::Train, new_location.tile);
|
||||
|
||||
st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
|
||||
|
||||
@@ -1722,7 +1722,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
|
||||
|
||||
/* if we deleted the whole station, delete the train facility. */
|
||||
if (st->train_station.tile == INVALID_TILE) {
|
||||
st->facilities &= ~FACIL_TRAIN;
|
||||
st->facilities.Reset(StationFacility::Train);
|
||||
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
|
||||
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_TRAINS);
|
||||
MarkCatchmentTilesDirty();
|
||||
@@ -2067,7 +2067,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8_t width,
|
||||
}
|
||||
|
||||
/* Initialize an empty station. */
|
||||
st->AddFacility(is_truck_stop ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, cur_tile);
|
||||
st->AddFacility(is_truck_stop ? StationFacility::TruckStop : StationFacility::BusStop, cur_tile);
|
||||
|
||||
st->rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
|
||||
|
||||
@@ -2175,7 +2175,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags, int repla
|
||||
*primary_stop = cur_stop->next;
|
||||
/* removed the only stop? */
|
||||
if (*primary_stop == nullptr) {
|
||||
st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
|
||||
st->facilities.Reset(is_truck ? StationFacility::TruckStop : StationFacility::BusStop);
|
||||
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
|
||||
}
|
||||
} else {
|
||||
@@ -2294,7 +2294,7 @@ CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlag flags, int repl
|
||||
|
||||
/* if we deleted the whole waypoint, delete the road facility. */
|
||||
if (wp->road_waypoint_area.tile == INVALID_TILE) {
|
||||
wp->facilities &= ~(FACIL_BUS_STOP | FACIL_TRUCK_STOP);
|
||||
wp->facilities.Reset(StationFacility::BusStop).Reset(StationFacility::TruckStop);
|
||||
SetWindowWidgetDirty(WC_STATION_VIEW, wp->index, WID_SV_ROADVEHS);
|
||||
wp->UpdateVirtCoord();
|
||||
DeleteStationIfEmpty(wp);
|
||||
@@ -2571,7 +2571,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
Town *t = ClosestTownFromTile(tile, UINT_MAX);
|
||||
uint num = 0;
|
||||
for (const Station *st : Station::Iterate()) {
|
||||
if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
|
||||
if (st->town == t && st->facilities.Test(StationFacility::Airport) && st->airport.type != AT_OILRIG) num++;
|
||||
}
|
||||
if (num >= 2) {
|
||||
authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT;
|
||||
@@ -2606,7 +2606,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
|
||||
/* Always add the noise, so there will be no need to recalculate when option toggles */
|
||||
nearest->noise_reached += newnoise_level;
|
||||
|
||||
st->AddFacility(FACIL_AIRPORT, tile);
|
||||
st->AddFacility(StationFacility::Airport, tile);
|
||||
st->airport.type = airport_type;
|
||||
st->airport.layout = layout;
|
||||
st->airport.flags = 0;
|
||||
@@ -2709,7 +2709,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
|
||||
st->rect.AfterRemoveRect(st, st->airport);
|
||||
|
||||
st->airport.Clear();
|
||||
st->facilities &= ~FACIL_AIRPORT;
|
||||
st->facilities.Reset(StationFacility::Airport);
|
||||
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
|
||||
|
||||
InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
|
||||
@@ -2735,7 +2735,7 @@ CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id)
|
||||
if (!Station::IsValidID(station_id)) return CMD_ERROR;
|
||||
Station *st = Station::Get(station_id);
|
||||
|
||||
if (!(st->facilities & FACIL_AIRPORT) || st->owner == OWNER_NONE) return CMD_ERROR;
|
||||
if (!st->facilities.Test(StationFacility::Airport) || st->owner == OWNER_NONE) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckOwnership(st->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
@@ -2850,7 +2850,7 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_
|
||||
st->ship_station.Add(tile);
|
||||
TileIndex flat_tile = tile + TileOffsByDiagDir(direction);
|
||||
st->ship_station.Add(flat_tile);
|
||||
st->AddFacility(FACIL_DOCK, tile);
|
||||
st->AddFacility(StationFacility::Dock, tile);
|
||||
|
||||
st->rect.BeforeAddRect(dock_area.tile, dock_area.w, dock_area.h, StationRect::ADD_TRY);
|
||||
|
||||
@@ -2965,7 +2965,7 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
|
||||
if (st->ship_station.tile == INVALID_TILE) {
|
||||
st->ship_station.Clear();
|
||||
st->docking_station.Clear();
|
||||
st->facilities &= ~FACIL_DOCK;
|
||||
st->facilities.Reset(StationFacility::Dock);
|
||||
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
|
||||
}
|
||||
|
||||
@@ -2992,7 +2992,7 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
|
||||
/* If we no longer have a dock, mark the order as invalid and send
|
||||
* the ship to the next order (or, if there is none, make it
|
||||
* wander the world). */
|
||||
if (s->current_order.IsType(OT_GOTO_STATION) && !(st->facilities & FACIL_DOCK)) {
|
||||
if (s->current_order.IsType(OT_GOTO_STATION) && !st->facilities.Test(StationFacility::Dock)) {
|
||||
s->SetDestTile(s->GetOrderStationLocation(st->index));
|
||||
}
|
||||
}
|
||||
@@ -3690,7 +3690,7 @@ static bool ClickTile_Station(TileIndex tile)
|
||||
{
|
||||
const BaseStation *bst = BaseStation::GetByTile(tile);
|
||||
|
||||
if (bst->facilities & FACIL_WAYPOINT) {
|
||||
if (bst->facilities.Test(StationFacility::Waypoint)) {
|
||||
ShowWaypointWindow(Waypoint::From(bst));
|
||||
} else if (IsHangar(tile)) {
|
||||
const Station *st = Station::From(bst);
|
||||
@@ -3795,7 +3795,7 @@ static bool StationHandleBigTick(BaseStation *st)
|
||||
}
|
||||
|
||||
|
||||
if ((st->facilities & FACIL_WAYPOINT) == 0) UpdateStationAcceptance(Station::From(st), true);
|
||||
if (!st->facilities.Test(StationFacility::Waypoint)) UpdateStationAcceptance(Station::From(st), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -4186,7 +4186,7 @@ void IncreaseStats(Station *st, const Vehicle *front, StationID next_station_id,
|
||||
/* called for every station each tick */
|
||||
static void StationHandleSmallTick(BaseStation *st)
|
||||
{
|
||||
if ((st->facilities & FACIL_WAYPOINT) != 0 || !st->IsInUse()) return;
|
||||
if (st->facilities.Test(StationFacility::Waypoint) || !st->IsInUse()) return;
|
||||
|
||||
uint8_t b = st->delete_ctr + 1;
|
||||
if (b >= Ticks::STATION_RATING_TICKS) b = 0;
|
||||
@@ -4383,10 +4383,10 @@ static bool CanMoveGoodsToStation(const Station *st, CargoType type)
|
||||
|
||||
if (IsCargoInClass(type, CargoClass::Passengers)) {
|
||||
/* Passengers are never served by just a truck stop. */
|
||||
if (st->facilities == FACIL_TRUCK_STOP) return false;
|
||||
if (st->facilities == StationFacility::TruckStop) return false;
|
||||
} else {
|
||||
/* Non-passengers are never served by just a bus stop. */
|
||||
if (st->facilities == FACIL_BUS_STOP) return false;
|
||||
if (st->facilities == StationFacility::BusStop) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -4526,7 +4526,7 @@ void BuildOilRig(TileIndex tile)
|
||||
st->airport.type = AT_OILRIG;
|
||||
st->airport.Add(tile);
|
||||
st->ship_station.Add(tile);
|
||||
st->facilities = FACIL_AIRPORT | FACIL_DOCK;
|
||||
st->facilities = {StationFacility::Airport, StationFacility::Dock};
|
||||
st->build_date = TimerGameCalendar::date;
|
||||
UpdateStationDockingTiles(st);
|
||||
|
||||
@@ -4557,7 +4557,8 @@ void DeleteOilRig(TileIndex tile)
|
||||
MakeWaterKeepingClass(tile, OWNER_NONE);
|
||||
|
||||
/* The oil rig station is not supposed to be shared with anything else */
|
||||
assert(st->facilities == (FACIL_AIRPORT | FACIL_DOCK) && st->airport.type == AT_OILRIG);
|
||||
[[maybe_unused]] static constexpr StationFacilities expected_facility{StationFacility::Airport, StationFacility::Dock};
|
||||
assert(st->facilities == expected_facility && st->airport.type == AT_OILRIG);
|
||||
if (st->industry != nullptr && st->industry->neutral_station == st) {
|
||||
/* Don't leave dangling neutral station pointer */
|
||||
st->industry->neutral_station = nullptr;
|
||||
@@ -4567,6 +4568,7 @@ void DeleteOilRig(TileIndex tile)
|
||||
|
||||
static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
|
||||
if (IsAnyRoadStopTile(tile)) {
|
||||
for (RoadTramType rtt : _roadtramtypes) {
|
||||
/* Update all roadtypes, no matter if they are present */
|
||||
|
||||
Reference in New Issue
Block a user