(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
-Feature-ish: make maximum pathfinder penalties for finding depots customisable, also increase it slightly to 20 tiles worth of penalties.
This commit is contained in:
@@ -1127,7 +1127,7 @@ static void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, const Vehicle *
|
||||
|
||||
/*** Road vehicles ***/
|
||||
|
||||
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
|
||||
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
|
||||
{
|
||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||
|
||||
@@ -1140,7 +1140,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dista
|
||||
* number by this. It might not be completely what we want, but it will
|
||||
* work for now :-) We can possibly change this when the old pathfinder
|
||||
* is removed. */
|
||||
return FindDepotData(ftd.node.tile, ftd.best_path_dist / NPF_TILE_LENGTH);
|
||||
return FindDepotData(ftd.node.tile, ftd.best_path_dist);
|
||||
}
|
||||
|
||||
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs)
|
||||
@@ -1187,7 +1187,7 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
|
||||
|
||||
/*** Trains ***/
|
||||
|
||||
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_distance)
|
||||
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty)
|
||||
{
|
||||
const Train *last = v->Last();
|
||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||
@@ -1202,7 +1202,7 @@ FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_distance)
|
||||
* number by this. It might not be completely what we want, but it will
|
||||
* work for now :-) We can possibly change this when the old pathfinder
|
||||
* is removed. */
|
||||
return FindDepotData(ftd.node.tile, ftd.best_path_dist / NPF_TILE_LENGTH, NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE));
|
||||
return FindDepotData(ftd.node.tile, ftd.best_path_dist, NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE));
|
||||
}
|
||||
|
||||
bool NPFTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir trackdir, bool override_railtype)
|
||||
|
@@ -19,12 +19,12 @@
|
||||
/**
|
||||
* Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using NPF.
|
||||
* @param v vehicle that needs to go to some depot
|
||||
* @param max_distance max distance (number of track tiles) from the current vehicle position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
||||
* @param max_penalty max distance (in pathfinder penalty) from the current vehicle position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_penalty
|
||||
* was reached and no depot was seen)
|
||||
* @return the data about the depot
|
||||
*/
|
||||
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance);
|
||||
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty);
|
||||
|
||||
/**
|
||||
* Finds the best path for given road vehicle using NPF.
|
||||
@@ -49,12 +49,12 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
|
||||
/**
|
||||
* Used when user sends train to the nearest depot or if train needs servicing using NPF
|
||||
* @param v train that needs to go to some depot
|
||||
* @param max_distance max distance (number of track tiles) from the current train position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
||||
* @param max_penalty max max_penalty (in pathfinder penalty) from the current train position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_penalty
|
||||
* was reached and no depot was seen)
|
||||
* @return the data about the depot
|
||||
*/
|
||||
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_distance);
|
||||
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty);
|
||||
|
||||
/**
|
||||
* Try to extend the reserved path of a train to the nearest safe tile using NPF.
|
||||
|
@@ -43,7 +43,7 @@ static const int YAPF_INFINITE_PENALTY = 1000 * YAPF_TILE_LENGTH;
|
||||
*/
|
||||
struct FindDepotData {
|
||||
TileIndex tile; ///< The tile of the depot
|
||||
uint best_length; ///< The distance towards the depot, or UINT_MAX if not found
|
||||
uint best_length; ///< The distance towards the depot in penalty, or UINT_MAX if not found
|
||||
bool reverse; ///< True if reversing is necessary for the train to get to this depot
|
||||
|
||||
/**
|
||||
|
@@ -52,18 +52,18 @@ Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdi
|
||||
/**
|
||||
* Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
|
||||
* @param v vehicle that needs to go to some depot
|
||||
* @param max_distance max distance (number of track tiles) from the current vehicle position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
||||
* @param max_penalty max distance (in pathfinder penalty) from the current vehicle position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_penalty
|
||||
* was reached and no depot was seen)
|
||||
* @return the data about the depot
|
||||
*/
|
||||
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance);
|
||||
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty);
|
||||
|
||||
/**
|
||||
* Used when user sends train to the nearest depot or if train needs servicing using YAPF.
|
||||
* @param v train that needs to go to some depot
|
||||
* @param max_distance max distance (number of track tiles) from the current train position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
||||
* @param max_penalty max distance (int pathfinder penalty) from the current train position
|
||||
* (used also as optimization - the pathfinder can stop path finding if max_penalty
|
||||
* was reached and no depot was seen)
|
||||
* @return the data about the depot
|
||||
*/
|
||||
|
@@ -217,7 +217,7 @@ public:
|
||||
return 't';
|
||||
}
|
||||
|
||||
static bool stFindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
|
||||
static bool stFindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
|
||||
{
|
||||
Tpf pf1;
|
||||
/*
|
||||
@@ -229,15 +229,15 @@ public:
|
||||
* so it will only impact performance when you do not manually set
|
||||
* depot orders and you do not disable automatic servicing.
|
||||
*/
|
||||
if (max_distance != 0) pf1.DisableCache(true);
|
||||
bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed);
|
||||
if (max_penalty != 0) pf1.DisableCache(true);
|
||||
bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_penalty, reverse_penalty, depot_tile, reversed);
|
||||
|
||||
#if DEBUG_YAPF_CACHE
|
||||
Tpf pf2;
|
||||
TileIndex depot_tile2 = INVALID_TILE;
|
||||
bool reversed2 = false;
|
||||
pf2.DisableCache(true);
|
||||
bool result2 = pf2.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, &depot_tile2, &reversed2);
|
||||
bool result2 = pf2.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_penalty, reverse_penalty, &depot_tile2, &reversed2);
|
||||
if (result1 != result2 || (result1 && (*depot_tile != depot_tile2 || *reversed != reversed2))) {
|
||||
DEBUG(yapf, 0, "CACHE ERROR: FindNearestDepotTwoWay() = [%s, %s]", result1 ? "T" : "F", result2 ? "T" : "F");
|
||||
DumpState(pf1, pf2);
|
||||
@@ -247,12 +247,12 @@ public:
|
||||
return result1;
|
||||
}
|
||||
|
||||
FORCEINLINE bool FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
|
||||
FORCEINLINE bool FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
|
||||
{
|
||||
/* set origin and destination nodes */
|
||||
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
|
||||
Yapf().SetDestination(v);
|
||||
Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance);
|
||||
Yapf().SetMaxCost(max_penalty);
|
||||
|
||||
/* find the best path */
|
||||
bool bFound = Yapf().FindPath(v);
|
||||
@@ -600,7 +600,7 @@ bool YapfTrainCheckReverse(const Train *v)
|
||||
return reverse;
|
||||
}
|
||||
|
||||
FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance)
|
||||
FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_penalty)
|
||||
{
|
||||
FindDepotData fdd;
|
||||
|
||||
@@ -618,8 +618,8 @@ FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance)
|
||||
pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg
|
||||
}
|
||||
|
||||
bool ret = pfnFindNearestDepotTwoWay(v, origin.tile, origin.trackdir, last_tile, td_rev, max_distance, YAPF_INFINITE_PENALTY, &fdd.tile, &fdd.reverse);
|
||||
fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND
|
||||
bool ret = pfnFindNearestDepotTwoWay(v, origin.tile, origin.trackdir, last_tile, td_rev, max_penalty, YAPF_INFINITE_PENALTY, &fdd.tile, &fdd.reverse);
|
||||
fdd.best_length = ret ? max_penalty / 2 : UINT_MAX; // some fake distance or NOT_FOUND
|
||||
return fdd;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user