1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 07:13:07 +01:00

Park: pass ParkData& and GameState_t& refs down

This commit is contained in:
Aaron van Geffen
2025-09-11 13:41:58 +02:00
parent f6e4d5a90d
commit 37e143565b
6 changed files with 53 additions and 60 deletions

View File

@@ -499,7 +499,8 @@ namespace OpenRCT2::Editor
ResultWithMessage CheckPark() ResultWithMessage CheckPark()
{ {
auto& gameState = getGameState(); auto& gameState = getGameState();
int32_t parkSize = Park::UpdateSize(gameState); auto& park = gameState.park;
int32_t parkSize = Park::UpdateSize(park, gameState);
if (parkSize == 0) if (parkSize == 0)
{ {
return { false, STR_PARK_MUST_OWN_SOME_LAND }; return { false, STR_PARK_MUST_OWN_SOME_LAND };

View File

@@ -83,7 +83,9 @@ namespace OpenRCT2::GameActions
auto* ctx = OpenRCT2::GetContext(); auto* ctx = OpenRCT2::GetContext();
auto& uiContext = ctx->GetUiContext(); auto& uiContext = ctx->GetUiContext();
auto* windowManager = uiContext.GetWindowManager(); auto* windowManager = uiContext.GetWindowManager();
Park::UpdateSize(gameState);
auto& park = gameState.park;
Park::UpdateSize(park, gameState);
windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP));
GfxInvalidateScreen(); GfxInvalidateScreen();

View File

@@ -156,7 +156,8 @@ namespace OpenRCT2::GameActions
} }
ride.remove(); ride.remove();
getGameState().park.value = Park::CalculateParkValue(); auto& park = gameState.park;
park.value = Park::CalculateParkValue(park, gameState);
// Close windows related to the demolished ride // Close windows related to the demolished ride
auto* windowMgr = Ui::GetWindowManager(); auto* windowMgr = Ui::GetWindowManager();

View File

@@ -102,9 +102,9 @@ void ScenarioReset(GameState_t& gameState)
News::InitQueue(gameState); News::InitQueue(gameState);
auto& park = gameState.park; auto& park = gameState.park;
park.rating = Park::CalculateParkRating(); park.rating = Park::CalculateParkRating(park, gameState);
park.value = Park::CalculateParkValue(); park.value = Park::CalculateParkValue(park, gameState);
park.companyValue = Park::CalculateCompanyValue(); park.companyValue = Park::CalculateCompanyValue(park);
park.historicalProfit = gameState.scenarioOptions.initialCash - park.bankLoan; park.historicalProfit = gameState.scenarioOptions.initialCash - park.bankLoan;
park.cash = gameState.scenarioOptions.initialCash; park.cash = gameState.scenarioOptions.initialCash;
@@ -138,7 +138,7 @@ void ScenarioReset(GameState_t& gameState)
ResetAllRideBuildDates(); ResetAllRideBuildDates();
ResetDate(); ResetDate();
Duck::RemoveAll(); Duck::RemoveAll();
Park::UpdateSize(gameState); Park::UpdateSize(park, gameState);
MapCountRemainingLandRights(); MapCountRemainingLandRights();
Staff::ResetStats(); Staff::ResetStats();

View File

