OpenTTD Source 20260421-master-gc2fbc6fdeb
CYapfFollowShipT< Types > Class Template Reference

Node Follower module of YAPF for ships. More...

Inheritance diagram for CYapfFollowShipT< Types >:
CYapfT< CYapfShip_TypesT< CYapfShip > > CYapfShip

Public Types

typedef Types::Tpf Tpf
 the pathfinder class (derived from THIS class).
typedef Types::TrackFollower TrackFollower
typedef Types::NodeList::Item Node
 this will be our node type.
typedef Node::Key Key
 key to hash tables.

Public Member Functions

void PfFollowNode (Node &old_node)
 Called by YAPF to move from the given node to the next tile.
void RestrictSearch (const std::vector< WaterRegionPatchDesc > &path)
 Restricts the search by creating corridor or water regions through which the ship is allowed to travel.
char TransportTypeChar () const
 Return debug report character to identify the transportation type.

Static Public Member Functions

static Trackdir GetRandomTrackdir (TrackdirBits trackdirs)
 Returns a random trackdir out of a set of trackdirs.
static std::pair< TileIndex, TrackdirGetRandomFollowUpTileTrackdir (const Ship *v, TileIndex tile, Trackdir dir)
 Returns a random tile/trackdir that can be reached from the current tile/trackdir, or tile/INVALID_TRACK if none is available.
static Trackdir CreateRandomPath (const Ship *v, ShipPathCache &path_cache, int path_length)
 Creates a random path, avoids 90 degree turns.
static Trackdir ChooseShipTrack (const Ship *v, TileIndex tile, TrackdirBits forward_dirs, TrackdirBits reverse_dirs, bool &path_found, ShipPathCache &path_cache, Trackdir &best_origin_dir)
static bool CheckShipReverse (const Ship *v, Trackdir *trackdir)
 Check whether a ship should reverse to reach its destination.

Protected Member Functions

TpfYapf ()
 Access the inherited path finder.

Protected Attributes

std::vector< WaterRegionDescwater_region_corridor

Detailed Description

template<class Types>
class CYapfFollowShipT< Types >

Node Follower module of YAPF for ships.

Definition at line 110 of file yapf_ship.cpp.

Member Typedef Documentation

◆ Key

template<class Types>
typedef Node::Key CYapfFollowShipT< Types >::Key

key to hash tables.

Definition at line 115 of file yapf_ship.cpp.

◆ Node

template<class Types>
typedef Types::NodeList::Item CYapfFollowShipT< Types >::Node

this will be our node type.

Definition at line 114 of file yapf_ship.cpp.

◆ Tpf

template<class Types>
typedef Types::Tpf CYapfFollowShipT< Types >::Tpf

the pathfinder class (derived from THIS class).

Definition at line 112 of file yapf_ship.cpp.

◆ TrackFollower

template<class Types>
typedef Types::TrackFollower CYapfFollowShipT< Types >::TrackFollower

Definition at line 113 of file yapf_ship.cpp.

Member Function Documentation

◆ CheckShipReverse()

template<class Types>
bool CYapfFollowShipT< Types >::CheckShipReverse ( const Ship * v,
Trackdir * trackdir )
inlinestatic

Check whether a ship should reverse to reach its destination.

Called when leaving depot.

Parameters
vShip.
trackdir[out] the best of all possible reversed trackdirs.
Returns
true if the reverse direction is better.

Definition at line 300 of file yapf_ship.cpp.

References DiagdirReachesTrackdirs(), Vehicle::direction, GetRandomTrackdir(), GetTileTrackStatus(), Ship::GetVehicleTrackdir(), Invalid, INVALID_TRACKDIR, ReverseDiagDir(), ReverseTrackdir(), Ship::state, Vehicle::tile, TRACKDIR_BIT_NONE, TrackdirToTrackdirBits(), TrackStatusToTrackdirBits(), TRANSPORT_WATER, and VehicleExitDir().

Referenced by YapfShipCheckReverse().

◆ ChooseShipTrack()

