summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/default/default.cpp2
-rw-r--r--src/elrail.cpp2
-rw-r--r--src/rail_cmd.cpp12
-rw-r--r--src/rail_map.h11
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/roadveh_cmd.cpp6
-rw-r--r--src/track_func.h28
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp10
-rw-r--r--src/vehicle.cpp14
-rw-r--r--src/water_cmd.cpp2
-rw-r--r--src/yapf/yapf_road.cpp4
12 files changed, 63 insertions, 32 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index db9fcd141..5af37de10 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -2198,7 +2198,7 @@ static void AiBuildRailConstruct(Player *p)
int32 bridge_len = GetTunnelBridgeLength(t1, t2);
DiagDirection dir = (TileX(t1) == TileX(t2) ? DIAGDIR_SE : DIAGDIR_SW);
- Track track = AxisToTrack(DiagDirToAxis(dir));
+ Track track = DiagDirToDiagTrack(dir);
if (t2 < t1) dir = ReverseDiagDir(dir);
diff --git a/src/elrail.cpp b/src/elrail.cpp
index 81ddb3dea..11c6f8953 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -104,7 +104,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
*override = 1 << GetTunnelBridgeDirection(t);
}
- return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
+ return DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t));
case MP_ROAD:
if (!IsLevelCrossing(t)) return TRACK_BIT_NONE;
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 012085a2f..05803936b 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -778,7 +778,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player);
- YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
+ YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
}
return cost.AddCost(_price.build_train_depot);
@@ -1247,7 +1247,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case RAIL_TILE_WAYPOINT:
if (flags & DC_EXEC) {
/* notify YAPF about the track layout change */
- YapfNotifyTrackLayoutChange(tile, AxisToTrack(GetWaypointAxis(tile)));
+ YapfNotifyTrackLayoutChange(tile, GetRailWaypointTrack(tile));
}
cost.AddCost(RailConvertCost(type, totype));
break;
@@ -1255,7 +1255,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case RAIL_TILE_DEPOT:
if (flags & DC_EXEC) {
/* notify YAPF about the track layout change */
- YapfNotifyTrackLayoutChange(tile, AxisToTrack(DiagDirToAxis(GetRailDepotDirection(tile))));
+ YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
/* Update build vehicle window related to this depot */
InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
@@ -1296,7 +1296,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
- Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
+ Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
@@ -1345,7 +1345,7 @@ static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
DoClearSquare(tile);
delete GetDepotByTile(tile);
AddSideToSignalBuffer(tile, dir, owner);
- YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
+ YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
@@ -2150,7 +2150,7 @@ static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode,
if (side != INVALID_DIAGDIR && side != dir) break;
- trackbits = AxisToTrackBits(DiagDirToAxis(dir));
+ trackbits = DiagDirToDiagTrackBits(dir);
break;
}
diff --git a/src/rail_map.h b/src/rail_map.h
index 2789b419a..8c436d055 100644
--- a/src/rail_map.h
+++ b/src/rail_map.h
@@ -168,6 +168,17 @@ static inline DiagDirection GetRailDepotDirection(TileIndex t)
return (DiagDirection)GB(_m[t].m5, 0, 2);
}
+/**
+ * Returns the track of a depot, ignoring direction
+ * @pre IsRailDepotTile(t)
+ * @param t the tile to get the depot track from
+ * @return the track of the depot
+ */
+static inline Track GetRailDepotTrack(TileIndex t)
+{
+ return DiagDirToDiagTrack(GetRailDepotDirection(t));
+}
+
/**
* Returns the axis of the waypoint
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 19758274c..22a4fac0f 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1391,7 +1391,7 @@ static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, u
if (side != INVALID_DIAGDIR && side != dir) break;
- trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(DiagDirToAxis(dir)));
+ trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir));
break;
}
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index f5b52a6fc..cf6d011db 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -970,7 +970,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return;
- od.trackdir = DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
+ od.trackdir = DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
/* Are the current and the next tile suitable for overtaking?
* - Does the track continue along od.trackdir
@@ -1135,7 +1135,7 @@ static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection ent
NPFFindStationOrTileData fstd;
NPFFillWithOrderData(&fstd, v);
- Trackdir trackdir = DiagdirToDiagTrackdir(enterdir);
+ Trackdir trackdir = DiagDirToDiagTrackdir(enterdir);
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
NPFFoundTargetData ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, v->owner, INVALID_RAILTYPES);
@@ -1325,7 +1325,7 @@ static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev,
}
if (diag_dir == INVALID_DIAGDIR) return INVALID_TRACKDIR;
- dir = DiagdirToDiagTrackdir(diag_dir);
+ dir = DiagDirToDiagTrackdir(diag_dir);
} else {
if (already_reversed && prev->tile != tile) {
/*
diff --git a/src/track_func.h b/src/track_func.h
index 88d8d423e..e6591212a 100644
--- a/src/track_func.h
+++ b/src/track_func.h
@@ -24,8 +24,6 @@ static inline Track AxisToTrack(Axis a)
return (Track)a;
}
-
-
/**
* Maps a Track to the corresponding TrackBits value
* @param track the track to convert
@@ -277,7 +275,7 @@ static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
* Converts TrackBits to TrackdirBits while allowing both directions.
*
* @param bits The TrackBits
- * @return The TrackDirBits containing of bits in both directions.
+ * @return The TrackdirBits containing of bits in both directions.
*/
static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
{
@@ -436,13 +434,35 @@ static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
}
/**
+ * Maps a (4-way) direction to the diagonal track incidating with that diagdir
+ *
+ * @param diagdir The direction
+ * @return The resulting Track
+ */
+static inline Track DiagDirToDiagTrack(DiagDirection diagdir)
+{
+ return (Track)(diagdir & 1);
+}
+
+/**
+ * Maps a (4-way) direction to the diagonal track bits incidating with that diagdir
+ *
+ * @param diagdir The direction
+ * @return The resulting TrackBits
+ */
+static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
+{
+ return TrackToTrackBits(DiagDirToDiagTrack(diagdir));
+}
+
+/**
* Maps a (4-way) direction to the diagonal trackdir that runs in that
* direction.
*
* @param diagdir The direction
* @return The resulting Trackdir direction
*/
-static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
+static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
{
extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
return _dir_to_diag_trackdir[diagdir];
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index c6bc5d135..e788a16de 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1764,7 +1764,7 @@ static void AdvanceWagonsAfterSwap(Vehicle *v)
if (d <= 0) {
leave->vehstatus &= ~VS_HIDDEN; // move it out of the depot
- leave->u.rail.track = AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(leave->tile)));
+ leave->u.rail.track = TrackToTrackBits(GetRailDepotTrack(leave->tile));
for (int i = 0; i >= d; i--) TrainController(leave, NULL, false); // maybe move it, and maybe let another wagon leave
}
} else {
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 96c57833c..c53a52a10 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -494,7 +494,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32
delta = TileOffsByDiagDir(direction);
DiagDirection tunnel_in_way_dir;
- if (OtherAxis(DiagDirToAxis(direction)) == AXIS_X) {
+ if (DiagDirToAxis(direction) == AXIS_Y) {
tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
} else {
tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
@@ -558,7 +558,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32
MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4));
MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_player);
- YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
+ YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
} else {
MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3));
MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3));
@@ -623,7 +623,7 @@ static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
AddSideToSignalBuffer(tile, ReverseDiagDir(dir), owner);
AddSideToSignalBuffer(endtile, dir, owner);
- Track track = AxisToTrack(DiagDirToAxis(dir));
+ Track track = DiagDirToDiagTrack(dir);
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
} else {
@@ -691,7 +691,7 @@ static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
AddSideToSignalBuffer(tile, ReverseDiagDir(direction), owner);
AddSideToSignalBuffer(endtile, direction, owner);
- Track track = AxisToTrack(DiagDirToAxis(direction));
+ Track track = DiagDirToDiagTrack(direction);
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
}
@@ -1233,7 +1233,7 @@ static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType
DiagDirection dir = GetTunnelBridgeDirection(tile);
if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
- return CombineTrackStatus(TrackBitsToTrackdirBits(AxisToTrackBits(DiagDirToAxis(dir))), TRACKDIR_BIT_NONE);
+ return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE);
}
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index baf5a6dfa..1ad06f503 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1867,34 +1867,34 @@ Trackdir GetVehicleTrackdir(const Vehicle *v)
switch (v->type) {
case VEH_TRAIN:
if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards
- return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot
+ return DiagDirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot
if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel, so just use his direction and assume a diagonal track
- return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
+ return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction);
case VEH_SHIP:
if (v->IsInDepot())
// We'll assume the ship is facing outwards
- return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile));
+ return DiagDirToDiagTrackdir(GetShipDepotDirection(v->tile));
return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction);
case VEH_ROAD:
if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards
- return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile));
+ return DiagDirToDiagTrackdir(GetRoadDepotDirection(v->tile));
if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards
- return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station
+ return DiagDirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station
- if (IsDriveThroughStopTile(v->tile)) return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
+ if (IsDriveThroughStopTile(v->tile)) return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */
if (!IsReversingRoadTrackdir((Trackdir)v->u.road.state)) return (Trackdir)v->u.road.state;
/* Vehicle is turning around, get the direction from vehicle's direction */
- return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
+ return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
/* case VEH_AIRCRAFT: case VEH_EFFECT: case VEH_DISASTER: */
default: return INVALID_TRACKDIR;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index ddbf185ff..5faee5264 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -1123,7 +1123,7 @@ static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode,
switch (GetWaterTileType(tile)) {
case WATER_TILE_CLEAR: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
- case WATER_TILE_LOCK: ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
+ case WATER_TILE_LOCK: ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
default: return 0;
}
diff --git a/src/yapf/yapf_road.cpp b/src/yapf/yapf_road.cpp
index a0ea6864f..8f775bc3c 100644
--- a/src/yapf/yapf_road.cpp
+++ b/src/yapf/yapf_road.cpp
@@ -88,7 +88,7 @@ public:
if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break;
// stop if we have just entered the depot
- if (IsRoadDepotTile(tile) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
+ if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
// next time we will reverse and leave the depot
break;
}
@@ -264,7 +264,7 @@ public:
// handle special case - when next tile is destination tile
if (tile == v->dest_tile) {
// choose diagonal trackdir reachable from enterdir
- return (Trackdir)DiagdirToDiagTrackdir(enterdir);
+ return DiagDirToDiagTrackdir(enterdir);
}
// our source tile will be the next vehicle tile (should be the given one)
TileIndex src_tile = tile;