@@ -78,11 +78,11 @@ namespace OpenRCT2::Park
return result; return result;
} }
static money64 calculateTotalRideValueForMoney() static money64 calculateTotalRideValueForMoney(const ParkData& park, const GameState_t& gameState)
{ {
money64 totalRideValue = 0; money64 totalRideValue = 0;
bool ridePricesUnlocked = RidePricesUnlocked() && !(getGameState().park.flags & PARK_FLAGS_NO_MONEY); bool ridePricesUnlocked = RidePricesUnlocked() && !(gameState.park.flags & PARK_FLAGS_NO_MONEY);
for (auto& ride : GetRideManager()) for (auto& ride : RideManager(gameState))
{ {
if (ride.status != RideStatus::open) if (ride.status != RideStatus::open)
continue; continue;
@@ -108,15 +108,12 @@ namespace OpenRCT2::Park
return totalRideValue; return totalRideValue;
} }
static uint32_t calculateSuggestedMaxGuests() static uint32_t calculateSuggestedMaxGuests(const ParkData& park, const GameState_t& gameState)
{ {
uint32_t suggestedMaxGuests = 0; uint32_t suggestedMaxGuests = 0;
uint32_t difficultGenerationBonus = 0; uint32_t difficultGenerationBonus = 0;
// TODO: pass park by ref for (auto& ride : RideManager(gameState))
auto& park = getGameState().park;
for (auto& ride : GetRideManager())
{ {
if (ride.status != RideStatus::open) if (ride.status != RideStatus::open)
continue; continue;
@@ -172,11 +169,8 @@ namespace OpenRCT2::Park
return suggestedMaxGuests; return suggestedMaxGuests;
} }
static uint32_t calculateGuestGenerationProbability() static uint32_t calculateGuestGenerationProbability(ParkData& park)
{ {
// TODO: pass park by ref
auto& park = getGameState().park;
// Begin with 50 + park rating // Begin with 50 + park rating
uint32_t probability = 50 + std::clamp(park.rating - 200, 0, 650); uint32_t probability = 50 + std::clamp(park.rating - 200, 0, 650);
@@ -227,11 +221,8 @@ namespace OpenRCT2::Park
return probability; return probability;
} }
static void generateGuests(GameState_t& gameState) static void generateGuests(ParkData& park, GameState_t& gameState)
{ {
// TODO: pass park by ref
auto& park = gameState.park;
// Generate a new guest for some probability // Generate a new guest for some probability
if (static_cast<int32_t>(ScenarioRand() & 0xFFFF) < park.guestGenerationProbability) if (static_cast<int32_t>(ScenarioRand() & 0xFFFF) < park.guestGenerationProbability)
{ {
@@ -350,12 +341,12 @@ namespace OpenRCT2::Park
// Every ~13 seconds // Every ~13 seconds
if (currentTicks % 512 == 0) if (currentTicks % 512 == 0)
{ {
park.rating = CalculateParkRating(); park.rating = CalculateParkRating(park, gameState);
park.value = Park::CalculateParkValue(); park.value = CalculateParkValue(park, gameState);
park.companyValue = CalculateCompanyValue(); park.companyValue = CalculateCompanyValue(park);
park.totalRideValueForMoney = calculateTotalRideValueForMoney(); park.totalRideValueForMoney = calculateTotalRideValueForMoney(park, gameState);
park.suggestedGuestMaximum = calculateSuggestedMaxGuests(); park.suggestedGuestMaximum = calculateSuggestedMaxGuests(park, gameState);
park.guestGenerationProbability = calculateGuestGenerationProbability(); park.guestGenerationProbability = calculateGuestGenerationProbability(park);
windowMgr->InvalidateByClass(WindowClass::Finances); windowMgr->InvalidateByClass(WindowClass::Finances);
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
@@ -365,14 +356,14 @@ namespace OpenRCT2::Park
// Every ~102 seconds // Every ~102 seconds
if (currentTicks % 4096 == 0) if (currentTicks % 4096 == 0)
{ {
park.size = CalculateParkSize(); park.size = CalculateParkSize(park);
windowMgr->InvalidateByClass(WindowClass::ParkInformation); windowMgr->InvalidateByClass(WindowClass::ParkInformation);
} }
generateGuests(gameState); generateGuests(park, gameState);
} }
uint32_t CalculateParkSize() uint32_t CalculateParkSize(ParkData& park)
{ {
uint32_t tiles = 0; uint32_t tiles = 0;
TileElementIterator it; TileElementIterator it;
@@ -389,7 +380,6 @@ namespace OpenRCT2::Park
} while (TileElementIteratorNext(&it)); } while (TileElementIteratorNext(&it));
// TODO: pass park by ref // TODO: pass park by ref
auto& park = getGameState().park;
if (tiles != park.size) if (tiles != park.size)
{ {
park.size = tiles; park.size = tiles;
@@ -400,17 +390,15 @@ namespace OpenRCT2::Park
return tiles; return tiles;
} }
int32_t CalculateParkRating() int32_t CalculateParkRating(const ParkData& park, const GameState_t& gameState)
{ {
auto& gameState = getGameState();
if (gameState.cheats.forcedParkRating != kForcedParkRatingDisabled) if (gameState.cheats.forcedParkRating != kForcedParkRatingDisabled)
{ {
return gameState.cheats.forcedParkRating; return gameState.cheats.forcedParkRating;
} }
int32_t result = 1150; int32_t result = 1150;
if (gameState.park.flags & PARK_FLAGS_DIFFICULT_PARK_RATING) if (park.flags & PARK_FLAGS_DIFFICULT_PARK_RATING)
{ {
result = 1050; result = 1050;
} }
@@ -418,7 +406,7 @@ namespace OpenRCT2::Park
// Guests // Guests
{ {
// -150 to +3 based on a range of guests from 0 to 2000 // -150 to +3 based on a range of guests from 0 to 2000
result -= 150 - (std::min<int32_t>(2000, gameState.park.numGuestsInPark) / 13); result -= 150 - (std::min<int32_t>(2000, park.numGuestsInPark) / 13);
// Find the number of happy peeps and the number of peeps who can't find the park exit // Find the number of happy peeps and the number of peeps who can't find the park exit
uint32_t happyGuestCount = 0; uint32_t happyGuestCount = 0;
@@ -440,9 +428,9 @@ namespace OpenRCT2::Park
// Peep happiness -500 to +0 // Peep happiness -500 to +0
result -= 500; result -= 500;
if (gameState.park.numGuestsInPark > 0) if (park.numGuestsInPark > 0)
{ {
result += 2 * std::min(250u, (happyGuestCount * 300) / gameState.park.numGuestsInPark); result += 2 * std::min(250u, (happyGuestCount * 300) / park.numGuestsInPark);
} }
// Up to 25 guests can be lost without affecting the park rating. // Up to 25 guests can be lost without affecting the park rating.
@@ -459,7 +447,7 @@ namespace OpenRCT2::Park
int32_t totalRideUptime = 0; int32_t totalRideUptime = 0;
int32_t totalRideIntensity = 0; int32_t totalRideIntensity = 0;
int32_t totalRideExcitement = 0; int32_t totalRideExcitement = 0;
for (auto& ride : GetRideManager()) for (auto& ride : RideManager(gameState))
{ {
totalRideUptime += 100 - ride.downtime; totalRideUptime += 100 - ride.downtime;
if (RideHasRatings(ride)) if (RideHasRatings(ride))
@@ -513,34 +501,35 @@ namespace OpenRCT2::Park
result -= 600 - (4 * (150 - std::min<int32_t>(150, litterCount))); result -= 600 - (4 * (150 - std::min<int32_t>(150, litterCount)));
} }
result -= gameState.park.ratingCasualtyPenalty; result -= park.ratingCasualtyPenalty;
result = std::clamp(result, 0, 999); result = std::clamp(result, 0, 999);
return result; return result;
} }
money64 CalculateParkValue() money64 CalculateParkValue(const ParkData& park, const GameState_t& gameState)
{ {
// Sum ride values // Sum ride values
money64 result = 0; money64 result = 0;
for (const auto& ride : GetRideManager()) for (const auto& ride : RideManager(gameState))
{ {
result += calculateRideValue(ride); result += calculateRideValue(ride);
} }
// TODO: pass park by ref
auto& park = getGameState().park;
// +7.00 per guest // +7.00 per guest
result += static_cast<money64>(park.numGuestsInPark) * 7.00_GBP; result += static_cast<money64>(park.numGuestsInPark) * 7.00_GBP;
return result; return result;
} }
money64 CalculateCompanyValue() // TODO: refactor S4Importer so this hack is no longer needed
money64 CalculateParkValue()
{ {
// TODO: pass park by ref auto& gameState = getGameState();
auto& park = getGameState().park; return CalculateParkValue(gameState.park, gameState);
}
money64 CalculateCompanyValue(const ParkData& park)
{
auto result = park.value - park.bankLoan; auto result = park.value - park.bankLoan;
// Clamp addition to prevent overflow // Clamp addition to prevent overflow
@@ -648,12 +637,9 @@ namespace OpenRCT2::Park
windowMgr->InvalidateByClass(WindowClass::Finances); windowMgr->InvalidateByClass(WindowClass::Finances);
} }
uint32_t UpdateSize(GameState_t& gameState) uint32_t UpdateSize(ParkData& park, GameState_t& gameState)
{ {
// TODO: pass park by ref auto tiles = CalculateParkSize(park, gameState);
auto& park = gameState.park;
auto tiles = CalculateParkSize();
if (tiles != park.size) if (tiles != park.size)
{ {
park.size = tiles; park.size = tiles;
@@ -754,7 +740,9 @@ namespace OpenRCT2::Park
{ {
auto& gameState = getGameState(); auto& gameState = getGameState();
gameState.cheats.forcedParkRating = rating; gameState.cheats.forcedParkRating = rating;
gameState.park.rating = CalculateParkRating();
auto& park = gameState.park;
park.rating = CalculateParkRating(park, gameState);
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
ContextBroadcastIntent(&intent); ContextBroadcastIntent(&intent);

View File

@@ -27,10 +27,11 @@ namespace OpenRCT2::Park
void Initialise(GameState_t& gameState); void Initialise(GameState_t& gameState);
void Update(GameState_t& gameState, const Date& date); void Update(GameState_t& gameState, const Date& date);
uint32_t CalculateParkSize(); uint32_t CalculateParkSize(ParkData& park);
int32_t CalculateParkRating(); int32_t CalculateParkRating(const ParkData& park, const GameState_t& gameState);
money64 CalculateParkValue(const ParkData& park, const GameState_t& gameState);
money64 CalculateParkValue(); money64 CalculateParkValue();
money64 CalculateCompanyValue(); money64 CalculateCompanyValue(const ParkData& park);
Guest* GenerateGuest(); Guest* GenerateGuest();
@@ -39,7 +40,7 @@ namespace OpenRCT2::Park
void SetForcedRating(int32_t rating); void SetForcedRating(int32_t rating);
int32_t GetForcedRating(); int32_t GetForcedRating();
uint32_t UpdateSize(GameState_t& gameState); uint32_t UpdateSize(ParkData& park, GameState_t& gameState);
void UpdateFences(const CoordsXY& coords); void UpdateFences(const CoordsXY& coords);
void UpdateFencesAroundTile(const CoordsXY& coords); void UpdateFencesAroundTile(const CoordsXY& coords);