OpenTTD Source 20260414-master-g8a7bc482ad
YapfShipRegions Class Reference

Water region based YAPF implementation for ships. More...

Inheritance diagram for YapfShipRegions:
CYapfBaseT< WaterRegionTypes > CYapfSegmentCostCacheNoneT< WaterRegionTypes >

Public Member Functions

 YapfShipRegions (int max_nodes)
void AddOrigin (const WaterRegionPatchDesc &water_region_patch)
bool HasOrigin (const WaterRegionPatchDesc &water_region_patch)
void SetDestination (const WaterRegionPatchDesc &water_region_patch)
void PfFollowNode (Node &old_node)
 Called by YAPF to move from the given node to the next tile.
bool PfDetectDestination (Node &n) const
 Called by YAPF to detect if node ends in the desired destination.
bool PfCalcCost (Node &n, const TrackFollower *follower)
 Called by YAPF to calculate the cost from the origin to the given node.
bool PfCalcEstimate (Node &n)
 Called by YAPF to calculate cost estimate.
char TransportTypeChar () const
 Return debug report character to identify the transportation type.
Public Member Functions inherited from CYapfBaseT< WaterRegionTypes >
 CYapfBaseT ()
 default constructor
 ~CYapfBaseT ()
 default destructor
const YAPFSettingsPfGetSettings () const
 Return current settings (can be custom - company based - but later).
bool FindPath (const VehicleType *v)
 Main pathfinder routine:
NodeGetBestNode ()
 If path was found return the best node that has reached the destination.
NodeCreateNewNode ()
 Calls NodeList::CreateNewNode() - allocates new node that can be filled and used as argument for AddStartupNode() or AddNewNode().
void AddStartupNode (Node &n)
 Add new node (created by CreateNewNode and filled with data) into open list.
void AddMultipleNodes (Node *parent, const TrackFollower &tf)
 Add multiple nodes - direct children of the given node.
void AddNewNode (Node &n, const TrackFollower &follower)
 AddNewNode() - called by Tderived::PfFollowNode() for each child node.
const VehicleTypeGetVehicle () const
void DumpBase (DumpTarget &dmp) const
Public Member Functions inherited from CYapfSegmentCostCacheNoneT< WaterRegionTypes >
bool PfNodeCacheFetch (Node &)
 Called by YAPF to attach cached or local segment cost data to the given node.

Static Public Member Functions

static std::vector< WaterRegionPatchDescFindWaterRegionPath (const Ship *v, TileIndex start_tile, int max_returned_path_length)
 Finds a path at the water region level.

Private Types

using Node = typename WaterRegionTypes::NodeList::Item

Private Member Functions

YapfShipRegionsYapf ()

Private Attributes

std::vector< WaterRegionPatchKeyorigin_keys
WaterRegionPatchKey dest

Additional Inherited Members

Public Types inherited from CYapfBaseT< WaterRegionTypes >
typedef WaterRegionTypes::Tpf Tpf
 the pathfinder class (derived from THIS class)
typedef WaterRegionTypes::TrackFollower TrackFollower
typedef WaterRegionTypes::NodeList NodeList
 our node list
typedef WaterRegionTypes::VehicleType VehicleType
 the type of vehicle
typedef NodeList::Item Node
 this will be our node type
typedef Node::Key Key
 key to hash tables
using PfFollowNodeFunc
 Called by YAPF to move from the given node to the next tile.
using PfCalcCostFunc
 Called by YAPF to calculate the cost from the origin to the given node.
using PfCalcEstimateFunc
 Called by YAPF to calculate cost estimate.
using PfDetectDestinationFunc
 Called by YAPF to detect if node ends in the desired destination.
using PfDetectDestinationTileFunc
 Called by YAPF to detect if node ends in the desired destination.
using TransportTypeCharFunc
 Return debug report character to identify the transportation type.
Public Types inherited from CYapfSegmentCostCacheNoneT< WaterRegionTypes >
typedef WaterRegionTypes::Tpf Tpf
 the pathfinder class (derived from THIS class)
typedef WaterRegionTypes::NodeList::Item Node
 this will be our node type
Data Fields inherited from CYapfBaseT< WaterRegionTypes >
NodeList nodes
 node list multi-container
