Skip to content

Commit

Permalink
OpenRCT2#21193: Move gParkEntranceFee to GameState_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Broxzier committed Jan 24, 2024
1 parent ab80a9b commit 5a4087c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 30 deletions.
14 changes: 7 additions & 7 deletions src/openrct2-ui/windows/EditorScenarioOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ class EditorScenarioOptionsWindow final : public Window
Invalidate();
break;
case WIDX_ENTRY_PRICE_INCREASE:
if (gParkEntranceFee < MAX_ENTRANCE_FEE)
if (gameState.ParkEntranceFee < MAX_ENTRANCE_FEE)
{
auto scenarioSetSetting = ScenarioSetSettingAction(
ScenarioSetSetting::ParkChargeEntryFee, gParkEntranceFee + 1.00_GBP);
ScenarioSetSetting::ParkChargeEntryFee, gameState.ParkEntranceFee + 1.00_GBP);
GameActions::Execute(&scenarioSetSetting);
}
else
Expand All @@ -1068,10 +1068,10 @@ class EditorScenarioOptionsWindow final : public Window
Invalidate();
break;
case WIDX_ENTRY_PRICE_DECREASE:
if (gParkEntranceFee > 0.00_GBP)
if (gameState.ParkEntranceFee > 0.00_GBP)
{
auto scenarioSetSetting = ScenarioSetSettingAction(
ScenarioSetSetting::ParkChargeEntryFee, gParkEntranceFee - 1.00_GBP);
ScenarioSetSetting::ParkChargeEntryFee, gameState.ParkEntranceFee - 1.00_GBP);
GameActions::Execute(&scenarioSetSetting);
}
else
Expand Down Expand Up @@ -1202,6 +1202,7 @@ class EditorScenarioOptionsWindow final : public Window
WindowDrawWidgets(*this, dpi);
DrawTabImages(dpi);

const auto& gameState = GetGameState();
const auto& landCostWidget = widgets[WIDX_LAND_COST];
if (landCostWidget.type != WindowWidgetType::Empty)
{
Expand Down Expand Up @@ -1237,7 +1238,6 @@ class EditorScenarioOptionsWindow final : public Window
// Pay for park or rides label
screenCoords = windowPos + ScreenCoordsXY{ payForParkOrRidesWidget.left + 1, payForParkOrRidesWidget.top };

auto& gameState = GetGameState();
auto ft = Formatter();
// Pay for park and/or rides value
if (gameState.ParkFlags & PARK_FLAGS_UNLOCK_ALL_PRICES)
Expand All @@ -1260,7 +1260,7 @@ class EditorScenarioOptionsWindow final : public Window
// Entry price value
screenCoords = windowPos + ScreenCoordsXY{ entryPriceWidget.left + 1, entryPriceWidget.top };
auto ft = Formatter();
ft.Add<money64>(gParkEntranceFee);
ft.Add<money64>(gameState.ParkEntranceFee);
DrawTextBasic(dpi, screenCoords, STR_CURRENCY_FORMAT_LABEL, ft);
}

Expand All @@ -1272,7 +1272,7 @@ class EditorScenarioOptionsWindow final : public Window
// Climate value
screenCoords = windowPos + ScreenCoordsXY{ climateWidget.left + 1, climateWidget.top };
auto ft = Formatter();
ft.Add<StringId>(ClimateNames[static_cast<uint8_t>(GetGameState().Climate)]);
ft.Add<StringId>(ClimateNames[static_cast<uint8_t>(gameState.Climate)]);
DrawTextBasic(dpi, screenCoords, STR_WINDOW_COLOUR_2_STRINGID, ft);
}

Expand Down
5 changes: 3 additions & 2 deletions src/openrct2-ui/windows/Park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,18 +823,19 @@ class ParkWindow final : public Window

