mirror of https://github.com/OpenTTD/OpenTTD
(svn r647) Cleanup custom station classes handling. (pasky)
parent
cd6cb84889
commit
86d19cb577
23
grfspecial.c
23
grfspecial.c
|
@ -710,12 +710,25 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
|
||||||
{ /* Class ID */
|
{ /* Class ID */
|
||||||
FOR_EACH_ENGINE {
|
FOR_EACH_ENGINE {
|
||||||
struct StationSpec *stat = &_cur_grffile->stations[stid + i];
|
struct StationSpec *stat = &_cur_grffile->stations[stid + i];
|
||||||
|
uint32 classid;
|
||||||
|
|
||||||
/* classid, for a change, is always little-endian */
|
/* classid, for a change, is always little-endian */
|
||||||
stat->classid = *(buf++) << 24;
|
classid = *(buf++) << 24;
|
||||||
stat->classid |= *(buf++) << 16;
|
classid |= *(buf++) << 16;
|
||||||
stat->classid |= *(buf++) << 8;
|
classid |= *(buf++) << 8;
|
||||||
stat->classid |= *(buf++);
|
classid |= *(buf++);
|
||||||
|
|
||||||
|
switch (classid) {
|
||||||
|
case 'DFLT':
|
||||||
|
stat->sclass = STAT_CLASS_DFLT;
|
||||||
|
break;
|
||||||
|
case 'WAYP':
|
||||||
|
stat->sclass = STAT_CLASS_WAYP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
stat->sclass = STAT_CLASS_CUSTOM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1288,7 +1301,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
|
||||||
stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
|
stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
|
||||||
stat->grfid = _cur_grffile->grfid;
|
stat->grfid = _cur_grffile->grfid;
|
||||||
SetCustomStation(stid, stat);
|
SetCustomStation(stid, stat);
|
||||||
stat->classid = 0;
|
stat->sclass = STAT_CLASS_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1564,7 +1564,7 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
|
|
||||||
if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) {
|
if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) {
|
||||||
// look for customization
|
// look for customization
|
||||||
struct StationSpec *stat = GetCustomStation('WAYP', _map3_hi[ti->tile]);
|
struct StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _map3_hi[ti->tile]);
|
||||||
|
|
||||||
if (stat) {
|
if (stat) {
|
||||||
DrawTileSeqStruct const *seq;
|
DrawTileSeqStruct const *seq;
|
||||||
|
@ -1677,7 +1677,7 @@ void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stat = GetCustomStation('WAYP', stat_id - 1);
|
stat = GetCustomStation(STAT_CLASS_WAYP, stat_id - 1);
|
||||||
assert(stat);
|
assert(stat);
|
||||||
relocation = GetCustomStationRelocation(stat, NULL, 1);
|
relocation = GetCustomStationRelocation(stat, NULL, 1);
|
||||||
// emulate station tile - open with building
|
// emulate station tile - open with building
|
||||||
|
|
|
@ -307,7 +307,7 @@ static void BuildRailClick_Sign(Window *w)
|
||||||
|
|
||||||
static void BuildRailClick_Waypoint(Window *w)
|
static void BuildRailClick_Waypoint(Window *w)
|
||||||
{
|
{
|
||||||
_waypoint_count = GetCustomStationsCount('WAYP');
|
_waypoint_count = GetCustomStationsCount(STAT_CLASS_WAYP);
|
||||||
if (HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint)
|
if (HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint)
|
||||||
&& _waypoint_count > 1)
|
&& _waypoint_count > 1)
|
||||||
ShowBuildWaypointPicker();
|
ShowBuildWaypointPicker();
|
||||||
|
|
17
station.h
17
station.h
|
@ -97,7 +97,18 @@ struct StationSpec {
|
||||||
uint32 grfid;
|
uint32 grfid;
|
||||||
int localidx; // per-GRFFile station index + 1; SetCustomStation() takes care of this
|
int localidx; // per-GRFFile station index + 1; SetCustomStation() takes care of this
|
||||||
|
|
||||||
uint32 classid;
|
enum StationClass {
|
||||||
|
STAT_CLASS_NONE, // unused station slot or so
|
||||||
|
STAT_CLASS_DFLT, // default station class
|
||||||
|
STAT_CLASS_WAYP, // waypoints
|
||||||
|
|
||||||
|
/* TODO: When we actually support custom classes, they are
|
||||||
|
* going to be allocated dynamically (with some classid->sclass
|
||||||
|
* mapping, there's a TTDPatch limit on 16 custom classes in
|
||||||
|
* the whole game at the same time) with base at
|
||||||
|
* STAT_CLASS_CUSTOM. --pasky */
|
||||||
|
STAT_CLASS_CUSTOM, // some custom class
|
||||||
|
} sclass;
|
||||||
|
|
||||||
byte tiles;
|
byte tiles;
|
||||||
DrawTileSprites renderdata[8];
|
DrawTileSprites renderdata[8];
|
||||||
|
@ -114,11 +125,11 @@ struct StationSpec {
|
||||||
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())
|
/* Here, @stid is global station index (in continous range 0..GetCustomStationsCount())
|
||||||
* (lookup is therefore very fast as we do this very frequently). */
|
* (lookup is therefore very fast as we do this very frequently). */
|
||||||
struct StationSpec *GetCustomStation(uint32 classid, byte stid);
|
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid);
|
||||||
/* Get sprite offset for a given custom station and station structure (may be
|
/* Get sprite offset for a given custom station and station structure (may be
|
||||||
* NULL if ctype is set - that means we are in a build dialog). The station
|
* NULL if ctype is set - that means we are in a build dialog). The station
|
||||||
* structure is used for variational sprite groups. */
|
* structure is used for variational sprite groups. */
|
||||||
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype);
|
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype);
|
||||||
int GetCustomStationsCount(uint32 classid);
|
int GetCustomStationsCount(enum StationClass sclass);
|
||||||
|
|
||||||
#endif /* STATION_H */
|
#endif /* STATION_H */
|
||||||
|
|
|
@ -967,7 +967,7 @@ void SetCustomStation(byte local_stid, struct StationSpec *spec)
|
||||||
{
|
{
|
||||||
int stid = -1;
|
int stid = -1;
|
||||||
|
|
||||||
assert(spec->classid == 'WAYP');
|
assert(spec->sclass == STAT_CLASS_WAYP);
|
||||||
|
|
||||||
if (spec->localidx != 0) {
|
if (spec->localidx != 0) {
|
||||||
/* Already allocated, try to resolve to global stid */
|
/* Already allocated, try to resolve to global stid */
|
||||||
|
@ -998,9 +998,9 @@ void SetCustomStation(byte local_stid, struct StationSpec *spec)
|
||||||
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
|
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StationSpec *GetCustomStation(uint32 classid, byte stid)
|
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid)
|
||||||
{
|
{
|
||||||
assert(classid == 'WAYP');
|
assert(sclass == STAT_CLASS_WAYP);
|
||||||
if (stid > _waypoint_highest_id)
|
if (stid > _waypoint_highest_id)
|
||||||
return NULL;
|
return NULL;
|
||||||
return &_waypoint_data[stid];
|
return &_waypoint_data[stid];
|
||||||
|
@ -1092,7 +1092,7 @@ uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat
|
||||||
{
|
{
|
||||||
struct RealSpriteGroup *rsg;
|
struct RealSpriteGroup *rsg;
|
||||||
|
|
||||||
assert(spec->classid == 'WAYP');
|
assert(spec->sclass == STAT_CLASS_WAYP);
|
||||||
|
|
||||||
rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat);
|
rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat);
|
||||||
|
|
||||||
|
@ -1112,9 +1112,9 @@ uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat
|
||||||
return 0x42D;
|
return 0x42D;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCustomStationsCount(uint32 classid)
|
int GetCustomStationsCount(enum StationClass sclass)
|
||||||
{
|
{
|
||||||
assert(classid == 'WAYP');
|
assert(sclass == STAT_CLASS_WAYP);
|
||||||
return _waypoint_highest_id + 1;
|
return _waypoint_highest_id + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue