Skip to content

Commit

Permalink
OpenRCT2#21193: Move gParkFlags to GameState_t, refactor uses
Browse files Browse the repository at this point in the history
Also changed a few instances where GetGameState was called inside the same function.
The change in Peep.cpp is needed because of a function conflict. FormatStringID exists both in the global and in the OpenRCT2 namespace.
  • Loading branch information
Broxzier committed Jan 22, 2024
1 parent 8e88f46 commit e90d78f
Show file tree
Hide file tree
Showing 60 changed files with 366 additions and 242 deletions.
3 changes: 2 additions & 1 deletion src/openrct2-ui/input/Shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/CheatSetAction.h>
Expand Down Expand Up @@ -283,7 +284,7 @@ static void ShortcutShowFinancialInformation()
return;

if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)))
if (!(gParkFlags & PARK_FLAGS_NO_MONEY))
if (!(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY))
ContextOpenWindow(WindowClass::Finances);
}

Expand Down
15 changes: 9 additions & 6 deletions src/openrct2-ui/windows/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/CheatSetAction.h>
#include <openrct2/actions/ParkSetDateAction.h>
Expand All @@ -28,11 +29,12 @@
#include <openrct2/world/Park.h>
#include <openrct2/world/Surface.h>

using namespace OpenRCT2;
using OpenRCT2::Date;

constexpr auto CHEATS_MONEY_DEFAULT = 10000.00_GBP;
constexpr auto CHEATS_MONEY_INCREMENT_DIV = 5000.00_GBP;

using OpenRCT2::Date;

