From 0fe0225751c801015e8153ef8457c984312f3c72 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 4 Feb 2011 16:40:38 +0000 Subject: [PATCH] (svn r21962) -Feature-ish: GUI setting to disable reversing at signals --- src/lang/english.txt | 1 + src/saveload/afterload.cpp | 10 ++++++++++ src/saveload/saveload.cpp | 2 +- src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.h | 1 + src/train_cmd.cpp | 8 ++++---- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index f33056147e..bc2905064a 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1356,6 +1356,7 @@ STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS :{LTBLUE}Pathfin STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS_OPF :Original {BLUE}(Recommended) STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS_NPF :NPF STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS_YAPF :YAPF {RED}(Not recommended) +STR_CONFIG_SETTING_REVERSE_AT_SIGNALS :{LTBLUE}Automatic reversing at signals: {ORANGE}{STRING1} STR_CONFIG_SETTING_QUERY_CAPTION :{WHITE}Change setting value diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 531db1d1d8..a256087d21 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2551,6 +2551,16 @@ bool AfterLoadGame() } } + if (IsSavegameVersionBefore(159)) { + /* If the savegame is old (before version 100), then the value of 255 + * for these settings did not mean "disabled". As such everything + * before then did reverse. + * To simplify stuff we disable all turning around or we do not + * disable anything at all. So, if some reversing was disabled we + * will keep reversing disabled, otherwise it'll be turned on. */ + _settings_game.pf.reverse_at_signals = IsSavegameVersionBefore(100) || (_settings_game.pf.wait_oneway_signal != 255 && _settings_game.pf.wait_twoway_signal != 255 && _settings_game.pf.wait_for_pbs_path != 255); + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps(); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index ec85aedafb..9d22150ad1 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -223,7 +223,7 @@ * 156 21728 * 157 21862 * 158 21933 - * 159 21960 + * 159 21962 */ extern const uint16 SAVEGAME_VERSION = 159; ///< Current savegame version of OpenTTD. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index d2367d33ae..2d279269b6 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1449,6 +1449,7 @@ static SettingEntry _settings_vehicles_servicing[] = { static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)}; static SettingEntry _settings_vehicles_trains[] = { + SettingEntry("pf.reverse_at_signals"), SettingEntry("vehicle.train_acceleration_model"), SettingEntry("vehicle.train_slope_steepness"), SettingEntry("vehicle.max_train_length"), diff --git a/src/settings_type.h b/src/settings_type.h index 6a1ad7fb3c..e5738d6861 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -313,6 +313,7 @@ struct PathfinderSettings { bool roadveh_queue; ///< buggy road vehicle queueing bool forbid_90_deg; ///< forbid trains to make 90 deg turns + bool reverse_at_signals; ///< whether to reverse at signals at all byte wait_oneway_signal; ///< waitingtime in days before a oneway signal byte wait_twoway_signal; ///< waitingtime in days before a twoway signal diff --git a/src/table/settings.h b/src/table/settings.h index 5f87f74ae9..92129a8329 100644 --- a/src/table/settings.h +++ b/src/table/settings.h @@ -473,6 +473,7 @@ const SettingDesc _settings[] = { SDT_VAR(GameSettings, vehicle.extend_vehicle_life, SLE_UINT8, 0, 0, 0, 0, 100, 0, STR_NULL, NULL), SDT_VAR(GameSettings, economy.dist_local_authority, SLE_UINT8, 0, 0, 20, 5, 60, 0, STR_NULL, NULL), + SDT_CONDBOOL(GameSettings, pf.reverse_at_signals, 159, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_SETTING_REVERSE_AT_SIGNALS, NULL), SDT_VAR(GameSettings, pf.wait_oneway_signal, SLE_UINT8, 0, 0, 15, 2, 255, 0, STR_NULL, NULL), SDT_VAR(GameSettings, pf.wait_twoway_signal, SLE_UINT8, 0, 0, 41, 2, 255, 0, STR_NULL, NULL), SDT_CONDVAR(GameSettings, economy.town_noise_population[0], SLE_UINT16, 96, SL_MAX_VERSION, 0, 0, 800, 200, 65535, 0, STR_NULL, NULL), diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 139a7faa8c..98f6aa5ded 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2990,12 +2990,12 @@ static void TrainController(Train *v, Vehicle *nomove) v->cur_speed = 0; v->subspeed = 0; v->progress = 255 - 100; - if (_settings_game.pf.wait_oneway_signal == 255 || ++v->wait_counter < _settings_game.pf.wait_oneway_signal * 20) return; + if (!_settings_game.pf.reverse_at_signals || ++v->wait_counter < _settings_game.pf.wait_oneway_signal * 20) return; } else if (HasSignalOnTrackdir(gp.new_tile, i)) { v->cur_speed = 0; v->subspeed = 0; v->progress = 255 - 10; - if (_settings_game.pf.wait_twoway_signal == 255 || ++v->wait_counter < _settings_game.pf.wait_twoway_signal * 73) { + if (!_settings_game.pf.reverse_at_signals || ++v->wait_counter < _settings_game.pf.wait_twoway_signal * 73) { DiagDirection exitdir = TrackdirToExitdir(i); TileIndex o_tile = TileAddByDiagDir(gp.new_tile, exitdir); @@ -3010,7 +3010,7 @@ static void TrainController(Train *v, Vehicle *nomove) * reversing of stuck trains is disabled, don't reverse. * This does not apply if the reason for reversing is a one-way * signal blocking us, because a train would then be stuck forever. */ - if (_settings_game.pf.wait_for_pbs_path == 255 && !HasOnewaySignalBlockingTrackdir(gp.new_tile, i) && + if (!_settings_game.pf.reverse_at_signals && !HasOnewaySignalBlockingTrackdir(gp.new_tile, i) && UpdateSignalsOnSegment(v->tile, enterdir, v->owner) == SIGSEG_PBS) { v->wait_counter = 0; return; @@ -3578,7 +3578,7 @@ static bool TrainLocoHandler(Train *v, bool mode) ++v->wait_counter; /* Should we try reversing this tick if still stuck? */ - bool turn_around = v->wait_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.wait_for_pbs_path < 255; + bool turn_around = v->wait_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.reverse_at_signals; if (!turn_around && v->wait_counter % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == TFP_NONE) return true; if (!TryPathReserve(v)) {