12 #include "../../stdafx.h" 13 #include "../../ship.h" 18 #include "../../safeguards.h" 21 template <
class Types>
25 typedef typename Types::Tpf
Tpf;
26 typedef typename Types::TrackFollower TrackFollower;
27 typedef typename Types::NodeList::Titem
Node;
28 typedef typename Node::Key
Key;
34 return *
static_cast<Tpf *
>(
this);
45 TrackFollower F(
Yapf().GetVehicle());
46 if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
47 Yapf().AddMultipleNodes(&old_node, F);
84 pf.SetOrigin(src_tile, trackdirs);
85 pf.SetDestination(v->
dest_tile, dest_trackdirs);
87 path_found = pf.FindPath(v);
91 Node *pNode = pf.GetBestNode();
94 Node *pPrevNode = NULL;
95 while (pNode->m_parent != NULL) {
97 pNode = pNode->m_parent;
100 Node &best_next_node = *pPrevNode;
101 assert(best_next_node.GetTile() == tile);
102 next_trackdir = best_next_node.GetTrackdir();
104 return next_trackdir;
125 pf.SetDestination(v->
dest_tile, dest_trackdirs);
127 if (!pf.FindPath(v))
return false;
129 Node *pNode = pf.GetBestNode();
130 if (pNode == NULL)
return false;
134 while (pNode->m_parent != NULL) {
135 pNode = pNode->m_parent;
138 Trackdir best_trackdir = pNode->GetTrackdir();
139 assert(best_trackdir == td1 || best_trackdir == td2);
140 return best_trackdir == td2;
145 template <
class Types>
149 typedef typename Types::Tpf
Tpf;
150 typedef typename Types::TrackFollower TrackFollower;
151 typedef typename Types::NodeList::Titem
Node;
152 typedef typename Node::Key
Key;
158 return *
static_cast<Tpf *
>(
this);
172 if (n.GetTrackdir() !=
NextTrackdir(n.m_parent->GetTrackdir())) {
183 if (speed_frac > 0) c +=
YAPF_TILE_LENGTH * (1 + tf->m_tiles_skipped) * speed_frac / (256 - speed_frac);
186 n.m_cost = n.m_parent->m_cost + c;
195 template <
class Tpf_,
class Ttrack_follower,
class Tnode_list>
218 struct CYapfShip1 :
CYapfT<CYapfShip_TypesT<CYapfShip1, CFollowTrackWater , CShipNodeListTrackDir> > {};
220 struct CYapfShip2 :
CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , CShipNodeListExitDir > > {};
222 struct CYapfShip3 :
CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
238 Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks, path_found);
249 PfnCheckReverseShip pfnCheckReverseShip = CYapfShip2::CheckShipReverse;
253 pfnCheckReverseShip = &CYapfShip3::CheckShipReverse;
255 pfnCheckReverseShip = &CYapfShip1::CheckShipReverse;
258 bool reverse = pfnCheckReverseShip(v, tile, td, td_rev);
Information about a ship vehicle.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
CYapfShip_TypesT< Tpf_, Ttrack_follower, Tnode_list > Types
Types - shortcut for this struct type.
Ttrack_follower TrackFollower
track follower helper class
byte ocean_speed_frac
Fraction of maximum speed for ocean tiles.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
char TransportTypeChar() const
return debug report character to identify the transportation type
Track
These are used to specify a single track.
TileIndex dest_tile
Heading for this tile.
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Tnode_list NodeList
node list type
PathfinderSettings pf
settings for all pathfinders
Node::Key Key
key to hash tables
static Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead. ...
bool forbid_90_deg
forbid trains to make 90 deg turns
YAPF destination provider base class - used when destination is single tile / multiple trackdirs...
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
Tpf & Yapf()
to access inherited path finder
CYapfBaseT< Types > PfBase
pathfinder components (modules)
Types::NodeList::Titem Node
this will be our node type
TrackBits
Bitfield corresponding to Track.
Cost Provider module of YAPF for ships.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
CYapfBaseT - A-star type path finder base class.
Tpf & Yapf()
to access inherited path finder
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
Config struct of YAPF for ships.
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
VehicleType
Available vehicle types.
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Node Follower module of YAPF for ships.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Trackdir
Enumeration for tracks and directions.
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
TileIndex tile
Current tile index.
static bool CheckShipReverse(const Ship *v, TileIndex tile, Trackdir td1, Trackdir td2)
Check whether a ship should reverse to reach its destination.
DiagDirection
Enumeration for diagonal directions.
All ships have this type.
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Flag for an invalid track.
uint32 TileIndex
The index/ID of a Tile.
Base includes/functions for YAPF.
Types::NodeList::Titem Node
this will be our node type
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
Ship controller helper - path finder invoker.
bool PfCalcCost(Node &n, const TrackFollower *tf)
Called by YAPF to calculate the cost from the origin to the given node.
Flag for an invalid trackdir.
Tpf_ Tpf
Tpf - pathfinder type.
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
#define TILE_ADD(x, y)
Adds to tiles together.
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Node::Key Key
key to hash tables
byte canal_speed_frac
Fraction of maximum speed for canal/river tiles.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
bool YapfShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using YAPF. ...
Node tailored for ship pathfinding.
static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
Runs the pathfinder to choose a track to continue along.