Require ParkData& param for most Park functions

This commit is contained in:
Aaron van Geffen committed 2026-02-13 14:36:05 +01:00
1 parent cbc6a7a75d
commit 001df30eb5
15 files changed
+80 -64

No files matched your search

@@ -737,7 +737,9 @@ namespace OpenRCT2::Ui::Windows
void ShowObjectiveDropdown()
{
const auto& gameState = getGameState();
const auto& park = gameState.park;
const auto& scenarioOptions = gameState.scenarioOptions;
auto objectiveType = EnumValue(scenarioOptions.objective.Type);
int32_t numItems = 0;
@@ -752,7 +754,7 @@ namespace OpenRCT2::Ui::Windows
// This objective can only work if the player can ask money for rides.
const bool objectiveAllowedByPaymentSettings = (obj != Scenario::ObjectiveType::monthlyRideIncome)
|| Park::RidePricesUnlocked();
|| Park::RidePricesUnlocked(park);
if (objectiveAllowedByMoneyUsage && objectiveAllowedByPaymentSettings)
{
@@ -1036,15 +1038,18 @@ namespace OpenRCT2::Ui::Windows
onPrepareDraw();
invalidateWidget(WIDX_TAB_1);
auto objectiveType = getGameState().scenarioOptions.objective.Type;
auto& gameState = getGameState();
auto& park = gameState.park;
auto objectiveType = gameState.scenarioOptions.objective.Type;
// Check if objective is allowed by money and pay-per-ride settings.
const bool objectiveAllowedByMoneyUsage = !(getGameState().park.flags & PARK_FLAGS_NO_MONEY)
const bool objectiveAllowedByMoneyUsage = !(park.flags & PARK_FLAGS_NO_MONEY)
|| !ObjectiveNeedsMoney(objectiveType);
// This objective can only work if the player can ask money for rides.
const bool objectiveAllowedByPaymentSettings = (objectiveType != Scenario::ObjectiveType::monthlyRideIncome)
|| Park::RidePricesUnlocked();
|| Park::RidePricesUnlocked(park);
if (!objectiveAllowedByMoneyUsage || !objectiveAllowedByPaymentSettings)
{
@@ -1616,7 +1621,9 @@ namespace OpenRCT2::Ui::Windows
SetPressedTab();
auto& gameState = getGameState();
bool noMoney = gameState.park.flags & PARK_FLAGS_NO_MONEY;
auto& park = gameState.park;
bool noMoney = park.flags & PARK_FLAGS_NO_MONEY;
setWidgetPressed(WIDX_NO_MONEY, noMoney);
setWidgetDisabled(WIDX_GROUP_LOAN, noMoney);
@@ -1629,7 +1636,7 @@ namespace OpenRCT2::Ui::Windows
setWidgetDisabled(WIDX_MAXIMUM_LOAN_INCREASE, noMoney);
setWidgetDisabled(WIDX_MAXIMUM_LOAN_DECREASE, noMoney);
if (gameState.park.flags & PARK_FLAGS_RCT1_INTEREST)
if (park.flags & PARK_FLAGS_RCT1_INTEREST)
{
widgets[WIDX_INTEREST_RATE_LABEL].type = WidgetType::empty;
widgets[WIDX_INTEREST_RATE].type = WidgetType::empty;
@@ -1662,7 +1669,7 @@ namespace OpenRCT2::Ui::Windows
setWidgetDisabled(WIDX_PAY_FOR_PARK_OR_RIDES_DROPDOWN, noMoney);
setWidgetDisabled(WIDX_FORBID_MARKETING, noMoney);
if (!Park::EntranceFeeUnlocked())
if (!Park::EntranceFeeUnlocked(park))
{
widgets[WIDX_ENTRY_PRICE_LABEL].type = WidgetType::empty;
widgets[WIDX_ENTRY_PRICE].type = WidgetType::empty;
@@ -1681,7 +1688,7 @@ namespace OpenRCT2::Ui::Windows
setWidgetDisabled(WIDX_ENTRY_PRICE_DECREASE, noMoney);
}
setWidgetPressed(WIDX_FORBID_MARKETING, gameState.park.flags & PARK_FLAGS_FORBID_MARKETING_CAMPAIGN);
setWidgetPressed(WIDX_FORBID_MARKETING, park.flags & PARK_FLAGS_FORBID_MARKETING_CAMPAIGN);
widgets[WIDX_CLOSE].type = gLegacyScene == LegacyScene::scenarioEditor ? WidgetType::empty : WidgetType::closeBox;
}
+16 -9
View File
@@ -412,6 +412,7 @@ namespace OpenRCT2::Ui::Windows
#pragma region Entrance page
void onMouseUpEntrance(WidgetIndex widgetIndex)
{
auto& park = getGameState().park;
switch (widgetIndex)
{
case WIDX_BUY_LAND_RIGHTS:
@@ -422,16 +423,15 @@ namespace OpenRCT2::Ui::Windows
break;
case WIDX_RENAME:
{
auto& park = getGameState().park;
WindowTextInputRawOpen(
this, WIDX_RENAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, park.name.c_str(), kUserStringMaxLength);
break;
}
case WIDX_CLOSE_LIGHT:
Park::SetOpen(false);
Park::SetOpen(park, false);
break;
case WIDX_OPEN_LIGHT:
Park::SetOpen(true);
Park::SetOpen(park, true);
break;
}
}
@@ -468,6 +468,7 @@ namespace OpenRCT2::Ui::Windows
void onDropdownEntrance(WidgetIndex widgetIndex, int32_t dropdownIndex)
{
auto& park = getGameState().park;
if (widgetIndex == WIDX_OPEN_OR_CLOSE)
{
if (dropdownIndex == -1)
@@ -475,11 +476,11 @@ namespace OpenRCT2::Ui::Windows
if (dropdownIndex != 0)
{
Park::SetOpen(true);
Park::SetOpen(park, true);
}
else
{
Park::SetOpen(false);
Park::SetOpen(park, false);
}
}
}
@@ -812,6 +813,8 @@ namespace OpenRCT2::Ui::Windows
void onMouseDownPrice(WidgetIndex widgetIndex)
{
auto& gameState = getGameState();
auto& park = gameState.park;
switch (widgetIndex)
{
case WIDX_INCREASE_PRICE:
@@ -831,7 +834,7 @@ namespace OpenRCT2::Ui::Windows
case WIDX_PRICE:
{
utf8 _moneyInputText[kMoneyStringMaxlength] = {};
MoneyToString(Park::GetEntranceFee(), _moneyInputText, kMoneyStringMaxlength, false);
MoneyToString(Park::GetEntranceFee(park), _moneyInputText, kMoneyStringMaxlength, false);
WindowTextInputRawOpen(
this, WIDX_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneyInputText, kMoneyStringMaxlength);
}
@@ -853,14 +856,16 @@ namespace OpenRCT2::Ui::Windows
widgets[WIDX_PRICE_LABEL].tooltip = kStringIdNone;
widgets[WIDX_PRICE].tooltip = kStringIdNone;
if (!Park::EntranceFeeUnlocked())
auto& park = getGameState().park;
if (!Park::EntranceFeeUnlocked(park))
{
widgets[WIDX_PRICE_LABEL].tooltip = STR_ADMISSION_PRICE_PAY_PER_RIDE_TIP;
widgets[WIDX_PRICE].tooltip = STR_ADMISSION_PRICE_PAY_PER_RIDE_TIP;
}
// If the entry price is locked at free, disable the widget, unless the unlock_all_prices cheat is active.
if ((getGameState().park.flags & PARK_FLAGS_NO_MONEY) || !Park::EntranceFeeUnlocked())
if ((park.flags & PARK_FLAGS_NO_MONEY) || !Park::EntranceFeeUnlocked(park))
{
widgets[WIDX_PRICE].type = WidgetType::labelCentred;
widgets[WIDX_INCREASE_PRICE].type = WidgetType::empty;
@@ -887,7 +892,9 @@ namespace OpenRCT2::Ui::Windows
ft.Add<money64>(getGameState().park.totalIncomeFromAdmissions);
drawText(rt, screenCoords, STR_INCOME_FROM_ADMISSIONS, ft);
money64 parkEntranceFee = Park::GetEntranceFee();
auto& park = getGameState().park;
money64 parkEntranceFee = Park::GetEntranceFee(park);
ft = Formatter();
ft.Add<money64>(parkEntranceFee);
+7 -2
View File
@@ -6573,7 +6573,10 @@ namespace OpenRCT2::Ui::Windows
auto rideEntry = ride->getRideEntry();
const auto& rtd = ride->getRideTypeDescriptor();
return Park::RidePricesUnlocked() || rtd.specialType == RtdSpecialType::toilet
auto& park = getGameState().park;
return Park::RidePricesUnlocked(park) || rtd.specialType == RtdSpecialType::toilet
|| (rideEntry != nullptr && rideEntry->shop_item[0] != ShopItem::none);
}
@@ -6734,9 +6737,11 @@ namespace OpenRCT2::Ui::Windows
widgets[WIDX_PRIMARY_PRICE_LABEL].tooltip = kStringIdNone;
widgets[WIDX_PRIMARY_PRICE].tooltip = kStringIdNone;
auto& park = getGameState().park;
// If ride prices are locked, do not allow setting the price, unless we're dealing with a shop or toilet.
const auto& rtd = ride->getRideTypeDescriptor();
if (!Park::RidePricesUnlocked() && rideEntry->shop_item[0] == ShopItem::none
if (!Park::RidePricesUnlocked(park) && rideEntry->shop_item[0] == ShopItem::none
&& rtd.specialType != RtdSpecialType::toilet)
{
disabledWidgets |= (1uLL << WIDX_PRIMARY_PRICE);
+1 -1
View File
@@ -61,7 +61,7 @@ namespace OpenRCT2
gameState.currentTicks = 0;
MapInit(mapSize);
Park::Initialise(gameState);
Park::Initialise(gameState.park, gameState);
FinanceInit();
BannerInit(gameState);
RideInitAll();
@@ -234,7 +234,7 @@ namespace OpenRCT2::GameActions
gameState.scenarioOptions.objective.Type = Scenario::ObjectiveType::haveFun;
break;
case CheatType::setForcedParkRating:
Park::SetForcedRating(_param1);
Park::SetForcedRating(park, _param1);
break;
case CheatType::allowArbitraryRideTypeChanges:
gameState.cheats.allowArbitraryRideTypeChanges = _param1 != 0;
@@ -48,7 +48,7 @@ namespace OpenRCT2::GameActions
LOG_ERROR("Can't set park entrance fee because the park has no money");
return Result(Status::disallowed, STR_ERR_CANT_CHANGE_PARK_ENTRANCE_FEE, kStringIdNone);
}
else if (!Park::EntranceFeeUnlocked())
else if (!Park::EntranceFeeUnlocked(park))
{
LOG_ERROR("Park entrance fee is locked");
return Result(Status::disallowed, STR_ERR_CANT_CHANGE_PARK_ENTRANCE_FEE, kStringIdNone);
@@ -206,7 +206,7 @@ namespace OpenRCT2::GameActions
ride->ratings.setNull();
if (!(gameState.park.flags & PARK_FLAGS_NO_MONEY))
if (!(park.flags & PARK_FLAGS_NO_MONEY))
{
for (auto i = 0; i < RCT2::ObjectLimits::kMaxShopItemsPerRideEntry; i++)
{
@@ -215,7 +215,7 @@ namespace OpenRCT2::GameActions
if (rideEntry->shop_item[0] == ShopItem::none)
{
if (!Park::RidePricesUnlocked() || gameState.park.entranceFee > 0)
if (!Park::RidePricesUnlocked(park) || park.entranceFee > 0)
{
ride->price[0] = 0;
}
+1 -1
View File
@@ -1886,7 +1886,7 @@ namespace OpenRCT2
return true;
}
auto entranceFee = Park::GetEntranceFee();
auto entranceFee = Park::GetEntranceFee(gameState.park);
if (entranceFee != 0)
{
if (guest->HasItem(ShopItem::voucher))
+3 -3
View File
@@ -183,13 +183,13 @@ static bool AwardIsDeservedBestValue(GameState_t& gameState, int32_t activeAward
if (activeAwardTypes & EnumToFlag(AwardType::mostDisappointing))
return false;
if ((park.flags & PARK_FLAGS_NO_MONEY) || !Park::EntranceFeeUnlocked())
if ((park.flags & PARK_FLAGS_NO_MONEY) || !Park::EntranceFeeUnlocked(park))
return false;
if (park.totalRideValueForMoney < 10.00_GBP)
return false;
if (Park::GetEntranceFee() + 0.10_GBP >= park.totalRideValueForMoney / 2)
if (Park::GetEntranceFee(park) + 0.10_GBP >= park.totalRideValueForMoney / 2)
return false;
return true;
@@ -238,7 +238,7 @@ static bool AwardIsDeservedWorstValue(GameState_t& gameState, int32_t activeAwar
if (park.flags & PARK_FLAGS_NO_MONEY)
return false;
const auto parkEntranceFee = Park::GetEntranceFee();
const auto parkEntranceFee = Park::GetEntranceFee(park);
if (parkEntranceFee == 0.00_GBP)
return false;
if (parkEntranceFee <= park.totalRideValueForMoney)
+7 -4
View File
@@ -57,16 +57,18 @@ uint16_t MarketingGetCampaignGuestGenerationProbability(int32_t campaignType)
if (campaign == nullptr)
return 0;
auto& park = getGameState().park;
// Lower probability of guest generation if price was already low
auto probability = AdvertisingCampaignGuestGenerationProbabilities[campaign->Type];
switch (campaign->Type)
{
case ADVERTISING_CAMPAIGN_PARK_ENTRY_FREE:
if (Park::GetEntranceFee() < 4.00_GBP)
if (Park::GetEntranceFee(park) < 4.00_GBP)
probability /= 8;
break;
case ADVERTISING_CAMPAIGN_PARK_ENTRY_HALF_PRICE:
if (Park::GetEntranceFee() < 6.00_GBP)
if (Park::GetEntranceFee(park) < 6.00_GBP)
probability /= 8;
break;
case ADVERTISING_CAMPAIGN_RIDE_FREE:
@@ -186,17 +188,18 @@ void MarketingSetGuestCampaign(Guest* peep, int32_t campaignType)
bool MarketingIsCampaignTypeApplicable(int32_t campaignType)
{
auto& gameState = getGameState();
auto& park = gameState.park;
switch (campaignType)
{
case ADVERTISING_CAMPAIGN_PARK_ENTRY_FREE:
case ADVERTISING_CAMPAIGN_PARK_ENTRY_HALF_PRICE:
if (!Park::EntranceFeeUnlocked())
if (!Park::EntranceFeeUnlocked(park))
return false;
return true;
case ADVERTISING_CAMPAIGN_RIDE_FREE:
if (!Park::RidePricesUnlocked())
if (!Park::RidePricesUnlocked(park))
return false;
[[fallthrough]];
+3 -2
View File
@@ -5074,11 +5074,12 @@ bool Ride::isRide() const
money64 RideGetPrice(const Ride& ride)
{
if (getGameState().park.flags & PARK_FLAGS_NO_MONEY)
auto& park = getGameState().park;
if (park.flags & PARK_FLAGS_NO_MONEY)
return 0;
if (ride.isRide())
{
if (!Park::RidePricesUnlocked())
if (!Park::RidePricesUnlocked(park))
{
return 0;
}
+1 -1
View File
@@ -226,7 +226,7 @@ static void ScenarioCheckEntranceFeeTooHigh()
const auto& park = getGameState().park;
const auto max_fee = AddClamp(park.totalRideValueForMoney, park.totalRideValueForMoney / 2);
if ((park.flags & PARK_FLAGS_PARK_OPEN) && Park::GetEntranceFee() > max_fee)
if ((park.flags & PARK_FLAGS_PARK_OPEN) && Park::GetEntranceFee(park) > max_fee)
{
if (!park.entrances.empty())
{
@@ -404,8 +404,13 @@ namespace OpenRCT2::Scripting
JS_UNPACK_INT32(valueInt, ctx, value);
JS_THROW_IF_GAME_STATE_NOT_MUTABLE();
int32_t adjusted = std::max(-1, std::min(valueInt, 999));
getGameState().cheats.forcedParkRating = adjusted;
Park::SetForcedRating(adjusted);
auto& gameState = getGameState();
auto& park = gameState.park;
gameState.cheats.forcedParkRating = adjusted;
Park::SetForcedRating(park, adjusted);
return JS_UNDEFINED;
}
+9 -21
View File
@@ -81,7 +81,7 @@ namespace OpenRCT2::Park
static money64 calculateTotalRideValueForMoney(const ParkData& park, const GameState_t& gameState)
{
money64 totalRideValue = 0;
bool ridePricesUnlocked = RidePricesUnlocked() && !(gameState.park.flags & PARK_FLAGS_NO_MONEY);
bool ridePricesUnlocked = RidePricesUnlocked(park) && !(gameState.park.flags & PARK_FLAGS_NO_MONEY);
for (auto& ride : RideManager(gameState))
{
if (ride.status != RideStatus::open)
@@ -190,7 +190,7 @@ namespace OpenRCT2::Park
}
// Penalty for overpriced entrance fee relative to total ride value
auto entranceFee = GetEntranceFee();
auto entranceFee = GetEntranceFee(park);
if (entranceFee > park.totalRideValueForMoney)
{
probability /= 4;
@@ -263,10 +263,8 @@ namespace OpenRCT2::Park
history[0] = newItem;
}
void Initialise(GameState_t& gameState)
void Initialise(ParkData& park, GameState_t& gameState)
{
auto& park = gameState.park;
park.name = LanguageGetString(STR_UNNAMED_PARK);
gameState.pluginStorage = {};
park.staffHandymanColour = Drawing::Colour::brightRed;
@@ -627,7 +625,7 @@ namespace OpenRCT2::Park
return tiles;
}
void SetOpen(bool open)
void SetOpen(const ParkData& park, bool open)
{
auto parkSetParameter = GameActions::ParkSetParameterAction(
open ? GameActions::ParkParameter::Open : GameActions::ParkParameter::Close);
@@ -713,12 +711,11 @@ namespace OpenRCT2::Park
UpdateFences({ coords.x, coords.y - kCoordsXYStep });
}
void SetForcedRating(int32_t rating)
void SetForcedRating(ParkData& park, int32_t rating)
{
auto& gameState = getGameState();
gameState.cheats.forcedParkRating = rating;
auto& park = gameState.park;
park.rating = CalculateParkRating(park, gameState);
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
@@ -730,16 +727,13 @@ namespace OpenRCT2::Park
return getGameState().cheats.forcedParkRating;
}
money64 GetEntranceFee()
money64 GetEntranceFee(const ParkData& park)
{
// TODO: pass park by ref
auto& park = getGameState().park;
if (park.flags & PARK_FLAGS_NO_MONEY)
{
return 0;
}
if (!EntranceFeeUnlocked())
if (!EntranceFeeUnlocked(park))
{
return 0;
}
@@ -747,11 +741,8 @@ namespace OpenRCT2::Park
return park.entranceFee;
}
bool RidePricesUnlocked()
bool RidePricesUnlocked(const ParkData& park)
{
// TODO: pass park by ref
auto& park = getGameState().park;
if (park.flags & PARK_FLAGS_UNLOCK_ALL_PRICES)
{
return true;
@@ -763,11 +754,8 @@ namespace OpenRCT2::Park
return false;
}
bool EntranceFeeUnlocked()
bool EntranceFeeUnlocked(const ParkData& park)
{
// TODO: pass park by ref
auto& park = getGameState().park;
if (park.flags & PARK_FLAGS_UNLOCK_ALL_PRICES)
{
return true;
+6 -6
View File
@@ -22,7 +22,7 @@ namespace OpenRCT2::Park
{
struct ParkData;
void Initialise(GameState_t& gameState);
void Initialise(ParkData& park, GameState_t& gameState);
void Update(ParkData& park, GameState_t& gameState);
uint32_t CalculateParkSize(ParkData& park);
@@ -34,7 +34,7 @@ namespace OpenRCT2::Park
void ResetHistories(ParkData& park);
void UpdateHistories(ParkData& park);
void SetForcedRating(int32_t rating);
void SetForcedRating(ParkData& park, int32_t rating);
int32_t GetForcedRating();
uint32_t UpdateSize(ParkData& park);
@@ -45,9 +45,9 @@ namespace OpenRCT2::Park
uint8_t CalculateGuestInitialHappiness(uint8_t percentage);
bool IsOpen(const ParkData& park);
void SetOpen(bool open);
money64 GetEntranceFee();
void SetOpen(const ParkData& park, bool open);
money64 GetEntranceFee(const ParkData& park);
bool RidePricesUnlocked();
bool EntranceFeeUnlocked();
bool RidePricesUnlocked(const ParkData& park);
bool EntranceFeeUnlocked(const ParkData& park);
} // namespace OpenRCT2::Park