Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/ci-build.yml
#	.github/workflows/codeql.yml
#	.github/workflows/release-linux.yml
#	.github/workflows/release-macos.yml
#	.github/workflows/release-windows.yml
#	src/map.cpp
#	src/music/midifile.hpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/pathfinder/yapf/yapf_rail.cpp
#	src/pbs.cpp
#	src/saveload/afterload.cpp
#	src/saveload/saveload.h
#	src/saveload/vehicle_sl.cpp
#	src/script/api/script_text.cpp
#	src/ship_cmd.cpp
#	src/train_cmd.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/vehicle_func.h
#	src/vehicle_gui.cpp
#	src/vehicle_gui_base.h
#	src/viewport.cpp
#	src/waypoint_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2024-03-12 17:44:28 +00:00
87 changed files with 3648 additions and 2256 deletions

View File

@@ -399,7 +399,7 @@ protected:
/* move to the platform end */
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
diff *= m_tiles_skipped;
m_new_tile = TILE_ADD(m_new_tile, diff);
m_new_tile = TileAdd(m_new_tile, diff);
return true;
}

View File

@@ -644,7 +644,7 @@ static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
if (IsRailStationTile(target->node.tile)) {
DiagDirection dir = TrackdirToExitdir(target->node.direction);
uint len = Station::GetByTile(target->node.tile)->GetPlatformLength(target->node.tile, dir);
TileIndex end_tile = TILE_ADD(target->node.tile, (len - 1) * TileOffsByDiagDir(dir));
TileIndex end_tile = TileAdd(target->node.tile, (len - 1) * TileOffsByDiagDir(dir));
/* Update only end tile, trackdir of a station stays the same. */
ftd->node.tile = end_tile;

View File

@@ -117,8 +117,8 @@ public:
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() < best_open_node->GetCostEstimate()) {
if (Yapf().PfDetectDestination(*best_open_node)) {
m_pBestDestNode = best_open_node;
break;
}
@@ -246,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()));
@@ -310,61 +300,6 @@ public:
dmp.WriteStructT("m_nodes", &m_nodes);
dmp.WriteValue("m_num_steps", m_num_steps);
}
/* methods that should be implemented at derived class Types::Tpf (derived from CYapfBaseT) */
#if 0
/** Example: PfSetStartupNodes() - set source (origin) nodes */
inline void PfSetStartupNodes()
{
/* example: */
Node &n1 = *base::m_nodes.CreateNewNode();
.
. // setup node members here
.
base::m_nodes.InsertOpenNode(n1);
}
/** Example: PfFollowNode() - set following (child) nodes of the given node */
inline void PfFollowNode(Node &org)
{
for (each follower of node org) {
Node &n = *base::m_nodes.CreateNewNode();
.
. // setup node members here
.
n.m_parent = &org; // set node's parent to allow back tracking
AddNewNode(n);
}
}
/** Example: PfCalcCost() - set path cost from origin to the given node */
inline bool PfCalcCost(Node &n)
{
/* evaluate last step cost */
int cost = ...;
/* set the node cost as sum of parent's cost and last step cost */
n.m_cost = n.m_parent->m_cost + cost;
return true; // true if node is valid follower (i.e. no obstacle was found)
}
/** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */
inline bool PfCalcEstimate(Node &n)
{
/* evaluate the distance to our destination */
int distance = ...;
/* set estimate as sum of cost from origin + distance to the target */
n.m_estimate = n.m_cost + distance;
return true; // true if node is valid (i.e. not too far away :)
}
/** Example: PfDetectDestination() - return true if the given node is our destination */
inline bool PfDetectDestination(Node &n)
{
bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
return bDest;
}
#endif
};
#endif /* YAPF_BASE_HPP */

View File

@@ -106,7 +106,7 @@ private:
if (HasStationReservation(tile)) return false;
SetRailStationReservation(tile, true);
MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE);
tile = TILE_ADD(tile, diff);
tile = TileAdd(tile, diff);
} while (IsCompatibleTrainStationTile(tile, start) && tile != m_origin_tile);
TriggerStationRandomisation(nullptr, start, SRT_PATH_RESERVATION);
@@ -143,7 +143,7 @@ private:
TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(td)));
while ((tile != m_res_fail_tile || td != m_res_fail_td) && IsCompatibleTrainStationTile(tile, start)) {
SetRailStationReservation(tile, false);
tile = TILE_ADD(tile, diff);
tile = TileAdd(tile, diff);
}
} else if (tile != m_res_fail_tile || td != m_res_fail_td) {
UnreserveRailTrackdir(tile, td);
@@ -639,6 +639,11 @@ public:
this->FindSafePositionOnNode(pPrev);
}
/* If the best PF node has no parent, then there is no (valid) best next trackdir to return.
* This occurs when the PF is called while the train is already at its destination. */
if (pPrev == nullptr) return INVALID_TRACKDIR;
/* return trackdir from the best origin node (one of start nodes) */
Node &best_next_node = *pPrev;
next_trackdir = best_next_node.GetTrackdir();