summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/api/ai_rail.cpp1
-rw-r--r--src/ai/api/ai_rail.hpp1
-rw-r--r--src/rail_cmd.cpp15
-rw-r--r--src/rail_map.h2
-rw-r--r--src/road.cpp2
-rw-r--r--src/road_cmd.cpp8
-rw-r--r--src/yapf/yapf_costrail.hpp2
7 files changed, 21 insertions, 10 deletions
diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp
index 7719d5576..b067b0904 100644
--- a/src/ai/api/ai_rail.cpp
+++ b/src/ai/api/ai_rail.cpp
@@ -203,6 +203,7 @@
if (IsRailWaypointTile(tile)) return ::GetRailWaypointBits(tile);
if (IsRailStationTile(tile)) return ::TrackToTrackBits(::GetRailStationTrack(tile));
if (IsLevelCrossingTile(tile)) return ::GetCrossingRailBits(tile);
+ if (IsRailDepotTile(tile)) return ::TRACK_BIT_NONE;
return ::GetTrackBits(tile);
}
diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp
index 5ea5ad2a4..a16c27e1e 100644
--- a/src/ai/api/ai_rail.hpp
+++ b/src/ai/api/ai_rail.hpp
@@ -293,6 +293,7 @@ public:
/**
* Get all RailTracks on the given tile.
+ * @note A depot has no railtracks.
* @param tile The tile to check.
* @pre IsRailTile(tile).
* @return A bitmask of RailTrack with all RailTracks on the tile.
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 44d71d9fc..21be9352f 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -321,6 +321,8 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
case MP_RAILWAY:
if (!CheckTileOwnership(tile)) return CMD_ERROR;
+ if (!IsPlainRailTile(tile)) return CMD_ERROR;
+
if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
if (!CheckTrackCombination(tile, trackbit, flags) ||
@@ -554,6 +556,8 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
*/
bool FloodHalftile(TileIndex t)
{
+ assert(IsPlainRailTile(t));
+
bool flooded = false;
if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
@@ -1043,7 +1047,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
end_tile = p1;
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
- if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
+ if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) return CMD_ERROR;
/* for vertical/horizontal tracks, double the given signals density
* since the original amount will be too dense (shorter tracks) */
@@ -1169,6 +1173,7 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1
if (!ValParamTrackOrientation(track) ||
!IsTileType(tile, MP_RAILWAY) ||
+ !IsPlainRailTile(tile) ||
!HasTrack(tile, track) ||
!EnsureNoTrainOnTrack(tile, track) ||
!HasSignalOnTrack(tile, track)) {
@@ -2175,7 +2180,7 @@ static void TileLoop_Track(TileIndex tile)
(rail & TRACK_BIT_X)
)) {
TileIndex n = tile + TileDiffXY(0, -1);
- TrackBits nrail = GetTrackBits(n);
+ TrackBits nrail = (IsTileType(n, MP_RAILWAY) && IsPlainRailTile(n) ? GetTrackBits(n) : TRACK_BIT_NONE);
if (!IsTileType(n, MP_RAILWAY) ||
!IsTileOwner(n, owner) ||
@@ -2190,7 +2195,7 @@ static void TileLoop_Track(TileIndex tile)
(rail & TRACK_BIT_X)
)) {
TileIndex n = tile + TileDiffXY(0, 1);
- TrackBits nrail = GetTrackBits(n);
+ TrackBits nrail = (IsTileType(n, MP_RAILWAY) && IsPlainRailTile(n) ? GetTrackBits(n) : TRACK_BIT_NONE);
if (!IsTileType(n, MP_RAILWAY) ||
!IsTileOwner(n, owner) ||
@@ -2206,7 +2211,7 @@ static void TileLoop_Track(TileIndex tile)
(rail & TRACK_BIT_Y)
)) {
TileIndex n = tile + TileDiffXY(-1, 0);
- TrackBits nrail = GetTrackBits(n);
+ TrackBits nrail = (IsTileType(n, MP_RAILWAY) && IsPlainRailTile(n) ? GetTrackBits(n) : TRACK_BIT_NONE);
if (!IsTileType(n, MP_RAILWAY) ||
!IsTileOwner(n, owner) ||
@@ -2221,7 +2226,7 @@ static void TileLoop_Track(TileIndex tile)
(rail & TRACK_BIT_Y)
)) {
TileIndex n = tile + TileDiffXY(1, 0);
- TrackBits nrail = GetTrackBits(n);
+ TrackBits nrail = (IsTileType(n, MP_RAILWAY) && IsPlainRailTile(n) ? GetTrackBits(n) : TRACK_BIT_NONE);
if (!IsTileType(n, MP_RAILWAY) ||
!IsTileOwner(n, owner) ||
diff --git a/src/rail_map.h b/src/rail_map.h
index 7c8c31f85..195aef9f5 100644
--- a/src/rail_map.h
+++ b/src/rail_map.h
@@ -141,6 +141,7 @@ static inline void SetRailType(TileIndex t, RailType r)
*/
static inline TrackBits GetTrackBits(TileIndex tile)
{
+ assert(IsPlainRailTile(tile));
return (TrackBits)GB(_m[tile].m5, 0, 6);
}
@@ -151,6 +152,7 @@ static inline TrackBits GetTrackBits(TileIndex tile)
*/
static inline void SetTrackBits(TileIndex t, TrackBits b)
{
+ assert(IsPlainRailTile(t));
SB(_m[t].m5, 0, 6, b);
}
diff --git a/src/road.cpp b/src/road.cpp
index 01f777d23..597098a2e 100644
--- a/src/road.cpp
+++ b/src/road.cpp
@@ -18,7 +18,7 @@
bool IsPossibleCrossing(const TileIndex tile, Axis ax)
{
return (IsTileType(tile, MP_RAILWAY) &&
- !HasSignals(tile) &&
+ GetRailTileType(tile) == RAIL_TILE_NORMAL &&
GetTrackBits(tile) == (ax == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) &&
GetFoundationSlope(tile, NULL) == SLOPE_FLAT);
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index de011e3af..4590111e2 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -321,6 +321,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (rt == ROADTYPE_ROAD && HasTileRoadType(tile, ROADTYPE_TRAM) && (flags & DC_EXEC || crossing_check)) return CMD_ERROR;
if (flags & DC_EXEC) {
+ Track railtrack = GetCrossingRailTrack(tile);
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
if (rts == ROADTYPES_NONE) {
TrackBits tracks = GetCrossingRailBits(tile);
@@ -332,7 +333,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
/* If we ever get HWAY and it is possible without road then we will need to promote ownership and invalidate town index here, too */
}
MarkTileDirtyByTile(tile);
- YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
+ YapfNotifyTrackLayoutChange(tile, railtrack);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2);
}
@@ -549,9 +550,10 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) {
- YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
+ Track railtrack = AxisToTrack(OtherAxis(roaddir));
+ YapfNotifyTrackLayoutChange(tile, railtrack);
/* Always add road to the roadtypes (can't draw without it) */
- bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(OtherAxis(roaddir)));
+ bool reserved = HasBit(GetTrackReservation(tile), railtrack);
MakeRoadCrossing(tile, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
SetCrossingReservation(tile, reserved);
UpdateLevelCrossing(tile, false);
diff --git a/src/yapf/yapf_costrail.hpp b/src/yapf/yapf_costrail.hpp
index 81ef6a82a..a622d2671 100644
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -111,7 +111,7 @@ public:
FORCEINLINE int SwitchCost(TileIndex tile1, TileIndex tile2, DiagDirection exitdir)
{
- if (IsTileType(tile1, MP_RAILWAY) && IsTileType(tile2, MP_RAILWAY)) {
+ if (IsTileType(tile1, MP_RAILWAY) && IsTileType(tile2, MP_RAILWAY) && IsPlainRailTile(tile1) && IsPlainRailTile(tile2)) {
bool t1 = KillFirstBit(GetTrackBits(tile1) & DiagdirReachesTracks(ReverseDiagDir(exitdir))) != TRACK_BIT_NONE;
bool t2 = KillFirstBit(GetTrackBits(tile2) & DiagdirReachesTracks(exitdir)) != TRACK_BIT_NONE;
if (t1 && t2) return Yapf().PfGetSettings().rail_doubleslip_penalty;