From ad30a3c4caaad54f1b0b279bb0fc78254016efe3 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 9 Feb 2009 22:49:28 +0000 Subject: (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... --- src/ai/api/ai_rail.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/ai/api') diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp index 5d08690d9..9ef1c4f53 100644 --- a/src/ai/api/ai_rail.cpp +++ b/src/ai/api/ai_rail.cpp @@ -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; -- cgit v1.2.3-70-g09d2