mirror of https://github.com/OpenTTD/OpenTTD
(svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
parent
2a776775e5
commit
635bfcd1c8
171
rail_cmd.c
171
rail_cmd.c
|
@ -1182,18 +1182,6 @@ static void DrawTrackDetails(const TileInfo* ti)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void DrawSpecialBuilding(
|
|
||||||
uint32 image, uint32 offset,
|
|
||||||
const TileInfo* ti,
|
|
||||||
byte x, byte y, byte z,
|
|
||||||
byte xsize, byte ysize, byte zsize)
|
|
||||||
{
|
|
||||||
if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
|
|
||||||
image += offset;
|
|
||||||
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
|
|
||||||
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw ground sprite and track bits
|
* Draw ground sprite and track bits
|
||||||
* @param ti TileInfo
|
* @param ti TileInfo
|
||||||
|
@ -1310,40 +1298,55 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
|
|
||||||
if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
|
if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
|
||||||
} else {
|
} else {
|
||||||
/* draw depots / waypoints */
|
// draw depot/waypoint
|
||||||
const DrawTrackSeqStruct *drss;
|
const DrawTileSprites* dts;
|
||||||
bool is_depot = GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT;
|
const DrawTileSeqStruct* dtss;
|
||||||
|
uint32 relocation;
|
||||||
|
|
||||||
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
|
||||||
|
|
||||||
if (IsRailWaypoint(ti->tile)) {
|
if (GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
|
||||||
|
dts = &_depot_gfx_table[GetRailDepotDirection(ti->tile)];
|
||||||
|
|
||||||
|
relocation = rti->total_offset;
|
||||||
|
|
||||||
|
image = dts->ground_sprite;
|
||||||
|
if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
|
||||||
|
|
||||||
|
// adjust ground tile for desert
|
||||||
|
// don't adjust for snow, because snow in depots looks weird
|
||||||
|
if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_DESERT) {
|
||||||
|
if (image != SPR_FLAT_GRASS_TILE) {
|
||||||
|
image += rti->snow_offset; // tile with tracks
|
||||||
|
} else {
|
||||||
|
image = SPR_FLAT_SNOWY_TILE; // flat ground
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// look for customization
|
// look for customization
|
||||||
byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
|
byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
|
||||||
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
|
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
|
||||||
|
|
||||||
if (statspec != NULL) {
|
if (statspec != NULL) {
|
||||||
DrawTileSeqStruct const *seq;
|
|
||||||
// emulate station tile - open with building
|
// emulate station tile - open with building
|
||||||
uint tile = 2;
|
const Station* st = ComposeWaypointStation(ti->tile);
|
||||||
const DrawTileSprites *cust;
|
uint gfx = 2;
|
||||||
Station *st = ComposeWaypointStation(ti->tile);
|
|
||||||
|
|
||||||
uint32 relocation = GetCustomStationRelocation(statspec, st, ti->tile);
|
|
||||||
|
|
||||||
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
|
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
|
||||||
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
|
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
|
||||||
if (callback != CALLBACK_FAILED) tile = callback;
|
if (callback != CALLBACK_FAILED) gfx = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statspec->renderdata == NULL) {
|
if (statspec->renderdata == NULL) {
|
||||||
cust = GetStationTileLayout(tile);
|
dts = GetStationTileLayout(gfx);
|
||||||
} else {
|
} else {
|
||||||
cust = &statspec->renderdata[(tile < statspec->tiles ? tile : 0) + GetWaypointAxis(ti->tile)];
|
dts = &statspec->renderdata[(gfx < statspec->tiles ? gfx : 0) + GetWaypointAxis(ti->tile)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there is no sprite layout, we fall back to the default waypoint graphics. */
|
if (dts != NULL && dts->seq != NULL) {
|
||||||
if (cust != NULL && cust->seq != NULL) {
|
relocation = GetCustomStationRelocation(statspec, st, ti->tile);
|
||||||
image = cust->ground_sprite;
|
|
||||||
|
image = dts->ground_sprite;
|
||||||
if (HASBIT(image, 31)) {
|
if (HASBIT(image, 31)) {
|
||||||
CLRBIT(image, 31);
|
CLRBIT(image, 31);
|
||||||
image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
|
image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
|
||||||
|
@ -1351,38 +1354,16 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
} else {
|
} else {
|
||||||
image += rti->total_offset;
|
image += rti->total_offset;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
DrawGroundSprite(image);
|
goto default_waypoint;
|
||||||
|
|
||||||
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
|
||||||
|
|
||||||
foreach_draw_tile_seq(seq, cust->seq) {
|
|
||||||
DrawSpecialBuilding(
|
|
||||||
seq->image + relocation, 0, ti,
|
|
||||||
seq->delta_x, seq->delta_y, seq->delta_z,
|
|
||||||
seq->width, seq->height, seq->unk
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drss = is_depot ? _track_depot_layout_table[GetRailDepotDirection(ti->tile)] : _track_waypoint_layout_table[GetWaypointAxis(ti->tile)];
|
|
||||||
|
|
||||||
image = drss++->image;
|
|
||||||
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
|
|
||||||
* whether the sprite is railtype dependent. Rewrite this asap */
|
|
||||||
if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset;
|
|
||||||
|
|
||||||
// adjust ground tile for desert
|
|
||||||
// (don't adjust for arctic depots, because snow in depots looks weird)
|
|
||||||
// type >= 4 means waypoints
|
|
||||||
if (IsSnowRailGround(ti->tile) && (_opt.landscape == LT_DESERT || !is_depot)) {
|
|
||||||
if (image != SPR_FLAT_GRASS_TILE) {
|
|
||||||
image += rti->snow_offset; // tile with tracks
|
|
||||||
} else {
|
} else {
|
||||||
image = SPR_FLAT_SNOWY_TILE; // flat ground
|
default_waypoint:
|
||||||
|
// There is no custom layout, fall back to the default graphics
|
||||||
|
dts = &_waypoint_gfx_table[GetWaypointAxis(ti->tile)];
|
||||||
|
relocation = 0;
|
||||||
|
image = dts->ground_sprite + rti->total_offset;
|
||||||
|
if (IsSnowRailGround(ti->tile)) image += rti->snow_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1390,59 +1371,55 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
|
|
||||||
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
||||||
|
|
||||||
for (; drss->image != 0; drss++) {
|
foreach_draw_tile_seq(dtss, dts->seq) {
|
||||||
DrawSpecialBuilding(
|
uint32 image = dtss->image + relocation;
|
||||||
drss->image, is_depot ? rti->total_offset : 0, ti,
|
|
||||||
drss->subcoord_x, drss->subcoord_y, 0,
|
if (_display_opt & DO_TRANS_BUILDINGS) {
|
||||||
drss->width, drss->height, 0x17
|
MAKE_TRANSPARENT(image);
|
||||||
|
} else if (image & PALETTE_MODIFIER_COLOR) {
|
||||||
|
image |= _drawtile_track_palette;
|
||||||
|
}
|
||||||
|
AddSortableSpriteToDraw(
|
||||||
|
image,
|
||||||
|
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
|
||||||
|
dtss->width, dtss->height,
|
||||||
|
dtss->unk, ti->z + dtss->delta_z
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype)
|
|
||||||
|
static void DrawTileSequence(int x, int y, uint32 ground, const DrawTileSeqStruct* dtss, uint32 offset)
|
||||||
{
|
{
|
||||||
uint32 ormod, img;
|
uint32 palette = PLAYER_SPRITE_COLOR(_local_player);
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
|
|
||||||
const DrawTrackSeqStruct *dtss;
|
|
||||||
|
|
||||||
ormod = PLAYER_SPRITE_COLOR(_local_player);
|
|
||||||
|
|
||||||
dtss = _track_depot_layout_table[image];
|
|
||||||
|
|
||||||
x += 33;
|
|
||||||
y += 17;
|
|
||||||
|
|
||||||
img = dtss++->image;
|
|
||||||
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
|
|
||||||
* whether the sprite is railtype dependent. Rewrite this asap */
|
|
||||||
if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
|
|
||||||
DrawSprite(img, x, y);
|
|
||||||
|
|
||||||
|
DrawSprite(ground, x, y);
|
||||||
for (; dtss->image != 0; dtss++) {
|
for (; dtss->image != 0; dtss++) {
|
||||||
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
|
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
|
||||||
image = dtss->image;
|
uint32 image = dtss->image + offset;
|
||||||
if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
|
|
||||||
DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y);
|
if (image & PALETTE_MODIFIER_COLOR) image |= palette;
|
||||||
|
DrawSprite(image, x + pt.x, y + pt.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
|
||||||
|
{
|
||||||
|
const DrawTileSprites* dts = &_depot_gfx_table[dir];
|
||||||
|
uint32 image = dts->ground_sprite;
|
||||||
|
uint32 offset = GetRailTypeInfo(railtype)->total_offset;
|
||||||
|
|
||||||
|
if (image != SPR_FLAT_GRASS_TILE) image += offset;
|
||||||
|
DrawTileSequence(x + 33, y + 17, image, dts->seq, offset);
|
||||||
|
}
|
||||||
|
|
||||||
void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
|
void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
|
||||||
{
|
{
|
||||||
const DrawTrackSeqStruct *dtss = _track_waypoint_layout_table[0];
|
uint32 offset = GetRailTypeInfo(railtype)->total_offset;
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
|
const DrawTileSprites* dts = &_waypoint_gfx_table[AXIS_X];
|
||||||
uint32 img;
|
|
||||||
|
|
||||||
img = dtss++->image;
|
DrawTileSequence(x, y, dts->ground_sprite + offset, dts->seq, 0);
|
||||||
if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
|
|
||||||
DrawSprite(img, x, y);
|
|
||||||
|
|
||||||
for (; dtss->image != 0; dtss++) {
|
|
||||||
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
|
|
||||||
img = dtss->image;
|
|
||||||
if (img & PALETTE_MODIFIER_COLOR) img |= PLAYER_SPRITE_COLOR(_local_player);
|
|
||||||
DrawSprite(img, x + pt.x, y + pt.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SetSignalsData {
|
typedef struct SetSignalsData {
|
||||||
|
|
|
@ -1,66 +1,52 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
typedef struct DrawTrackSeqStruct {
|
#define TILE_SEQ_LINE(img, dx, dy, sx, sy) { dx, dy, 0, sx, sy, 23, img },
|
||||||
SpriteID image;
|
#define TILE_SEQ_END() { 0x80, 0, 0, 0, 0, 0, 0 }
|
||||||
byte subcoord_x;
|
|
||||||
byte subcoord_y;
|
|
||||||
byte width;
|
|
||||||
byte height;
|
|
||||||
} DrawTrackSeqStruct;
|
|
||||||
|
|
||||||
#define TILE_SEQ_BEGIN(x) { x, 0, 0, 0, 0 },
|
|
||||||
#define TILE_SEQ_LINE(a, b, c, d, e) { a, b, c, d, e },
|
|
||||||
#define TILE_SEQ_END() { 0, 0, 0, 0, 0 }
|
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_depot_layout_table_0[] = {
|
static const DrawTileSeqStruct _depot_gfx_NE[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_FLAT_GRASS_TILE)
|
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_NE | PALETTE_MODIFIER_COLOR, 2, 13, 13, 1)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_NE | PALETTE_MODIFIER_COLOR, 2, 13, 13, 1)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_depot_layout_table_1[] = {
|
static const DrawTileSeqStruct _depot_gfx_SE[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_RAIL_TRACK_Y | PALETTE_MODIFIER_COLOR)
|
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SE_1 | PALETTE_MODIFIER_COLOR, 2, 2, 1, 13)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SE_1 | PALETTE_MODIFIER_COLOR, 2, 2, 1, 13)
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SE_2 | PALETTE_MODIFIER_COLOR, 13, 2, 1, 13)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SE_2 | PALETTE_MODIFIER_COLOR, 13, 2, 1, 13)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_depot_layout_table_2[] = {
|
static const DrawTileSeqStruct _depot_gfx_SW[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_RAIL_TRACK_X | PALETTE_MODIFIER_COLOR)
|
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SW_1 | PALETTE_MODIFIER_COLOR, 2, 2, 13, 1)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SW_1 | PALETTE_MODIFIER_COLOR, 2, 2, 13, 1)
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SW_2 | PALETTE_MODIFIER_COLOR, 2, 13, 13, 1)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_SW_2 | PALETTE_MODIFIER_COLOR, 2, 13, 13, 1)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_depot_layout_table_3[] = {
|
static const DrawTileSeqStruct _depot_gfx_NW[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_FLAT_GRASS_TILE)
|
|
||||||
TILE_SEQ_LINE(SPR_RAIL_DEPOT_NW | PALETTE_MODIFIER_COLOR, 13, 2, 1, 13)
|
TILE_SEQ_LINE(SPR_RAIL_DEPOT_NW | PALETTE_MODIFIER_COLOR, 13, 2, 1, 13)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_waypoint_table_0[] = {
|
static const DrawTileSprites const _depot_gfx_table[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_RAIL_TRACK_X | PALETTE_MODIFIER_COLOR)
|
{ SPR_FLAT_GRASS_TILE, _depot_gfx_NE },
|
||||||
|
{ SPR_RAIL_TRACK_Y, _depot_gfx_SE },
|
||||||
|
{ SPR_RAIL_TRACK_X, _depot_gfx_SW },
|
||||||
|
{ SPR_FLAT_GRASS_TILE, _depot_gfx_NW }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static const DrawTileSeqStruct _waypoint_gfx_X[] = {
|
||||||
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_X_1, 0, 0, 16, 5)
|
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_X_1, 0, 0, 16, 5)
|
||||||
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_X_2, 0, 11, 16, 5)
|
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_X_2, 0, 11, 16, 5)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static const DrawTrackSeqStruct _track_waypoint_table_1[] = {
|
static const DrawTileSeqStruct _waypoint_gfx_Y[] = {
|
||||||
TILE_SEQ_BEGIN(SPR_RAIL_TRACK_Y | PALETTE_MODIFIER_COLOR)
|
|
||||||
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_Y_1, 0, 0, 5, 16)
|
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_Y_1, 0, 0, 5, 16)
|
||||||
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_Y_2, 11, 0, 5, 16)
|
TILE_SEQ_LINE(PALETTE_MODIFIER_COLOR | SPR_WAYPOINT_Y_2, 11, 0, 5, 16)
|
||||||
TILE_SEQ_END()
|
TILE_SEQ_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const DrawTileSprites const _waypoint_gfx_table[] = {
|
||||||
static const DrawTrackSeqStruct* const _track_depot_layout_table[] = {
|
{ SPR_RAIL_TRACK_X, _waypoint_gfx_X },
|
||||||
_track_depot_layout_table_0,
|
{ SPR_RAIL_TRACK_Y, _waypoint_gfx_Y }
|
||||||
_track_depot_layout_table_1,
|
|
||||||
_track_depot_layout_table_2,
|
|
||||||
_track_depot_layout_table_3,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const DrawTrackSeqStruct* const _track_waypoint_layout_table[] = {
|
|
||||||
_track_waypoint_table_0,
|
|
||||||
_track_waypoint_table_1,
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue