mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(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).
This commit is contained in:
parent
2b5b1f4e06
commit
5fcd71cf28
52
grfspecial.c
52
grfspecial.c
@ -934,7 +934,7 @@ static void VehicleChangeInfo(byte *buf, int len)
|
|||||||
while (numprops-- && buf < bufend) {
|
while (numprops-- && buf < bufend) {
|
||||||
uint8 prop = grf_load_byte(&buf);
|
uint8 prop = grf_load_byte(&buf);
|
||||||
|
|
||||||
if (feature == 4)
|
if (feature == GSF_STATION)
|
||||||
// stations don't share those common properties
|
// stations don't share those common properties
|
||||||
goto run_handler;
|
goto run_handler;
|
||||||
|
|
||||||
@ -1193,15 +1193,33 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
|
|||||||
if (feature == GSF_STATION) {
|
if (feature == GSF_STATION) {
|
||||||
// We do things differently for stations.
|
// 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++) {
|
for (i = 0; i < idcount; i++) {
|
||||||
struct StationSpec *stat;
|
|
||||||
uint8 stid = buf[3 + i];
|
uint8 stid = buf[3 + i];
|
||||||
int j;
|
StationSpec *stat = &_cur_grffile->stations[stid];
|
||||||
|
byte *bp = &buf[4 + idcount];
|
||||||
|
|
||||||
|
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) {
|
if (groupid >= _cur_grffile->spritegroups_count) {
|
||||||
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
|
grfmsg(GMS_WARN, "VehicleMapSpriteGroup: Spriteset %x out of range %x, skipping.",
|
||||||
@ -1209,19 +1227,15 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stat = &_cur_grffile->stations[stid];
|
for (i = 0; i < idcount; i++) {
|
||||||
|
uint8 stid = buf[3 + i];
|
||||||
|
struct StationSpec *stat = &_cur_grffile->stations[stid];
|
||||||
|
|
||||||
// relocate sprite indexes based on spriteset locations
|
stat->relocation[0] = _cur_grffile->spritegroups[groupid];
|
||||||
for (j = 0; j < stat->tiles; j++) {
|
stat->grfid = _cur_grffile->grfid;
|
||||||
DrawTileSeqStruct *seq;
|
SetCustomStation(stid, stat);
|
||||||
|
stat->classid = 0;
|
||||||
foreach_draw_tile_seq(seq, (DrawTileSeqStruct*) stat->renderdata[j].seq) {
|
|
||||||
seq->image += _cur_grffile->spritegroups[groupid].loading[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
stat->grfid = _cur_grffile->grfid;
|
|
||||||
SetCustomStation(stid, stat);
|
|
||||||
stat->classid = 0;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
26
rail_cmd.c
26
rail_cmd.c
@ -1544,19 +1544,21 @@ 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
|
||||||
DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', _map3_hi[ti->tile]);
|
struct StationSpec *stat = GetCustomStation('WAYP', _map3_hi[ti->tile]);
|
||||||
|
|
||||||
if (cust) {
|
if (stat) {
|
||||||
DrawTileSeqStruct const *seq;
|
DrawTileSeqStruct const *seq;
|
||||||
|
// emulate station tile - open with building
|
||||||
cust = &cust[2 + (m5 & 0x1)]; // emulate station tile - open with building
|
DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
|
||||||
|
uint32 relocation = GetCustomStationRelocation(stat, 0);
|
||||||
|
|
||||||
image = cust->ground_sprite;
|
image = cust->ground_sprite;
|
||||||
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
|
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
|
||||||
DrawGroundSprite(image);
|
DrawGroundSprite(image);
|
||||||
|
|
||||||
foreach_draw_tile_seq(seq, cust->seq) {
|
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->delta_x, seq->delta_y, seq->delta_z,
|
||||||
seq->width, seq->height, seq->unk);
|
seq->width, seq->height, seq->unk);
|
||||||
}
|
}
|
||||||
@ -1622,16 +1624,18 @@ void DrawTrainDepotSprite(int x, int y, int image, int railtype)
|
|||||||
|
|
||||||
void DrawWaypointSprite(int x, int y, int stat_id)
|
void DrawWaypointSprite(int x, int y, int stat_id)
|
||||||
{
|
{
|
||||||
// TODO: We should use supersets with cargo-id FF, if available. --pasky
|
struct StationSpec *stat = GetCustomStation('WAYP', stat_id);
|
||||||
DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', stat_id);
|
uint32 relocation;
|
||||||
|
DrawTileSprites *cust;
|
||||||
DrawTileSeqStruct const *seq;
|
DrawTileSeqStruct const *seq;
|
||||||
uint32 ormod, img;
|
uint32 ormod, img;
|
||||||
|
|
||||||
assert(cust);
|
assert(stat);
|
||||||
|
|
||||||
|
relocation = GetCustomStationRelocation(stat, 1);
|
||||||
// emulate station tile - open with building
|
// emulate station tile - open with building
|
||||||
// add 1 to get the other direction
|
// add 1 to get the other direction
|
||||||
cust = &cust[2];
|
cust = &stat->renderdata[2];
|
||||||
|
|
||||||
ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player));
|
ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player));
|
||||||
|
|
||||||
@ -1644,7 +1648,9 @@ void DrawWaypointSprite(int x, int y, int stat_id)
|
|||||||
|
|
||||||
foreach_draw_tile_seq(seq, cust->seq) {
|
foreach_draw_tile_seq(seq, cust->seq) {
|
||||||
Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef STATION_H
|
#ifndef STATION_H
|
||||||
#define STATION_H
|
#define STATION_H
|
||||||
|
|
||||||
|
#include "engine.h"
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
|
|
||||||
typedef struct GoodsEntry {
|
typedef struct GoodsEntry {
|
||||||
@ -117,6 +118,10 @@ struct StationSpec {
|
|||||||
|
|
||||||
byte tiles;
|
byte tiles;
|
||||||
DrawTileSprites renderdata[8];
|
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
|
/* Here, @stid is local per-GRFFile station index. If spec->localidx is not yet
|
||||||
@ -126,7 +131,8 @@ 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). */
|
||||||
DrawTileSprites *GetCustomStationRenderdata(uint32 classid, byte stid);
|
struct StationSpec *GetCustomStation(uint32 classid, byte stid);
|
||||||
|
uint32 GetCustomStationRelocation(struct StationSpec *spec, byte ctype);
|
||||||
int GetCustomStationsCount(uint32 classid);
|
int GetCustomStationsCount(uint32 classid);
|
||||||
|
|
||||||
#endif /* STATION_H */
|
#endif /* STATION_H */
|
||||||
|
@ -994,12 +994,33 @@ void SetCustomStation(byte local_stid, struct StationSpec *spec)
|
|||||||
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
|
memcpy(&_waypoint_data[stid], spec, sizeof(*spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTileSprites *GetCustomStationRenderdata(uint32 classid, byte stid)
|
struct StationSpec *GetCustomStation(uint32 classid, byte stid)
|
||||||
{
|
{
|
||||||
assert(classid == 'WAYP');
|
assert(classid == 'WAYP');
|
||||||
if (stid > _waypoint_highest_id)
|
if (stid > _waypoint_highest_id)
|
||||||
return NULL;
|
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)
|
int GetCustomStationsCount(uint32 classid)
|
||||||
|
Loading…
Reference in New Issue
Block a user