summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c4
-rw-r--r--pathfind.c2
-rw-r--r--rail.h8
-rw-r--r--rail_cmd.c76
-rw-r--r--rail_map.h5
-rw-r--r--road_cmd.c2
-rw-r--r--train_cmd.c3
-rw-r--r--tunnelbridge_cmd.c3
-rw-r--r--water_cmd.c19
-rw-r--r--waypoint.c7
10 files changed, 66 insertions, 63 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index df24bff56..c7142bb56 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -96,7 +96,7 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
return r;
if (IsTileType(tile, MP_RAILWAY)) {
- static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
+ static const TrackBits _railway_modes[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT };
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4};
@@ -113,7 +113,7 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
// If we have a single diagonal track there, the other side of
// tile can be terraformed.
- if ((_m[tile].m5 & ~0x40) == _railway_modes[mode]) {
+ if (IsPlainRailTile(tile) && GetTrackBits(tile) == _railway_modes[mode]) {
if (ts->direction == 1) return 0;
skip_clear = true;
}
diff --git a/pathfind.c b/pathfind.c
index f548c90e2..b70e51887 100644
--- a/pathfind.c
+++ b/pathfind.c
@@ -782,7 +782,7 @@ start_at:
}
/* Regular rail tile, determine which tracks exist. */
- allbits = _m[tile].m5 & TRACK_BIT_MASK;
+ allbits = GetTrackBits(tile);
/* Which tracks are reachable? */
bits = allbits & DiagdirReachesTracks(direction);
diff --git a/rail.h b/rail.h
index a9b3c3874..83ed575b7 100644
--- a/rail.h
+++ b/rail.h
@@ -213,14 +213,6 @@ static inline bool IsPlainRailTile(TileIndex tile)
return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS;
}
-/**
- * Returns the tracks present on the given plain rail tile (IsPlainRailTile())
- */
-static inline TrackBits GetTrackBits(TileIndex tile)
-{
- assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
- return (TrackBits)(_m[tile].m5 & TRACK_BIT_MASK);
-}
/**
* Returns whether the given track is present on the given tile. Tile must be
diff --git a/rail_cmd.c b/rail_cmd.c
index ed8fd7f26..21c1e92f5 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -130,7 +130,7 @@ static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags
}
-static const byte _valid_tileh_slopes[][15] = {
+static const TrackBits _valid_tileh_slopes[][15] = {
// set of normal ones
{
@@ -199,7 +199,7 @@ static const byte _valid_tileh_slopes[][15] = {
},
};
-uint GetRailFoundation(uint tileh, uint bits)
+uint GetRailFoundation(uint tileh, TrackBits bits)
{
int i;
@@ -350,8 +350,9 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
break;
}
- if (IsLevelCrossing(tile) && (m5 & 0x08 ? TRACK_X : TRACK_Y) == track)
+ if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
return_cmd_error(STR_1007_ALREADY_BUILT);
+ }
/* FALLTHROUGH */
default:
@@ -1341,18 +1342,17 @@ static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow,
static void DrawTile_Track(TileInfo *ti)
{
- byte m5;
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
PalSpriteID image;
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
- m5 = (byte)ti->map5;
if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
+ TrackBits rails = GetTrackBits(ti->tile);
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;
- DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
+ DrawTrackBits(ti, rails, earth, snow, false);
if (_display_opt & DO_FULL_DETAIL) {
_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
@@ -1370,21 +1370,21 @@ static void DrawTile_Track(TileInfo *ti)
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
- if (!(m5 & TRACK_BIT_Y)) {
- if (!(m5 & TRACK_BIT_X)) {
- if (m5 & TRACK_BIT_LEFT) {
+ if (!(rails & TRACK_BIT_Y)) {
+ if (!(rails & TRACK_BIT_X)) {
+ if (rails & TRACK_BIT_LEFT) {
MAYBE_DRAW_SIGNAL(2, 0x509, 0);
MAYBE_DRAW_SIGNAL(3, 0x507, 1);
}
- if (m5 & TRACK_BIT_RIGHT) {
+ if (rails & TRACK_BIT_RIGHT) {
MAYBE_DRAW_SIGNAL(0, 0x509, 2);
MAYBE_DRAW_SIGNAL(1, 0x507, 3);
}
- if (m5 & TRACK_BIT_UPPER) {
+ if (rails & TRACK_BIT_UPPER) {
MAYBE_DRAW_SIGNAL(3, 0x505, 4);
MAYBE_DRAW_SIGNAL(2, 0x503, 5);
}
- if (m5 & TRACK_BIT_LOWER) {
+ if (rails & TRACK_BIT_LOWER) {
MAYBE_DRAW_SIGNAL(1, 0x505, 6);
MAYBE_DRAW_SIGNAL(0, 0x503, 7);
}
@@ -1400,7 +1400,7 @@ static void DrawTile_Track(TileInfo *ti)
} else {
/* draw depots / waypoints */
const DrawTrackSeqStruct *drss;
- byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints
+ byte type = ti->map5 & 0x3F; // 0-3: depots, 4-5: waypoints
if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
@@ -1412,7 +1412,7 @@ static void DrawTile_Track(TileInfo *ti)
if (stat != NULL) {
DrawTileSeqStruct const *seq;
// emulate station tile - open with building
- const DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
+ const DrawTileSprites *cust = &stat->renderdata[2 + (ti->map5 & 0x1)];
uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
/* We don't touch the 0x8000 bit. In all this
@@ -1790,8 +1790,10 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
// check if it's a foundation
if (ti->tileh != 0) {
- if ((ti->map5 & 0x80) == 0) {
- uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
+ if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
+ return z + 8;
+ } else {
+ uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
if (f != 0) {
if (f < 15) {
@@ -1801,9 +1803,6 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
// inclined foundation
th = _inclined_tileh[f - 15];
}
- } else if ((ti->map5 & RAIL_TILE_TYPE_MASK) == RAIL_TYPE_DEPOT_WAYPOINT) {
- // depot or waypoint
- return z + 8;
}
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, th) + z;
}
@@ -1814,8 +1813,10 @@ static uint GetSlopeTileh_Track(const TileInfo *ti)
{
// check if it's a foundation
if (ti->tileh != 0) {
- if ((ti->map5 & 0x80) == 0) {
- uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
+ if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
+ return 0;
+ } else {
+ uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
if (f != 0) {
if (f < 15) {
// leveled foundation
@@ -1824,9 +1825,6 @@ static uint GetSlopeTileh_Track(const TileInfo *ti)
// inclined foundation
return _inclined_tileh[f - 15];
}
- } else if ((ti->map5 & 0xC0) == 0xC0) {
- // depot or waypoint
- return 0;
}
}
return ti->tileh;
@@ -1876,7 +1874,7 @@ static void TileLoop_Track(TileIndex tile)
if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
/* determine direction of fence */
- TrackBits rail = _m[tile].m5 & TRACK_BIT_MASK;
+ TrackBits rail = GetTrackBits(tile);
switch (rail) {
case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
@@ -1964,20 +1962,17 @@ modify_me:;
static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
{
- byte m5, a;
+ byte a;
uint16 b;
- uint32 ret;
if (mode != TRANSPORT_RAIL) return 0;
- m5 = _m[tile].m5;
-
if (GetRailTileType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
- ret = (m5 | (m5 << 8)) & 0x3F3F;
+ TrackBits rails = GetTrackBits(tile);
+ uint32 ret = rails * 0x101;
+
if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
- if ( (ret & 0xFF) == 3)
- /* Diagonal crossing? */
- ret |= 0x40;
+ if (rails == TRACK_BIT_CROSS) ret |= 0x40;
} else {
/* has_signals */
@@ -1998,13 +1993,14 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
if ((b & 0x20) == 0) ret |= 0x20080000;
if ((b & 0x10) == 0) ret |= 0x08200000;
}
- } else if (m5 & 0x40) {
- static const byte _train_spec_tracks[6] = {1,2,1,2,1,2};
- m5 = _train_spec_tracks[m5 & 0x3F];
- ret = (m5 << 8) + m5;
- } else
- return 0;
- return ret;
+ return ret;
+ } else {
+ if (_m[tile].m5 & 0x40) {
+ return GetRailWaypointBits(tile) * 0x101;
+ } else {
+ return 0;
+ }
+ }
}
static void ClickTile_Track(TileIndex tile)
diff --git a/rail_map.h b/rail_map.h
index 42d790982..1f88113c0 100644
--- a/rail_map.h
+++ b/rail_map.h
@@ -105,6 +105,11 @@ typedef enum TrackBits {
TRACK_BIT_MASK = 0x3FU
} TrackBits;
+static inline TrackBits GetTrackBits(TileIndex tile)
+{
+ return (TrackBits)GB(_m[tile].m5, 0, 6);
+}
+
static inline DiagDirection GetRailDepotDirection(TileIndex t)
{
diff --git a/road_cmd.c b/road_cmd.c
index 58e35721a..a0c7066e3 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -1034,7 +1034,7 @@ static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode)
switch (mode) {
case TRANSPORT_RAIL:
if (!IsLevelCrossing(tile)) return 0;
- return _m[tile].m5 & 8 ? 0x101 : 0x202;
+ return GetCrossingRailBits(tile) * 0x101;
case TRANSPORT_ROAD:
switch (GetRoadType(tile)) {
diff --git a/train_cmd.c b/train_cmd.c
index 57dff8b87..189947c99 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -2652,7 +2652,8 @@ static const DiagDirection _otherside_signal_directions[] = {
static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
{
- if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) {
+ if (IsTileType(tile, MP_RAILWAY) &&
+ GetRailTileType(tile) == RAIL_TYPE_SIGNALS) {
uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]);
UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
}
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 0095fca85..1d6159eb1 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -328,7 +328,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
break;
case MP_RAILWAY:
- if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
+ if (GetRailTileType(tile) != RAIL_TYPE_NORMAL ||
+ GetTrackBits(tile) != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
goto not_valid_below;
}
transport_under = TRANSPORT_RAIL;
diff --git a/water_cmd.c b/water_cmd.c
index 284aa1084..a67361d63 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -519,14 +519,21 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
// make coast..
switch (GetTileType(target)) {
case MP_RAILWAY: {
- uint slope = GetTileSlope(target, NULL);
- byte tracks = GB(_m[target].m5, 0, 6);
+ TrackBits tracks;
+ uint slope;
+
+ if (!IsPlainRailTile(tile)) break;
+
+ tracks = GetTrackBits(target);
+ slope = GetTileSlope(target, NULL);
if (!(
- (slope == 1 && tracks == 0x20) ||
- (slope == 2 && tracks == 0x04) ||
- (slope == 4 && tracks == 0x10) ||
- (slope == 8 && tracks == 0x08)))
+ (slope == 1 && tracks == TRACK_BIT_RIGHT) &&
+ (slope == 2 && tracks == TRACK_BIT_UPPER) &&
+ (slope == 4 && tracks == TRACK_BIT_LEFT) &&
+ (slope == 8 && tracks == TRACK_BIT_LOWER)
+ )) {
break;
+ }
}
/* FALLTHROUGH */
diff --git a/waypoint.c b/waypoint.c
index cb51b2ef3..7d2087a35 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -182,9 +182,10 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* if custom gfx are used, make sure it is within bounds */
if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR;
- if (!IsTileType(tile, MP_RAILWAY) || (
- (axis = AXIS_X, _m[tile].m5 != TRACK_BIT_X) &&
- (axis = AXIS_Y, _m[tile].m5 != TRACK_BIT_Y)
+ if (!IsTileType(tile, MP_RAILWAY) ||
+ GetRailTileType(tile) != RAIL_TYPE_NORMAL || (
+ (axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) &&
+ (axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y)
)) {
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
}