template<class Types>
Trackdir CYapfFollowShipT< Types >::ChooseShipTrack ( const Ship * v,
TileIndex tile,
TrackdirBits forward_dirs,
TrackdirBits reverse_dirs,
bool & path_found,
ShipPathCache & path_cache,
Trackdir & best_origin_dir )
inlinestatic

Definition at line 212 of file yapf_ship.cpp.

◆ CreateRandomPath()

template<class Types>
Trackdir CYapfFollowShipT< Types >::CreateRandomPath ( const Ship * v,
ShipPathCache & path_cache,
int path_length )
inlinestatic

Creates a random path, avoids 90 degree turns.

Parameters
vThe ship to create the path for.
[in,out]path_cacheCache of the path for the ship.
path_lengthThe length of the random path to create.
Returns
The next track direction to take, or INVALID_TRACKDIR when there is no option.

Definition at line 193 of file yapf_ship.cpp.

References Vehicle::first, GetRandomFollowUpTileTrackdir(), Ship::GetVehicleTrackdir(), INVALID_TRACKDIR, and Vehicle::tile.

◆ GetRandomFollowUpTileTrackdir()

template<class Types>
std::pair< TileIndex, Trackdir > CYapfFollowShipT< Types >::GetRandomFollowUpTileTrackdir ( const Ship * v,
TileIndex tile,
Trackdir dir )
inlinestatic

Returns a random tile/trackdir that can be reached from the current tile/trackdir, or tile/INVALID_TRACK if none is available.

Parameters
vThe ship to get the direction for.
tileThe start tile.
dirthe start direction.
Returns
The next tile and a direction.

Definition at line 174 of file yapf_ship.cpp.

References GetRandomTrackdir(), INVALID_TRACKDIR, TRACKDIR_BIT_NONE, and TrackdirCrossesTrackdirs().

Referenced by CreateRandomPath().

◆ GetRandomTrackdir()

template<class Types>
Trackdir CYapfFollowShipT< Types >::GetRandomTrackdir ( TrackdirBits trackdirs)
inlinestatic

Returns a random trackdir out of a set of trackdirs.

Parameters
trackdirsThe possible track dirs.
Returns
One of the possible track dirs.

Definition at line 160 of file yapf_ship.cpp.

References CountBits(), FindFirstTrackdir(), RandomRange(), and RemoveFirstTrackdir().

Referenced by CheckShipReverse(), and GetRandomFollowUpTileTrackdir().

◆ PfFollowNode()

template<class Types>
void CYapfFollowShipT< Types >::PfFollowNode ( Node & old_node)
inline

Called by YAPF to move from the given node to the next tile.

For each reachable trackdir on the new tile creates new node, initializes it and adds it to the open list by calling Yapf().AddNewNode(n).

Parameters
old_nodeThe node to follow from.

Definition at line 128 of file yapf_ship.cpp.

References GetWaterRegionInfo(), and Yapf().

◆ RestrictSearch()

template<class Types>
void CYapfFollowShipT< Types >::RestrictSearch ( const std::vector< WaterRegionPatchDesc > & path)
inline

Restricts the search by creating corridor or water regions through which the ship is allowed to travel.

Parameters
pathThe path to restrict the search by.

Definition at line 143 of file yapf_ship.cpp.

◆ TransportTypeChar()

template<class Types>
char CYapfFollowShipT< Types >::TransportTypeChar ( ) const
inline

Return debug report character to identify the transportation type.

Returns
The debug representation

Definition at line 150 of file yapf_ship.cpp.

◆ Yapf()

template<class Types>
Tpf & CYapfFollowShipT< Types >::Yapf ( )
inlineprotected

Access the inherited path finder.

Returns
The current path finder.

Definition at line 119 of file yapf_ship.cpp.

Referenced by PfFollowNode().

Field Documentation

◆ water_region_corridor

template<class Types>
std::vector<WaterRegionDesc> CYapfFollowShipT< Types >::water_region_corridor
protected

Definition at line 124 of file yapf_ship.cpp.


The documentation for this class was generated from the following file: