diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index 6a8f2d6e0f..4755f98376 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -636,12 +637,12 @@ static void window_cheats_money_mousedown(rct_window* w, rct_widgetindex widgetI break; case WIDX_YEAR_UP: year_spinner_value++; - year_spinner_value = std::clamp(year_spinner_value, 1, 8192); + year_spinner_value = std::clamp(year_spinner_value, 1, MAX_YEAR); widget_invalidate(w, WIDX_YEAR_BOX); break; case WIDX_YEAR_DOWN: year_spinner_value--; - year_spinner_value = std::clamp(year_spinner_value, 1, 8192); + year_spinner_value = std::clamp(year_spinner_value, 1, MAX_YEAR); widget_invalidate(w, WIDX_YEAR_BOX); break; case WIDX_MONTH_UP: @@ -669,16 +670,22 @@ static void window_cheats_money_mousedown(rct_window* w, rct_widgetindex widgetI widget_invalidate(w, WIDX_DAY_BOX); break; case WIDX_DATE_SET: - date_set(year_spinner_value, month_spinner_value, day_spinner_value); + { + auto setDateAction = ParkSetDateAction(year_spinner_value, month_spinner_value, day_spinner_value); + GameActions::Execute(&setDateAction); window_invalidate_by_class(WC_BOTTOM_TOOLBAR); break; + } case WIDX_DATE_RESET: - date_set(1, 1, 1); + { + auto setDateAction = ParkSetDateAction(1, 1, 1); + GameActions::Execute(&setDateAction); window_invalidate_by_class(WC_BOTTOM_TOOLBAR); widget_invalidate(w, WIDX_YEAR_BOX); widget_invalidate(w, WIDX_MONTH_BOX); widget_invalidate(w, WIDX_DAY_BOX); break; + } } } diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index ba69293988..d1b1025e61 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -632,10 +632,6 @@ void game_command_cheat( } set_forced_park_rating(*edx); break; - case CHEAT_RESETDATE: - date_reset(); - window_invalidate_by_class(WC_BOTTOM_TOOLBAR); - break; case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES: gCheatsAllowArbitraryRideTypeChanges = *edx != 0; window_invalidate_by_class(WC_RIDE); @@ -975,8 +971,6 @@ const char* cheats_get_cheat_string(int cheat, int edx, int edi) return cheat_string; } - case CHEAT_RESETDATE: - return language_get_string(STR_CHEAT_RESET_DATE); case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES: return language_get_string(STR_CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES); case CHEAT_SETMONEY: diff --git a/src/openrct2/Cheats.h b/src/openrct2/Cheats.h index 9adb950882..b690ba18c1 100644 --- a/src/openrct2/Cheats.h +++ b/src/openrct2/Cheats.h @@ -78,13 +78,11 @@ enum CHEAT_HAVEFUN, CHEAT_SETFORCEDPARKRATING, CHEAT_NEVERENDINGMARKETING, - CHEAT_RESETDATE, CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES, CHEAT_OWNALLLAND, CHEAT_DISABLERIDEVALUEAGING, CHEAT_IGNORERESEARCHSTATUS, CHEAT_ENABLEALLDRAWABLETRACKPIECES, - CHEAT_DATE_SET, }; enum diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index b944b2a875..4700b2ecd9 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -97,6 +97,7 @@ enum GAME_COMMAND GAME_COMMAND_PLACE_FOOTPATH_SCENERY, // GA GAME_COMMAND_REMOVE_FOOTPATH_SCENERY, // GA GAME_COMMAND_GUEST_SET_FLAGS, // GA + GAME_COMMAND_SET_DATE, // GA GAME_COMMAND_COUNT, }; diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index f13264d1d8..54937b3c56 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -27,6 +27,7 @@ #include "MazeSetTrackAction.hpp" #include "ParkEntranceRemoveAction.hpp" #include "ParkMarketingAction.hpp" +#include "ParkSetDateAction.hpp" #include "ParkSetLoanAction.hpp" #include "ParkSetNameAction.hpp" #include "ParkSetParameterAction.hpp" @@ -127,5 +128,6 @@ namespace GameActions Register(); Register(); Register(); + Register(); } } // namespace GameActions diff --git a/src/openrct2/actions/ParkSetDateAction.hpp b/src/openrct2/actions/ParkSetDateAction.hpp new file mode 100644 index 0000000000..72d776c7e5 --- /dev/null +++ b/src/openrct2/actions/ParkSetDateAction.hpp @@ -0,0 +1,65 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../Context.h" +#include "../core/MemoryStream.h" +#include "../localisation/StringIds.h" +#include "../management/Finance.h" +#include "../ui/UiContext.h" +#include "../ui/WindowManager.h" +#include "../windows/Intent.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(ParkSetDateAction, GAME_COMMAND_SET_DATE, GameActionResult) +{ +private: + int32_t _year = 0; + int32_t _month = 0; + int32_t _day = 0; + +public: + ParkSetDateAction() + { + } + ParkSetDateAction(int32_t year, int32_t month, int32_t day) + : _year(year) + , _month(month) + , _day(day) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + stream << DS_TAG(_year) << DS_TAG(_month) << DS_TAG(_day); + } + + GameActionResult::Ptr Query() const override + { + if (_year <= 0 || _year > MAX_YEAR || _month <= 0 || _month > MONTH_COUNT || _day <= 0 || _day > 31) + { + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + return MakeResult(); + } + + GameActionResult::Ptr Execute() const override + { + date_set(_year, _month, _day); + return MakeResult(); + } +}; diff --git a/src/openrct2/localisation/Date.h b/src/openrct2/localisation/Date.h index 4930c413bd..52eb12a1ed 100644 --- a/src/openrct2/localisation/Date.h +++ b/src/openrct2/localisation/Date.h @@ -12,6 +12,8 @@ #include "../common.h" +constexpr int32_t MAX_YEAR = 8192; + enum { MONTH_MARCH, diff --git a/src/openrct2/localisation/Localisation.Date.cpp b/src/openrct2/localisation/Localisation.Date.cpp index 7df295312d..6507a9afdd 100644 --- a/src/openrct2/localisation/Localisation.Date.cpp +++ b/src/openrct2/localisation/Localisation.Date.cpp @@ -67,7 +67,7 @@ void date_reset() void date_set(int32_t year, int32_t month, int32_t day) { - year = std::clamp(year, 1, 8192); + year = std::clamp(year, 1, MAX_YEAR); month = std::clamp(month, 1, (int)MONTH_COUNT); day = std::clamp(day, 1, (int)days_in_month[month - 1]); gDateMonthsElapsed = (year - 1) * MONTH_COUNT + month - 1; diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index f99b9e0019..84da62b965 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -31,7 +31,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "13" +#define NETWORK_STREAM_VERSION "14" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/network/NetworkAction.cpp b/src/openrct2/network/NetworkAction.cpp index 531be704eb..368b506f96 100644 --- a/src/openrct2/network/NetworkAction.cpp +++ b/src/openrct2/network/NetworkAction.cpp @@ -237,6 +237,7 @@ const std::array NetworkActions::Action "PERMISSION_CHEAT", { GAME_COMMAND_CHEAT, + GAME_COMMAND_SET_DATE, }, }, NetworkAction{