OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef YAPF_DESTRAIL_HPP
11 #define YAPF_DESTRAIL_HPP
18 void SetDestination(
const Train *v,
bool override_rail_type =
false)
20 m_compatible_railtypes = v->compatible_railtypes;
24 bool IsCompatibleRailType(
RailType rt)
26 return HasBit(m_compatible_railtypes, rt);
31 return m_compatible_railtypes;
35 template <
class Types>
38 typedef typename Types::Tpf
Tpf;
39 typedef typename Types::NodeList::Titem
Node;
40 typedef typename Node::Key
Key;
45 return *
static_cast<Tpf *
>(
this);
67 n.m_estimate = n.m_cost;
72 template <
class Types>
75 typedef typename Types::Tpf
Tpf;
76 typedef typename Types::NodeList::Titem
Node;
77 typedef typename Node::Key
Key;
83 return *
static_cast<Tpf *
>(
this);
105 n.m_estimate = n.m_cost;
110 template <
class Types>
113 typedef typename Types::Tpf
Tpf;
114 typedef typename Types::NodeList::Titem
Node;
115 typedef typename Node::Key
Key;
120 StationID m_dest_station_id;
126 return *
static_cast<Tpf *
>(
this);
130 void SetDestination(
const Train *v)
134 case OT_GOTO_WAYPOINT:
141 Yapf().DisableCache(
true);
145 case OT_GOTO_STATION:
159 m_dest_station_id = INVALID_STATION;
163 CYapfDestinationRailBase::SetDestination(v);
175 if (m_dest_station_id != INVALID_STATION) {
185 return (tile == m_destTile) &&
HasTrackdir(m_destTrackdirs, td);
194 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
195 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
197 n.m_estimate = n.m_cost;
203 int x1 = 2 *
TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
204 int y1 = 2 *
TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
205 int x2 = 2 *
TileX(m_destTile);
206 int y2 = 2 *
TileY(m_destTile);
207 int dx =
abs(x1 - x2);
208 int dy =
abs(y1 - y2);
209 int dmin = std::min(dx, dy);
210 int dxy =
abs(dx - dy);
212 n.m_estimate = n.m_cost + d;
213 assert(n.m_estimate >= n.m_parent->m_estimate);
Tpf & Yapf()
to access inherited path finder
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
bool IsType(OrderType type) const
Check whether this order is of the given type.
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
DestinationID GetDestination() const
Gets the destination of this order.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
RailType
Enumeration for all possible railtypes.
Types::NodeList::Titem Node
this will be our node type
DiagDirection
Enumeration for diagonal directions.
static Waypoint * Get(size_t index)
Gets station with given index.
RailTypes
Allow incrementing of Track variables.
Node::Key Key
key to hash tables
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Node::Key Key
key to hash tables
OrderType GetType() const
Get the type of order of this order.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
TileIndex dest_tile
Heading for this tile.
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
bool IsSingleTile() const
Is this a single tile waypoint?
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
TileIndex tile
Current tile index.
Order current_order
The current order (+ status, like: loading)
Tpf & Yapf()
to access inherited path finder
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
'Train' is either a loco or a wagon.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
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.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Node::Key Key
key to hash tables
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
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.
Types::NodeList::Titem Node
this will be our node type
Trackdir
Enumeration for tracks and directions.
Tpf & Yapf()
to access inherited path finder
static debug_inline bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
@ TRANSPORT_RAIL
Transport by train.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
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...
bool PfDetectDestination(TileIndex tile, Trackdir)
Called by YAPF to detect if node ends in the desired destination.
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
TrackdirBits
Allow incrementing of Trackdir variables.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Types::TrackFollower TrackFollower
TrackFollower. Need to typedef for gcc 2.95.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.