OpenTTD Source
1.11.0-beta2
|
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;
125 return *
static_cast<Tpf *
>(
this);
129 void SetDestination(
const Train *v)
132 case OT_GOTO_WAYPOINT:
139 Yapf().DisableCache(
true);
143 case OT_GOTO_STATION:
151 m_dest_station_id = INVALID_STATION;
155 CYapfDestinationRailBase::SetDestination(v);
167 if (m_dest_station_id != INVALID_STATION) {
173 return (tile == m_destTile) &&
HasTrackdir(m_destTrackdirs, td);
182 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
183 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
185 n.m_estimate = n.m_cost;
191 int x1 = 2 *
TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
192 int y1 = 2 *
TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
193 int x2 = 2 *
TileX(m_destTile);
194 int y2 = 2 *
TileY(m_destTile);
195 int dx =
abs(x1 - x2);
196 int dy =
abs(y1 - y2);
197 int dmin = std::min(dx, dy);
198 int dxy =
abs(dx - dy);
200 n.m_estimate = n.m_cost + d;
201 assert(n.m_estimate >= n.m_parent->m_estimate);
Tpf & Yapf()
to access inherited path finder
uint32 TileIndex
The index/ID 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
Enumeration of bitmasks for the TrackDirs.
@ TRANSPORT_RAIL
Transport by train.
DestinationID GetDestination() const
Gets the destination of this order.
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Types::NodeList::Titem Node
this will be our node type
static Waypoint * Get(size_t index)
Gets station with given index.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Node::Key Key
key to hash tables
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
static uint TileX(TileIndex tile)
Get the X component of a tile.
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.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
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.
RailType
Enumeration for all possible railtypes.
bool IsSingleTile() const
Is this a single tile waypoint?
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
TileIndex tile
Current tile index.
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Order current_order
The current order (+ status, like: loading)
Tpf & Yapf()
to access inherited path finder
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail 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
DiagDirection
Enumeration for diagonal directions.
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.
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...
Types::NodeList::Titem Node
this will be our node type
Tpf & Yapf()
to access inherited path finder
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
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.
Trackdir
Enumeration for tracks and directions.
static bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
RailTypes
The different railtypes we support, but then a bitmask of them.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Types::TrackFollower TrackFollower
TrackFollower. Need to typedef for gcc 2.95.