(svn r4767) - Newstations: fix loading / use of custom ground sprites

pull/155/head
peter1138 18 years ago
parent 00930cf8d9
commit 9d6ddd364e

@ -826,19 +826,10 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
for (t = 0; t < statspec->tiles; t++) {
DrawTileSprites *dts = &statspec->renderdata[t];
uint seq_count = 0;
PalSpriteID ground_sprite;
dts->seq = NULL;
ground_sprite = grf_load_dword(&buf);
if (ground_sprite == 0) continue;
if (HASBIT(ground_sprite, 31)) {
// Bit 31 indicates that we should use a custom sprite.
dts->ground_sprite = GB(ground_sprite, 0, 15) - 0x42D;
dts->ground_sprite += _cur_grffile->first_spriteset;
} else {
dts->ground_sprite = ground_sprite;
}
dts->ground_sprite = grf_load_dword(&buf);
if (dts->ground_sprite == 0) continue;
while (buf < *bufp + len) {
DrawTileSeqStruct *dtss;
@ -856,13 +847,15 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
dtss->unk = grf_load_byte(&buf);
dtss->image = grf_load_dword(&buf);
/* Remap the colour map bit from 14 to 31 */
/* Remap flags as ours collide */
if (HASBIT(dtss->image, 31)) {
CLRBIT(dtss->image, 31);
SETBIT(dtss->image, 30);
}
if (HASBIT(dtss->image, 14)) {
CLRBIT(dtss->image, 14);
SETBIT(dtss->image, 31);
}
dtss->image -= 0x42D;
}
}
}
@ -1500,11 +1493,6 @@ static void NewSpriteGroup(byte *buf, int len)
return;
}
if (_cur_grffile->first_spriteset == 0) {
DEBUG(grf, 6) ("NewSpriteGroup: Setting 0x%X as first Sprite ID", _cur_grffile->spriteset_start);
_cur_grffile->first_spriteset = _cur_grffile->spriteset_start;
}
check_length(bufend - buf, 2 * num_loaded + 2 * num_loading, "NewSpriteGroup (Real) (1)");
group = AllocateSpriteGroup();
@ -1628,6 +1616,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
StationSpec *statspec = _cur_grffile->stations[stid];
statspec->spritegroup[GC_DEFAULT] = _cur_grffile->spritegroups[groupid];
statspec->groundgroup = _cur_grffile->spritegroups[0];
statspec->grfid = _cur_grffile->grfid;
statspec->localidx = stid;
SetCustomStationSpec(statspec);

@ -18,7 +18,6 @@ typedef struct GRFFile {
uint32 grfid;
uint16 flags;
uint16 sprite_offset;
SpriteID first_spriteset; ///< Holds the first spriteset's sprite offset.
byte grf_version;
struct GRFFile *next;

@ -465,7 +465,33 @@ SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *
if (group == NULL || group->type != SGT_RESULT) return 0;
return group->g.result.sprite;
return group->g.result.sprite - 0x42D;
}
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile)
{
const SpriteGroup *group;
ResolverObject object;
CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA;
NewStationResolver(&object, statspec, st, tile);
object.callback_param1 = 1; /* Indicate we are resolving the ground sprite */
group = Resolve(statspec->spritegroup[ctype], &object);
if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT_NA) {
group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object);
}
if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT) {
group = Resolve(statspec->spritegroup[GC_DEFAULT], &object);
}
if ((group == NULL || group->type != SGT_RESULT)) {
group = Resolve(statspec->groundgroup, &object);
}
if (group == NULL || group->type != SGT_RESULT) return 0;
return group->g.result.sprite - 0x42D;
}
@ -593,8 +619,6 @@ bool DeallocateSpecFromStation(Station *st, byte specindex)
*/
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
{
extern uint16 _custom_sprites_base;
const StationSpec *statspec;
const DrawTileSprites *sprites;
const DrawTileSeqStruct *seq;
@ -616,20 +640,31 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
if (statspec->renderdata == NULL) {
sprites = GetStationTileLayout(tile + axis);
relocation -= 0x42D;
} else {
sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : axis];
}
image = sprites->ground_sprite;
image += (image < _custom_sprites_base) ? rti->total_offset : rti->custom_ground_offset;
if (HASBIT(image, 31)) {
CLRBIT(image, 31);
image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE);
image += rti->custom_ground_offset;
} else {
image += rti->total_offset;
}
if (image & PALETTE_MODIFIER_COLOR) image &= SPRITE_MASK;
DrawSprite(image, x, y);
foreach_draw_tile_seq(seq, sprites->seq) {
Point pt;
image = seq->image + relocation;
image = seq->image;
if (HASBIT(image, 30)) {
CLRBIT(image, 30);
image += rti->total_offset;
} else {
image += relocation;
}
if ((byte)seq->delta_z != 0x80) {
pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);

@ -71,6 +71,7 @@ typedef struct StationSpec {
* evaluating callbacks.
*/
SpriteGroup *spritegroup[NUM_GLOBAL_CID];
SpriteGroup *groundgroup;
} StationSpec;
/**
@ -103,6 +104,7 @@ uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, i
* NULL - that means we are in a build dialog). The station structure is used
* for variational sprite groups. */
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile);
/* Check if a rail station tile is traversable. */

