summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-13 10:48:44 +0000
committerrubidium <rubidium@openttd.org>2009-12-13 10:48:44 +0000
commit472e5501fa99b9db5c1ebccadf929e56e59fefdd (patch)
tree168696f40e69790495f936179cfa332faea5c3f7
parent3cfcae07e2732a11005da79dc0a113b22d83951b (diff)
downloadopenttd-472e5501fa99b9db5c1ebccadf929e56e59fefdd.tar.xz
(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.
-rw-r--r--src/pathfinder/npf/npf.cpp8
-rw-r--r--src/pathfinder/npf/npf_func.h12
-rw-r--r--src/pathfinder/pathfinder_type.h2
-rw-r--r--src/pathfinder/yapf/yapf.h10
-rw-r--r--src/pathfinder/yapf/yapf_rail.cpp18
-rw-r--r--src/roadveh_cmd.cpp17
-rw-r--r--src/saveload/saveload.cpp2
-rw-r--r--src/settings_type.h2
-rw-r--r--src/ship_cmd.cpp10
-rw-r--r--src/table/settings.h11
-rw-r--r--src/train_cmd.cpp17
11 files changed, 65 insertions, 44 deletions
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp
index 1fe5fe07f..1e732a125 100644
--- a/src/pathfinder/npf/npf.cpp
+++ b/src/pathfinder/npf/npf.cpp
@@ -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)
diff --git a/src/pathfinder/npf/npf_func.h b/src/pathfinder/npf/npf_func.h
index 14c4d2c53..6684d9897 100644
--- a/src/pathfinder/npf/npf_func.h
+++ b/src/pathfinder/npf/npf_func.h
@@ -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.
diff --git a/src/pathfinder/pathfinder_type.h b/src/pathfinder/pathfinder_type.h
index 0bb3f2e5d..5943537c2 100644
--- a/src/pathfinder/pathfinder_type.h
+++ b/src/pathfinder/pathfinder_type.h
@@ -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
/**
diff --git a/src/pathfinder/yapf/yapf.h b/src/pathfinder/yapf/yapf.h
index 1f7b4a6a5..54e46ce75 100644
--- a/src/pathfinder/yapf/yapf.h
+++ b/src/pathfinder/yapf/yapf.h
@@ -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
*/
diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp
index 5cb4957fd..4365ac50f 100644
--- a/src/pathfinder/yapf/yapf_rail.cpp
+++ b/src/pathfinder/yapf/yapf_rail.cpp
@@ -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;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 50de1073f..ce3ab61d2 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -358,8 +358,8 @@ static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance
if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
switch (_settings_game.pf.pathfinder_for_roadvehs) {
- case VPF_NPF: return NPFRoadVehicleFindNearestDepot(v, max_distance);
- case VPF_YAPF: return YapfRoadVehicleFindNearestDepot(v, max_distance);
+ case VPF_NPF: return NPFRoadVehicleFindNearestDepot(v, _settings_game.pf.npf.maximum_go_to_depot_penalty);
+ case VPF_YAPF: return YapfRoadVehicleFindNearestDepot(v, _settings_game.pf.yapf.maximum_go_to_depot_penalty);
default: NOT_REACHED();
}
@@ -1608,8 +1608,6 @@ bool RoadVehicle::Tick()
static void CheckIfRoadVehNeedsService(RoadVehicle *v)
{
- static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16;
-
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
if (Company::Get(v->owner)->settings.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
@@ -1617,9 +1615,16 @@ static void CheckIfRoadVehNeedsService(RoadVehicle *v)
return;
}
- FindDepotData rfdd = FindClosestRoadDepot(v, MAX_ACCEPTABLE_DEPOT_DIST);
+ uint max_penalty;
+ switch (_settings_game.pf.pathfinder_for_roadvehs) {
+ case VPF_NPF: max_penalty = _settings_game.pf.npf.maximum_go_to_depot_penalty; break;
+ case VPF_YAPF: max_penalty = _settings_game.pf.yapf.maximum_go_to_depot_penalty; break;
+ default: NOT_REACHED();
+ }
+
+ FindDepotData rfdd = FindClosestRoadDepot(v, max_penalty);
/* Only go to the depot if it is not too far out of our way. */
- if (rfdd.best_length == UINT_MAX || rfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {
+ if (rfdd.best_length == UINT_MAX || rfdd.best_length > max_penalty) {
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
/* If we were already heading for a depot but it has
* suddenly moved farther away, we continue our normal
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index d07e7a336..d00aefda0 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -47,7 +47,7 @@
#include "saveload_internal.h"
-extern const uint16 SAVEGAME_VERSION = 130;
+extern const uint16 SAVEGAME_VERSION = 131;
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/settings_type.h b/src/settings_type.h
index fcbf40fbb..851e495b7 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -208,6 +208,7 @@ struct NPFSettings {
* of not being perfect anymore.
*/
uint32 npf_max_search_nodes;
+ uint32 maximum_go_to_depot_penalty; ///< What is the maximum penalty that may be endured for going to a depot
uint32 npf_rail_firstred_penalty; ///< the penalty for when the first signal is red (and it is not an exit or combo signal)
uint32 npf_rail_firstred_exit_penalty; ///< the penalty for when the first signal is red (and it is an exit or combo signal)
@@ -231,6 +232,7 @@ struct NPFSettings {
struct YAPFSettings {
bool disable_node_optimization; ///< whether to use exit-dir instead of trackdir in node key
uint32 max_search_nodes; ///< stop path-finding when this number of nodes visited
+ uint32 maximum_go_to_depot_penalty; ///< What is the maximum penalty that may be endured for going to a depot
bool ship_use_yapf; ///< use YAPF for ships
bool road_use_yapf; ///< use YAPF for road
bool rail_use_yapf; ///< use YAPF for rail
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 730c521b8..9bc96ab88 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -126,9 +126,17 @@ static void CheckIfShipNeedsService(Vehicle *v)
return;
}
+ uint max_distance;
+ switch (_settings_game.pf.pathfinder_for_ships) {
+ case VPF_OPF: max_distance = 12; break;
+ case VPF_NPF: max_distance = _settings_game.pf.npf.maximum_go_to_depot_penalty / NPF_TILE_LENGTH; break;
+ case VPF_YAPF: max_distance = _settings_game.pf.yapf.maximum_go_to_depot_penalty / YAPF_TILE_LENGTH; break;
+ default: NOT_REACHED();
+ }
+
const Depot *depot = FindClosestShipDepot(v);
- if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
+ if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > max_distance) {
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
v->current_order.MakeDummy();
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
diff --git a/src/table/settings.h b/src/table/settings.h
index f08f5245e..bda619107 100644
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -464,18 +464,18 @@ const SettingDesc _settings[] = {
SDT_VAR(GameSettings, pf.npf.npf_rail_lastred_penalty, SLE_UINT, 0, 0, ( 10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_VAR(GameSettings, pf.npf.npf_rail_station_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_VAR(GameSettings, pf.npf.npf_rail_slope_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
- SDT_VAR(GameSettings, pf.npf.npf_rail_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL),
+ SDT_VAR(GameSettings, pf.npf.npf_rail_curve_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_VAR(GameSettings, pf.npf.npf_rail_depot_reverse_penalty, SLE_UINT, 0, 0, ( 50 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.npf.npf_rail_pbs_cross_penalty, SLE_UINT,100, SL_MAX_VERSION, 0, 0, ( 3 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.npf.npf_rail_pbs_signal_back_penalty, SLE_UINT,100, SL_MAX_VERSION, 0, 0, ( 15 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_VAR(GameSettings, pf.npf.npf_buoy_penalty, SLE_UINT, 0, 0, ( 2 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
- SDT_VAR(GameSettings, pf.npf.npf_water_curve_penalty, SLE_UINT, 0, 0, (NPF_TILE_LENGTH / 4), 0, 100000, 0, STR_NULL, NULL),
- SDT_VAR(GameSettings, pf.npf.npf_road_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL),
+ SDT_VAR(GameSettings, pf.npf.npf_water_curve_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
+ SDT_VAR(GameSettings, pf.npf.npf_road_curve_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_VAR(GameSettings, pf.npf.npf_crossing_penalty, SLE_UINT, 0, 0, ( 3 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.npf.npf_road_drive_through_penalty, SLE_UINT, 47, SL_MAX_VERSION, 0, 0, ( 8 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.npf.npf_road_dt_occupied_penalty, SLE_UINT,130, SL_MAX_VERSION, 0, 0, ( 8 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.npf.npf_road_bay_occupied_penalty, SLE_UINT,130, SL_MAX_VERSION, 0, 0, ( 15 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
-
+ SDT_CONDVAR(GameSettings, pf.npf.maximum_go_to_depot_penalty, SLE_UINT,131, SL_MAX_VERSION, 0, 0, ( 20 * NPF_TILE_LENGTH), 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDBOOL(GameSettings, pf.yapf.disable_node_optimization, 28, SL_MAX_VERSION, 0, 0, false, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.max_search_nodes, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10000, 500, 1000000, 0, STR_NULL, NULL),
@@ -486,7 +486,7 @@ const SettingDesc _settings[] = {
SDT_CONDVAR(GameSettings, pf.yapf.rail_lastred_exit_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 100 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_station_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_slope_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 2 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
- SDT_CONDVAR(GameSettings, pf.yapf.rail_curve45_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
+ SDT_CONDVAR(GameSettings, pf.yapf.rail_curve45_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_curve90_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 6 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_depot_reverse_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 50 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_crossing_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
@@ -508,6 +508,7 @@ const SettingDesc _settings[] = {
SDT_CONDVAR(GameSettings, pf.yapf.road_stop_penalty, SLE_UINT, 47, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.road_stop_occupied_penalty, SLE_UINT,130, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.road_stop_bay_occupied_penalty, SLE_UINT,130, SL_MAX_VERSION, 0, 0, 15 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
+ SDT_CONDVAR(GameSettings, pf.yapf.maximum_go_to_depot_penalty, SLE_UINT,131, SL_MAX_VERSION, 0, 0, 20 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, game_creation.land_generator, SLE_UINT8, 30, SL_MAX_VERSION, 0,MS, 1, 0, 1, 0, STR_CONFIG_SETTING_LAND_GENERATOR, NULL),
SDT_CONDVAR(GameSettings, game_creation.oil_refinery_limit, SLE_UINT8, 30, SL_MAX_VERSION, 0, 0, 32, 12, 48, 0, STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE, NULL),
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index ceb039e01..5ae13df14 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2093,8 +2093,8 @@ static FindDepotData FindClosestTrainDepot(Train *v, int max_distance)
if (IsRailDepotTile(origin.tile)) return FindDepotData(origin.tile, 0);
switch (_settings_game.pf.pathfinder_for_trains) {
- case VPF_NPF: return NPFTrainFindNearestDepot(v, max_distance);
- case VPF_YAPF: return YapfTrainFindNearestDepot(v, max_distance);
+ case VPF_NPF: return NPFTrainFindNearestDepot(v, _settings_game.pf.npf.maximum_go_to_depot_penalty);
+ case VPF_YAPF: return YapfTrainFindNearestDepot(v, _settings_game.pf.yapf.maximum_go_to_depot_penalty);
default: NOT_REACHED();
}
@@ -4100,17 +4100,22 @@ bool Train::Tick()
static void CheckIfTrainNeedsService(Train *v)
{
- static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16;
-
if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
}
- FindDepotData tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST);
+ uint max_penalty;
+ switch (_settings_game.pf.pathfinder_for_trains) {
+ case VPF_NPF: max_penalty = _settings_game.pf.npf.maximum_go_to_depot_penalty; break;
+ case VPF_YAPF: max_penalty = _settings_game.pf.yapf.maximum_go_to_depot_penalty; break;
+ default: NOT_REACHED();
+ }
+
+ FindDepotData tfdd = FindClosestTrainDepot(v, max_penalty);
/* Only go to the depot if it is not too far out of our way. */
- if (tfdd.best_length == UINT_MAX || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {
+ if (tfdd.best_length == UINT_MAX || tfdd.best_length > max_penalty) {
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
/* If we were already heading for a depot but it has
* suddenly moved farther away, we continue our normal