10#ifndef YAPF_DESTRAIL_HPP
11#define YAPF_DESTRAIL_HPP
13#include "../../train.h"
14#include "../pathfinder_func.h"
15#include "../pathfinder_type.h"
22 void SetDestination(
const Train *v,
bool override_rail_type =
false)
24 this->compatible_railtypes = v->compatible_railtypes;
28 bool IsCompatibleRailType(
RailType rt)
30 return HasBit(this->compatible_railtypes, rt);
35 return this->compatible_railtypes;
42 typedef typename Types::Tpf
Tpf;
43 typedef typename Types::NodeList::Item
Node;
44 typedef typename Node::Key
Key;
49 return *
static_cast<Tpf *
>(
this);
78 typedef typename Types::Tpf
Tpf;
79 typedef typename Types::NodeList::Item
Node;
80 typedef typename Node::Key
Key;
86 return *
static_cast<Tpf *
>(
this);
113template <
class Types>
116 typedef typename Types::Tpf
Tpf;
117 typedef typename Types::NodeList::Item
Node;
118 typedef typename Node::Key
Key;
123 StationID dest_station_id;
129 return *
static_cast<Tpf *
>(
this);
133 void SetDestination(
const Train *v)
135 this->any_depot =
false;
137 case OT_GOTO_WAYPOINT:
144 Yapf().DisableCache(
true);
148 case OT_GOTO_STATION:
156 this->any_depot =
true;
162 this->dest_station_id = INVALID_STATION;
166 this->CYapfDestinationRailBase::SetDestination(v);
178 if (this->dest_station_id != INVALID_STATION) {
184 if (this->any_depot) {
188 return (tile == this->dest_tile) &&
HasTrackdir(this->dest_trackdirs, td);
197 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
198 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
206 int x1 = 2 *
TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
207 int y1 = 2 *
TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
208 int x2 = 2 *
TileX(this->dest_tile);
209 int y2 = 2 *
TileY(this->dest_tile);
210 int dx =
abs(x1 - x2);
211 int dy =
abs(y1 - y2);
212 int dmin = std::min(dx, dy);
213 int dxy =
abs(dx - dy);
215 n.estimate = n.cost + d;
216 assert(n.estimate >= n.parent->estimate);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Types::NodeList::Item Node
this will be our node type
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Tpf & Yapf()
to access inherited path finder
Node::Key Key
key to hash tables
bool PfDetectDestination(TileIndex tile, Trackdir)
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.
Types::TrackFollower TrackFollower
TrackFollower. Need to typedef for gcc 2.95.
bool PfDetectDestination(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Tpf & Yapf()
to access inherited path finder
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Types::NodeList::Item Node
this will be our node type
Node::Key Key
key to hash tables
Node::Key Key
key to hash tables
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.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Item Node
this will be our node type
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
DiagDirection
Enumeration for diagonal directions.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
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...
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
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.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static debug_inline bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
RailTypes
Allow incrementing of Track variables.
RailType
Enumeration for all possible railtypes.
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
OrderType GetType() const
Get the type of order of this order.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
static Waypoint * Get(size_t index)
Gets station with given index.
'Train' is either a loco or a wagon.
Order current_order
The current order (+ status, like: loading)
TileIndex tile
Current tile index.
TileIndex dest_tile
Heading for this tile.
bool IsSingleTile() const
Is this a single tile waypoint?
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Trackdir
Enumeration for tracks and directions.
TrackdirBits
Allow incrementing of Trackdir variables.
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
@ TRANSPORT_RAIL
Transport by train.