@ -30,8 +30,6 @@
#include "newgrf_callbacks.h"
#include "newgrf_station.h"
extern uint16 _custom_sprites_base;
const byte _track_sloped_sprites[14] = {
14, 15, 22, 13,
0, 21, 17, 12,
@ -1338,7 +1336,6 @@ static void DrawTile_Track(TileInfo *ti)
if (statspec->renderdata == NULL) {
cust = GetStationTileLayout(tile);
relocation -= 0x42D;
} else {
cust = &statspec->renderdata[(tile < statspec->tiles ? tile : 0) + GetWaypointAxis(ti->tile)];
}
@ -1346,7 +1343,13 @@ static void DrawTile_Track(TileInfo *ti)
/* If there is no sprite layout, we fall back to the default waypoint graphics. */
if (cust != NULL && cust->seq != NULL) {
image = cust->ground_sprite;
image += (image < _custom_sprites_base) ? rti->total_offset : rti->custom_ground_offset;
if (HASBIT(image, 31)) {
CLRBIT(image, 31);
image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
image += rti->custom_ground_offset;
} else {
image += rti->total_offset;
}
DrawGroundSprite(image);

@ -1986,8 +1986,6 @@ const DrawTileSprites *GetStationTileLayout(byte gfx)
return &_station_display_datas[gfx];
}
extern uint16 _custom_sprites_base;
static void DrawTile_Station(TileInfo *ti)
{
uint32 image_or_modificator;
@ -1996,8 +1994,9 @@ static void DrawTile_Station(TileInfo *ti)
const DrawTileSprites *t = NULL;
RailType railtype = GetRailType(ti->tile);
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
SpriteID offset;
uint32 relocation = 0;
const Station *st = NULL;
const StationSpec *statspec = NULL;
{
PlayerID owner = GetTileOwner(ti->tile);
@ -2011,8 +2010,8 @@ static void DrawTile_Station(TileInfo *ti)
if (IsCustomStationSpecIndex(ti->tile)) {
// look for customization
const Station *st = GetStationByTile(ti->tile);
const StationSpec *statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
st = GetStationByTile(ti->tile);
statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
//debug("Cust-o-mized %p", statspec);
@ -2036,12 +2035,15 @@ static void DrawTile_Station(TileInfo *ti)
if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationGfx(ti->tile)];
image = t->ground_sprite;
if (HASBIT(image, 31)) {
CLRBIT(image, 31);
image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
image += rti->custom_ground_offset;
} else {
image += rti->total_offset;
}
if (image & PALETTE_MODIFIER_COLOR) image |= image_or_modificator;
// For custom sprites, there's no railtype-based pitching.
offset = (image & SPRITE_MASK) < _custom_sprites_base ? rti->total_offset : rti->custom_ground_offset;
image += offset;
// station_land array has been increased from 82 elements to 114
// but this is something else. If AI builds station with 114 it looks all weird
DrawGroundSprite(image);
@ -2049,8 +2051,14 @@ static void DrawTile_Station(TileInfo *ti)
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
foreach_draw_tile_seq(dtss, t->seq) {
image = dtss->image + relocation;
image += offset;
image = dtss->image;
if (HASBIT(image, 30)) {
CLRBIT(image, 30);
image += rti->total_offset;
} else {
image += relocation;
}
if (_display_opt & DO_TRANS_BUILDINGS) {
MAKE_TRANSPARENT(image);
} else {

Loading…
Cancel
Save