OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
13 #include "../../debug.h"
14 #include "../../settings_type.h"
46 template <
class Types>
49 typedef typename Types::Tpf
Tpf;
50 typedef typename Types::TrackFollower TrackFollower;
53 typedef typename NodeList::Titem
Node;
54 typedef typename Node::Key
Key;
92 return *
static_cast<Tpf *
>(
this);
115 Yapf().PfSetStartupNodes();
120 if (best_open_node ==
nullptr)
break;
122 if (
Yapf().PfDetectDestination(*best_open_node)) {
127 Yapf().PfFollowNode(*best_open_node);
130 m_nodes.PopOpenNode(best_open_node->GetKey());
131 m_nodes.InsertClosedNode(*best_open_node);
136 if (_debug_yapf_level >= 3) {
138 const char ttc =
Yapf().TransportTypeChar();
143 Debug(yapf, 3,
"[YAPF{}]{}{:4d} - {} rounds - {} open - {} closed - CHR {:4.1f}% - C {} D {}",
144 ttc, destination_found ?
'-' :
'!', veh_idx,
m_num_steps,
m_nodes.OpenCount(),
m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
148 return destination_found;
173 Yapf().PfNodeCacheFetch(n);
175 if (
m_nodes.FindOpenNode(n.m_key) ==
nullptr) {
191 n.Set(parent, tf.m_new_tile, td, is_choice);
192 Yapf().AddNewNode(n, tf);
206 bool intermediate_on_branch =
false;
207 while (n !=
nullptr && (n->m_segment->m_end_segment_reason & ESRB_CHOICE_FOLLOWS) == 0) {
211 if (intermediate_on_branch)
Yapf().m_pBestIntermediateNode = n;
221 bool bCached =
Yapf().PfNodeCacheFetch(n);
228 bool bValid =
Yapf().PfCalcCost(n, &tf);
230 if (bValid) bValid =
Yapf().PfCalcEstimate(n);
241 if (openNode !=
nullptr) {
244 if (n.GetCostEstimate() < openNode->GetCostEstimate()) {
246 m_nodes.PopOpenNode(n.GetKey());
249 m_nodes.InsertOpenNode(*openNode);
256 Node *closedNode =
m_nodes.FindClosedNode(n.GetKey());
257 if (closedNode !=
nullptr) {
260 int node_est = n.GetCostEstimate();
261 int closed_est = closedNode->GetCostEstimate();
262 if (node_est < closed_est) {
const YAPFSettings & PfGetSettings() const
return current settings (can be custom - company based - but later)
uint16_t UnitID
Type for the company global vehicle unit number.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
void PruneIntermediateNodeBranch(Node *n)
In some cases an intermediate node branch should be pruned.
Settings related to the yet another pathfinder.
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int m_stats_cache_hits
stats - how many node's costs were reused from cache
void AddMultipleNodes(Node *parent, const TrackFollower &tf)
add multiple nodes - direct children of the given node
void WriteStructT(const std::string &name, const S *s)
Dump nested object (or only its name if this instance is already known).
const YAPFSettings * m_settings
current settings (_settings_game.yapf)
@ TRACKDIR_BIT_NONE
No track build.
CYapfBaseT()
default constructor
Tpf & Yapf()
to access inherited path finder
Class that represents the dump-into-string target.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
NodeList m_nodes
node list multi-container
int m_num_steps
this is there for debugging purposes (hope it doesn't hurt)
Types::VehicleType VehicleType
the type of vehicle
Node * GetBestNode()
If path was found return the best node that has reached the destination.
Node::Key Key
key to hash tables
void AddNewNode(Node &n, const TrackFollower &tf)
AddNewNode() - called by Tderived::PfFollowNode() for each child node.
int m_max_search_nodes
maximum number of nodes we are allowed to visit before we give up
Node * m_pBestDestNode
pointer to the destination node found at last round
void AddStartupNode(Node &n)
Add new node (created by CreateNewNode and filled with data) into open list.
Trackdir
Enumeration for tracks and directions.
int m_stats_cost_calcs
stats - how many node's costs were calculated
bool FindPath(const VehicleType *v)
Main pathfinder routine:
Node & CreateNewNode()
Calls NodeList::CreateNewNode() - allocates new node that can be filled and used as argument for AddS...
Types::NodeList NodeList
our node list
~CYapfBaseT()
default destructor
Node * m_pBestIntermediateNode
here should be node closest to the destination if path not found
VehicleType
Available vehicle types.
const VehicleType * m_veh
vehicle that we are trying to drive
CYapfBaseT - A-star type path finder base class.
TrackdirBits
Allow incrementing of Trackdir variables.
NodeList::Titem Node
this will be our node type
void WriteValue(const std::string &name, int value)
Write 'name = value' with indent and new-line.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.