void OnMouseDownPrice(WidgetIndex widgetIndex)
{
const auto& gameState = GetGameState();
switch (widgetIndex)
{
case WIDX_INCREASE_PRICE:
{
const auto newFee = std::min(MAX_ENTRANCE_FEE, gParkEntranceFee + 1.00_GBP);
const auto newFee = std::min(MAX_ENTRANCE_FEE, gameState.ParkEntranceFee + 1.00_GBP);
auto gameAction = ParkSetEntranceFeeAction(newFee);
GameActions::Execute(&gameAction);
break;
}
case WIDX_DECREASE_PRICE:
{
const auto newFee = std::max(0.00_GBP, gParkEntranceFee - 1.00_GBP);
const auto newFee = std::max(0.00_GBP, gameState.ParkEntranceFee - 1.00_GBP);
auto gameAction = ParkSetEntranceFeeAction(newFee);
GameActions::Execute(&gameAction);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ namespace Editor
{
gameState.ParkFlags |= PARK_FLAGS_NO_MONEY;

if (gParkEntranceFee == 0)
if (gameState.ParkEntranceFee == 0)
{
gameState.ParkFlags |= PARK_FLAGS_PARK_FREE_ENTRY;
}
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace OpenRCT2
uint32_t CurrentTicks{};
uint64_t ParkFlags;
uint16_t ParkRating;
money64 ParkEntranceFee;
ClimateType Climate;
ClimateState ClimateNext;
money64 Cash;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/actions/ParkSetEntranceFeeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GameActions::Result ParkSetEntranceFeeAction::Query() const

GameActions::Result ParkSetEntranceFeeAction::Execute() const
{
gParkEntranceFee = _fee;
GetGameState().ParkEntranceFee = _fee;
WindowInvalidateByClass(WindowClass::ParkInformation);
return GameActions::Result();
}
5 changes: 3 additions & 2 deletions src/openrct2/actions/RideCreateAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ GameActions::Result RideCreateAction::Execute() const
price = 0;
}

if (!(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY))
const auto& gameState = GetGameState();
if (!(gameState.ParkFlags & PARK_FLAGS_NO_MONEY))
{
for (auto i = 0; i < RCT2::ObjectLimits::MaxShopItemsPerRideEntry; i++)
{
Expand All @@ -219,7 +220,7 @@ GameActions::Result RideCreateAction::Execute() const

if (rideEntry->shop_item[0] == ShopItem::None)
{
if (!ParkRidePricesUnlocked() || gParkEntranceFee > 0)
if (!ParkRidePricesUnlocked() || gameState.ParkEntranceFee > 0)
{
ride->price[0] = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/actions/ScenarioSetSettingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
{
gameState.ParkFlags |= PARK_FLAGS_PARK_FREE_ENTRY;
gameState.ParkFlags &= ~PARK_FLAGS_UNLOCK_ALL_PRICES;
gParkEntranceFee = 0.00_GBP;
gameState.ParkEntranceFee = 0.00_GBP;
}
else if (_value == 1)
{
gameState.ParkFlags &= ~PARK_FLAGS_PARK_FREE_ENTRY;
gameState.ParkFlags &= ~PARK_FLAGS_UNLOCK_ALL_PRICES;
gParkEntranceFee = 10.00_GBP;
gameState.ParkEntranceFee = 10.00_GBP;
}
else
{
gameState.ParkFlags |= PARK_FLAGS_PARK_FREE_ENTRY;
gameState.ParkFlags |= PARK_FLAGS_UNLOCK_ALL_PRICES;
gParkEntranceFee = 10.00_GBP;
gameState.ParkEntranceFee = 10.00_GBP;
}
}
else
Expand All @@ -194,7 +194,7 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
}
break;
case ScenarioSetSetting::ParkChargeEntryFee:
gParkEntranceFee = std::clamp<money64>(_value, 0.00_GBP, MAX_ENTRANCE_FEE);
gameState.ParkEntranceFee = std::clamp<money64>(_value, 0.00_GBP, MAX_ENTRANCE_FEE);
WindowInvalidateByClass(WindowClass::ParkInformation);
break;
case ScenarioSetSetting::ForbidTreeRemoval:
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,11 @@ namespace OpenRCT2
{
money16 tempParkEntranceFee{};
cs.ReadWrite(tempParkEntranceFee);
gParkEntranceFee = ToMoney64(tempParkEntranceFee);
gameState.ParkEntranceFee = ToMoney64(tempParkEntranceFee);
}
else
{
cs.ReadWrite(gParkEntranceFee);
cs.ReadWrite(gameState.ParkEntranceFee);
}

cs.ReadWrite(gStaffHandymanColour);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ namespace RCT1

void ImportFinance(GameState_t& gameState)
{
gParkEntranceFee = _s4.ParkEntranceFee;
gameState.ParkEntranceFee = _s4.ParkEntranceFee;
gLandPrice = ToMoney64(_s4.LandPrice);
gConstructionRightsPrice = ToMoney64(_s4.ConstructionRightsPrice);

Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace RCT2
gameState.ParkFlags &= ~PARK_FLAGS_NO_MONEY;
}

gParkEntranceFee = _s6.ParkEntranceFee;
gameState.ParkEntranceFee = _s6.ParkEntranceFee;
// rct1_park_entranceX
// rct1_park_entrance_y
// Pad013573EE
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/scenario/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void ScenarioReset()
if (gameState.ParkFlags & PARK_FLAGS_NO_MONEY)
{
gameState.ParkFlags |= PARK_FLAGS_PARK_OPEN;
gParkEntranceFee = 0;
gameState.ParkEntranceFee = 0;
}

gameState.ParkFlags |= PARK_FLAGS_SPRITES_INITIALISED;
Expand Down
7 changes: 4 additions & 3 deletions src/openrct2/scripting/bindings/world/ScPark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ namespace OpenRCT2::Scripting

money64 ScPark::entranceFee_get() const
{
return gParkEntranceFee;
return GetGameState().ParkEntranceFee;
}
void ScPark::entranceFee_set(money64 value)
{
ThrowIfGameStateNotMutable();

if (gParkEntranceFee != value)
auto& gameState = GetGameState();
if (gameState.ParkEntranceFee != value)
{
gParkEntranceFee = value;
gameState.ParkEntranceFee = value;
WindowInvalidateByClass(WindowClass::ParkInformation);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/world/Park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

using namespace OpenRCT2;

money64 gParkEntranceFee;
uint32_t gParkSize;
money64 gLandPrice;
money64 gConstructionRightsPrice;
Expand Down Expand Up @@ -191,15 +190,16 @@ int32_t ParkGetForcedRating()

money64 ParkGetEntranceFee()
{
if (GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY)
const auto& gameState = GetGameState();
if (gameState.ParkFlags & PARK_FLAGS_NO_MONEY)
{
return 0;
}
if (!ParkEntranceFeeUnlocked())
{
return 0;
}
return gParkEntranceFee;
return gameState.ParkEntranceFee;
}

bool ParkRidePricesUnlocked()
Expand Down Expand Up @@ -277,7 +277,7 @@ void Park::Initialise()

SetAllSceneryItemsInvented();

gParkEntranceFee = 10.00_GBP;
gameState.ParkEntranceFee = 10.00_GBP;

gPeepSpawns.clear();
ParkEntranceReset();
Expand Down
1 change: 0 additions & 1 deletion src/openrct2/world/Park.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ namespace OpenRCT2
};
} // namespace OpenRCT2

extern money64 gParkEntranceFee;
extern uint32_t gParkSize;
extern money64 gLandPrice;
extern money64 gConstructionRightsPrice;
Expand Down

0 comments on commit 5a4087c

Please sign in to comment.