mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
This commit is contained in:
parent
ccc496ba2c
commit
5847317526
|
@ -1219,6 +1219,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
|
||||||
seq->image += _cur_grffile->spritegroups[groupid].loading[0];
|
seq->image += _cur_grffile->spritegroups[groupid].loading[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stat->grfid = _cur_grffile->grfid;
|
||||||
SetCustomStation(stid, stat);
|
SetCustomStation(stid, stat);
|
||||||
stat->classid = 0;
|
stat->classid = 0;
|
||||||
}
|
}
|
||||||
|
|
11
station.h
11
station.h
|
@ -110,13 +110,22 @@ typedef struct DrawTileSprites {
|
||||||
|
|
||||||
|
|
||||||
struct StationSpec {
|
struct StationSpec {
|
||||||
int globalidx;
|
uint32 grfid;
|
||||||
|
int localidx; // per-GRFFile station index + 1; SetCustomStation() takes care of this
|
||||||
|
|
||||||
uint32 classid;
|
uint32 classid;
|
||||||
|
|
||||||
byte tiles;
|
byte tiles;
|
||||||
DrawTileSprites renderdata[8];
|
DrawTileSprites renderdata[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Here, @stid is local per-GRFFile station index. If spec->localidx is not yet
|
||||||
|
* set, it gets new dynamically allocated global index and spec->localidx is
|
||||||
|
* set to @stid, otherwise we take it as that we are replacing it and try to
|
||||||
|
* search for it first (that isn't much fast but we do it only very seldom). */
|
||||||
void SetCustomStation(byte stid, struct StationSpec *spec);
|
void SetCustomStation(byte stid, struct StationSpec *spec);
|
||||||
|
/* Here, @stid is global station index (in continous range 0..GetCustomStationsCount())
|
||||||
|
* (lookup is therefore very fast as we do this very frequently). */
|
||||||
DrawTileSprites *GetCustomStationRenderdata(uint32 classid, byte stid);
|
DrawTileSprites *GetCustomStationRenderdata(uint32 classid, byte stid);
|
||||||
int GetCustomStationsCount(uint32 classid);
|
int GetCustomStationsCount(uint32 classid);
|
||||||
|
|
||||||
|
|
|
@ -958,19 +958,39 @@ uint GetStationPlatforms(Station *st, uint tile)
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Multiple classes! */
|
/* 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 int _waypoint_highest_id = -1;
|
||||||
static struct StationSpec _waypoint_data[256];
|
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');
|
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));
|
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue