Changeset - r11091:b193ed34bfbb
[Not reviewed]
master
0 4 0
peter1138 - 16 years ago 2009-02-09 22:49:28
peter1138@openttd.org
(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...
4 files changed with 18 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_rail.cpp
Show inline comments
 
@@ -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;
src/newgrf_station.cpp
Show inline comments
 
@@ -23,7 +23,7 @@
 

	
 
#include "table/strings.h"
 

	
 
StationClass _station_classes[STAT_CLASS_MAX];
 
static StationClass _station_classes[STAT_CLASS_MAX];
 

	
 
enum {
 
	MAX_SPECLIST = 255,
 
@@ -156,8 +156,14 @@ const StationSpec *GetCustomStationSpec(
 
	return NULL;
 
}
 

	
 

	
 
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx)
 
/**
 
 * Retrieve a station spec by GRF location.
 
 * @param grfid    GRF ID of station spec.
 
 * @param localidx Index within GRF file of station spec.
 
 * @param index    Pointer to return the index of the station spec in its station class. If NULL then not used.
 
 * @return The station spec.
 
 */
 
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index)
 
{
 
	uint j;
 

	
 
@@ -165,7 +171,10 @@ const StationSpec *GetCustomStationSpecB
 
		for (j = 0; j < _station_classes[i].stations; j++) {
 
			const StationSpec *statspec = _station_classes[i].spec[j];
 
			if (statspec == NULL) continue;
 
			if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) return statspec;
 
			if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) {
 
				if (index != NULL) *index = j;
 
				return statspec;
 
			}
 
		}
 
	}
 

	
src/newgrf_station.h
Show inline comments
 
@@ -118,7 +118,7 @@ uint GetNumCustomStations(StationClassID
 

	
 
void SetCustomStationSpec(StationSpec *statspec);
 
const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station);
 
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx);
 
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index);
 

	
 
/* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
 
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
src/saveload/station_sl.cpp
Show inline comments
 
@@ -20,7 +20,7 @@ void AfterLoadStations()
 
		for (uint i = 0; i < st->num_specs; i++) {
 
			if (st->speclist[i].grfid == 0) continue;
 

	
 
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
 
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
 
		}
 

	
 
		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
0 comments (0 inline, 0 general)