From 63e97754fbf907cfefd277087bfbac5e0d4434e8 Mon Sep 17 00:00:00 2001 From: truelight Date: Thu, 6 Jan 2005 22:31:58 +0000 Subject: (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries (in prepare of dynamic arrays): - DEREF_XXX is changed into GetXXX - All direct call are directed via GetXXX - struct Industry has now an index-field - ENUM'd some stuff - Replaced home built loops with FOR_ALL_XXX - Added _stations_size, _vehicles_size, ... which gives the length of the array (which will be dynamic in the near future) - Changed lengtof(XXX) to _XXX_size (e.g. _stations_size) - Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX) - Made the sort-functions of all 4 dynamic - Made all 4 Initialize functions more of the same - Some minor tab-fixing and stuff (tnx to Tron for proof-reading my 100kb patch ;)) Note for all: please do NOT directly call _stations, _vehicles, _towns and _industries, but use the right wrapper to access them. Thank you. Ps: please also do not use 'v++', where v is of type Vehicle *. --- station.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'station.h') diff --git a/station.h b/station.h index c6a9179e5..17a0bb4da 100644 --- a/station.h +++ b/station.h @@ -94,12 +94,20 @@ void ShowStationViewWindow(int station); void UpdateAllStationVirtCoord(); VARDEF Station _stations[250]; -VARDEF bool _station_sort_dirty[MAX_PLAYERS]; -VARDEF bool _global_station_sort_dirty; +VARDEF uint _stations_size; + +VARDEF SortStruct *_station_sort; -#define DEREF_STATION(i) (&_stations[i]) -#define FOR_ALL_STATIONS(st) for(st=_stations; st != endof(_stations); st++) +static inline Station *GetStation(uint index) +{ + assert(index < _stations_size); + return &_stations[index]; +} +#define FOR_ALL_STATIONS(st) for(st = _stations; st != &_stations[_stations_size]; st++) + +VARDEF bool _station_sort_dirty[MAX_PLAYERS]; +VARDEF bool _global_station_sort_dirty; void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad); void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad); -- cgit v1.2.3-54-g00ecf