Add NewGRFClass helper method for whether class ID is valid (for iteration)

This commit is contained in:
Jonathan G Rennison
2023-01-03 03:51:40 +00:00
parent 417416d19b
commit 6a7cad1b47
7 changed files with 19 additions and 8 deletions

View File

@@ -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(); \