(svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...

This commit is contained in:
peter1138
2009-02-09 22:49:28 +00:00
parent 5c8cf85613
commit 4b1728079c
4 changed files with 18 additions and 16 deletions

View File

@@ -155,16 +155,9 @@
uint16 res = GetAiPurchaseCallbackResult(GSF_STATION, cargo_id, 0, source_industry, goal_industry, min(255, distance / 2), AICE_STATION_GET_STATION_ID, source_station ? 0 : 1, min(15, num_platforms) << 4 | min(15, platform_length), &file);
uint32 p2 = INVALID_STATION << 16;
if (res != CALLBACK_FAILED) {
extern StationClass _station_classes[STAT_CLASS_MAX];
const StationSpec *spec = GetCustomStationSpecByGrf(file->grfid, res);
int index = -1;
for (uint j = 0; j < _station_classes[spec->sclass].stations; j++) {
if (spec == _station_classes[spec->sclass].spec[j]) {
index = j;
break;
}
}
if (index == -1) {
int index = 0;
const StationSpec *spec = GetCustomStationSpecByGrf(file->grfid, res, &index);
if (spec == NULL) {
DEBUG(grf, 1, "%s returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
} else {
p2 |= spec->sclass | index << 8;