diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp index 9c467ee455..2d602b7ce8 100644 --- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp +++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp @@ -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; } diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 1804cad22a..975de6bcc8 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -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(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(parkEntranceFee); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 91c2666288..c2d0a6b2a8 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -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); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index d1e9c1495b..971e6ce0d0 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -61,7 +61,7 @@ namespace OpenRCT2 gameState.currentTicks = 0; MapInit(mapSize); - Park::Initialise(gameState); + Park::Initialise(gameState.park, gameState); FinanceInit(); BannerInit(gameState); RideInitAll(); diff --git a/src/openrct2/actions/cheats/CheatSetAction.cpp b/src/openrct2/actions/cheats/CheatSetAction.cpp index d23e182d52..7a156f107e 100644 --- a/src/openrct2/actions/cheats/CheatSetAction.cpp +++ b/src/openrct2/actions/cheats/CheatSetAction.cpp @@ -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; diff --git a/src/openrct2/actions/park/ParkSetEntranceFeeAction.cpp b/src/openrct2/actions/park/ParkSetEntranceFeeAction.cpp index 90667e374d..9df6b3ace4 100644 --- a/src/openrct2/actions/park/ParkSetEntranceFeeAction.cpp +++ b/src/openrct2/actions/park/ParkSetEntranceFeeAction.cpp @@ -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); diff --git a/src/openrct2/actions/ride/RideCreateAction.cpp b/src/openrct2/actions/ride/RideCreateAction.cpp index f53eadd224..180f6d4eba 100644 --- a/src/openrct2/actions/ride/RideCreateAction.cpp +++ b/src/openrct2/actions/ride/RideCreateAction.cpp @@ -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; } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 74ce9d6442..7cbbf52f95 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -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)) diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 4ace4097d9..a234b3e7d0 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -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) diff --git a/src/openrct2/management/Marketing.cpp b/src/openrct2/management/Marketing.cpp index 041e4c873b..0da569aa19 100644 --- a/src/openrct2/management/Marketing.cpp +++ b/src/openrct2/management/Marketing.cpp @@ -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]]; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index af393f1041..4807bce2bb 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -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; } diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 79d8b5a613..bf7dd04c18 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -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()) { diff --git a/src/openrct2/scripting/bindings/game/ScCheats.hpp b/src/openrct2/scripting/bindings/game/ScCheats.hpp index 02c01adb53..c89fe79d46 100644 --- a/src/openrct2/scripting/bindings/game/ScCheats.hpp +++ b/src/openrct2/scripting/bindings/game/ScCheats.hpp @@ -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; } diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 5e8ca979fd..31be062d73 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -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; diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 9d3b71b0f3..83d1452963 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -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