Merge branch 'more_cond_orders-sx' into jgrpp

# Conflicts:
#	config.lib
#	projects/openttd_vs100.vcxproj
#	projects/openttd_vs100.vcxproj.filters
#	projects/openttd_vs80.vcproj
#	projects/openttd_vs90.vcproj
#	src/order_gui.cpp
#	src/order_type.h
#	src/saveload/afterload.cpp
#	src/saveload/extended_ver_sl.cpp
This commit is contained in:
Jonathan G Rennison
2019-01-06 22:35:57 +00:00
36 changed files with 13882 additions and 58 deletions

View File

@@ -35,6 +35,10 @@ public:
typedef typename Node::Key Key; ///< key to hash tables
protected:
int m_max_cost;
CYapfCostRoadT() : m_max_cost(0) {};
/** to access inherited path finder */
Tpf& Yapf()
{
@@ -105,6 +109,11 @@ protected:
}
public:
inline void SetMaxCost(int max_cost)
{
m_max_cost = max_cost;
}
/**
* 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
@@ -120,6 +129,8 @@ public:
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
TileIndex tile = n.m_key.m_tile;
Trackdir trackdir = n.m_key.m_td;
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
for (;;) {
/* base tile cost depending on distance between edges */
segment_cost += Yapf().OneTileCost(tile, trackdir);
@@ -128,6 +139,12 @@ public:
/* we have reached the vehicle's destination - segment should end here to avoid target skipping */
if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
/* Finish if we already exceeded the maximum path cost (i.e. when
* searching for the nearest depot). */
if (m_max_cost > 0 && (parent_cost + segment_cost) > m_max_cost) {
return false;
}
/* stop if we have just entered the depot */
if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
/* next time we will reverse and leave the depot */
@@ -172,7 +189,6 @@ public:
n.m_segment_last_td = trackdir;
/* save also tile cost */
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
n.m_cost = parent_cost + segment_cost;
return true;
}
@@ -453,15 +469,12 @@ public:
* @param tile Tile of the vehicle.
* @param td Trackdir of the vehicle.
* @param max_distance max length (penalty) for paths.
* @todo max_distance not used by YAPF for road vehicles.
* It can be removed or copy the SetMaxCost() strategy
* applied in YAPF for rail. The best depot can be at
* a distance greater than max_distance.
*/
inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
{
/* Set origin. */
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
Yapf().SetMaxCost(max_distance);
/* Find the best path and return if no depot is found. */
if (!Yapf().FindPath(v)) return FindDepotData();