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
@@ -97,7 +97,7 @@
|
||||
|
||||
const Station *st = ::Station::GetByTile(tile);
|
||||
if (st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return -1;
|
||||
if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
|
||||
if (!st->facilities.Test(StationFacility::Airport)) return -1;
|
||||
|
||||
return st->airport.GetNumHangars();
|
||||
}
|
||||
@@ -111,7 +111,7 @@
|
||||
|
||||
const Station *st = ::Station::GetByTile(tile);
|
||||
if (st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return INVALID_TILE;
|
||||
if ((st->facilities & FACIL_AIRPORT) == 0) return INVALID_TILE;
|
||||
if (!st->facilities.Test(StationFacility::Airport)) return INVALID_TILE;
|
||||
|
||||
return st->airport.GetHangarTile(0);
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ template <bool Tfrom, bool Tvia>
|
||||
if (!IsValidStation(station_id)) return false;
|
||||
if (!HasExactlyOneBit(station_type)) return false;
|
||||
|
||||
return (::Station::Get(station_id)->facilities & static_cast<StationFacility>(station_type)) != 0;
|
||||
return ::Station::Get(station_id)->facilities.Any(static_cast<StationFacilities>(station_type));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptStation::HasRoadType(StationID station_id, ScriptRoad::RoadType road_type)
|
||||
|
||||
@@ -43,12 +43,12 @@ public:
|
||||
* Type of stations known in the game.
|
||||
*/
|
||||
enum StationType {
|
||||
/* Note: these values represent part of the in-game StationFacility enum */
|
||||
STATION_TRAIN = (int)::FACIL_TRAIN, ///< Train station
|
||||
STATION_TRUCK_STOP = (int)::FACIL_TRUCK_STOP, ///< Truck station
|
||||
STATION_BUS_STOP = (int)::FACIL_BUS_STOP, ///< Bus station
|
||||
STATION_AIRPORT = (int)::FACIL_AIRPORT, ///< Airport
|
||||
STATION_DOCK = (int)::FACIL_DOCK, ///< Dock
|
||||
/* Note: these values represent part of the in-game StationFacilities enum */
|
||||
STATION_TRAIN = (1 << to_underlying(::StationFacility::Train)), ///< Train station
|
||||
STATION_TRUCK_STOP = (1 << to_underlying(::StationFacility::TruckStop)), ///< Truck station
|
||||
STATION_BUS_STOP = (1 << to_underlying(::StationFacility::BusStop)), ///< Bus station
|
||||
STATION_AIRPORT = (1 << to_underlying(::StationFacility::Airport)), ///< Airport
|
||||
STATION_DOCK = (1 << to_underlying(::StationFacility::Dock)), ///< Dock
|
||||
STATION_ANY = STATION_TRAIN | STATION_TRUCK_STOP | STATION_BUS_STOP | STATION_AIRPORT | STATION_DOCK, ///< All station types
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
ScriptList::FillList<Station>(this,
|
||||
[is_deity, owner, station_type](const Station *st) {
|
||||
return (is_deity || st->owner == owner) && (st->facilities & static_cast<StationFacility>(station_type)) != 0;
|
||||
return (is_deity || st->owner == owner) && st->facilities.Any(static_cast<StationFacilities>(station_type));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,20 +130,20 @@ ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, Scr
|
||||
|
||||
const StationRect *rect = &::Station::Get(station_id)->rect;
|
||||
|
||||
uint station_type_value = 0;
|
||||
EnumBitSet<StationType, uint8_t> station_types = {};
|
||||
/* Convert ScriptStation::StationType to ::StationType, but do it in a
|
||||
* bitmask, so we can scan for multiple entries at the same time. */
|
||||
if ((station_type & ScriptStation::STATION_TRAIN) != 0) station_type_value |= (1 << to_underlying(::StationType::Rail));
|
||||
if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << to_underlying(::StationType::Truck));
|
||||
if ((station_type & ScriptStation::STATION_BUS_STOP) != 0) station_type_value |= (1 << to_underlying(::StationType::Bus));
|
||||
if ((station_type & ScriptStation::STATION_AIRPORT) != 0) station_type_value |= (1 << to_underlying(::StationType::Airport)) | (1 << to_underlying(::StationType::Oilrig));
|
||||
if ((station_type & ScriptStation::STATION_DOCK) != 0) station_type_value |= (1 << to_underlying(::StationType::Dock)) | (1 << to_underlying(::StationType::Oilrig));
|
||||
if ((station_type & ScriptStation::STATION_TRAIN) != 0) station_types.Set(::StationType::Rail);
|
||||
if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_types.Set(::StationType::Truck);
|
||||
if ((station_type & ScriptStation::STATION_BUS_STOP) != 0) station_types.Set(::StationType::Bus);
|
||||
if ((station_type & ScriptStation::STATION_AIRPORT) != 0) station_types.Set(::StationType::Airport).Set(::StationType::Oilrig);
|
||||
if ((station_type & ScriptStation::STATION_DOCK) != 0) station_types.Set(::StationType::Dock).Set(::StationType::Oilrig);
|
||||
|
||||
TileArea ta(::TileXY(rect->left, rect->top), rect->Width(), rect->Height());
|
||||
for (TileIndex cur_tile : ta) {
|
||||
if (!::IsTileType(cur_tile, MP_STATION)) continue;
|
||||
if (::GetStationIndex(cur_tile) != station_id) continue;
|
||||
if (!HasBit(station_type_value, to_underlying(::GetStationType(cur_tile)))) continue;
|
||||
if (!station_types.Test(::GetStationType(cur_tile))) continue;
|
||||
this->AddTile(cur_tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@
|
||||
|
||||
int 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++;
|
||||
}
|
||||
return std::max(0, 2 - num);
|
||||
}
|
||||
|
||||
@@ -33,5 +33,5 @@
|
||||
if (!IsValidWaypoint(waypoint_id)) return false;
|
||||
if (!HasExactlyOneBit(waypoint_type)) return false;
|
||||
|
||||
return (::Waypoint::Get(waypoint_id)->facilities & static_cast<StationFacility>(waypoint_type)) != 0;
|
||||
return ::Waypoint::Get(waypoint_id)->facilities.Any(static_cast<StationFacilities>(waypoint_type));
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public:
|
||||
* Type of waypoints known in the game.
|
||||
*/
|
||||
enum WaypointType {
|
||||
/* Note: these values represent part of the in-game StationFacility enum */
|
||||
WAYPOINT_RAIL = (int)::FACIL_TRAIN, ///< Rail waypoint
|
||||
WAYPOINT_BUOY = (int)::FACIL_DOCK, ///< Buoy
|
||||
/* Note: these values represent part of the in-game StationFacilities enum */
|
||||
WAYPOINT_RAIL = (1U << to_underlying(::StationFacility::Train)), ///< Rail waypoint
|
||||
WAYPOINT_BUOY = (1U << to_underlying(::StationFacility::Dock)), ///< Buoy
|
||||
WAYPOINT_ANY = WAYPOINT_RAIL | WAYPOINT_BUOY, ///< All waypoint types
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_typ
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
ScriptList::FillList<Waypoint>(this,
|
||||
[is_deity, owner, waypoint_type](const Waypoint *wp) {
|
||||
return (is_deity || wp->owner == owner || wp->owner == OWNER_NONE) && (wp->facilities & static_cast<StationFacility>(waypoint_type)) != 0;
|
||||
return (is_deity || wp->owner == owner || wp->owner == OWNER_NONE) && wp->facilities.Any(static_cast<StationFacilities>(waypoint_type));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user