Change: Expose NewGRF classes and specs as spans and simplify iteration.

This replaces some index-based loops with range loops.
This commit is contained in:
Peter Nelson
2024-04-09 17:54:43 +01:00
committed by Peter Nelson
parent 052f421327
commit 77f27e0804
6 changed files with 40 additions and 40 deletions

View File

@@ -465,13 +465,12 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
*/
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
{
for (uint i = 0; i < RoadStopClass::GetClassCount(); i++) {
for (const auto &cls : RoadStopClass::Classes()) {
/* Ignore the waypoint class. */
if (i == ROADSTOP_CLASS_WAYP) continue;
const RoadStopClass *roadstopclass = RoadStopClass::Get((RoadStopClassID)i);
if (cls.Index() == ROADSTOP_CLASS_WAYP) continue;
/* Ignore the default class with only the default station. */
if (i == ROADSTOP_CLASS_DFLT && roadstopclass->GetSpecCount() == 1) continue;
if (GetIfClassHasNewStopsByType(roadstopclass, rs, roadtype)) return true;
if (cls.Index() == ROADSTOP_CLASS_DFLT && cls.GetSpecCount() == 1) continue;
if (GetIfClassHasNewStopsByType(&cls, rs, roadtype)) return true;
}
return false;
}
@@ -485,8 +484,8 @@ bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
*/
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
{
for (uint j = 0; j < roadstopclass->GetSpecCount(); j++) {
if (GetIfStopIsForType(roadstopclass->GetSpec(j), rs, roadtype)) return true;
for (const auto spec : roadstopclass->Specs()) {
if (GetIfStopIsForType(spec, rs, roadtype)) return true;
}
return false;
}