Add NewGRFClass helper method for whether class ID is valid (for iteration)
This commit is contained in:
@@ -233,7 +233,7 @@ class BuildAirportWindow : public PickerWindowBase {
|
||||
{
|
||||
DropDownList list;
|
||||
|
||||
for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; AirportClass::IsClassIDValid((AirportClassID)i); i++) {
|
||||
list.emplace_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ public:
|
||||
switch (widget) {
|
||||
case WID_AP_CLASS_DROPDOWN: {
|
||||
Dimension d = {0, 0};
|
||||
for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; AirportClass::IsClassIDValid((AirportClassID)i); i++) {
|
||||
SetDParam(0, AirportClass::Get((AirportClassID)i)->name);
|
||||
d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
|
||||
}
|
||||
|
@@ -59,6 +59,7 @@ public:
|
||||
static uint GetUIClassCount();
|
||||
static bool HasUIClass();
|
||||
static Tid GetUIClass(uint index);
|
||||
static bool IsClassIDValid(Tid cls_id);
|
||||
static NewGRFClass *Get(Tid cls_id);
|
||||
|
||||
static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
|
||||
|
@@ -95,6 +95,15 @@ DEFINE_NEWGRF_CLASS_METHOD(void)::Assign(Tspec *spec)
|
||||
Get(spec->cls_id)->Insert(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the class ID is valid (for iteration).
|
||||
* @return Whether the class ID is valid.
|
||||
*/
|
||||
DEFINE_NEWGRF_CLASS_METHOD(bool)::IsClassIDValid(Tid cls_id)
|
||||
{
|
||||
return cls_id < Tmax && classes[cls_id].global_id != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a particular class.
|
||||
* @param cls_id The id for the class.
|
||||
@@ -232,6 +241,7 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id,
|
||||
template Tid name::Allocate(uint32 global_id); \
|
||||
template void name::Insert(Tspec *spec); \
|
||||
template void name::Assign(Tspec *spec); \
|
||||
template bool name::IsClassIDValid(Tid cls_id); \
|
||||
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
|
||||
template uint name::GetClassCount(); \
|
||||
template uint name::GetUIClassCount(); \
|
||||
|
@@ -501,7 +501,7 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
|
||||
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
|
||||
{
|
||||
if (!(RoadStopClass::GetClassCount() > 1 || RoadStopClass::Get(ROADSTOP_CLASS_DFLT)->GetSpecCount() > 1)) return false;
|
||||
for (uint i = 0; i < RoadStopClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; RoadStopClass::IsClassIDValid((RoadStopClassID)i); i++) {
|
||||
// We don't want to check the default or waypoint classes. These classes are always available.
|
||||
if (i == ROADSTOP_CLASS_DFLT || i == ROADSTOP_CLASS_WAYP) continue;
|
||||
RoadStopClass *roadstopclass = RoadStopClass::Get((RoadStopClassID)i);
|
||||
|
@@ -153,7 +153,7 @@ public:
|
||||
|
||||
this->object_classes.clear();
|
||||
|
||||
for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; ObjectClass::IsClassIDValid((ObjectClassID)i); i++) {
|
||||
ObjectClass *objclass = ObjectClass::Get((ObjectClassID)i);
|
||||
if (objclass->GetUISpecCount() == 0) continue; // Is this needed here?
|
||||
object_classes.push_back((ObjectClassID)i);
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
/* Check if the previously selected object class is not available anymore as a
|
||||
* result of starting a new game without the corresponding NewGRF. */
|
||||
bool available = false;
|
||||
for (uint i = 0; ObjectClass::GetClassCount(); ++i) {
|
||||
for (uint i = 0; ObjectClass::IsClassIDValid((ObjectClassID)i); ++i) {
|
||||
if ((ObjectClassID)i == _selected_object_class) {
|
||||
available = true;
|
||||
break;
|
||||
|
@@ -1202,7 +1202,7 @@ public:
|
||||
|
||||
this->station_classes.clear();
|
||||
|
||||
for (uint i = 0; i < StationClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; StationClass::IsClassIDValid((StationClassID)i); i++) {
|
||||
StationClassID station_class_id = (StationClassID)i;
|
||||
if (station_class_id == StationClassID::STAT_CLASS_WAYP) {
|
||||
// Skip waypoints.
|
||||
@@ -1236,7 +1236,7 @@ public:
|
||||
/* Check if the previously selected station class is not available anymore as a
|
||||
* result of starting a new game without the corresponding NewGRF. */
|
||||
bool available = false;
|
||||
for (uint i = 0; i < StationClass::GetClassCount(); ++i) {
|
||||
for (uint i = 0; StationClass::IsClassIDValid((StationClassID)i); ++i) {
|
||||
if ((StationClassID)i == _railstation.station_class) {
|
||||
available = true;
|
||||
break;
|
||||
|
@@ -1374,7 +1374,7 @@ public:
|
||||
|
||||
this->roadstop_classes.clear();
|
||||
|
||||
for (uint i = 0; i < RoadStopClass::GetClassCount(); i++) {
|
||||
for (uint i = 0; RoadStopClass::IsClassIDValid((RoadStopClassID)i); i++) {
|
||||
RoadStopClassID rs_id = (RoadStopClassID)i;
|
||||
if (rs_id == ROADSTOP_CLASS_WAYP) {
|
||||
// Skip waypoints.
|
||||
|
Reference in New Issue
Block a user