mirror of https://github.com/OpenTTD/OpenTTD
(svn r10489) -Codechange [YAPF]: FollowTrack_t now has new data member - m_err. It indicates the reason why the given track/trackdir can't be followed when method CFollowTrackT<>::Follow() returned false.
parent
d9a2e25dd7
commit
d3c7a7fa8c
|
@ -31,6 +31,7 @@ struct CFollowTrackT : public FollowTrack_t
|
||||||
m_exitdir = INVALID_DIAGDIR;
|
m_exitdir = INVALID_DIAGDIR;
|
||||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||||
m_tiles_skipped = 0;
|
m_tiles_skipped = 0;
|
||||||
|
m_err = EC_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCEINLINE static TransportType TT() {return Ttr_type_;}
|
FORCEINLINE static TransportType TT() {return Ttr_type_;}
|
||||||
|
@ -45,6 +46,7 @@ struct CFollowTrackT : public FollowTrack_t
|
||||||
{
|
{
|
||||||
m_old_tile = old_tile;
|
m_old_tile = old_tile;
|
||||||
m_old_td = old_td;
|
m_old_td = old_td;
|
||||||
|
m_err = EC_NONE;
|
||||||
assert((GetTileTrackStatus(m_old_tile, TT(), m_veh->u.road.compatible_roadtypes) & TrackdirToTrackdirBits(m_old_td)) != 0);
|
assert((GetTileTrackStatus(m_old_tile, TT(), m_veh->u.road.compatible_roadtypes) & TrackdirToTrackdirBits(m_old_td)) != 0);
|
||||||
m_exitdir = TrackdirToExitdir(m_old_td);
|
m_exitdir = TrackdirToExitdir(m_old_td);
|
||||||
if (EnteredDepot()) return true;
|
if (EnteredDepot()) return true;
|
||||||
|
@ -53,9 +55,18 @@ struct CFollowTrackT : public FollowTrack_t
|
||||||
if (!QueryNewTileTrackStatus()) return TryReverse();
|
if (!QueryNewTileTrackStatus()) return TryReverse();
|
||||||
if (!CanEnterNewTile()) return false;
|
if (!CanEnterNewTile()) return false;
|
||||||
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
|
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
|
||||||
if (!Allow90degTurns())
|
if (m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Allow90degTurns()) {
|
||||||
m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
|
m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
|
||||||
return (m_new_td_bits != TRACKDIR_BIT_NONE);
|
if (m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||||
|
m_err = EC_90DEG;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -126,16 +137,20 @@ protected:
|
||||||
// road stop can be left at one direction only unless it's a drive-through stop
|
// road stop can be left at one direction only unless it's a drive-through stop
|
||||||
if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
|
if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
|
||||||
DiagDirection exitdir = GetRoadStopDir(m_old_tile);
|
DiagDirection exitdir = GetRoadStopDir(m_old_tile);
|
||||||
if (exitdir != m_exitdir)
|
if (exitdir != m_exitdir) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// road depots can be also left in one direction only
|
// road depots can be also left in one direction only
|
||||||
if (IsRoadTT() && IsTileDepotType(m_old_tile, TT())) {
|
if (IsRoadTT() && IsTileDepotType(m_old_tile, TT())) {
|
||||||
DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
|
DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
|
||||||
if (exitdir != m_exitdir)
|
if (exitdir != m_exitdir) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,29 +160,37 @@ protected:
|
||||||
if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
|
if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
|
||||||
// road stop can be entered from one direction only unless it's a drive-through stop
|
// road stop can be entered from one direction only unless it's a drive-through stop
|
||||||
DiagDirection exitdir = GetRoadStopDir(m_new_tile);
|
DiagDirection exitdir = GetRoadStopDir(m_new_tile);
|
||||||
if (ReverseDiagDir(exitdir) != m_exitdir)
|
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// road and rail depots can also be entered from one direction only
|
// road and rail depots can also be entered from one direction only
|
||||||
if (IsRoadTT() && IsTileDepotType(m_new_tile, TT())) {
|
if (IsRoadTT() && IsTileDepotType(m_new_tile, TT())) {
|
||||||
DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
|
DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
|
||||||
if (ReverseDiagDir(exitdir) != m_exitdir)
|
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
// don't try to enter other player's depots
|
// don't try to enter other player's depots
|
||||||
if (GetTileOwner(m_new_tile) != m_veh->owner) {
|
if (GetTileOwner(m_new_tile) != m_veh->owner) {
|
||||||
|
m_err = EC_OWNER;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IsRailTT() && IsTileDepotType(m_new_tile, TT())) {
|
if (IsRailTT() && IsTileDepotType(m_new_tile, TT())) {
|
||||||
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
|
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
|
||||||
if (ReverseDiagDir(exitdir) != m_exitdir)
|
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// rail transport is possible only on tiles with the same owner as vehicle
|
// rail transport is possible only on tiles with the same owner as vehicle
|
||||||
if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh->owner) {
|
if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh->owner) {
|
||||||
// different owner
|
// different owner
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +199,7 @@ protected:
|
||||||
RailType rail_type = GetTileRailType(m_new_tile);
|
RailType rail_type = GetTileRailType(m_new_tile);
|
||||||
if (!HASBIT(m_veh->u.rail.compatible_railtypes, rail_type)) {
|
if (!HASBIT(m_veh->u.rail.compatible_railtypes, rail_type)) {
|
||||||
// incompatible rail type
|
// incompatible rail type
|
||||||
|
m_err = EC_RAIL_TYPE;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,12 +209,18 @@ protected:
|
||||||
if (IsTunnel(m_new_tile)) {
|
if (IsTunnel(m_new_tile)) {
|
||||||
if (!m_is_tunnel) {
|
if (!m_is_tunnel) {
|
||||||
DiagDirection tunnel_enterdir = GetTunnelDirection(m_new_tile);
|
DiagDirection tunnel_enterdir = GetTunnelDirection(m_new_tile);
|
||||||
if (tunnel_enterdir != m_exitdir) return false;
|
if (tunnel_enterdir != m_exitdir) {
|
||||||
|
EC_NO_WAY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (IsBridge(m_new_tile)) {
|
} else if (IsBridge(m_new_tile)) {
|
||||||
if (!m_is_bridge) {
|
if (!m_is_bridge) {
|
||||||
DiagDirection ramp_enderdir = GetBridgeRampDirection(m_new_tile);
|
DiagDirection ramp_enderdir = GetBridgeRampDirection(m_new_tile);
|
||||||
if (ramp_enderdir != m_exitdir) return false;
|
if (ramp_enderdir != m_exitdir) {
|
||||||
|
EC_NO_WAY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,6 +277,7 @@ protected:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_err = EC_NO_WAY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,14 @@ extern int _aystar_stats_closed_size;
|
||||||
/** Base struct for track followers. */
|
/** Base struct for track followers. */
|
||||||
struct FollowTrack_t
|
struct FollowTrack_t
|
||||||
{
|
{
|
||||||
|
enum ErrorCode {
|
||||||
|
EC_NONE,
|
||||||
|
EC_OWNER,
|
||||||
|
EC_RAIL_TYPE,
|
||||||
|
EC_90DEG,
|
||||||
|
EC_NO_WAY,
|
||||||
|
};
|
||||||
|
|
||||||
const Vehicle* m_veh; ///< moving vehicle
|
const Vehicle* m_veh; ///< moving vehicle
|
||||||
TileIndex m_old_tile; ///< the origin (vehicle moved from) before move
|
TileIndex m_old_tile; ///< the origin (vehicle moved from) before move
|
||||||
Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move
|
Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move
|
||||||
|
@ -99,6 +107,7 @@ struct FollowTrack_t
|
||||||
bool m_is_bridge; ///< last turn passed bridge ramp
|
bool m_is_bridge; ///< last turn passed bridge ramp
|
||||||
bool m_is_station; ///< last turn passed station
|
bool m_is_station; ///< last turn passed station
|
||||||
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
|
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
|
||||||
|
ErrorCode m_err;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Initializes FollowTrack_t structure */
|
/** Initializes FollowTrack_t structure */
|
||||||
|
|
|
@ -376,6 +376,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||||
tf_local.Init(v, &Yapf().m_perf_ts_cost);
|
tf_local.Init(v, &Yapf().m_perf_ts_cost);
|
||||||
|
|
||||||
if (!tf_local.Follow(cur.tile, cur.td)) {
|
if (!tf_local.Follow(cur.tile, cur.td)) {
|
||||||
|
assert(tf_local.m_err != TrackFollower::EC_NONE);
|
||||||
/* Can't move to the next tile (EOL?). */
|
/* Can't move to the next tile (EOL?). */
|
||||||
end_segment_reason |= ESRB_DEAD_END;
|
end_segment_reason |= ESRB_DEAD_END;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue