summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rail.h2
-rw-r--r--rail_cmd.c136
2 files changed, 82 insertions, 56 deletions
diff --git a/rail.h b/rail.h
index d7a7d6908..be03813be 100644
--- a/rail.h
+++ b/rail.h
@@ -576,4 +576,6 @@ static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
}
+void DrawTrackBits(TileInfo *ti, TrackBits track, bool earth, bool snow, bool flat);
+
#endif /* RAIL_H */
diff --git a/rail_cmd.c b/rail_cmd.c
index 8720dae0c..99ebfd322 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1366,76 +1366,100 @@ static void DrawSpecialBuilding(uint32 image, uint32 offset,
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
}
-static void DrawTile_Track(TileInfo *ti)
+/**
+ * Draw ground sprite and track bits
+ * @param ti TileInfo
+ * @param track TrackBits to draw
+ * @param earth Draw as earth
+ * @param snow Draw as snow
+ * @param flat Always draw foundation
+ */
+void DrawTrackBits(TileInfo *ti, TrackBits track, bool earth, bool snow, bool flat)
{
- byte m5;
const RailtypeInfo *rti = GetRailTypeInfo(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)));
+ PalSpriteID image;
+ bool junction = false;
+
+ // Select the sprite to use.
+ (image = rti->base_sprites.track_y, track == TRACK_BIT_DIAG2) ||
+ (image++, track == TRACK_BIT_DIAG1) ||
+ (image++, track == TRACK_BIT_UPPER) ||
+ (image++, track == TRACK_BIT_LOWER) ||
+ (image++, track == TRACK_BIT_RIGHT) ||
+ (image++, track == TRACK_BIT_LEFT) ||
+ (image++, track == (TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2)) ||
+
+ (image = rti->base_sprites.track_ns, track == (TRACK_BIT_UPPER | TRACK_BIT_LOWER)) ||
+ (image++, track == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)) ||
+
+ (junction = true, false) ||
+ (image = rti->base_sprites.ground, !(track & (TRACK_BIT_RIGHT | TRACK_BIT_UPPER | TRACK_BIT_DIAG1))) ||
+ (image++, !(track & (TRACK_BIT_LEFT | TRACK_BIT_LOWER | TRACK_BIT_DIAG1))) ||
+ (image++, !(track & (TRACK_BIT_LEFT | TRACK_BIT_UPPER | TRACK_BIT_DIAG2))) ||
+ (image++, !(track & (TRACK_BIT_RIGHT | TRACK_BIT_LOWER | TRACK_BIT_DIAG2))) ||
+ (image++, true);
- m5 = (byte)ti->map5;
- if (!(m5 & RAIL_TYPE_SPECIAL)) {
- bool special;
-
- m5 &= TRACK_BIT_MASK;
+ if (ti->tileh != 0) {
+ int foundation;
- special = false;
+ if (flat) {
+ foundation = ti->tileh;
+ } else {
+ foundation = GetRailFoundation(ti->tileh, track);
+ }
- // select the sprite to use based on the map5 byte.
- (image = rti->base_sprites.track_y, m5 == TRACK_BIT_DIAG2) ||
- (image++, m5 == TRACK_BIT_DIAG1) ||
- (image++, m5 == TRACK_BIT_UPPER) ||
- (image++, m5 == TRACK_BIT_LOWER) ||
- (image++, m5 == TRACK_BIT_RIGHT) ||
- (image++, m5 == TRACK_BIT_LEFT) ||
- (image++, m5 == (TRACK_BIT_DIAG1|TRACK_BIT_DIAG2)) ||
+ if (foundation != 0)
+ DrawFoundation(ti, foundation);
- (image = rti->base_sprites.track_ns, m5 == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) ||
- (image++, m5 == (TRACK_BIT_LEFT|TRACK_BIT_RIGHT)) ||
+ // DrawFoundation() modifies ti.
+ // Default sloped sprites..
+ if (ti->tileh != 0)
+ image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
+ }
- (special=true, false) ||
+ if (earth) {
+ image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // Use brown palette
+ } else if (snow) {
+ image += rti->snow_offset;
+ }
- (image = rti->base_sprites.ground, !(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))) ||
- (image++, true);
+ DrawGroundSprite(image);
- if (ti->tileh != 0) {
- int f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
- if (f) DrawFoundation(ti, f);
+ // Draw track pieces individually for junction tiles
+ if (junction) {
+ if (track & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y);
+ if (track & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x);
+ if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n);
+ if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s);
+ if (track & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w);
+ if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e);
+ }
- // default sloped sprites..
- if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
- }
+ if (_debug_pbs_level >= 1) {
+ byte pbs = PBSTileReserved(ti->tile) & track;
+ if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y | PALETTE_CRASH);
+ if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x | PALETTE_CRASH);
+ if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n | PALETTE_CRASH);
+ if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s | PALETTE_CRASH);
+ if (pbs & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w | PALETTE_CRASH);
+ if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
+ }
+}
- if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN) {
- image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // use a brown palette
- } else if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT) {
- image += rti->snow_offset;
- }
+static void DrawTile_Track(TileInfo *ti)
+{
+ byte m5;
+ const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
+ PalSpriteID image;
- DrawGroundSprite(image);
+ _drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
- if (special) {
- if (m5 & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y);
- if (m5 & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x);
- if (m5 & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n);
- if (m5 & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s);
- if (m5 & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w);
- if (m5 & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e);
- }
+ m5 = (byte)ti->map5;
+ if (!(m5 & RAIL_TYPE_SPECIAL)) {
+ bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
+ bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
- if (_debug_pbs_level >= 1) {
- byte pbs = PBSTileReserved(ti->tile);
- if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y | PALETTE_CRASH);
- if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x | PALETTE_CRASH);
- if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n | PALETTE_CRASH);
- if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s | PALETTE_CRASH);
- if (pbs & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w | PALETTE_CRASH);
- if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
- }
+ DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
if (_display_opt & DO_FULL_DETAIL) {
_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);