changeset 9800:bdb6b0b9fcd3 draft

(svn r13942) -Codechange [YAPP]: Add a penalty for double slips to YAPF. (michi_cc)
author rubidium <rubidium@openttd.org>
date Sat, 02 Aug 2008 22:51:23 +0000
parents e869d089a8b4
children c176d03c14c4
files src/settings.cpp src/settings_type.h src/yapf/yapf_costrail.hpp
diffstat 3 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1727,6 +1727,7 @@
 	 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),
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -220,6 +220,7 @@
 	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)
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -105,6 +105,16 @@
 		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 @@
 		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) */