summaryrefslogtreecommitdiff
path: root/yapf
diff options
context:
space:
mode:
Diffstat (limited to 'yapf')
-rw-r--r--yapf/follow_track.hpp61
-rw-r--r--yapf/yapf.h1
-rw-r--r--yapf/yapf_costbase.hpp2
-rw-r--r--yapf/yapf_rail.cpp42
-rw-r--r--yapf/yapf_road.cpp1
5 files changed, 29 insertions, 78 deletions
diff --git a/yapf/follow_track.hpp b/yapf/follow_track.hpp
index a197ef8bb..7c37b50bb 100644
--- a/yapf/follow_track.hpp
+++ b/yapf/follow_track.hpp
@@ -27,7 +27,7 @@ struct CFollowTrackT : public FollowTrack_t
m_new_tile = INVALID_TILE;
m_new_td_bits = TRACKDIR_BIT_NONE;
m_exitdir = INVALID_DIAGDIR;
- m_is_station = m_is_tunnel = false;
+ m_is_station = m_is_bridge = m_is_tunnel = false;
m_tiles_skipped = 0;
}
@@ -60,6 +60,9 @@ protected:
/** Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped */
FORCEINLINE void FollowTileExit()
{
+ m_is_station = m_is_bridge = m_is_tunnel = false;
+ m_tiles_skipped = 0;
+
// extra handling for tunnels in our direction
if (IsTunnelTile(m_old_tile)) {
DiagDirection tunnel_enterdir = GetTunnelDirection(m_old_tile);
@@ -73,11 +76,22 @@ protected:
}
assert(ReverseDiagDir(tunnel_enterdir) == m_exitdir);
}
- // not a tunnel or station
- m_is_tunnel = false;
- m_tiles_skipped = 0;
- // normal or station tile
+ // extra handling for bridge ramp in our direction
+ if (IsBridgeTile(m_old_tile)) {
+ DiagDirection bridge_enterdir = GetBridgeRampDirection(m_old_tile);
+ if (bridge_enterdir == m_exitdir) {
+ // we are entering the bridge ramp
+ m_new_tile = GetOtherBridgeEnd(m_old_tile);
+ uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile);
+ m_tiles_skipped = bridge_length;
+ m_is_bridge = true;
+ return;
+ }
+ assert(ReverseDiagDir(bridge_enterdir) == m_exitdir);
+ }
+
+ // normal or station tile, do one step
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
m_new_tile = TILE_ADD(m_old_tile, diff);
@@ -152,22 +166,7 @@ protected:
// rail transport is possible only on tiles with the same owner as vehicle
if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh->owner) {
// different owner
- if (IsBridgeTile(m_new_tile)) {
- if (IsBridgeMiddle(m_new_tile)) {
- // bridge middle has no owner - tile is owned by the owner of the under-bridge track
- if (GetBridgeAxis(m_new_tile) != DiagDirToAxis(m_exitdir)) {
- // so it must be under bridge track (and wrong owner)
- return false;
- }
- // in the middle of the bridge - when we came here, it should be ok
- } else {
- // different owner, on the bridge ramp
- return false;
- }
- } else {
- // different owner, not a bridge
- return false;
- }
+ return false;
}
// rail transport is possible only on compatible rail types
@@ -215,7 +214,7 @@ protected:
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
m_exitdir = exitdir;
m_tiles_skipped = 0;
- m_is_tunnel = m_is_station = false;
+ m_is_tunnel = m_is_bridge = m_is_station = false;
return true;
}
}
@@ -249,20 +248,10 @@ public:
int max_speed = INT_MAX; // no limit
// for now we handle only on-bridge speed limit
- if (IsBridgeTile(m_old_tile) && !IsWaterTT() && IsDiagonalTrackdir(m_old_td)) {
- bool is_on_bridge = true;
- if (IsBridgeMiddle(m_old_tile)) {
- // get track axis
- Axis track_axis = DiagDirToAxis(TrackdirToExitdir(m_old_td));
- // get under-bridge axis
- Axis bridge_axis = GetBridgeAxis(m_old_tile);
- if (track_axis != bridge_axis) is_on_bridge = false;
- }
- if (is_on_bridge) {
- int spd = _bridge[GetBridgeType(m_old_tile)].speed;
- if (IsRoadTT()) spd *= 2;
- if (max_speed > spd) max_speed = spd;
- }
+ if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
+ int spd = _bridge[GetBridgeType(m_old_tile)].speed;
+ if (IsRoadTT()) spd *= 2;
+ if (max_speed > spd) max_speed = spd;
}
// if min speed was requested, return it
diff --git a/yapf/yapf.h b/yapf/yapf.h
index 3bf8468e9..6b58b4e08 100644
--- a/yapf/yapf.h
+++ b/yapf/yapf.h
@@ -95,6 +95,7 @@ typedef struct FollowTrack_t
TrackdirBits m_new_td_bits; ///< the new set of available trackdirs
DiagDirection m_exitdir; ///< exit direction (leaving the old tile)
bool m_is_tunnel; ///< last turn passed tunnel
+ bool m_is_bridge; ///< last turn passed bridge ramp
bool m_is_station; ///< last turn passed station
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
} FollowTrack_t;
diff --git a/yapf/yapf_costbase.hpp b/yapf/yapf_costbase.hpp
index b58df0c4d..df4d9e787 100644
--- a/yapf/yapf_costbase.hpp
+++ b/yapf/yapf_costbase.hpp
@@ -9,7 +9,7 @@ struct CYapfCostBase {
FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td)
{
if (IsDiagonalTrackdir(td)) {
- if (IsBridgeTile(tile) && IsBridgeRamp(tile)) {
+ if (IsBridgeTile(tile)) {
// it is bridge ramp, check if we are entering the bridge
if (GetBridgeRampDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
// we are entering the bridge
diff --git a/yapf/yapf_rail.cpp b/yapf/yapf_rail.cpp
index 0dc596927..d7edfaa02 100644
--- a/yapf/yapf_rail.cpp
+++ b/yapf/yapf_rail.cpp
@@ -243,8 +243,6 @@ bool YapfCheckReverseTrain(Vehicle* v)
return reverse;
}
-static TileIndex YapfGetVehicleOutOfTunnelTile(const Vehicle *v, bool bReverse);
-
bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed)
{
*depot_tile = INVALID_TILE;
@@ -252,12 +250,8 @@ bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_pe
Vehicle* last_veh = GetLastVehicleInChain(v);
- bool first_in_tunnel = v->u.rail.track == 0x40;
- bool last_in_tunnel = last_veh->u.rail.track == 0x40;
-
- // tile where the engine and last wagon are
- TileIndex tile = first_in_tunnel ? YapfGetVehicleOutOfTunnelTile(v, false) : v->tile;
- TileIndex last_tile = last_in_tunnel ? YapfGetVehicleOutOfTunnelTile(last_veh, true) : last_veh->tile;
+ TileIndex tile = v->tile;
+ TileIndex last_tile = last_veh->tile;
// their trackdirs
Trackdir td = GetVehicleTrackdir(v);
@@ -276,38 +270,6 @@ bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_pe
return ret;
}
-/** Retrieve the exit-tile of the vehicle from inside a tunnel
-* Very similar to GetOtherTunnelEnd(), but we use the vehicle's
-* direction for determining which end of the tunnel to find
-* @param v the vehicle which is inside the tunnel and needs an exit
-* @param bReverse should we search for the tunnel exit in the opposite direction?
-* @return the exit-tile of the tunnel based on the vehicle's direction
-* taken from tunnelbridge_cmd.c where the function body was disabled by
-* #if 1 #else #endif (at r5951). Added bReverse argument to allow two-way
-* operation (YapfFindNearestRailDepotTwoWay). */
-static TileIndex YapfGetVehicleOutOfTunnelTile(const Vehicle *v, bool bReverse)
-{
- TileIndex tile = v->tile;
- DiagDirection dir = DirToDiagDir((Direction)v->direction);
- TileIndexDiff delta = TileOffsByDiagDir(dir);
- byte z = v->z_pos;
-
- if (bReverse) {
- delta = -delta;
- } else {
- dir = ReverseDiagDir(dir);
- }
- while (
- !IsTunnelTile(tile) ||
- GetTunnelDirection(tile) != dir ||
- GetTileZ(tile) != z
- ) {
- tile += delta;
- }
- return tile;
-}
-
-
/** if any track changes, this counter is incremented - that will invalidate segment cost cache */
int CSegmentCostCacheBase::s_rail_change_counter = 0;
diff --git a/yapf/yapf_road.cpp b/yapf/yapf_road.cpp
index 47dd91e54..02b306b31 100644
--- a/yapf/yapf_road.cpp
+++ b/yapf/yapf_road.cpp
@@ -428,7 +428,6 @@ uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile)
Depot* YapfFindNearestRoadDepot(const Vehicle *v)
{
TileIndex tile = v->tile;
- if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v);
Trackdir trackdir = GetVehicleTrackdir(v);
if ((GetTileTrackStatus(tile, TRANSPORT_ROAD) & TrackdirToTrackdirBits(trackdir)) == 0)
return NULL;