diff options
author | darkvater <darkvater@openttd.org> | 2004-11-14 14:53:15 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-11-14 14:53:15 +0000 |
commit | 58473175266f453b900e4262588ccce075ec05c3 (patch) | |
tree | 548d0fcde9c3e1cc23af25dbd64d758bbf662231 /station_cmd.c | |
parent | ccc496ba2ce07be7bd8faf0a084e983dbed5e80b (diff) | |
download | openttd-58473175266f453b900e4262588ccce075ec05c3.tar.xz |
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
Diffstat (limited to 'station_cmd.c')
-rw-r--r-- | station_cmd.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/station_cmd.c b/station_cmd.c index 05b235833..8d8ce56ea 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -958,19 +958,39 @@ uint GetStationPlatforms(Station *st, uint tile) /* TODO: Multiple classes! */ -/* FIXME: Also, we should actually allocate the station id (but - * SetCustomStation() needs to be able to override an existing custom station - * as well) on our own. This would also prevent possible weirdness if some GRF - * file used non-contignuous station ids. --pasky */ static int _waypoint_highest_id = -1; static struct StationSpec _waypoint_data[256]; -void SetCustomStation(byte stid, struct StationSpec *spec) +void SetCustomStation(byte local_stid, struct StationSpec *spec) { + int stid = -1; + assert(spec->classid == 'WAYP'); - if (stid > _waypoint_highest_id) - _waypoint_highest_id = stid; + + if (spec->localidx != 0) { + /* Already allocated, try to resolve to global stid */ + int i; + + for (i = 0; i <= _waypoint_highest_id; i++) { + if (_waypoint_data[i].grfid == spec->grfid + && _waypoint_data[i].localidx == local_stid + 1) { + stid = i; + break; + } + } + } + + if (stid == -1) { + /* Allocate new one. */ + if (_waypoint_highest_id >= 255) { + error("Too many custom stations allocated."); + return; + } + stid = ++_waypoint_highest_id; + spec->localidx = local_stid + 1; + } + memcpy(&_waypoint_data[stid], spec, sizeof(*spec)); } |