diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 6a363f7c0c..0b7b9778a9 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -252,7 +252,7 @@ class BuildAirportWindow : public PickerWindowBase { DropDownList list; for (const auto &cls : AirportClass::Classes()) { - list.push_back(MakeDropDownListStringItem(cls.name, cls.Index())); + list.push_back(MakeDropDownListStringItem(cls.name, cls.Index().base())); } return list; @@ -274,7 +274,7 @@ public: this->OnInvalidateData(); /* Ensure airport class is valid (changing NewGRFs). */ - _selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1)); + _selected_airport_class = Clamp(_selected_airport_class, AirportClassID::Begin(), static_cast(AirportClass::GetClassCount() - 1)); const AirportClass *ac = AirportClass::Get(_selected_airport_class); this->vscroll->SetCount(ac->GetSpecCount()); @@ -501,7 +501,7 @@ public: { switch (widget) { case WID_AP_CLASS_DROPDOWN: - ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN); + ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class.base(), WID_AP_CLASS_DROPDOWN); break; case WID_AP_AIRPORT_LIST: { @@ -639,6 +639,6 @@ static void ShowBuildAirportPicker(Window *parent) void InitializeAirportGui() { - _selected_airport_class = APC_BEGIN; + _selected_airport_class = AirportClassID::Begin(); _selected_airport_index = -1; } diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index 89a30ea480..8aa12cf42e 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -43,7 +43,7 @@ bool AirportClass::IsUIAvailable(uint) const } /* Instantiate AirportClass. */ -template class NewGRFClass; +template class NewGRFClass; AirportOverrideManager _airport_mngr(NEW_AIRPORT_OFFSET, NUM_AIRPORTS, AT_INVALID); diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index 55494bf978..82928bb5d9 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -70,18 +70,13 @@ public: } }; -/** List of default airport classes. */ -enum AirportClassID : uint8_t { - APC_BEGIN = 0, ///< Lowest valid airport class id - APC_SMALL = 0, ///< id for small airports class - APC_LARGE, ///< id for large airports class - APC_HUB, ///< id for hub airports class - APC_HELIPORT, ///< id for heliports - APC_MAX = 16, ///< maximum number of airport classes -}; +/** Class IDs for airports. */ +using AirportClassID = PoolID; -/** Allow incrementing of AirportClassID variables */ -DECLARE_INCREMENT_DECREMENT_OPERATORS(AirportClassID) +static constexpr AirportClassID APC_SMALL{0}; ///< id for small airports class. +static constexpr AirportClassID APC_LARGE{1}; ///< id for large airports class. +static constexpr AirportClassID APC_HUB{2}; ///< id for hub airports class. +static constexpr AirportClassID APC_HELIPORT{3}; ///< id for heliports. /** TTDP airport types. Used to map our types to TTDPatch's */ enum TTDPAirportType : uint8_t { @@ -149,7 +144,7 @@ private: }; /** Information related to airport classes. */ -using AirportClass = NewGRFClass; +using AirportClass = NewGRFClass; void BindAirportSpecs(); diff --git a/src/newgrf_class.h b/src/newgrf_class.h index 9cfe7d22b8..8c4331ccc0 100644 --- a/src/newgrf_class.h +++ b/src/newgrf_class.h @@ -12,7 +12,7 @@ #include "strings_type.h" -/* Base for each type of NewGRF spec to be used with NewGRFClass. */ +/** Base for each type of NewGRF spec to be used with NewGRFClass. */ template struct NewGRFSpecBase { Tindex class_index; ///< Class index of this spec, invalid until class is allocated. @@ -22,21 +22,21 @@ struct NewGRFSpecBase { /** * Struct containing information relating to NewGRF classes for stations and airports. */ -template +template class NewGRFClass { private: /* Tspec must be of NewGRFSpecBase. */ static_assert(std::is_base_of_v, Tspec>); uint ui_count = 0; ///< Number of specs in this class potentially available to the user. - Tindex index = static_cast(0); ///< Index of class within the list of classes. + Tindex index{}; ///< Index of class within the list of classes. std::vector spec; ///< List of specifications. /** * The actual classes. * @note This may be reallocated during initialization so pointers may be invalidated. */ - static inline std::vector> classes; + static inline std::vector> classes; /** Initialise the defaults. */ static void InsertDefaults(); @@ -61,7 +61,7 @@ public: * Get read-only span of all classes of this type. * @return Read-only span of classes. */ - static std::span const> Classes() { return NewGRFClass::classes; } + static std::span const> Classes() { return NewGRFClass::classes; } void Insert(Tspec *spec); diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h index ef12407031..703946a526 100644 --- a/src/newgrf_class_func.h +++ b/src/newgrf_class_func.h @@ -12,8 +12,8 @@ #include "table/strings.h" /** Reset the classes, i.e. clear everything. */ -template -void NewGRFClass::Reset() +template +void NewGRFClass::Reset() { NewGRFClass::classes.clear(); NewGRFClass::classes.shrink_to_fit(); @@ -28,8 +28,8 @@ void NewGRFClass::Reset() * @note Upon allocating the same global class ID for a * second time, this first allocation will be given. */ -template -Tindex NewGRFClass::Allocate(uint32_t global_id) +template +Tindex NewGRFClass::Allocate(uint32_t global_id) { auto found = std::ranges::find(NewGRFClass::classes, global_id, &NewGRFClass::global_id); @@ -37,13 +37,13 @@ Tindex NewGRFClass::Allocate(uint32_t global_id) if (found != std::end(NewGRFClass::classes)) return found->Index(); /* More slots available, allocate a slot to the global id. */ - if (NewGRFClass::classes.size() < Tmax) { + if (NewGRFClass::classes.size() < Tindex::End().base()) { auto it = NewGRFClass::classes.emplace(std::end(NewGRFClass::classes), global_id, STR_EMPTY); it->index = static_cast(std::distance(std::begin(NewGRFClass::classes), it)); return it->Index(); } - GrfMsg(2, "ClassAllocate: already allocated {} classes, using default", Tmax); + GrfMsg(2, "ClassAllocate: already allocated {} classes, using default", Tindex::End().base()); return static_cast(0); } @@ -51,8 +51,8 @@ Tindex NewGRFClass::Allocate(uint32_t global_id) * Insert a spec into the class, and update its index. * @param spec The spec to insert. */ -template -void NewGRFClass::Insert(Tspec *spec) +template +void NewGRFClass::Insert(Tspec *spec) { auto it = this->spec.insert(std::end(this->spec), spec); uint16_t index = static_cast(std::distance(std::begin(this->spec), it)); @@ -66,10 +66,10 @@ void NewGRFClass::Insert(Tspec *spec) * @param spec The spec to assign. * @note The spec must have a valid class index set. */ -template -void NewGRFClass::Assign(Tspec *spec) +template +void NewGRFClass::Assign(Tspec *spec) { - assert(static_cast(spec->class_index) < NewGRFClass::classes.size()); + assert(spec->class_index.base() < NewGRFClass::classes.size()); Get(spec->class_index)->Insert(spec); } @@ -78,19 +78,19 @@ void NewGRFClass::Assign(Tspec *spec) * @param class_index The index of the class. * @pre class_index < Tmax */ -template -NewGRFClass *NewGRFClass::Get(Tindex class_index) +template +NewGRFClass *NewGRFClass::Get(Tindex class_index) { - assert(static_cast(class_index) < NewGRFClass::classes.size()); - return &NewGRFClass::classes[class_index]; + assert(class_index.base() < NewGRFClass::classes.size()); + return &NewGRFClass::classes[class_index.base()]; } /** * Get the number of allocated classes. * @return The number of classes. */ -template -uint NewGRFClass::GetClassCount() +template +uint NewGRFClass::GetClassCount() { return static_cast(NewGRFClass::classes.size()); } @@ -99,8 +99,8 @@ uint NewGRFClass::GetClassCount() * Get the number of classes available to the user. * @return The number of classes. */ -template -uint NewGRFClass::GetUIClassCount() +template +uint NewGRFClass::GetUIClassCount() { return std::ranges::count_if(NewGRFClass::classes, [](const auto &cls) { return cls.GetUISpecCount() > 0; }); } @@ -110,8 +110,8 @@ uint NewGRFClass::GetUIClassCount() * @param index The index where to find the spec. * @return The spec at given location. */ -template -const Tspec *NewGRFClass::GetSpec(uint index) const +template +const Tspec *NewGRFClass::GetSpec(uint index) const { /* If the custom spec isn't defined any more, then the GRF file probably was not loaded. */ return index < this->GetSpecCount() ? this->spec[index] : nullptr; @@ -123,8 +123,8 @@ const Tspec *NewGRFClass::GetSpec(uint index) const * @param local_id Index within GRF file of spec. * @return The spec. */ -template -const Tspec *NewGRFClass::GetByGrf(uint32_t grfid, uint16_t local_id) +template +const Tspec *NewGRFClass::GetByGrf(uint32_t grfid, uint16_t local_id) { for (const auto &cls : NewGRFClass::classes) { for (const auto &spec : cls.spec) { diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index a77bb28042..366b492fd2 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -115,7 +115,7 @@ uint ObjectSpec::Index() const /* static */ void ObjectSpec::BindToClasses() { for (auto &spec : _object_specs) { - if (spec.IsEnabled() && spec.class_index != INVALID_OBJECT_CLASS) { + if (spec.IsEnabled() && spec.class_index != ObjectClassID::Invalid()) { ObjectClass::Assign(&spec); } } @@ -154,7 +154,7 @@ bool ObjectClass::IsUIAvailable(uint index) const } /* Instantiate ObjectClass. */ -template class NewGRFClass; +template class NewGRFClass; /* virtual */ uint32_t ObjectScopeResolver::GetRandomBits() const { diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 7b291701a4..040dc5c581 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -10,6 +10,7 @@ #ifndef NEWGRF_OBJECT_H #define NEWGRF_OBJECT_H +#include "core/pool_type.hpp" #include "newgrf_callbacks.h" #include "newgrf_spritegroup.h" #include "newgrf_town.h" @@ -45,13 +46,7 @@ static const uint8_t OBJECT_SIZE_1X1 = 0x11; ///< The value of a NewGRF's size p void ResetObjects(); /** Class IDs for objects. */ -enum ObjectClassID : uint16_t { - OBJECT_CLASS_BEGIN = 0, ///< The lowest valid value - OBJECT_CLASS_MAX = UINT16_MAX, ///< Maximum number of classes. - INVALID_OBJECT_CLASS = UINT16_MAX, ///< Class for the less fortunate. -}; -/** Allow incrementing of ObjectClassID variables */ -DECLARE_INCREMENT_DECREMENT_OPERATORS(ObjectClassID) +using ObjectClassID = PoolID; /** An object that isn't use for transport, industries or houses. * @note If you change this struct, adopt the initialization of @@ -164,7 +159,7 @@ private: }; /** Class containing information relating to object classes. */ -using ObjectClass = NewGRFClass; +using ObjectClass = NewGRFClass; uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span regs100 = {}, uint8_t view = 0); diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index c773acfe3b..3c22509264 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -49,7 +49,7 @@ bool RoadStopClass::IsUIAvailable(uint) const } /* Instantiate RoadStopClass. */ -template class NewGRFClass; +template class NewGRFClass; static const uint NUM_ROADSTOPSPECS_PER_STATION = 63; ///< Maximum number of parts per station. diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 86f9fc1dbc..6e558161af 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -28,13 +28,11 @@ static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1; static const uint32_t ROADSTOP_CLASS_LABEL_DEFAULT = 'DFLT'; static const uint32_t ROADSTOP_CLASS_LABEL_WAYPOINT = 'WAYP'; -enum RoadStopClassID : uint16_t { - ROADSTOP_CLASS_BEGIN = 0, ///< The lowest valid value - ROADSTOP_CLASS_DFLT = 0, ///< Default road stop class. - ROADSTOP_CLASS_WAYP, ///< Waypoint class. - ROADSTOP_CLASS_MAX = UINT16_MAX, ///< Maximum number of classes. -}; -DECLARE_INCREMENT_DECREMENT_OPERATORS(RoadStopClassID) +/** Class IDs for stations. */ +using RoadStopClassID = PoolID; + +static constexpr RoadStopClassID ROADSTOP_CLASS_DFLT{0}; ///< Default road stop class. +static constexpr RoadStopClassID ROADSTOP_CLASS_WAYP{1}; ///< Waypoint class. /** * Various different options for availability, restricting @@ -158,7 +156,7 @@ struct RoadStopSpec : NewGRFSpecBase { static const RoadStopSpec *Get(uint16_t index); }; -using RoadStopClass = NewGRFClass; +using RoadStopClass = NewGRFClass; std::optional GetRoadStopLayout(TileInfo *ti, const RoadStopSpec *spec, BaseStation *st, StationType type, int view, std::span regs100 = {}); void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 43ef0f6059..e55160e970 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -49,7 +49,7 @@ bool StationClass::IsUIAvailable(uint) const } /* Instantiate StationClass. */ -template class NewGRFClass; +template class NewGRFClass; static const uint NUM_STATIONSSPECS_PER_STATION = 255; ///< Maximum number of parts per station. diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 65021580e2..8ad3802525 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -100,15 +100,11 @@ struct StationResolverObject : public SpecializedResolverObject; -/** Allow incrementing of StationClassID variables */ -DECLARE_INCREMENT_DECREMENT_OPERATORS(StationClassID) +static constexpr StationClassID STAT_CLASS_DFLT{0}; ///< Default station class. +static constexpr StationClassID STAT_CLASS_WAYP{1}; ///< Waypoint class. /** Flags describing behaviour of NewGRF stations. */ enum class StationSpecFlag : uint8_t { @@ -183,7 +179,7 @@ struct StationSpec : NewGRFSpecBase { }; /** Class containing information relating to station classes. */ -using StationClass = NewGRFClass; +using StationClass = NewGRFClass; const StationSpec *GetStationSpec(TileIndex t); diff --git a/src/object_gui.cpp b/src/object_gui.cpp index d56068445b..9853196123 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -62,7 +62,7 @@ public: return false; } - int GetSelectedClass() const override { return _object_gui.sel_class; } + int GetSelectedClass() const override { return _object_gui.sel_class.base(); } void SetSelectedClass(int id) const override { _object_gui.sel_class = this->GetClassIndex(id); } StringID GetClassName(int id) const override @@ -111,7 +111,7 @@ public: for (const Object *o : Object::Iterate()) { if (GetTileOwner(o->location.tile) != _current_company) continue; const ObjectSpec *spec = ObjectSpec::Get(o->type); - if (spec == nullptr || spec->class_index == INVALID_OBJECT_CLASS || !spec->IsEverAvailable()) continue; + if (spec == nullptr || spec->class_index == ObjectClassID::Invalid() || !spec->IsEverAvailable()) continue; items.insert(GetPickerItem(spec)); } } @@ -432,5 +432,5 @@ Window *ShowBuildObjectPicker() /** Reset all data of the object GUI. */ void InitializeObjectGui() { - _object_gui.sel_class = ObjectClassID::OBJECT_CLASS_BEGIN; + _object_gui.sel_class = ObjectClassID::Begin(); } diff --git a/src/picker_gui.h b/src/picker_gui.h index 0767af6a59..7f8fa2bb43 100644 --- a/src/picker_gui.h +++ b/src/picker_gui.h @@ -231,7 +231,7 @@ public: PickerItem GetPickerItem(const typename T::spec_type *spec, int cls_id = -1, int id = -1) const { if (spec == nullptr) return {0, 0, cls_id, id}; - return {spec->grf_prop.grfid, spec->grf_prop.local_id, spec->class_index, spec->index}; + return {spec->grf_prop.grfid, spec->grf_prop.local_id, spec->class_index.base(), spec->index}; } PickerItem GetPickerItem(int cls_id, int id) const override diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 30e23d0b13..34fd57ded9 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1027,10 +1027,10 @@ public: bool HasClassChoice() const override { - return std::ranges::count_if(StationClass::Classes(), std::not_fn(IsWaypointClass)) > 1; + return std::ranges::count_if(StationClass::Classes(), [](const auto &cls) { return !IsWaypointClass(cls); }) > 1; } - int GetSelectedClass() const override { return _station_gui.sel_class; } + int GetSelectedClass() const override { return _station_gui.sel_class.base(); } void SetSelectedClass(int id) const override { _station_gui.sel_class = this->GetClassIndex(id); } StringID GetClassName(int id) const override @@ -1074,12 +1074,12 @@ public: for (const Station *st : Station::Iterate()) { if (st->owner != _local_company) continue; if (!default_added && StationUsesDefaultType(st)) { - items.insert({0, 0, STAT_CLASS_DFLT, 0}); + items.insert({0, 0, STAT_CLASS_DFLT.base(), 0}); default_added = true; } for (const auto &sm : st->speclist) { if (sm.spec == nullptr) continue; - items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index}); + items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index}); } } } @@ -1847,11 +1847,11 @@ public: bool HasClassChoice() const override { - return std::ranges::count_if(StationClass::Classes(), IsWaypointClass) > 1; + return std::ranges::count_if(StationClass::Classes(), [](const auto &cls) { return IsWaypointClass(cls); }) > 1; } void Close(int) override { ResetObjectToPlace(); } - int GetSelectedClass() const override { return _waypoint_gui.sel_class; } + int GetSelectedClass() const override { return _waypoint_gui.sel_class.base(); } void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); } StringID GetClassName(int id) const override @@ -1893,12 +1893,12 @@ public: for (const Waypoint *wp : Waypoint::Iterate()) { if (wp->owner != _local_company || HasBit(wp->waypoint_flags, WPF_ROAD)) continue; if (!default_added && StationUsesDefaultType(wp)) { - items.insert({0, 0, STAT_CLASS_WAYP, 0}); + items.insert({0, 0, STAT_CLASS_WAYP.base(), 0}); default_added = true; } for (const auto &sm : wp->speclist) { if (sm.spec == nullptr) continue; - items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index}); + items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index}); } } } @@ -1952,9 +1952,9 @@ static void ShowBuildWaypointPicker(Window *parent) void InitializeRailGui() { _build_depot_direction = DIAGDIR_NW; - _station_gui.sel_class = StationClassID::STAT_CLASS_DFLT; + _station_gui.sel_class = STAT_CLASS_DFLT; _station_gui.sel_type = 0; - _waypoint_gui.sel_class = StationClassID::STAT_CLASS_WAYP; + _waypoint_gui.sel_class = STAT_CLASS_WAYP; _waypoint_gui.sel_type = 0; } diff --git a/src/road_cmd.h b/src/road_cmd.h index 12a069be2c..c656c37ef5 100644 --- a/src/road_cmd.h +++ b/src/road_cmd.h @@ -15,8 +15,7 @@ #include "command_type.h" #include "station_type.h" #include "town_type.h" - -enum RoadStopClassID : uint16_t; +#include "newgrf_roadstop.h" void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt); void UpdateNearestTownForRoadTiles(bool invalidate); diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 5b3c40eefc..a2ba3896f4 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -203,7 +203,7 @@ void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t wid if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace(); bool connect_to_road = true; - if ((uint)spec_class < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) { + if (spec_class.base() < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) { const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index); if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false; } @@ -1275,7 +1275,7 @@ public: return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice); } - int GetSelectedClass() const override { return _roadstop_gui.sel_class; } + int GetSelectedClass() const override { return _roadstop_gui.sel_class.base(); } void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); } StringID GetClassName(int id) const override @@ -1327,12 +1327,12 @@ public: if (st->owner != _local_company) continue; if (roadstoptype == RoadStopType::Truck && !st->facilities.Test(StationFacility::TruckStop)) continue; if (roadstoptype == RoadStopType::Bus && !st->facilities.Test(StationFacility::BusStop)) continue; - items.insert({0, 0, ROADSTOP_CLASS_DFLT, 0}); // We would need to scan the map to find out if default is used. + items.insert({0, 0, ROADSTOP_CLASS_DFLT.base(), 0}); // We would need to scan the map to find out if default is used. for (const auto &sm : st->roadstop_speclist) { if (sm.spec == nullptr) continue; if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue; if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue; - items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index}); + items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index}); } } } @@ -1699,11 +1699,11 @@ public: bool HasClassChoice() const override { - return std::ranges::count_if(RoadStopClass::Classes(), IsWaypointClass) > 1; + return std::ranges::count_if(RoadStopClass::Classes(), [](const auto &cls) { return IsWaypointClass(cls); }) > 1; } void Close(int) override { ResetObjectToPlace(); } - int GetSelectedClass() const override { return _waypoint_gui.sel_class; } + int GetSelectedClass() const override { return _waypoint_gui.sel_class.base(); } void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); } StringID GetClassName(int id) const override @@ -1748,10 +1748,10 @@ public: { for (const Waypoint *wp : Waypoint::Iterate()) { if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue; - items.insert({0, 0, ROADSTOP_CLASS_WAYP, 0}); // We would need to scan the map to find out if default is used. + items.insert({0, 0, ROADSTOP_CLASS_WAYP.base(), 0}); // We would need to scan the map to find out if default is used. for (const auto &sm : wp->roadstop_speclist) { if (sm.spec == nullptr) continue; - items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index}); + items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index}); } } } @@ -1803,7 +1803,7 @@ void InitializeRoadGui() { _road_depot_orientation = DIAGDIR_NW; _roadstop_gui.orientation = DIAGDIR_NW; - _waypoint_gui.sel_class = RoadStopClassID::ROADSTOP_CLASS_WAYP; + _waypoint_gui.sel_class = ROADSTOP_CLASS_WAYP; _waypoint_gui.sel_type = 0; } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 670a6c78a7..83a378b5bc 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1444,7 +1444,7 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy if (!ValParamRailType(rt) || !IsValidAxis(axis)) return CMD_ERROR; /* Check if the given station class is valid */ - if (static_cast(spec_class) >= StationClass::GetClassCount()) return CMD_ERROR; + if (spec_class.base() >= StationClass::GetClassCount()) return CMD_ERROR; const StationClass *cls = StationClass::Get(spec_class); if (IsWaypointClass(*cls)) return CMD_ERROR; if (spec_index >= cls->GetSpecCount()) return CMD_ERROR; @@ -2078,7 +2078,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width bool distant_join = (station_to_join != StationID::Invalid()); /* Check if the given station class is valid */ - if (static_cast(spec_class) >= RoadStopClass::GetClassCount()) return CMD_ERROR; + if (spec_class.base() >= RoadStopClass::GetClassCount()) return CMD_ERROR; const RoadStopClass *cls = RoadStopClass::Get(spec_class); if (IsWaypointClass(*cls)) return CMD_ERROR; if (spec_index >= cls->GetSpecCount()) return CMD_ERROR; diff --git a/src/station_cmd.h b/src/station_cmd.h index 0ce331653a..60e6edd37d 100644 --- a/src/station_cmd.h +++ b/src/station_cmd.h @@ -14,12 +14,11 @@ #include "rail_type.h" #include "road_type.h" #include "station_type.h" +#include "newgrf_roadstop.h" +#include "newgrf_station.h" struct Town; -enum StationClassID : uint16_t; -enum RoadStopClassID : uint16_t; - extern Town *AirportGetNearestTown(const struct AirportSpec *as, Direction rotation, TileIndex tile, TileIterator &&it, uint &mindist); extern uint8_t GetAirportNoiseLevelForDistance(const struct AirportSpec *as, uint distance); diff --git a/src/table/airport_defaults.h b/src/table/airport_defaults.h index f067d3ffce..781645f4e8 100644 --- a/src/table/airport_defaults.h +++ b/src/table/airport_defaults.h @@ -391,7 +391,7 @@ extern const AirportSpec _origin_airport_specs[] = { static_assert(NEW_AIRPORT_OFFSET == lengthof(_origin_airport_specs)); -const AirportSpec AirportSpec::dummy = AS_GENERIC(&_airportfta_dummy, {}, {}, 0, 0, 0, 0, CalendarTime::MIN_YEAR, CalendarTime::MIN_YEAR, 0, ATP_TTDP_LARGE, APC_BEGIN, STR_NULL, 0, false); +const AirportSpec AirportSpec::dummy = AS_GENERIC(&_airportfta_dummy, {}, {}, 0, 0, 0, 0, CalendarTime::MIN_YEAR, CalendarTime::MIN_YEAR, 0, ATP_TTDP_LARGE, {}, STR_NULL, 0, false); #undef AS #undef AS_ND diff --git a/src/table/object_land.h b/src/table/object_land.h index 43ad677fac..b517ad9d23 100644 --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -106,7 +106,7 @@ static const DrawTileSpriteSpan _object_hq[] = { #undef TILE_SPRITE_LINE #undef TILE_SPRITE_LINE_NOTHING -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, introduction_date, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, StandardGRFFileProps{}, AnimationInfo{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, introduction_date, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}} +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, introduction_date, climate, gen_amount, flags) {{ObjectClassID::Invalid(), 0}, StandardGRFFileProps{}, AnimationInfo{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, introduction_date, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}} /* Climates * T = Temperate diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index ac7ea7a5bb..d371af9044 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -209,7 +209,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi { if (!IsValidAxis(axis)) return CMD_ERROR; /* Check if the given station class is valid */ - if (static_cast(spec_class) >= StationClass::GetClassCount()) return CMD_ERROR; + if (spec_class.base() >= StationClass::GetClassCount()) return CMD_ERROR; const StationClass *cls = StationClass::Get(spec_class); if (!IsWaypointClass(*cls)) return CMD_ERROR; if (spec_index >= cls->GetSpecCount()) return CMD_ERROR; @@ -343,7 +343,7 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi { if (!IsValidAxis(axis)) return CMD_ERROR; /* Check if the given station class is valid */ - if (static_cast(spec_class) >= RoadStopClass::GetClassCount()) return CMD_ERROR; + if (spec_class.base() >= RoadStopClass::GetClassCount()) return CMD_ERROR; const RoadStopClass *cls = RoadStopClass::Get(spec_class); if (!IsWaypointClass(*cls)) return CMD_ERROR; if (spec_index >= cls->GetSpecCount()) return CMD_ERROR; diff --git a/src/waypoint_cmd.h b/src/waypoint_cmd.h index 96ae377a0d..db680e5039 100644 --- a/src/waypoint_cmd.h +++ b/src/waypoint_cmd.h @@ -12,9 +12,8 @@ #include "command_type.h" #include "station_type.h" - -enum StationClassID : uint16_t; -enum RoadStopClassID : uint16_t; +#include "newgrf_roadstop.h" +#include "newgrf_station.h" CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent); CommandCost CmdRemoveFromRailWaypoint(DoCommandFlags flags, TileIndex start, TileIndex end, bool keep_rail); diff --git a/src/waypoint_func.h b/src/waypoint_func.h index b53003f640..e28e56e846 100644 --- a/src/waypoint_func.h +++ b/src/waypoint_func.h @@ -13,8 +13,7 @@ #include "rail_type.h" #include "command_type.h" #include "station_type.h" - -enum StationClassID : uint16_t; +#include "newgrf_station.h" CommandCost RemoveBuoy(TileIndex tile, DoCommandFlags flags);