int num_steps
 this is there for debugging purposes (hope it doesn't hurt)
Protected Member Functions inherited from CYapfBaseT< WaterRegionTypes >
TpfYapf ()
 Access the inherited path finder.
Protected Attributes inherited from CYapfBaseT< WaterRegionTypes >
Nodebest_dest_node
 pointer to the destination node found at last round
Nodebest_intermediate_node
 here should be node closest to the destination if path not found
const YAPFSettingssettings
 current settings (_settings_game.yapf)
int max_search_nodes
 maximum number of nodes we are allowed to visit before we give up
const VehicleTypevehicle
 vehicle that we are trying to drive
int stats_cost_calcs
 stats - how many node's costs were calculated
int stats_cache_hits
 stats - how many node's costs were reused from cache

Detailed Description

Water region based YAPF implementation for ships.

Definition at line 92 of file yapf_ship_regions.cpp.

Member Typedef Documentation

◆ Node

using YapfShipRegions::Node = typename WaterRegionTypes::NodeList::Item
private

Definition at line 97 of file yapf_ship_regions.cpp.

Constructor & Destructor Documentation

◆ YapfShipRegions()

YapfShipRegions::YapfShipRegions ( int max_nodes)
inlineexplicit

Definition at line 108 of file yapf_ship_regions.cpp.

Member Function Documentation

◆ AddOrigin()

void YapfShipRegions::AddOrigin ( const WaterRegionPatchDesc & water_region_patch)
inline

Definition at line 113 of file yapf_ship_regions.cpp.

◆ FindWaterRegionPath()

std::vector< WaterRegionPatchDesc > YapfShipRegions::FindWaterRegionPath ( const Ship * v,
TileIndex start_tile,
int max_returned_path_length )
inlinestatic

Finds a path at the water region level.

Note that the starting region is always included if the path was found.

Parameters
vThe ship to find a path for.
start_tileThe tile to start searching from.
max_returned_path_lengthThe maximum length of the path that will be returned.
Returns
A path of water region patches, or an empty vector if no path was found.

Definition at line 183 of file yapf_ship_regions.cpp.

References Vehicle::current_order, Vehicle::dest_tile, Dock, CYapfBaseT< Types >::FindPath(), CYapfBaseT< Types >::GetBestNode(), Order::GetDestination(), BaseStation::GetTileArea(), GetWaterRegionPatchInfo(), INVALID_TILE, IsDockingTile(), IsShipDestinationTile(), Order::IsType(), and Map::Size().

Referenced by YapfShipFindWaterRegionPath().

◆ HasOrigin()

bool YapfShipRegions::HasOrigin ( const WaterRegionPatchDesc & water_region_patch)
inline

Definition at line 124 of file yapf_ship_regions.cpp.

◆ PfCalcCost()

bool YapfShipRegions::PfCalcCost ( Node & n,
const TrackFollower * follower )
inline

Called by YAPF to calculate the cost from the origin to the given node.

Calculates only the cost of given node, adds it to the parent node cost and stores the result into Node::cost member.

Parameters
nThe node to consider.
followerThe track follower to the next node.
Returns
true iff the costs could be calculated.

Definition at line 152 of file yapf_ship_regions.cpp.

References DIAGDIRDIFF_90LEFT, DIAGDIRDIFF_90RIGHT, and DiagDirDifference().

◆ PfCalcEstimate()

bool YapfShipRegions::PfCalcEstimate ( Node & n)
inline

Called by YAPF to calculate cost estimate.

Calculates distance to the destination adds it to the actual cost from origin and stores the sum to the Node::estimate.

Parameters
nThe node to start from.
Returns
true iff the cost could be estimated.

Definition at line 167 of file yapf_ship_regions.cpp.

References PfDetectDestination().

◆ PfDetectDestination()

bool YapfShipRegions::PfDetectDestination ( Node & n) const
inline

Called by YAPF to detect if node ends in the desired destination.

Parameters
nThe current node.
Returns
true iff the destination has been reached.

Definition at line 146 of file yapf_ship_regions.cpp.

Referenced by PfCalcEstimate().

◆ PfFollowNode()

void YapfShipRegions::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 135 of file yapf_ship_regions.cpp.

References CYapfBaseT< Types >::AddNewNode(), CYapfBaseT< Types >::CreateNewNode(), VisitWaterRegionPatchNeighbours(), and CYapfBaseT< WaterRegionTypes >::Yapf().

◆ SetDestination()

void YapfShipRegions::SetDestination ( const WaterRegionPatchDesc & water_region_patch)
inline

Definition at line 129 of file yapf_ship_regions.cpp.

◆ TransportTypeChar()

char YapfShipRegions::TransportTypeChar ( ) const
inline

Return debug report character to identify the transportation type.

Returns
The debug representation

Definition at line 180 of file yapf_ship_regions.cpp.

◆ Yapf()

YapfShipRegions & YapfShipRegions::Yapf ( )
inlineprivate

Definition at line 102 of file yapf_ship_regions.cpp.

Field Documentation

◆ dest

WaterRegionPatchKey YapfShipRegions::dest
private

Definition at line 100 of file yapf_ship_regions.cpp.

◆ origin_keys

std::vector<WaterRegionPatchKey> YapfShipRegions::origin_keys
private

Definition at line 99 of file yapf_ship_regions.cpp.


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