1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 03:23:15 +01:00

Implement GameAction for setting date

This commit is contained in:
Michael Steenbeek
2019-03-31 19:48:51 +02:00
committed by GitHub
parent e38efcbec4
commit b618bbdcd4
10 changed files with 84 additions and 14 deletions

View File

@@ -14,6 +14,7 @@
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/actions/ParkSetDateAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
@@ -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;
}
}
}

View File

@@ -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:

View File

@@ -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

View File

@@ -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,
};

View File

@@ -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<WaterLowerAction>();
Register<WaterRaiseAction>();
Register<GuestSetFlagsAction>();
Register<ParkSetDateAction>();
}
} // namespace GameActions

View File

@@ -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();
}
};

View File

@@ -12,6 +12,8 @@
#include "../common.h"
constexpr int32_t MAX_YEAR = 8192;
enum
{
MONTH_MARCH,

View File

@@ -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;

View File

@@ -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;

View File

@@ -237,6 +237,7 @@ const std::array<NetworkAction, NETWORK_PERMISSION_COUNT> NetworkActions::Action
"PERMISSION_CHEAT",
{
GAME_COMMAND_CHEAT,
GAME_COMMAND_SET_DATE,
},
},
NetworkAction{