From d86a56cbefa9d3dd55a90db8750dfd3a967295e9 Mon Sep 17 00:00:00 2001 From: patch-import Date: Sun, 9 Aug 2015 11:23:07 +0100 Subject: [PATCH] Import day length patch Minor whitespace fixes. http://www.tt-forums.net/viewtopic.php?p=1148227#p1148227 --- src/date.cpp | 1 + src/date_func.h | 3 ++- src/lang/english.txt | 2 ++ src/misc.cpp | 1 + src/openttd.cpp | 16 +++++++++++----- src/saveload/misc_sl.cpp | 2 ++ src/saveload/saveload.cpp | 2 +- src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 13 +++++++++++++ src/timetable_cmd.cpp | 3 ++- src/vehicle.cpp | 2 +- 12 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/date.cpp b/src/date.cpp index 9c25af40ee..fe0fb78410 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -28,6 +28,7 @@ Month _cur_month; ///< Current month (0..11) Date _date; ///< Current date in days (day counter) DateFract _date_fract; ///< Fractional part of the day. uint16 _tick_counter; ///< Ever incrementing (and sometimes wrapping) tick counter for setting off various events +uint8 _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens /** * Set the date. diff --git a/src/date_func.h b/src/date_func.h index 6bbde59556..0d07bf59e7 100644 --- a/src/date_func.h +++ b/src/date_func.h @@ -18,7 +18,8 @@ extern Year _cur_year; extern Month _cur_month; extern Date _date; extern DateFract _date_fract; -extern uint16 _tick_counter; +extern uint16 _tick_counter; +extern uint8 _tick_skip_counter; void SetDate(Date date, DateFract fract); void ConvertDateToYMD(Date date, YearMonthDay *ymd); diff --git a/src/lang/english.txt b/src/lang/english.txt index 11ae31c4c3..bcae709d91 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1527,6 +1527,8 @@ STR_CONFIG_SETTING_ALLOW_SHARES :Allow buying sh STR_CONFIG_SETTING_ALLOW_SHARES_HELPTEXT :When enabled, allow buying and selling of company shares. Shares will only be available for companies reaching a certain age STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE :Percentage of leg profit to pay in feeder systems: {STRING2} STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE_HELPTEXT :Percentage of income given to the intermediate legs in feeder systems, giving more control over the income +STR_CONFIG_SETTING_DAY_LENGTH_FACTOR :Day length factor: {STRING2} +STR_CONFIG_SETTING_DAY_LENGTH_FACTOR_HELPTEXT :Game pace is slowed by this factor STR_CONFIG_SETTING_DRAG_SIGNALS_DENSITY :When dragging, place signals every: {STRING2} STR_CONFIG_SETTING_DRAG_SIGNALS_DENSITY_HELPTEXT :Set the distance at which signals will be built on a track up to the next obstacle (signal, junction), if signals are dragged STR_CONFIG_SETTING_DRAG_SIGNALS_DENSITY_VALUE :{COMMA} tile{P 0 "" s} diff --git a/src/misc.cpp b/src/misc.cpp index d9d506993f..602862e33c 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -62,6 +62,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin _pause_mode = PM_UNPAUSED; _fast_forward = 0; _tick_counter = 0; + _tick_skip_counter = 0; _cur_tileloop_tile = 1; _thd.redsq = INVALID_TILE; if (reset_settings) MakeNewgameSettingsLive(); diff --git a/src/openttd.cpp b/src/openttd.cpp index c149ebbd4d..68663ae279 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1377,11 +1377,17 @@ void StateGameLoop() Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); - AnimateAnimatedTiles(); - IncreaseDate(); - RunTileLoop(); - CallVehicleTicks(); - CallLandscapeTick(); + _tick_skip_counter++; + if (_tick_skip_counter < _settings_game.economy.day_length_factor) { + CallVehicleTicks(); + } else { + _tick_skip_counter = 0; + AnimateAnimatedTiles(); + IncreaseDate(); + RunTileLoop(); + CallVehicleTicks(); + CallLandscapeTick(); + } BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP); #ifndef DEBUG_DUMP_COMMANDS diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index c7bd31e81e..50f7beec19 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -75,6 +75,7 @@ static const SaveLoadGlobVarList _date_desc[] = { SLEG_CONDVAR(_date, SLE_INT32, 31, SL_MAX_VERSION), SLEG_VAR(_date_fract, SLE_UINT16), SLEG_VAR(_tick_counter, SLE_UINT16), + SLEG_CONDVAR(_tick_skip_counter, SLE_UINT8, 200, SL_MAX_VERSION), SLE_CONDNULL(2, 0, 156), // _vehicle_id_ctr_day SLEG_CONDVAR(_age_cargo_skip_counter, SLE_UINT8, 0, 161), SLE_CONDNULL(1, 0, 45), @@ -100,6 +101,7 @@ static const SaveLoadGlobVarList _date_check_desc[] = { SLEG_CONDVAR(_load_check_data.current_date, SLE_INT32, 31, SL_MAX_VERSION), SLE_NULL(2), // _date_fract SLE_NULL(2), // _tick_counter + SLEG_CONDVAR(_tick_skip_counter, SLE_UINT8, 200, SL_MAX_VERSION), SLE_CONDNULL(2, 0, 156), // _vehicle_id_ctr_day SLE_CONDNULL(1, 0, 161), // _age_cargo_skip_counter SLE_CONDNULL(1, 0, 45), diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index b7c04fa742..2d3363e43b 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -263,7 +263,7 @@ * 193 26802 * 194 26881 1.5.x */ -extern const uint16 SAVEGAME_VERSION = 194; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 200; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index f1af4804e4..07bc2e5b76 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1591,6 +1591,7 @@ static SettingsContainer &GetSettingsTree() SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING)); { accounting->Add(new SettingEntry("economy.inflation")); + accounting->Add(new SettingEntry("economy.day_length_factor")); accounting->Add(new SettingEntry("difficulty.initial_interest")); accounting->Add(new SettingEntry("difficulty.max_loan")); accounting->Add(new SettingEntry("difficulty.subsidy_multiplier")); diff --git a/src/settings_type.h b/src/settings_type.h index 41366a7719..a04c1c5e47 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -488,6 +488,7 @@ struct EconomySettings { uint16 town_noise_population[3]; ///< population to base decision on noise evaluation (@see town_council_tolerance) bool allow_town_level_crossings; ///< towns are allowed to build level crossings bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure + uint8 day_length_factor; ///< factor which the length of day is multiplied }; struct LinkGraphSettings { diff --git a/src/table/settings.ini b/src/table/settings.ini index f314f21e92..c8405c3eda 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -1262,6 +1262,19 @@ str = STR_CONFIG_SETTING_INFLATION strhelp = STR_CONFIG_SETTING_INFLATION_HELPTEXT cat = SC_BASIC +[SDT_VAR] +base = GameSettings +var = economy.day_length_factor +type = SLE_UINT8 +from = 200 +def = 1 +min = 1 +max = 125 +str = STR_CONFIG_SETTING_DAY_LENGTH_FACTOR +strhelp = STR_CONFIG_SETTING_DAY_LENGTH_FACTOR_HELPTEXT +strval = STR_JUST_COMMA +cat = SC_BASIC + [SDT_VAR] base = GameSettings var = construction.raw_industry_construction diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index c6eaf3da81..7ae68620e0 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -17,6 +17,7 @@ #include "vehicle_base.h" #include "cmd_helper.h" #include "core/sort_func.hpp" +#include "settings_type.h" #include "table/strings.h" @@ -384,7 +385,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED); if (v->timetable_start != 0) { - v->lateness_counter = (_date - v->timetable_start) * DAY_TICKS + _date_fract; + v->lateness_counter = (_date - v->timetable_start) * DAY_TICKS * _settings_game.economy.day_length_factor + _date_fract + _tick_skip_counter; v->timetable_start = 0; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 46f98fe63b..4b92a5da83 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -878,7 +878,7 @@ void CallVehicleTicks() { _vehicles_to_autoreplace.Clear(); - RunVehicleDayProc(); + if (_tick_skip_counter == 0) RunVehicleDayProc(); Station *st; FOR_ALL_STATIONS(st) LoadUnloadStation(st);