summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rail.c26
-rw-r--r--rail_cmd.c4
-rw-r--r--rail_map.h28
-rw-r--r--road_cmd.c12
-rw-r--r--station_cmd.c8
-rw-r--r--train_cmd.c2
-rw-r--r--train_gui.c2
-rw-r--r--tunnelbridge_cmd.c33
-rw-r--r--waypoint.c4
9 files changed, 68 insertions, 51 deletions
diff --git a/rail.c b/rail.c
index 6ff2c54dc..6ca3959ac 100644
--- a/rail.c
+++ b/rail.c
@@ -108,43 +108,39 @@ const Trackdir _reverse_trackdir[] = {
RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
{
- RailType type = INVALID_RAILTYPE;
DiagDirection exitdir = TrackdirToExitdir(trackdir);
switch (GetTileType(tile)) {
case MP_RAILWAY:
- /* railway track */
- type = _m[tile].m3 & RAILTYPE_MASK;
- break;
+ return GetRailType(tile);
+
case MP_STREET:
/* rail/road crossing */
- if (IsLevelCrossing(tile))
- type = _m[tile].m4 & RAILTYPE_MASK;
+ if (IsLevelCrossing(tile)) return GetRailTypeCrossing(tile);
break;
+
case MP_STATION:
- if (IsTrainStationTile(tile))
- type = _m[tile].m3 & RAILTYPE_MASK;
+ if (IsTrainStationTile(tile)) return GetRailType(tile);
break;
+
case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) {
if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
- return _m[tile].m3 & RAILTYPE_MASK;
+ return GetRailType(tile);
}
} else {
if (IsBridgeRamp(tile)) {
if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
- return _m[tile].m3 & RAILTYPE_MASK;
+ return GetRailType(tile);
}
} else {
if (GetBridgeAxis(tile) == DiagDirToAxis(exitdir)) {
if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
- /* on the bridge */
- return (_m[tile].m3 >> 4) & RAILTYPE_MASK;
+ return GetRailTypeOnBridge(tile);
}
} else {
if (IsTransportUnderBridge(tile) &&
GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
- /* under the bridge */
- return _m[tile].m3 & RAILTYPE_MASK;
+ return GetRailType(tile);
}
}
}
@@ -154,5 +150,5 @@ RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
default:
break;
}
- return type;
+ return INVALID_RAILTYPE;
}
diff --git a/rail_cmd.c b/rail_cmd.c
index f7d6d22b3..8b3473bd1 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -317,7 +317,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
if (m5 & RAIL_TYPE_SPECIAL ||
!IsTileOwner(tile, _current_player) ||
- GB(_m[tile].m3, 0, 4) != p1) {
+ GetRailType(tile) != p1) {
// Get detailed error message
return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
}
@@ -944,7 +944,7 @@ static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
// change type.
if (exec) {
- SB(_m[tile].m3, 0, 4, totype);
+ SetRailType(tile, totype);
MarkTileDirtyByTile(tile);
}
diff --git a/rail_map.h b/rail_map.h
index b6f9512fe..e03893470 100644
--- a/rail_map.h
+++ b/rail_map.h
@@ -36,7 +36,6 @@ typedef enum RailTypes {
RAILTYPE_MONO = 1,
RAILTYPE_MAGLEV = 2,
RAILTYPE_END,
- RAILTYPE_MASK = 0x3,
INVALID_RAILTYPE = 0xFF
} RailType;
@@ -45,6 +44,33 @@ static inline RailType GetRailType(TileIndex t)
return (RailType)GB(_m[t].m3, 0, 4);
}
+// TODO remove this by moving to the same bits as GetRailType()
+static inline RailType GetRailTypeCrossing(TileIndex t)
+{
+ return (RailType)GB(_m[t].m4, 0, 4);
+}
+
+static inline RailType GetRailTypeOnBridge(TileIndex t)
+{
+ return (RailType)GB(_m[t].m3, 4, 4);
+}
+
+static inline void SetRailType(TileIndex t, RailType r)
+{
+ SB(_m[t].m3, 0, 4, r);
+}
+
+// TODO remove this by moving to the same bits as SetRailType()
+static inline void SetRailTypeCrossing(TileIndex t, RailType r)
+{
+ SB(_m[t].m4, 0, 4, r);
+}
+
+static inline void SetRailTypeOnBridge(TileIndex t, RailType r)
+{
+ SB(_m[t].m3, 4, 4, r);
+}
+
/** These are used to specify a single track.
* Can be translated to a trackbit with TrackToTrackbit */
diff --git a/road_cmd.c b/road_cmd.c
index 5441075ce..58e35721a 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -195,7 +195,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
- MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GB(_m[tile].m4, 0, 4));
+ MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
MarkTileDirtyByTile(tile);
}
return cost;
@@ -345,7 +345,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
if (flags & DC_EXEC) {
- MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GB(_m[tile].m3, 0, 4), p2);
+ MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), p2);
MarkTileDirtyByTile(tile);
}
return _price.build_road * 2;
@@ -428,12 +428,10 @@ int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec)
// not owned by me?
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
- // tile is already of requested type?
- if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
+ if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR;
if (exec) {
- // change type.
- SB(_m[tile].m4, 0, 4, totype);
+ SetRailTypeCrossing(tile, totype);
MarkTileDirtyByTile(tile);
}
@@ -773,7 +771,7 @@ static void DrawTile_Road(TileInfo *ti)
case ROAD_CROSSING: {
if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
- image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing;
+ image = GetRailTypeInfo(GetRailTypeCrossing(ti->tile))->base_sprites.crossing;
if (GB(ti->map5, 3, 1) == 0) image++; /* direction */
diff --git a/station_cmd.c b/station_cmd.c
index edb05f6d3..4eaeb3003 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -1256,12 +1256,10 @@ int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
// tile is not a railroad station?
if (_m[tile].m5 >= 8) return CMD_ERROR;
- // tile is already of requested type?
- if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
+ if (GetRailType(tile) == totype) return CMD_ERROR;
if (exec) {
- // change type.
- SB(_m[tile].m3, 0, 4, totype);
+ SetRailType(tile, totype);
MarkTileDirtyByTile(tile);
}
@@ -1949,7 +1947,7 @@ static void DrawTile_Station(TileInfo *ti)
uint32 image;
const DrawTileSeqStruct *dtss;
const DrawTileSprites *t = NULL;
- RailType railtype = GB(_m[ti->tile].m3, 0, 4);
+ RailType railtype = GetRailType(ti->tile);
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
SpriteID offset;
uint32 relocation = 0;
diff --git a/train_cmd.c b/train_cmd.c
index 959291878..7bff82804 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -2562,7 +2562,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
return
IsTileOwner(tile, v->owner) && (
!IsFrontEngine(v) ||
- IsCompatibleRail(v->u.rail.railtype, GB(_m[tile].m4, 0, 4))
+ IsCompatibleRail(v->u.rail.railtype, GetRailTypeCrossing(tile))
);
default:
diff --git a/train_gui.c b/train_gui.c
index d8be51d8b..6325db403 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -335,7 +335,7 @@ static void ShowBuildTrainWindow(TileIndex tile)
if (tile != 0) {
w->caption_color = GetTileOwner(tile);
- WP(w,buildtrain_d).railtype = GB(_m[tile].m3, 0, 4);
+ WP(w,buildtrain_d).railtype = GetRailType(tile);
} else {
w->caption_color = _local_player;
WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player));
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 13e76260f..58b72bf2a 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -333,7 +333,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
transport_under = TRANSPORT_RAIL;
owner_under = GetTileOwner(tile);
- rail_under = GB(_m[tile].m3, 0, 4);
+ rail_under = GetRailType(tile);
break;
case MP_STREET:
@@ -672,7 +672,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
for (c = tile + delta; c != endtile; c += delta) {
if (IsTransportUnderBridge(c)) {
if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
- MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GB(_m[c].m3, 0, 3));
+ MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GetRailType(tile));
} else {
uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
@@ -721,14 +721,14 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
if (!CheckTileOwnership(tile)) return CMD_ERROR;
- if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
+ if (GetRailType(tile) == totype) return CMD_ERROR;
endtile = CheckTunnelBusy(tile, &length);
if (endtile == INVALID_TILE) return CMD_ERROR;
if (exec) {
- SB(_m[tile].m3, 0, 4, totype);
- SB(_m[endtile].m3, 0, 4, totype);
+ SetRailType(tile, totype);
+ SetRailType(endtile, totype);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
}
@@ -741,11 +741,10 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
return CMD_ERROR;
- // tile is already of requested type?
- if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
- // change type.
+ if (GetRailType(tile) == totype) return CMD_ERROR;
+
if (exec) {
- SB(_m[tile].m3, 0, 4, totype);
+ SetRailType(tile, totype);
MarkTileDirtyByTile(tile);
}
return _price.build_rail >> 1;
@@ -771,11 +770,11 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
return CMD_ERROR;
}
- if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
+ if (GetRailType(tile) == totype) return CMD_ERROR;
if (exec) {
- SB(_m[tile].m3, 0, 4, totype);
- SB(_m[endtile].m3, 0, 4, totype);
+ SetRailType(tile, totype);
+ SetRailType(endtile, totype);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
}
@@ -783,7 +782,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
delta = TileOffsByDir(GetBridgeRampDirection(tile));
for (tile += delta; tile != endtile; tile += delta) {
if (exec) {
- SB(_m[tile].m3, 4, 4, totype);
+ SetRailTypeOnBridge(tile, totype);
MarkTileDirtyByTile(tile);
}
cost += _price.build_rail >> 1;
@@ -918,7 +917,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (IsTunnel(ti->tile)) {
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
- image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel;
+ image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
} else {
image = SPR_TUNNEL_ENTRY_REAR_ROAD;
}
@@ -936,9 +935,9 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
RailType rt;
if (IsBridgeRamp(ti->tile)) {
- rt = GB(_m[ti->tile].m3, 0, 3);
+ rt = GetRailType(ti->tile);
} else {
- rt = GB(_m[ti->tile].m3, 4, 3);
+ rt = GetRailTypeOnBridge(ti->tile);
}
base_offset = GetRailTypeInfo(rt)->bridge_offset;
@@ -987,7 +986,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
}
if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) {
- const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4));
+ const RailtypeInfo* rti = GetRailTypeInfo(GetRailType(ti->tile));
if (ti->tileh == 0) {
image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);
diff --git a/waypoint.c b/waypoint.c
index 8ff180875..cb51b2ef3 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -213,7 +213,7 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
const StationSpec *spec = NULL;
- MakeRailWaypoint(tile, GetTileOwner(tile), axis, GB(_m[tile].m3, 0, 4), wp->index);
+ MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index);
MarkTileDirtyByTile(tile);
if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP))
@@ -300,7 +300,7 @@ int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
RedrawWaypointSign(wp);
if (justremove) {
- MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GB(_m[tile].m3, 0, 4));
+ MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile));
MarkTileDirtyByTile(tile);
} else {
DoClearSquare(tile);