# HG changeset patch # User peter1138 # Date 1146948520 0 # Node ID ebcaf412fb3a0ac649d5eb0cf832765ab181f937 # Parent 460bbb4a8154a59d8e4210272a5b05f46caaa688 (svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints. diff -r 460bbb4a8154 -r ebcaf412fb3a newgrf_station.c --- a/newgrf_station.c Sat May 06 20:33:22 2006 +0000 +++ b/newgrf_station.c Sat May 06 20:48:40 2006 +0000 @@ -5,8 +5,10 @@ #include "stdafx.h" #include "openttd.h" #include "variables.h" +#include "functions.h" #include "debug.h" #include "sprite.h" +#include "table/sprites.h" #include "table/strings.h" #include "station.h" #include "station_map.h" @@ -564,3 +566,60 @@ return freeable; } + +/** Draw representation of a station tile for GUI purposes. + * @param x, y Position of image. + * @param dir Direction. + * @param railtype Rail type. + * @param sclass, station Type of station. + * @return True if the tile was drawn (allows for fallback to default graphic) + */ +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; + const RailtypeInfo *rti = GetRailTypeInfo(railtype); + SpriteID relocation; + PalSpriteID image; + PalSpriteID colourmod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)); + uint tile = 2; + + statspec = GetCustomStationSpec(sclass, station); + if (statspec == NULL) return false; + + relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE); + + if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { + uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE); + if (callback != CALLBACK_FAILED) tile = callback; + } + + 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 (image & PALETTE_MODIFIER_COLOR) image &= SPRITE_MASK; + DrawSprite(image, x, y); + + foreach_draw_tile_seq(seq, sprites->seq) { + Point pt; + image = seq->image + relocation; + + if ((byte)seq->delta_z != 0x80) { + pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); + DrawSprite((image & SPRITE_MASK) | colourmod, x + pt.x, y + pt.y); + } + } + + return true; +} + diff -r 460bbb4a8154 -r ebcaf412fb3a newgrf_station.h --- a/newgrf_station.h Sat May 06 20:33:22 2006 +0000 +++ b/newgrf_station.h Sat May 06 20:48:40 2006 +0000 @@ -107,4 +107,7 @@ /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */ bool DeallocateSpecFromStation(Station *st, byte specindex); +/* Draw representation of a station tile for GUI purposes. */ +bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station); + #endif /* NEWGRF_STATION_H */ diff -r 460bbb4a8154 -r ebcaf412fb3a waypoint.c --- a/waypoint.c Sat May 06 20:33:22 2006 +0000 +++ b/waypoint.c Sat May 06 20:48:40 2006 +0000 @@ -15,7 +15,6 @@ #include "town.h" #include "waypoint.h" #include "variables.h" -#include "table/sprites.h" #include "table/strings.h" #include "vehicle.h" @@ -379,47 +378,14 @@ return &stat; } -extern uint16 _custom_sprites_base; - - /* Draw a waypoint */ void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype) { - const StationSpec *statspec; - uint32 relocation; - const DrawTileSprites *cust; - DrawTileSeqStruct const *seq; - const RailtypeInfo *rti = GetRailTypeInfo(railtype); - uint32 ormod, img; - - ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)); - x += 33; y += 17; - statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id); - if (statspec == NULL) { - // stat is NULL for default waypoints and when waypoint graphics are - // not loaded. + if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) { DrawDefaultWaypointSprite(x, y, railtype); - return; - } - - relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE); - // emulate station tile - open with building - // add 1 to get the other direction - cust = &statspec->renderdata[2]; - - img = cust->ground_sprite; - img += (img < _custom_sprites_base) ? rti->total_offset : rti->custom_ground_offset; - - if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK); - DrawSprite(img, x, y); - - foreach_draw_tile_seq(seq, cust->seq) { - Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); - uint32 image = seq->image + relocation; - DrawSprite((image & SPRITE_MASK) | ormod, x + pt.x, y + pt.y); } }