Merge branch 'master' into jgrpp

# Conflicts:
#	src/landscape.cpp
#	src/landscape.h
#	src/misc_gui.cpp
#	src/newgrf_commons.cpp
#	src/order_cmd.cpp
#	src/pathfinder/yapf/yapf_base.hpp
#	src/station_cmd.cpp
#	src/tunnelbridge_cmd.cpp
#	src/vehicle.cpp
#	src/water_cmd.cpp
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-03-09 21:44:36 +00:00
119 changed files with 1359 additions and 1148 deletions

View File

@@ -111,47 +111,43 @@ public:
m_veh = v;
Yapf().PfSetStartupNodes();
bool bDestFound = true;
for (;;) {
m_num_steps++;
Node *n = m_nodes.GetBestOpenNode();
if (n == nullptr) {
break;
}
Node *best_open_node = m_nodes.GetBestOpenNode();
if (best_open_node == nullptr) break;
/* if the best open node was worse than the best path found, we can finish */
if (m_pBestDestNode != nullptr && m_pBestDestNode->GetCost() < n->GetCostEstimate()) {
if (Yapf().PfDetectDestination(*best_open_node)) {
m_pBestDestNode = best_open_node;
break;
}
m_nodes.DequeueBestOpenNode();
Yapf().PfFollowNode(*n);
Yapf().PfFollowNode(*best_open_node);
if (m_max_search_nodes == 0 || m_nodes.ClosedCount() < m_max_search_nodes) {
m_nodes.PopAlreadyDequeuedOpenNode(n->GetKey());
m_nodes.InsertClosedNode(*n);
m_nodes.PopAlreadyDequeuedOpenNode(best_open_node->GetKey());
m_nodes.InsertClosedNode(*best_open_node);
} else {
m_nodes.ReenqueueOpenNode(*n);
bDestFound = false;
m_nodes.ReenqueueOpenNode(*best_open_node);
break;
}
}
bDestFound &= (m_pBestDestNode != nullptr);
const bool destination_found = (m_pBestDestNode != nullptr);
if (_debug_yapf_level >= 3) {
UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
char ttc = Yapf().TransportTypeChar();
float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
int cost = bDestFound ? m_pBestDestNode->m_cost : -1;
int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
const UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
const char ttc = Yapf().TransportTypeChar();
const float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
const int cost = destination_found ? m_pBestDestNode->m_cost : -1;
const int dist = destination_found ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
DEBUG(yapf, 3, "[YAPF%c]%c%4d- %d rounds - %d open - %d closed - CHR %4.1f%% - C %d D %d",
ttc, bDestFound ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
ttc, destination_found ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
);
}
return bDestFound;
return destination_found;
}
/**
@@ -250,16 +246,6 @@ public:
/* have the cost or estimate callbacks marked this node as invalid? */
if (!bValid) return;
/* detect the destination */
bool bDestination = Yapf().PfDetectDestination(n);
if (bDestination) {
if (m_pBestDestNode == nullptr || n < *m_pBestDestNode) {
m_pBestDestNode = &n;
}
m_nodes.FoundBestNode(n);
return;
}
/* The new node can be set as the best intermediate node only once we're
* certain it will be finalized by being inserted into the open list. */
bool set_intermediate = m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()));

View File

@@ -275,7 +275,10 @@ public:
}
node = node->m_parent;
}
assert(!path_cache.empty());
/* A empty path means we are already at the destination. The pathfinder shouldn't have been called at all.
* Return a random reachable trackdir to hopefully nudge the ship out of this strange situation. */
if (path_cache.empty()) return GetRandomFollowUpTrackdir(v, src_tile, trackdir, true);
/* Take out the last trackdir as the result. */
const Trackdir result = path_cache.front();