summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-04 10:01:06 +0000
committercelestar <celestar@openttd.org>2005-07-04 10:01:06 +0000
commitb872cf7f7bd6fdcc8b09903130cb961c004ad5de (patch)
treef320a390d3bb7c8aa0e6fb8514760f3e12d7a627
parentfb8e5f61b181ca34c43d0a0e8d39ee95af2eb60a (diff)
downloadopenttd-b872cf7f7bd6fdcc8b09903130cb961c004ad5de.tar.xz
(svn r2515) -Codechange: Removed a good deal of magic sprite numbers in the rail drawing code, and placed neatly into arrays and enums. This also makes way to implement more railtypes without having to do tons of ugly hacks.
-rw-r--r--rail_cmd.c109
-rw-r--r--table/sprites.h30
2 files changed, 124 insertions, 15 deletions
diff --git a/rail_cmd.c b/rail_cmd.c
index c5e432a0a..a1340428b 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1326,10 +1326,88 @@ static void DrawSpecialBuilding(uint32 image, uint32 tracktype_offs,
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
}
+/* Arrangement of the sprites
+ * 1) Single track in Y direction
+ * 2) Northern and southern trackbits set
+ * 3) "Basis" for 3-way switch
+ * 4) Single rail in Y direction without ground sprite
+ * 5) as above, X direction
+ * 6) as above, nortern track
+ * 7) as above, southern track
+ * 8) as above, eastern track
+ * 9) as above, western track
+ * 10) the offset of the snow sprites
+ */
+static SpriteID RailSpriteIDs[] = {
+ SPR_RAIL_TRACK_Y,
+ SPR_RAIL_TRACK_N_S,
+ SPR_RAIL_TRACK_BASE,
+ SPR_RAIL_SINGLE_Y,
+ SPR_RAIL_SINGLE_X,
+ SPR_RAIL_SINGLE_NORTH,
+ SPR_RAIL_SINGLE_SOUTH,
+ SPR_RAIL_SINGLE_EAST,
+ SPR_RAIL_SINGLE_WEST,
+ SPR_RAIL_SNOW_OFFSET,
+};
+
+static SpriteID MonoSpriteIDs[] = {
+ SPR_MONO_TRACK_Y,
+ SPR_MONO_TRACK_N_S,
+ SPR_MONO_TRACK_BASE,
+ SPR_MONO_SINGLE_Y,
+ SPR_MONO_SINGLE_X,
+ SPR_MONO_SINGLE_NORTH,
+ SPR_MONO_SINGLE_SOUTH,
+ SPR_MONO_SINGLE_EAST,
+ SPR_MONO_SINGLE_WEST,
+ SPR_MONO_SNOW_OFFSET,
+};
+
+static SpriteID MaglevSpriteIDs[] = {
+ SPR_MGLV_TRACK_Y,
+ SPR_MGLV_TRACK_N_S,
+ SPR_MGLV_TRACK_BASE,
+ SPR_MGLV_SINGLE_Y,
+ SPR_MGLV_SINGLE_X,
+ SPR_MGLV_SINGLE_NORTH,
+ SPR_MGLV_SINGLE_SOUTH,
+ SPR_MGLV_SINGLE_EAST,
+ SPR_MGLV_SINGLE_WEST,
+ SPR_MGLV_SNOW_OFFSET,
+};
+
+/** Sprite reference enum */
+enum {
+ TRACK_Y,
+ TRACK_N_S,
+ TRACK_BASE,
+ SINGLE_Y,
+ SINGLE_X,
+ SINGLE_NORTH,
+ SINGLE_SOUTH,
+ SINGLE_EAST,
+ SINGLE_WEST,
+ SNOW_OFFSET,
+};
+
+/** Contains the pointers to the arrays *SpriteIDs.
+ * There, all the Sprites are recorded that the
+ * Track Draw system requireds. Note: Pointer arrangement
+ * must match the tracktype number
+ */
+static SpriteID *TrackSpriteIDs[RAILTYPE_END] = {
+ RailSpriteIDs,
+ MonoSpriteIDs,
+ MaglevSpriteIDs
+};
+
static void DrawTile_Track(TileInfo *ti)
{
- uint32 tracktype_offs, image;
+ uint32 tracktype_offs;
byte m5;
+ SpriteID *TrackSet = TrackSpriteIDs[GetRailType(ti->tile)];
+ uint32 image; //XXX ok why the hell is SpriteID 16 bit when all the drawing routines need 32?
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
@@ -1344,7 +1422,7 @@ static void DrawTile_Track(TileInfo *ti)
special = false;
// select the sprite to use based on the map5 byte.
- (image = 0x3F3, m5 == TRACK_BIT_DIAG2) ||
+ (image = TrackSet[TRACK_Y], m5 == TRACK_BIT_DIAG2) ||
(image++, m5 == TRACK_BIT_DIAG1) ||
(image++, m5 == TRACK_BIT_UPPER) ||
(image++, m5 == TRACK_BIT_LOWER) ||
@@ -1352,12 +1430,12 @@ static void DrawTile_Track(TileInfo *ti)
(image++, m5 == TRACK_BIT_LEFT) ||
(image++, m5 == (TRACK_BIT_DIAG1|TRACK_BIT_DIAG2)) ||
- (image = 0x40B, m5 == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) ||
+ (image = TrackSet[TRACK_N_S], m5 == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) ||
(image++, m5 == (TRACK_BIT_LEFT|TRACK_BIT_RIGHT)) ||
(special=true, false) ||
- (image = 0x3FA, !(m5 & (TRACK_BIT_RIGHT|TRACK_BIT_UPPER|TRACK_BIT_DIAG1))) ||
+ (image = TrackSet[TRACK_BASE], !(m5 & (TRACK_BIT_RIGHT|TRACK_BIT_UPPER|TRACK_BIT_DIAG1))) ||
(image++, !(m5 & (TRACK_BIT_LEFT|TRACK_BIT_LOWER|TRACK_BIT_DIAG1))) ||
(image++, !(m5 & (TRACK_BIT_LEFT|TRACK_BIT_UPPER|TRACK_BIT_DIAG2))) ||
(image++, !(m5 & (TRACK_BIT_RIGHT|TRACK_BIT_LOWER|TRACK_BIT_DIAG2))) ||
@@ -1368,23 +1446,24 @@ static void DrawTile_Track(TileInfo *ti)
if (f) DrawFoundation(ti, f);
// default sloped sprites..
- if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
+ if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + TrackSet[TRACK_Y];
}
- if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN)
+ if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN) {
image = (image & 0xFFFF) | 0x3178000; // use a brown palette
- else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT)
- image += 26;
+ } else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT) {
+ image += TrackSet[SNOW_OFFSET];
+ }
- DrawGroundSprite(image + tracktype_offs);
+ DrawGroundSprite(image);
if (special) {
- if (m5 & TRACK_BIT_DIAG1) DrawGroundSprite(0x3ED + tracktype_offs);
- if (m5 & TRACK_BIT_DIAG2) DrawGroundSprite(0x3EE + tracktype_offs);
- if (m5 & TRACK_BIT_UPPER) DrawGroundSprite(0x3EF + tracktype_offs);
- if (m5 & TRACK_BIT_LOWER) DrawGroundSprite(0x3F0 + tracktype_offs);
- if (m5 & TRACK_BIT_LEFT) DrawGroundSprite(0x3F2 + tracktype_offs);
- if (m5 & TRACK_BIT_RIGHT) DrawGroundSprite(0x3F1 + tracktype_offs);
+ if (m5 & TRACK_BIT_DIAG1) DrawGroundSprite(TrackSet[SINGLE_Y]);
+ if (m5 & TRACK_BIT_DIAG2) DrawGroundSprite(TrackSet[SINGLE_X]);
+ if (m5 & TRACK_BIT_UPPER) DrawGroundSprite(TrackSet[SINGLE_NORTH]);
+ if (m5 & TRACK_BIT_LOWER) DrawGroundSprite(TrackSet[SINGLE_SOUTH]);
+ if (m5 & TRACK_BIT_LEFT) DrawGroundSprite(TrackSet[SINGLE_WEST]);
+ if (m5 & TRACK_BIT_RIGHT) DrawGroundSprite(TrackSet[SINGLE_EAST]);
}
if (_display_opt & DO_FULL_DETAIL) {
diff --git a/table/sprites.h b/table/sprites.h
index 9af9bb253..91b350de6 100644
--- a/table/sprites.h
+++ b/table/sprites.h
@@ -112,8 +112,20 @@ enum Sprites {
SPR_BOUGHT_LAND = 4790,
/* sprites for rail and rail stations*/
+ SPR_RAIL_SNOW_OFFSET = 26,
+ SPR_MONO_SNOW_OFFSET = 26,
+ SPR_MGLV_SNOW_OFFSET = 26,
+
+ SPR_RAIL_SINGLE_Y = 1005,
+ SPR_RAIL_SINGLE_X = 1006,
+ SPR_RAIL_SINGLE_NORTH = 1007,
+ SPR_RAIL_SINGLE_SOUTH = 1008,
+ SPR_RAIL_SINGLE_EAST = 1009,
+ SPR_RAIL_SINGLE_WEST = 1010,
SPR_RAIL_TRACK_Y = 1011,
SPR_RAIL_TRACK_X = 1012,
+ SPR_RAIL_TRACK_BASE = 1018,
+ SPR_RAIL_TRACK_N_S = 1035,
SPR_RAIL_TRACK_Y_SNOW = 1037,
SPR_RAIL_TRACK_X_SNOW = 1038,
SPR_RAIL_DEPOT_SE_1 = 1063,
@@ -140,6 +152,24 @@ enum Sprites {
SPR_RAIL_ROOF_GLASS_Y_TILE_A = 1084,
SPR_RAIL_ROOF_GLASS_X_TILE_B = 1085, //second half of the roof glass
SPR_RAIL_ROOF_GLASS_Y_TILE_B = 1086,
+ SPR_MONO_SINGLE_Y = 1087,
+ SPR_MONO_SINGLE_X = 1088,
+ SPR_MONO_SINGLE_NORTH = 1089,
+ SPR_MONO_SINGLE_SOUTH = 1090,
+ SPR_MONO_SINGLE_EAST = 1091,
+ SPR_MONO_SINGLE_WEST = 1092,
+ SPR_MONO_TRACK_Y = 1093,
+ SPR_MONO_TRACK_BASE = 1100,
+ SPR_MONO_TRACK_N_S = 1117,
+ SPR_MGLV_SINGLE_Y = 1169,
+ SPR_MGLV_SINGLE_X = 1170,
+ SPR_MGLV_SINGLE_NORTH = 1171,
+ SPR_MGLV_SINGLE_SOUTH = 1172,
+ SPR_MGLV_SINGLE_EAST = 1173,
+ SPR_MGLV_SINGLE_WEST = 1174,
+ SPR_MGLV_TRACK_Y = 1175,
+ SPR_MGLV_TRACK_BASE = 1182,
+ SPR_MGLV_TRACK_N_S = 1199,
SPR_WAYPOINT_X_1 = SPR_OPENTTD_BASE + 18,
SPR_WAYPOINT_X_2 = SPR_OPENTTD_BASE + 19,
SPR_WAYPOINT_Y_1 = SPR_OPENTTD_BASE + 20,