Codechange: Use find_if to find waypoint StationSpec when converting old savegames. (#12865)

This simplifies an indexed loop.
This commit is contained in:
Peter Nelson 2024-07-17 11:40:17 +01:00 committed by GitHub
parent 891e53c72e
commit e69c065d6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -86,14 +86,9 @@ void MoveWaypointsToBaseStations()
/* As of version 17, we recalculate the custom graphic ID of waypoints
* from the GRF ID / station index. */
for (OldWaypoint &wp : _old_waypoints) {
StationClass *stclass = StationClass::Get(STAT_CLASS_WAYP);
for (uint i = 0; i < stclass->GetSpecCount(); i++) {
const StationSpec *statspec = stclass->GetSpec(i);
if (statspec != nullptr && statspec->grf_prop.grffile->grfid == wp.grfid && statspec->grf_prop.local_id == wp.localidx) {
wp.spec = statspec;
break;
}
}
const auto specs = StationClass::Get(STAT_CLASS_WAYP)->Specs();
auto found = std::find_if(std::begin(specs), std::end(specs), [&wp](const StationSpec *spec) { return spec != nullptr && spec->grf_prop.grffile->grfid == wp.grfid && spec->grf_prop.local_id == wp.localidx; });
if (found != std::end(specs)) wp.spec = *found;
}
}