(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
--- a/grfspecial.c Sun Nov 14 15:11:25 2004 +0000
+++ b/grfspecial.c Sun Nov 14 16:11:48 2004 +0000
@@ -934,7 +934,7 @@
while (numprops-- && buf < bufend) {
uint8 prop = grf_load_byte(&buf);
- if (feature == 4)
+ if (feature == GSF_STATION)
// stations don't share those common properties
goto run_handler;
@@ -1193,15 +1193,33 @@
if (feature == GSF_STATION) {
// We do things differently for stations.
- /* XXX: Currently we don't support cargo-specific images, so
- * we go straight to the defaults. */
- byte *bp = buf + 4 + idcount + cidcount * 3;
- uint16 groupid = grf_load_word(&bp);
+ for (i = 0; i < idcount; i++) {
+ uint8 stid = buf[3 + i];
+ StationSpec *stat = &_cur_grffile->stations[stid];
+ byte *bp = &buf[4 + idcount];
- for (i = 0; i < idcount; i++) {
- struct StationSpec *stat;
- uint8 stid = buf[3 + i];
- int j;
+ for (c = 0; c < cidcount; c++) {
+ uint8 ctype = grf_load_byte(&bp);
+ uint16 groupid = grf_load_word(&bp);
+
+ if (groupid >= _cur_grffile->spritegroups_count) {
+ grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
+ groupid, _cur_grffile->spritegroups_count);
+ return;
+ }
+
+ if (ctype != 0xFF) {
+ /* TODO: No support for any other cargo. */
+ continue;
+ }
+
+ stat->relocation[1] = _cur_grffile->spritegroups[groupid];
+ }
+ }
+
+ {
+ byte *bp = buf + 4 + idcount + cidcount * 3;
+ uint16 groupid = grf_load_word(&bp);
if (groupid >= _cur_grffile->spritegroups_count) {
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
@@ -1209,19 +1227,15 @@
return;
}
- stat = &_cur_grffile->stations[stid];
-
- // relocate sprite indexes based on spriteset locations
- for (j = 0; j < stat->tiles; j++) {
- DrawTileSeqStruct *seq;
+ for (i = 0; i < idcount; i++) {
+ uint8 stid = buf[3 + i];
+ struct StationSpec *stat = &_cur_grffile->stations[stid];
- foreach_draw_tile_seq(seq, (DrawTileSeqStruct*) stat->renderdata[j].seq) {
- seq->image += _cur_grffile->spritegroups[groupid].loading[0];
- }
+ stat->relocation[0] = _cur_grffile->spritegroups[groupid];
+ stat->grfid = _cur_grffile->grfid;
+ SetCustomStation(stid, stat);
+ stat->classid = 0;
}
- stat->grfid = _cur_grffile->grfid;
- SetCustomStation(stid, stat);
- stat->classid = 0;
}
return;
}
--- a/rail_cmd.c Sun Nov 14 15:11:25 2004 +0000
+++ b/rail_cmd.c Sun Nov 14 16:11:48 2004 +0000
@@ -1544,19 +1544,21 @@
if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) {
// look for customization
- DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', _map3_hi[ti->tile]);
+ struct StationSpec *stat = GetCustomStation('WAYP', _map3_hi[ti->tile]);
- if (cust) {
+ if (stat) {
DrawTileSeqStruct const *seq;
-
- cust = &cust[2 + (m5 & 0x1)]; // emulate station tile - open with building
+ // emulate station tile - open with building
+ DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
+ uint32 relocation = GetCustomStationRelocation(stat, 0);
image = cust->ground_sprite;
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
DrawGroundSprite(image);
foreach_draw_tile_seq(seq, cust->seq) {
- DrawSpecialBuilding(seq->image|0x8000, 0, ti,
+ uint32 image = seq->image + relocation;
+ DrawSpecialBuilding(image|0x8000, 0, ti,
seq->delta_x, seq->delta_y, seq->delta_z,
seq->width, seq->height, seq->unk);
}
@@ -1622,16 +1624,18 @@
void DrawWaypointSprite(int x, int y, int stat_id)
{
- // TODO: We should use supersets with cargo-id FF, if available. --pasky
- DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', stat_id);
+ struct StationSpec *stat = GetCustomStation('WAYP', stat_id);
+ uint32 relocation;
+ DrawTileSprites *cust;
DrawTileSeqStruct const *seq;
uint32 ormod, img;
- assert(cust);
+ assert(stat);
+ relocation = GetCustomStationRelocation(stat, 1);
// emulate station tile - open with building
// add 1 to get the other direction
- cust = &cust[2];
+ cust = &stat->renderdata[2];
ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player));
@@ -1644,7 +1648,9 @@
foreach_draw_tile_seq(seq, cust->seq) {
Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);
- DrawSprite((seq->image&0x3FFF) | ormod, x + pt.x, y + pt.y);
+ uint32 image = seq->image + relocation;
+
+ DrawSprite((image&0x3FFF) | ormod, x + pt.x, y + pt.y);
}
}
--- a/station.h Sun Nov 14 15:11:25 2004 +0000
+++ b/station.h Sun Nov 14 16:11:48 2004 +0000
@@ -1,6 +1,7 @@
#ifndef STATION_H
#define STATION_H
+#include "engine.h"
#include "vehicle.h"
typedef struct GoodsEntry {
@@ -117,6 +118,10 @@
byte tiles;
DrawTileSprites renderdata[8];
+
+ /* Sprite offsets for renderdata->seq->image. relocation[0] is default
+ * whilst relocation[1] is "CID_PURCHASE". */
+ struct SpriteGroup relocation[2];
};
/* Here, @stid is local per-GRFFile station index. If spec->localidx is not yet
@@ -126,7 +131,8 @@
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);
+struct StationSpec *GetCustomStation(uint32 classid, byte stid);
+uint32 GetCustomStationRelocation(struct StationSpec *spec, byte ctype);
int GetCustomStationsCount(uint32 classid);
#endif /* STATION_H */
--- a/station_cmd.c Sun Nov 14 15:11:25 2004 +0000
+++ b/station_cmd.c Sun Nov 14 16:11:48 2004 +0000
@@ -994,12 +994,33 @@
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
}
-DrawTileSprites *GetCustomStationRenderdata(uint32 classid, byte stid)
+struct StationSpec *GetCustomStation(uint32 classid, byte stid)
{
assert(classid == 'WAYP');
if (stid > _waypoint_highest_id)
return NULL;
- return _waypoint_data[stid].renderdata;
+ return &_waypoint_data[stid];
+}
+
+uint32 GetCustomStationRelocation(struct StationSpec *spec, byte ctype)
+{
+ assert(spec->classid == 'WAYP');
+
+ /* In the future, variational spritegroups will kick in through this
+ * accessor. */
+
+ if (spec->relocation[ctype].loading_count != 0) {
+ return spec->relocation[ctype].loading[0];
+ } else if (spec->relocation[ctype].loading_count != 0) {
+ return spec->relocation[ctype].loaded[0];
+ } else {
+ error("Custom station 0x%08x::0x%02x has no sprites associated.",
+ spec->grfid, spec->localidx);
+ /* This is what gets subscribed of dtss->image in grfspecial.c,
+ * so it's probably kinda "default offset". Try to use it as
+ * emergency measure. */
+ return 0x42D;
+ }
}
int GetCustomStationsCount(uint32 classid)