1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 19:02:41 +01:00

Codechange: Add NewGRFSpecsBase class to hold class/index information.

Standardises how the class index is stored in the spec, instead of relying ot the Spec structs having the same members.

This allows retrieving class_index and index without searching or using pointer arithmetic.

'cls_id' is renamed to 'class_index' to make it clearer that it is an index rather than the multichar label of the class.
This commit is contained in:
Peter Nelson
2024-05-07 12:13:46 +01:00
committed by Peter Nelson
parent 733284cc16
commit d5671030b1
13 changed files with 83 additions and 78 deletions

View File

@@ -193,13 +193,12 @@
bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
if (res != CALLBACK_FAILED) {
int index = 0;
const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index);
const StationSpec *spec = StationClass::GetByGrf(file->grfid, res);
if (spec == nullptr) {
Debug(grf, 1, "{} returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
} else {
/* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */
if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, spec->cls_id, index, to_join, adjacent)) return true;
if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, spec->class_index, spec->index, to_join, adjacent)) return true;
}
}