// clang-format off
enum
{
Expand Down Expand Up @@ -453,11 +455,12 @@ class CheatsWindow final : public Window
// Set title
widgets[WIDX_TITLE].text = window_cheats_page_titles[page];

auto& gameState = GetGameState();
switch (page)
{
case WINDOW_CHEATS_PAGE_MONEY:
{
auto moneyDisabled = (gParkFlags & PARK_FLAGS_NO_MONEY) != 0;
auto moneyDisabled = (gameState.ParkFlags & PARK_FLAGS_NO_MONEY) != 0;
SetCheckboxValue(WIDX_NO_MONEY, moneyDisabled);
SetWidgetDisabled(WIDX_ADD_SET_MONEY_GROUP, moneyDisabled);
SetWidgetDisabled(WIDX_MONEY_SPINNER, moneyDisabled);
Expand All @@ -478,8 +481,8 @@ class CheatsWindow final : public Window
break;
}
case WINDOW_CHEATS_PAGE_MISC:
widgets[WIDX_OPEN_CLOSE_PARK].text = (gParkFlags & PARK_FLAGS_PARK_OPEN) ? STR_CHEAT_CLOSE_PARK
: STR_CHEAT_OPEN_PARK;
widgets[WIDX_OPEN_CLOSE_PARK].text = (gameState.ParkFlags & PARK_FLAGS_PARK_OPEN) ? STR_CHEAT_CLOSE_PARK
: STR_CHEAT_OPEN_PARK;
SetCheckboxValue(WIDX_FORCE_PARK_RATING, ParkGetForcedRating() >= 0);
SetCheckboxValue(WIDX_FREEZE_WEATHER, gCheatsFreezeWeather);
SetCheckboxValue(WIDX_NEVERENDING_MARKETING, gCheatsNeverendingMarketing);
Expand Down Expand Up @@ -779,7 +782,7 @@ class CheatsWindow final : public Window
switch (widgetIndex)
{
case WIDX_NO_MONEY:
CheatsSet(CheatType::NoMoney, gParkFlags & PARK_FLAGS_NO_MONEY ? 0 : 1);
CheatsSet(CheatType::NoMoney, GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY ? 0 : 1);
break;
case WIDX_MONEY_SPINNER:
MoneyToString(_moneySpinnerValue, _moneySpinnerText, MONEY_STRING_MAXLENGTH, false);
Expand Down
6 changes: 5 additions & 1 deletion src/openrct2-ui/windows/ClearScenery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/GameState.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Scenery.h>

using namespace OpenRCT2;

enum WindowClearSceneryWidgetIdx
{
WIDX_BACKGROUND,
Expand Down Expand Up @@ -186,7 +189,8 @@ class CleanSceneryWindow final : public Window
}

// Draw cost amount
if (gClearSceneryCost != MONEY64_UNDEFINED && gClearSceneryCost != 0 && !(gParkFlags & PARK_FLAGS_NO_MONEY))
if (gClearSceneryCost != MONEY64_UNDEFINED && gClearSceneryCost != 0
&& !(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY))
{
auto ft = Formatter();
ft.Add<money64>(gClearSceneryCost);
Expand Down
6 changes: 5 additions & 1 deletion src/openrct2-ui/windows/DemolishRidePrompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/RideDemolishAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Park.h>

using namespace OpenRCT2;

static constexpr int32_t WW = 200;
static constexpr int32_t WH = 100;

Expand Down Expand Up @@ -81,7 +84,8 @@ class DemolishRidePromptWindow final : public Window
auto currentRide = GetRide(rideId);
if (currentRide != nullptr)
{
auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID : STR_DEMOLISH_RIDE_ID_MONEY;
auto stringId = (GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID
: STR_DEMOLISH_RIDE_ID_MONEY;
auto ft = Formatter();
currentRide->FormatNameTo(ft);
ft.Add<money64>(_demolishRideCost);
Expand Down
7 changes: 5 additions & 2 deletions src/openrct2-ui/windows/EditorBottomToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <openrct2/Editor.h>
#include <openrct2/EditorObjectSelectionSession.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
Expand All @@ -27,6 +28,8 @@
#include <openrct2/world/Scenery.h>
#include <string>

using namespace OpenRCT2;

// clang-format off
enum {
WIDX_PREVIOUS_IMAGE, // 1
Expand Down Expand Up @@ -99,7 +102,7 @@ class EditorBottomToolbarWindow final : public Window
}
else if (!(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER))
{
if (GetNumFreeEntities() != MAX_ENTITIES || gParkFlags & PARK_FLAGS_SPRITES_INITIALISED)
if (GetNumFreeEntities() != MAX_ENTITIES || GetGameState().ParkFlags & PARK_FLAGS_SPRITES_INITIALISED)
{
HidePreviousStepButton();
}
Expand Down Expand Up @@ -134,7 +137,7 @@ class EditorBottomToolbarWindow final : public Window
if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON)
{
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
|| (GetNumFreeEntities() == MAX_ENTITIES && !(gParkFlags & PARK_FLAGS_SPRITES_INITIALISED)))
|| (GetNumFreeEntities() == MAX_ENTITIES && !(GetGameState().ParkFlags & PARK_FLAGS_SPRITES_INITIALISED)))
{
((this)->*(_previousButtonMouseUp[EnumValue(gEditorStep)]))();
}
Expand Down
12 changes: 6 additions & 6 deletions src/openrct2-ui/windows/EditorObjectiveOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <openrct2/sprites.h>
#include <openrct2/world/Park.h>

using namespace OpenRCT2;

static constexpr StringId WINDOW_TITLE = STR_OBJECTIVE_SELECTION;
static constexpr int32_t WH = 229;
static constexpr int32_t WW = 450;
Expand Down Expand Up @@ -432,17 +434,16 @@ class EditorObjectiveOptionsWindow final : public Window
{
int32_t numItems = 0, objectiveType;
Widget* dropdownWidget;
uint32_t parkFlags;

dropdownWidget = &widgets[WIDX_OBJECTIVE];
parkFlags = gParkFlags;

for (auto i = 0; i < OBJECTIVE_COUNT; i++)
{
if (i == OBJECTIVE_NONE || i == OBJECTIVE_BUILD_THE_BEST)
continue;

const bool objectiveAllowedByMoneyUsage = !(parkFlags & PARK_FLAGS_NO_MONEY) || !ObjectiveNeedsMoney(i);
const bool objectiveAllowedByMoneyUsage = !(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY)
|| !ObjectiveNeedsMoney(i);
// This objective can only work if the player can ask money for rides.
const bool objectiveAllowedByPaymentSettings = (i != OBJECTIVE_MONTHLY_RIDE_INCOME) || ParkRidePricesUnlocked();
if (objectiveAllowedByMoneyUsage && objectiveAllowedByPaymentSettings)
Expand Down Expand Up @@ -743,18 +744,17 @@ class EditorObjectiveOptionsWindow final : public Window
*/
void OnUpdateMain()
{
uint32_t parkFlags;
uint8_t objectiveType;

frame_no++;
OnPrepareDraw();
InvalidateWidget(WIDX_TAB_1);

parkFlags = gParkFlags;
objectiveType = gScenarioObjective.Type;

// Check if objective is allowed by money and pay-per-ride settings.
const bool objectiveAllowedByMoneyUsage = !(parkFlags & PARK_FLAGS_NO_MONEY) || !ObjectiveNeedsMoney(objectiveType);
const bool objectiveAllowedByMoneyUsage = !(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY)
|| !ObjectiveNeedsMoney(objectiveType);
// This objective can only work if the player can ask money for rides.
const bool objectiveAllowedByPaymentSettings = (objectiveType != OBJECTIVE_MONTHLY_RIDE_INCOME)
|| ParkRidePricesUnlocked();
Expand Down
Loading

0 comments on commit e90d78f

Please sign in to comment.