12 #ifndef YAPF_DESTRAIL_HPP 13 #define YAPF_DESTRAIL_HPP 20 void SetDestination(
const Train *v,
bool override_rail_type =
false)
22 m_compatible_railtypes = v->compatible_railtypes;
26 bool IsCompatibleRailType(
RailType rt)
28 return HasBit(m_compatible_railtypes, rt);
33 return m_compatible_railtypes;
37 template <
class Types>
40 typedef typename Types::Tpf
Tpf;
41 typedef typename Types::NodeList::Titem
Node;
42 typedef typename Node::Key
Key;
47 return *
static_cast<Tpf *
>(
this);
53 return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
69 n.m_estimate = n.m_cost;
74 template <
class Types>
77 typedef typename Types::Tpf
Tpf;
78 typedef typename Types::NodeList::Titem
Node;
79 typedef typename Node::Key
Key;
85 return *
static_cast<Tpf *
>(
this);
91 return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
97 return IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td,
true, !TrackFollower::Allow90degTurns()) &&
107 n.m_estimate = n.m_cost;
112 template <
class Types>
115 typedef typename Types::Tpf
Tpf;
116 typedef typename Types::NodeList::Titem
Node;
117 typedef typename Node::Key
Key;
122 StationID m_dest_station_id;
127 return *
static_cast<Tpf *
>(
this);
131 void SetDestination(
const Train *v)
134 case OT_GOTO_WAYPOINT:
141 Yapf().DisableCache(
true);
145 case OT_GOTO_STATION:
153 m_dest_station_id = INVALID_STATION;
157 CYapfDestinationRailBase::SetDestination(v);
163 return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
170 if (m_dest_station_id != INVALID_STATION) {
175 bDest = (tile == m_destTile)
187 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
188 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
189 if (PfDetectDestination(n)) {
190 n.m_estimate = n.m_cost;
196 int x1 = 2 *
TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
197 int y1 = 2 *
TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
198 int x2 = 2 *
TileX(m_destTile);
199 int y2 = 2 *
TileY(m_destTile);
200 int dx =
abs(x1 - x2);
201 int dy =
abs(y1 - y2);
202 int dmin =
min(dx, dy);
203 int dxy =
abs(dx - dy);
205 n.m_estimate = n.m_cost + d;
206 assert(n.m_estimate >= n.m_parent->m_estimate);
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailTypes
The different roadtypes we support, but then a bitmask of them.
RailType
Enumeration for all possible railtypes.
Types::NodeList::Titem Node
this will be our node type
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Flag for an invalid trackdirbit value.
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
Node::Key Key
key to hash tables
TileIndex dest_tile
Heading for this tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Tpf & Yapf()
to access inherited path finder
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel ...
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Node::Key Key
key to hash tables
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
bool IsType(OrderType type) const
Check whether this order is of the given type.
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
Determine whether a certain track on a tile is a safe position to end a path.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Trackdir
Enumeration for tracks and directions.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
TileIndex tile
Current tile index.
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
Tpf & Yapf()
to access inherited path finder
DiagDirection
Enumeration for diagonal directions.
static T min(const T a, const T b)
Returns the minimum of two values.
Tpf & Yapf()
to access inherited path finder
static TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
Calculates the tile of given station that is closest to a given tile for this we assume the station i...
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
'Train' is either a loco or a wagon.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Types::NodeList::Titem Node
this will be our node type
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
DestinationID GetDestination() const
Gets the destination of this order.
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
Types::NodeList::Titem Node
this will be our node type
uint32 TileIndex
The index/ID of a Tile.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Types::TrackFollower TrackFollower
TrackFollower. Need to typedef for gcc 2.95.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
OrderType GetType() const
Get the type of order of this order.
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
static Waypoint * Get(size_t index)
Gets station with given index.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Order current_order
The current order (+ status, like: loading)
Node::Key Key
key to hash tables