summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/settings.cpp1
-rw-r--r--src/settings_type.h1
-rw-r--r--src/yapf/yapf_costrail.hpp11
3 files changed, 13 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 032435faa..703b5c9d4 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1727,6 +1727,7 @@ const SettingDesc _patch_settings[] = {
SDT_CONDVAR(GameSettings, pf.yapf.rail_look_ahead_signal_p2, SLE_INT, 28, SL_MAX_VERSION, 0, 0, 5, -1000000, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_pbs_cross_penalty, SLE_UINT,100, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_pbs_signal_back_penalty, SLE_UINT,100, SL_MAX_VERSION, 0, 0, 15 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
+ SDT_CONDVAR(GameSettings, pf.yapf.rail_doubleslip_penalty, SLE_UINT,100, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_longer_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_longer_platform_per_tile_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 0 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL),
SDT_CONDVAR(GameSettings, pf.yapf.rail_shorter_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 40 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL),
diff --git a/src/settings_type.h b/src/settings_type.h
index 80e5960d6..d2d3a183f 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -220,6 +220,7 @@ struct YAPFSettings {
int32 rail_look_ahead_signal_p2; ///< constant in polynomial penalty function
uint32 rail_pbs_cross_penalty; ///< penalty for crossing a reserved tile
uint32 rail_pbs_signal_back_penalty; ///< penalty for passing a pbs signal from the backside
+ uint32 rail_doubleslip_penalty; ///< penalty for passing a double slip switch
uint32 rail_longer_platform_penalty; ///< penalty for longer station platform than train
uint32 rail_longer_platform_per_tile_penalty; ///< penalty for longer station platform than train (per tile)
diff --git a/src/yapf/yapf_costrail.hpp b/src/yapf/yapf_costrail.hpp
index 7ff99bb60..f959f1a3e 100644
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -105,6 +105,16 @@ public:
return cost;
}
+ FORCEINLINE int SwitchCost(TileIndex tile1, TileIndex tile2, DiagDirection exitdir)
+ {
+ if (IsTileType(tile1, MP_RAILWAY) && IsTileType(tile2, MP_RAILWAY)) {
+ bool t1 = KillFirstBit(GetTrackBits(tile1) & DiagdirReachesTracks(ReverseDiagDir(exitdir))) != TRACK_BIT_NONE;
+ bool t2 = KillFirstBit(GetTrackBits(tile2) & DiagdirReachesTracks(exitdir)) != TRACK_BIT_NONE;
+ if (t1 && t2) return Yapf().PfGetSettings().rail_doubleslip_penalty;
+ }
+ return 0;
+ }
+
/** Return one tile cost (base cost + level crossing penalty). */
FORCEINLINE int OneTileCost(TileIndex& tile, Trackdir trackdir)
{
@@ -305,6 +315,7 @@ public:
for (;;) {
/* Transition cost (cost of the move from previous tile) */
transition_cost = Yapf().CurveCost(prev.td, cur.td);
+ transition_cost += Yapf().SwitchCost(prev.tile, cur.tile, TrackdirToExitdir(prev.td));
/* First transition cost counts against segment entry cost, other transitions
* inside segment will come to segment cost (and will be cached) */