10#ifndef YAPF_COMMON_HPP
11#define YAPF_COMMON_HPP
21 typedef typename Types::Tpf
Tpf;
22 typedef typename Types::NodeList::Item
Node;
23 typedef typename Node::Key
Key;
29 return *
static_cast<Tpf *
>(
this);
40 bool is_choice = trackdirs.
Count() > 1;
43 node.Set(
nullptr, tile, td, is_choice);
44 Yapf().AddStartupNode(node);
53 typedef typename Types::Tpf
Tpf;
54 typedef typename Types::NodeList::Item
Node;
55 typedef typename Node::Key
Key;
61 return *
static_cast<Tpf *
>(
this);
78 node.Set(
nullptr, forward_tile, forward_td,
false);
79 Yapf().AddStartupNode(node);
83 node.Set(
nullptr, reverse_tile, reverse_td,
false);
84 node.cost = reverse_penalty;
85 Yapf().AddStartupNode(node);
96template <
class Ttypes>
98 :
public Ttypes::PfBase
99 ,
public Ttypes::PfCost
100 ,
public Ttypes::PfCache
101 ,
public Ttypes::PfOrigin
102 ,
public Ttypes::PfDestination
103 ,
public Ttypes::PfFollow
116 static constexpr int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
117 static constexpr int dg_dir_to_y_offs[] = {0, 1, 0, -1};
121 const int x1 = 2 *
TileX(start_tile) + dg_dir_to_x_offs[
static_cast<int>(exitdir)];
122 const int y1 = 2 *
TileY(start_tile) + dg_dir_to_y_offs[
static_cast<int>(exitdir)];
123 const int x2 = 2 *
TileX(destination_tile);
124 const int y2 = 2 *
TileY(destination_tile);
125 const int dx =
abs(x1 - x2);
126 const int dy =
abs(y1 - y2);
127 const int dmin = std::min(dx, dy);
128 const int dxy =
abs(dx - dy);
Functions related to bit mathematics.
uint Count() const
Count the number of set bits.
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Node::Key Key
key to hash tables
Tpf & Yapf()
Access the inherited path finder.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
Set origin tile / trackdir mask.
Types::NodeList::Item Node
this will be our node type
YAPF origin provider base class - used when there are two tile/trackdir origins.
Tpf & Yapf()
Access the inherited path finder.
Node::Key Key
key to hash tables
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Types::NodeList::Item Node
this will be our node type
void SetOrigin(TileIndex forward_tile, Trackdir forward_td, TileIndex reverse_tile=INVALID_TILE, Trackdir reverse_td=Trackdir::Invalid, int reverse_penalty=0)
Set origin (tiles, trackdirs, etc.).
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
DiagDirection
Enumeration for diagonal directions.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
All types related to tracks.
EnumBitSet< Trackdir, uint16_t > TrackdirBits
Bitset of Trackdir elements.
Trackdir
Enumeration for tracks and directions.
@ Invalid
Flag for an invalid trackdir.
int OctileDistanceCost(TileIndex start_tile, Trackdir start_td, TileIndex destination_tile)
Calculates the octile distance cost between a starting tile / trackdir and a destination tile.