Turn Park into struct

This commit is contained in:
Gymnasiast 2024-03-26 19:01:50 +01:00
parent 7b072808ee
commit 4f3b7aa8a9
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
18 changed files with 95 additions and 153 deletions

View File

@ -134,8 +134,8 @@ static InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& scre
break; break;
case ViewportInteractionItem::ParkEntrance: case ViewportInteractionItem::ParkEntrance:
{ {
auto& park = GetGameState().Park; auto& gameState = GetGameState();
auto parkName = park.Name.c_str(); auto parkName = gameState.Park.Name.c_str();
auto ft = Formatter(); auto ft = Formatter();
ft.Add<StringId>(STR_STRING); ft.Add<StringId>(STR_STRING);

View File

@ -662,9 +662,9 @@ static uint64_t window_editor_objective_options_page_hold_down_widgets[] = {
{ {
case WIDX_PARK_NAME: case WIDX_PARK_NAME:
{ {
auto& park = OpenRCT2::GetGameState().Park;
WindowTextInputRawOpen( WindowTextInputRawOpen(
this, WIDX_PARK_NAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, park.Name.c_str(), ParkNameMaxLength); this, WIDX_PARK_NAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, gameState.Park.Name.c_str(),
ParkNameMaxLength);
break; break;
} }
case WIDX_SCENARIO_NAME: case WIDX_SCENARIO_NAME:
@ -794,8 +794,7 @@ static uint64_t window_editor_objective_options_page_hold_down_widgets[] = {
if (gameState.ScenarioName.empty()) if (gameState.ScenarioName.empty())
{ {
auto& park = OpenRCT2::GetGameState().Park; gameState.ScenarioName = gameState.Park.Name;
gameState.ScenarioName = park.Name;
} }
break; break;
} }
@ -972,8 +971,7 @@ static uint64_t window_editor_objective_options_page_hold_down_widgets[] = {
widthToSet = widgets[WIDX_PARK_NAME].left - 16; widthToSet = widgets[WIDX_PARK_NAME].left - 16;
{ {
auto& park = OpenRCT2::GetGameState().Park; auto parkName = OpenRCT2::GetGameState().Park.Name.c_str();
auto parkName = park.Name.c_str();
ft = Formatter(); ft = Formatter();
ft.Add<StringId>(STR_STRING); ft.Add<StringId>(STR_STRING);

View File

@ -870,8 +870,7 @@ static Widget _windowFinancesResearchWidgets[] =
break; break;
default: default:
{ {
auto& park = OpenRCT2::GetGameState().Park; auto parkName = OpenRCT2::GetGameState().Park.Name.c_str();
auto parkName = park.Name.c_str();
ft.Add<StringId>(STR_STRING); ft.Add<StringId>(STR_STRING);
ft.Add<const char*>(parkName); ft.Add<const char*>(parkName);
} }

View File

@ -1629,8 +1629,7 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT);
std::pair<StringId, Formatter> InventoryFormatItem(Guest& guest, ShopItem item) const std::pair<StringId, Formatter> InventoryFormatItem(Guest& guest, ShopItem item) const
{ {
auto& park = OpenRCT2::GetGameState().Park; auto parkName = OpenRCT2::GetGameState().Park.Name.c_str();
auto parkName = park.Name.c_str();
// Default arguments // Default arguments
auto ft = Formatter(); auto ft = Formatter();

View File

@ -458,8 +458,7 @@ static Widget window_loadsave_widgets[] =
} }
else else
{ {
auto& park = OpenRCT2::GetGameState().Park; auto buffer = OpenRCT2::GetGameState().Park.Name;
auto buffer = park.Name;
if (buffer.empty()) if (buffer.empty())
{ {
buffer = LanguageGetString(STR_UNNAMED_PARK); buffer = LanguageGetString(STR_UNNAMED_PARK);

View File

@ -402,8 +402,7 @@ static constexpr WindowParkAward _parkAwards[] = {
void PrepareWindowTitleText() void PrepareWindowTitleText()
{ {
auto& park = OpenRCT2::GetGameState().Park; auto parkName = OpenRCT2::GetGameState().Park.Name.c_str();
auto parkName = park.Name.c_str();
auto ft = Formatter::Common(); auto ft = Formatter::Common();
ft.Add<StringId>(STR_STRING); ft.Add<StringId>(STR_STRING);
@ -456,7 +455,7 @@ static constexpr WindowParkAward _parkAwards[] = {
WindowDropdownShowText( WindowDropdownShowText(
{ windowPos.x + widget.left, windowPos.y + widget.top }, widget.height() + 1, colours[1], 0, 2); { windowPos.x + widget.left, windowPos.y + widget.top }, widget.height() + 1, colours[1], 0, 2);
if (ParkIsOpen()) if (GetGameState().Park.IsOpen())
{ {
gDropdownDefaultIndex = 0; gDropdownDefaultIndex = 0;
Dropdown::SetChecked(1, true); Dropdown::SetChecked(1, true);
@ -512,18 +511,18 @@ static constexpr WindowParkAward _parkAwards[] = {
// Set open / close park button state // Set open / close park button state
{ {
auto& park = OpenRCT2::GetGameState().Park; auto parkName = OpenRCT2::GetGameState().Park.Name.c_str();
auto parkName = park.Name.c_str();
auto ft = Formatter::Common(); auto ft = Formatter::Common();
ft.Add<StringId>(STR_STRING); ft.Add<StringId>(STR_STRING);
ft.Add<const char*>(parkName); ft.Add<const char*>(parkName);
} }
widgets[WIDX_OPEN_OR_CLOSE].image = ImageId(ParkIsOpen() ? SPR_OPEN : SPR_CLOSED); const bool parkIsOpen = gameState.Park.IsOpen();
const auto closeLightImage = SPR_G2_RCT1_CLOSE_BUTTON_0 + !ParkIsOpen() * 2 widgets[WIDX_OPEN_OR_CLOSE].image = ImageId(parkIsOpen ? SPR_OPEN : SPR_CLOSED);
const auto closeLightImage = SPR_G2_RCT1_CLOSE_BUTTON_0 + !parkIsOpen * 2
+ WidgetIsPressed(*this, WIDX_CLOSE_LIGHT); + WidgetIsPressed(*this, WIDX_CLOSE_LIGHT);
widgets[WIDX_CLOSE_LIGHT].image = ImageId(closeLightImage); widgets[WIDX_CLOSE_LIGHT].image = ImageId(closeLightImage);
const auto openLightImage = SPR_G2_RCT1_OPEN_BUTTON_0 + ParkIsOpen() * 2 + WidgetIsPressed(*this, WIDX_OPEN_LIGHT); const auto openLightImage = SPR_G2_RCT1_OPEN_BUTTON_0 + parkIsOpen * 2 + WidgetIsPressed(*this, WIDX_OPEN_LIGHT);
widgets[WIDX_OPEN_LIGHT].image = ImageId(openLightImage); widgets[WIDX_OPEN_LIGHT].image = ImageId(openLightImage);
// Only allow closing of park for guest / rating objective // Only allow closing of park for guest / rating objective
@ -605,7 +604,7 @@ static constexpr WindowParkAward _parkAwards[] = {
// Draw park closed / open label // Draw park closed / open label
auto ft = Formatter(); auto ft = Formatter();
ft.Add<StringId>(ParkIsOpen() ? STR_PARK_OPEN : STR_PARK_CLOSED); ft.Add<StringId>(GetGameState().Park.IsOpen() ? STR_PARK_OPEN : STR_PARK_CLOSED);
auto* labelWidget = &widgets[WIDX_STATUS]; auto* labelWidget = &widgets[WIDX_STATUS];
DrawTextEllipsised( DrawTextEllipsised(

View File

@ -499,13 +499,13 @@ namespace Editor
*/ */
ResultWithMessage CheckPark() ResultWithMessage CheckPark()
{ {
int32_t parkSize = ParkCalculateSize(); auto& gameState = GetGameState();
int32_t parkSize = ParkUpdateSize(gameState);
if (parkSize == 0) if (parkSize == 0)
{ {
return { false, STR_PARK_MUST_OWN_SOME_LAND }; return { false, STR_PARK_MUST_OWN_SOME_LAND };
} }
const auto& gameState = GetGameState();
if (gameState.ParkEntrances.empty()) if (gameState.ParkEntrances.empty())
{ {
return { false, STR_NO_PARK_ENTRANCES }; return { false, STR_NO_PARK_ENTRANCES };

View File

@ -70,7 +70,7 @@ namespace OpenRCT2
gameState.CurrentTicks = 0; gameState.CurrentTicks = 0;
MapInit(mapSize); MapInit(mapSize);
gameState.Park.Initialise(); ParkInitialise(gameState);
FinanceInit(); FinanceInit();
BannerInit(gameState); BannerInit(gameState);
RideInitAll(); RideInitAll();
@ -344,7 +344,7 @@ namespace OpenRCT2
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR)) if (!(gScreenFlags & SCREEN_FLAGS_EDITOR))
{ {
gameState.Park.Update(gameState.Date); ParkUpdate(gameState, gameState.Date);
} }
ResearchUpdate(); ResearchUpdate();

View File

@ -34,11 +34,12 @@
namespace OpenRCT2 namespace OpenRCT2
{ {
class Park; struct Park;
struct GameState_t struct GameState_t
{ {
::OpenRCT2::Park Park{}; ::OpenRCT2::Park Park{};
std::string PluginStorage;
uint32_t CurrentTicks{}; uint32_t CurrentTicks{};
::OpenRCT2::Date Date; ::OpenRCT2::Date Date;
uint64_t ParkFlags; uint64_t ParkFlags;

View File

@ -222,7 +222,7 @@ GameActions::Result CheatSetAction::Execute() const
GetGameState().Cheats.NeverendingMarketing = _param1 != 0; GetGameState().Cheats.NeverendingMarketing = _param1 != 0;
break; break;
case CheatType::OpenClosePark: case CheatType::OpenClosePark:
ParkSetOpen(!ParkIsOpen()); ParkSetOpen(!GetGameState().Park.IsOpen());
break; break;
case CheatType::HaveFun: case CheatType::HaveFun:
gameState.ScenarioObjective.Type = OBJECTIVE_HAVE_FUN; gameState.ScenarioObjective.Type = OBJECTIVE_HAVE_FUN;
@ -607,10 +607,9 @@ void CheatSetAction::ClearLoan() const
void CheatSetAction::GenerateGuests(int32_t count) const void CheatSetAction::GenerateGuests(int32_t count) const
{ {
auto& park = OpenRCT2::GetGameState().Park;
for (int32_t i = 0; i < count; i++) for (int32_t i = 0; i < count; i++)
{ {
park.GenerateGuest(); GenerateGuest();
} }
WindowInvalidateByClass(WindowClass::BottomToolbar); WindowInvalidateByClass(WindowClass::BottomToolbar);
} }

View File

@ -73,7 +73,7 @@ GameActions::Result MapChangeSizeAction::Execute() const
auto* ctx = OpenRCT2::GetContext(); auto* ctx = OpenRCT2::GetContext();
auto uiContext = ctx->GetUiContext(); auto uiContext = ctx->GetUiContext();
auto* windowManager = uiContext->GetWindowManager(); auto* windowManager = uiContext->GetWindowManager();
ParkCalculateSize(); ParkUpdateSize(gameState);
windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP));
GfxInvalidateScreen(); GfxInvalidateScreen();

View File

@ -156,7 +156,7 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride& ride) const
} }
ride.Delete(); ride.Delete();
GetGameState().ParkValue = GetGameState().Park.CalculateParkValue(); GetGameState().ParkValue = CalculateParkValue();
// Close windows related to the demolished ride // Close windows related to the demolished ride
WindowCloseByNumber(WindowClass::RideConstruction, rideId.ToUnderlying()); WindowCloseByNumber(WindowClass::RideConstruction, rideId.ToUnderlying());

View File

@ -649,29 +649,29 @@ namespace OpenRCT2
void ReadWritePluginStorageChunk(GameState_t& gameState, OrcaStream& os) void ReadWritePluginStorageChunk(GameState_t& gameState, OrcaStream& os)
{ {
auto& park = gameState.Park;
if (os.GetMode() == OrcaStream::Mode::WRITING) if (os.GetMode() == OrcaStream::Mode::WRITING)
{ {
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
// Dump the plugin storage to JSON (stored in park) // Dump the plugin storage to JSON (stored in park)
auto& scriptEngine = GetContext()->GetScriptEngine(); auto& scriptEngine = GetContext()->GetScriptEngine();
park.PluginStorage = scriptEngine.GetParkStorageAsJSON(); gameState.PluginStorage = scriptEngine.GetParkStorageAsJSON();
#endif #endif
if (park.PluginStorage.empty() || park.PluginStorage == "{}") if (gameState.PluginStorage.empty() || gameState.PluginStorage == "{}")
{ {
// Don't write the chunk if there is no plugin storage // Don't write the chunk if there is no plugin storage
return; return;
} }
} }
os.ReadWriteChunk( os.ReadWriteChunk(ParkFileChunkType::PLUGIN_STORAGE, [&gameState](OrcaStream::ChunkStream& cs) {
ParkFileChunkType::PLUGIN_STORAGE, [&park](OrcaStream::ChunkStream& cs) { cs.ReadWrite(park.PluginStorage); }); cs.ReadWrite(gameState.PluginStorage);
});
if (os.GetMode() == OrcaStream::Mode::READING) if (os.GetMode() == OrcaStream::Mode::READING)
{ {
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
auto& scriptEngine = GetContext()->GetScriptEngine(); auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.SetParkStorageFromJSON(park.PluginStorage); scriptEngine.SetParkStorageFromJSON(gameState.PluginStorage);
#endif #endif
} }
} }

View File

@ -275,8 +275,7 @@ namespace RCT1
{ {
// Use the ratio between the old and new park value to calcute the ratio to // Use the ratio between the old and new park value to calcute the ratio to
// use for the park value history and the goal. // use for the park value history and the goal.
auto& park = GetGameState().Park; _parkValueConversionFactor = (CalculateParkValue() * 10) / _s4.ParkValue;
_parkValueConversionFactor = (park.CalculateParkValue() * 10) / _s4.ParkValue;
} }
else else
{ {
@ -2149,8 +2148,7 @@ namespace RCT1
// Park rating // Park rating
gameState.ParkRating = _s4.ParkRating; gameState.ParkRating = _s4.ParkRating;
auto& park = OpenRCT2::GetGameState().Park; ResetParkHistories(gameState);
park.ResetHistories();
std::copy(std::begin(_s4.ParkRatingHistory), std::end(_s4.ParkRatingHistory), gameState.ParkRatingHistory); std::copy(std::begin(_s4.ParkRatingHistory), std::end(_s4.ParkRatingHistory), gameState.ParkRatingHistory);
for (size_t i = 0; i < std::size(_s4.GuestsInParkHistory); i++) for (size_t i = 0; i < std::size(_s4.GuestsInParkHistory); i++)
{ {

View File

@ -307,8 +307,7 @@ namespace RCT2
gameState.ParkRating = _s6.ParkRating; gameState.ParkRating = _s6.ParkRating;
auto& park = OpenRCT2::GetGameState().Park; ResetParkHistories(gameState);
park.ResetHistories();
std::copy(std::begin(_s6.ParkRatingHistory), std::end(_s6.ParkRatingHistory), gameState.ParkRatingHistory); std::copy(std::begin(_s6.ParkRatingHistory), std::end(_s6.ParkRatingHistory), gameState.ParkRatingHistory);
for (size_t i = 0; i < std::size(_s6.GuestsInParkHistory); i++) for (size_t i = 0; i < std::size(_s6.GuestsInParkHistory); i++)
{ {
@ -504,7 +503,7 @@ namespace RCT2
ConvertScenarioStringsToUTF8(gameState); ConvertScenarioStringsToUTF8(gameState);
DetermineRideEntranceAndExitLocations(); DetermineRideEntranceAndExitLocations();
park.Name = GetUserString(_s6.ParkName); gameState.Park.Name = GetUserString(_s6.ParkName);
FixLandOwnership(); FixLandOwnership();
FixWater(); FixWater();

View File

@ -100,10 +100,9 @@ void ScenarioReset(GameState_t& gameState)
ScenerySetDefaultPlacementConfiguration(); ScenerySetDefaultPlacementConfiguration();
News::InitQueue(); News::InitQueue();
auto& park = GetGameState().Park; gameState.ParkRating = CalculateParkRating();
gameState.ParkRating = park.CalculateParkRating(); gameState.ParkValue = CalculateParkValue();
gameState.ParkValue = park.CalculateParkValue(); gameState.CompanyValue = CalculateCompanyValue();
gameState.CompanyValue = park.CalculateCompanyValue();
gameState.HistoricalProfit = gameState.InitialCash - gameState.BankLoan; gameState.HistoricalProfit = gameState.InitialCash - gameState.BankLoan;
gameState.Cash = gameState.InitialCash; gameState.Cash = gameState.InitialCash;
@ -120,7 +119,7 @@ void ScenarioReset(GameState_t& gameState)
} }
if (localisedStringIds[1] != STR_NONE) if (localisedStringIds[1] != STR_NONE)
{ {
park.Name = LanguageGetString(localisedStringIds[1]); gameState.Park.Name = LanguageGetString(localisedStringIds[1]);
} }
if (localisedStringIds[2] != STR_NONE) if (localisedStringIds[2] != STR_NONE)
{ {
@ -132,7 +131,7 @@ void ScenarioReset(GameState_t& gameState)
// Set the last saved game path // Set the last saved game path
auto env = GetContext()->GetPlatformEnvironment(); auto env = GetContext()->GetPlatformEnvironment();
auto savePath = env->GetDirectoryPath(DIRBASE::USER, DIRID::SAVE); auto savePath = env->GetDirectoryPath(DIRBASE::USER, DIRID::SAVE);
gScenarioSavePath = Path::Combine(savePath, park.Name + u8".park"); gScenarioSavePath = Path::Combine(savePath, gameState.Park.Name + u8".park");
gameState.CurrentExpenditure = 0; gameState.CurrentExpenditure = 0;
gameState.CurrentProfit = 0; gameState.CurrentProfit = 0;
@ -145,13 +144,13 @@ void ScenarioReset(GameState_t& gameState)
gameState.ScenarioCompletedCompanyValue = kMoney64Undefined; gameState.ScenarioCompletedCompanyValue = kMoney64Undefined;
gameState.ScenarioCompletedBy = "?"; gameState.ScenarioCompletedBy = "?";
park.ResetHistories(); ResetParkHistories(gameState);
FinanceResetHistory(); FinanceResetHistory();
AwardReset(); AwardReset();
ResetAllRideBuildDates(); ResetAllRideBuildDates();
ResetDate(); ResetDate();
Duck::RemoveAll(); Duck::RemoveAll();
ParkCalculateSize(); ParkUpdateSize(gameState);
MapCountRemainingLandRights(); MapCountRemainingLandRights();
Staff::ResetStats(); Staff::ResetStats();

View File

@ -50,6 +50,14 @@ using namespace OpenRCT2;
// If this value is more than or equal to 0, the park rating is forced to this value. Used for cheat // If this value is more than or equal to 0, the park rating is forced to this value. Used for cheat
static int32_t _forcedParkRating = -1; static int32_t _forcedParkRating = -1;
static money64 calculateRideValue(const Ride& ride);
static money64 calculateTotalRideValueForMoney();
static uint32_t calculateSuggestedMaxGuests();
static uint32_t calculateGuestGenerationProbability();
static void generateGuests(GameState_t& gameState);
static Guest* generateGuestFromCampaign(int32_t campaign);
/** /**
* Choose a random peep spawn and iterates through until defined spawn is found. * Choose a random peep spawn and iterates through until defined spawn is found.
*/ */
@ -152,8 +160,7 @@ void ParkUpdateFencesAroundTile(const CoordsXY& coords)
void ParkSetForcedRating(int32_t rating) void ParkSetForcedRating(int32_t rating)
{ {
_forcedParkRating = rating; _forcedParkRating = rating;
auto& park = GetGameState().Park; GetGameState().ParkRating = CalculateParkRating();
GetGameState().ParkRating = park.CalculateParkRating();
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
ContextBroadcastIntent(&intent); ContextBroadcastIntent(&intent);
} }
@ -210,27 +217,10 @@ bool Park::IsOpen() const
return (GetGameState().ParkFlags & PARK_FLAGS_PARK_OPEN) != 0; return (GetGameState().ParkFlags & PARK_FLAGS_PARK_OPEN) != 0;
} }
uint16_t Park::GetParkRating() const void ParkInitialise(GameState_t& gameState)
{ {
return GetGameState().ParkRating; gameState.Park.Name = LanguageGetString(STR_UNNAMED_PARK);
} gameState.PluginStorage = {};
money64 Park::GetParkValue() const
{
return GetGameState().ParkValue;
}
money64 Park::GetCompanyValue() const
{
return GetGameState().CompanyValue;
}
void Park::Initialise()
{
auto& gameState = GetGameState();
Name = LanguageGetString(STR_UNNAMED_PARK);
PluginStorage = {};
gameState.StaffHandymanColour = COLOUR_BRIGHT_RED; gameState.StaffHandymanColour = COLOUR_BRIGHT_RED;
gameState.StaffMechanicColour = COLOUR_LIGHT_BLUE; gameState.StaffMechanicColour = COLOUR_LIGHT_BLUE;
gameState.StaffSecurityColour = COLOUR_YELLOW; gameState.StaffSecurityColour = COLOUR_YELLOW;
@ -272,7 +262,7 @@ void Park::Initialise()
gameState.LandPrice = 90.00_GBP; gameState.LandPrice = 90.00_GBP;
gameState.ConstructionRightsPrice = 40.00_GBP; gameState.ConstructionRightsPrice = 40.00_GBP;
gameState.ParkFlags = PARK_FLAGS_NO_MONEY | PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gameState.ParkFlags = PARK_FLAGS_NO_MONEY | PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
ResetHistories(); ResetParkHistories(gameState);
FinanceResetHistory(); FinanceResetHistory();
AwardReset(); AwardReset();
@ -280,17 +270,16 @@ void Park::Initialise()
gameState.ScenarioDetails = String::ToStd(LanguageGetString(STR_NO_DETAILS_YET)); gameState.ScenarioDetails = String::ToStd(LanguageGetString(STR_NO_DETAILS_YET));
} }
void Park::Update(const Date& date) void ParkUpdate(GameState_t& gameState, const Date& date)
{ {
PROFILED_FUNCTION(); PROFILED_FUNCTION();
// Every new week // Every new week
if (date.IsWeekStart()) if (date.IsWeekStart())
{ {
UpdateHistories(); UpdateParkHistories(gameState);
} }
auto& gameState = GetGameState();
const auto currentTicks = gameState.CurrentTicks; const auto currentTicks = gameState.CurrentTicks;
// Every ~13 seconds // Every ~13 seconds
@ -299,9 +288,9 @@ void Park::Update(const Date& date)
gameState.ParkRating = CalculateParkRating(); gameState.ParkRating = CalculateParkRating();
gameState.ParkValue = CalculateParkValue(); gameState.ParkValue = CalculateParkValue();
gameState.CompanyValue = CalculateCompanyValue(); gameState.CompanyValue = CalculateCompanyValue();
gameState.TotalRideValueForMoney = CalculateTotalRideValueForMoney(); gameState.TotalRideValueForMoney = calculateTotalRideValueForMoney();
gameState.SuggestedGuestMaximum = CalculateSuggestedMaxGuests(); gameState.SuggestedGuestMaximum = calculateSuggestedMaxGuests();
gameState.GuestGenerationProbability = CalculateGuestGenerationProbability(); gameState.GuestGenerationProbability = calculateGuestGenerationProbability();
WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::Finances);
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
@ -315,10 +304,10 @@ void Park::Update(const Date& date)
WindowInvalidateByClass(WindowClass::ParkInformation); WindowInvalidateByClass(WindowClass::ParkInformation);
} }
GenerateGuests(); generateGuests(gameState);
} }
uint32_t Park::CalculateParkSize() const uint32_t CalculateParkSize()
{ {
uint32_t tiles = 0; uint32_t tiles = 0;
TileElementIterator it; TileElementIterator it;
@ -344,7 +333,7 @@ uint32_t Park::CalculateParkSize() const
return tiles; return tiles;
} }
int32_t Park::CalculateParkRating() const int32_t CalculateParkRating()
{ {
if (_forcedParkRating >= 0) if (_forcedParkRating >= 0)
{ {
@ -461,13 +450,13 @@ int32_t Park::CalculateParkRating() const
return result; return result;
} }
money64 Park::CalculateParkValue() const money64 CalculateParkValue()
{ {
// Sum ride values // Sum ride values
money64 result = 0; money64 result = 0;
for (const auto& ride : GetRideManager()) for (const auto& ride : GetRideManager())
{ {
result += CalculateRideValue(ride); result += calculateRideValue(ride);
} }
// +7.00 per guest // +7.00 per guest
@ -476,7 +465,7 @@ money64 Park::CalculateParkValue() const
return result; return result;
} }
money64 Park::CalculateRideValue(const Ride& ride) const static money64 calculateRideValue(const Ride& ride)
{ {
money64 result = 0; money64 result = 0;
if (ride.value != RIDE_VALUE_UNDEFINED) if (ride.value != RIDE_VALUE_UNDEFINED)
@ -487,7 +476,7 @@ money64 Park::CalculateRideValue(const Ride& ride) const
return result; return result;
} }
money64 Park::CalculateCompanyValue() const money64 CalculateCompanyValue()
{ {
const auto& gameState = GetGameState(); const auto& gameState = GetGameState();
@ -499,7 +488,7 @@ money64 Park::CalculateCompanyValue() const
return result; return result;
} }
money64 Park::CalculateTotalRideValueForMoney() const static money64 calculateTotalRideValueForMoney()
{ {
money64 totalRideValue = 0; money64 totalRideValue = 0;
bool ridePricesUnlocked = ParkRidePricesUnlocked() && !(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY); bool ridePricesUnlocked = ParkRidePricesUnlocked() && !(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY);
@ -529,7 +518,7 @@ money64 Park::CalculateTotalRideValueForMoney() const
return totalRideValue; return totalRideValue;
} }
uint32_t Park::CalculateSuggestedMaxGuests() const static uint32_t calculateSuggestedMaxGuests()
{ {
uint32_t suggestedMaxGuests = 0; uint32_t suggestedMaxGuests = 0;
uint32_t difficultGenerationBonus = 0; uint32_t difficultGenerationBonus = 0;
@ -577,7 +566,7 @@ uint32_t Park::CalculateSuggestedMaxGuests() const
return suggestedMaxGuests; return suggestedMaxGuests;
} }
uint32_t Park::CalculateGuestGenerationProbability() const static uint32_t calculateGuestGenerationProbability()
{ {
auto& gameState = GetGameState(); auto& gameState = GetGameState();
@ -631,7 +620,7 @@ uint32_t Park::CalculateGuestGenerationProbability() const
return probability; return probability;
} }
uint8_t Park::CalculateGuestInitialHappiness(uint8_t percentage) uint8_t CalculateGuestInitialHappiness(uint8_t percentage)
{ {
percentage = std::clamp<uint8_t>(percentage, 15, 98); percentage = std::clamp<uint8_t>(percentage, 15, 98);
@ -653,10 +642,8 @@ uint8_t Park::CalculateGuestInitialHappiness(uint8_t percentage)
return 40; return 40;
} }
void Park::GenerateGuests() static void generateGuests(GameState_t& gameState)
{ {
auto& gameState = GetGameState();
// Generate a new guest for some probability // Generate a new guest for some probability
if (static_cast<int32_t>(ScenarioRand() & 0xFFFF) < gameState.GuestGenerationProbability) if (static_cast<int32_t>(ScenarioRand() & 0xFFFF) < gameState.GuestGenerationProbability)
{ {
@ -675,12 +662,12 @@ void Park::GenerateGuests()
auto random = ScenarioRandMax(std::numeric_limits<uint16_t>::max()); auto random = ScenarioRandMax(std::numeric_limits<uint16_t>::max());
if (random < probability) if (random < probability)
{ {
GenerateGuestFromCampaign(campaign.Type); generateGuestFromCampaign(campaign.Type);
} }
} }
} }
Guest* Park::GenerateGuestFromCampaign(int32_t campaign) static Guest* generateGuestFromCampaign(int32_t campaign)
{ {
auto peep = GenerateGuest(); auto peep = GenerateGuest();
if (peep != nullptr) if (peep != nullptr)
@ -690,7 +677,7 @@ Guest* Park::GenerateGuestFromCampaign(int32_t campaign)
return peep; return peep;
} }
Guest* Park::GenerateGuest() Guest* GenerateGuest()
{ {
Guest* peep = nullptr; Guest* peep = nullptr;
const auto spawn = GetRandomPeepSpawn(); const auto spawn = GetRandomPeepSpawn();
@ -721,16 +708,14 @@ template<typename T, size_t TSize> static void HistoryPushRecord(T history[TSize
history[0] = newItem; history[0] = newItem;
} }
void Park::ResetHistories() void ResetParkHistories(GameState_t& gameState)
{ {
auto& gameState = GetGameState();
std::fill(std::begin(gameState.ParkRatingHistory), std::end(gameState.ParkRatingHistory), ParkRatingHistoryUndefined); std::fill(std::begin(gameState.ParkRatingHistory), std::end(gameState.ParkRatingHistory), ParkRatingHistoryUndefined);
std::fill(std::begin(gameState.GuestsInParkHistory), std::end(gameState.GuestsInParkHistory), GuestsInParkHistoryUndefined); std::fill(std::begin(gameState.GuestsInParkHistory), std::end(gameState.GuestsInParkHistory), GuestsInParkHistoryUndefined);
} }
void Park::UpdateHistories() void UpdateParkHistories(GameState_t& gameState)
{ {
auto& gameState = GetGameState();
uint8_t guestChangeModifier = 1; uint8_t guestChangeModifier = 1;
int32_t changeInGuestsInPark = static_cast<int32_t>(gameState.NumGuestsInPark) int32_t changeInGuestsInPark = static_cast<int32_t>(gameState.NumGuestsInPark)
- static_cast<int32_t>(gameState.NumGuestsInParkLastWeek); - static_cast<int32_t>(gameState.NumGuestsInParkLastWeek);
@ -774,15 +759,9 @@ void Park::UpdateHistories()
WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::Finances);
} }
int32_t ParkIsOpen() uint32_t ParkUpdateSize(GameState_t& gameState)
{ {
return GetGameState().Park.IsOpen(); auto tiles = CalculateParkSize();
}
uint32_t ParkCalculateSize()
{
auto& gameState = GetGameState();
auto tiles = GetGameState().Park.CalculateParkSize();
if (tiles != gameState.ParkSize) if (tiles != gameState.ParkSize)
{ {
gameState.ParkSize = tiles; gameState.ParkSize = tiles;
@ -790,8 +769,3 @@ uint32_t ParkCalculateSize()
} }
return tiles; return tiles;
} }
uint8_t CalculateGuestInitialHappiness(uint8_t percentage)
{
return Park::CalculateGuestInitialHappiness(percentage);
}

View File

@ -47,57 +47,35 @@ enum : uint32_t
}; };
struct Guest; struct Guest;
struct rct_ride;
namespace OpenRCT2 namespace OpenRCT2
{ {
struct Date; struct Date;
class Park final struct Park final
{ {
public:
std::string Name; std::string Name;
std::string PluginStorage;
Park() = default;
Park(const Park&) = delete;
bool IsOpen() const; bool IsOpen() const;
uint16_t GetParkRating() const;
money64 GetParkValue() const;
money64 GetCompanyValue() const;
void Initialise();
void Update(const Date& date);
uint32_t CalculateParkSize() const;
int32_t CalculateParkRating() const;
money64 CalculateParkValue() const;
money64 CalculateCompanyValue() const;
static uint8_t CalculateGuestInitialHappiness(uint8_t percentage);
Guest* GenerateGuest();
void ResetHistories();
void UpdateHistories();
private:
money64 CalculateRideValue(const Ride& ride) const;
money64 CalculateTotalRideValueForMoney() const;
uint32_t CalculateSuggestedMaxGuests() const;
uint32_t CalculateGuestGenerationProbability() const;
void GenerateGuests();
Guest* GenerateGuestFromCampaign(int32_t campaign);
}; };
} // namespace OpenRCT2 } // namespace OpenRCT2
void ParkInitialise(OpenRCT2::GameState_t& gameState);
void ParkUpdate(OpenRCT2::GameState_t& gameState, const OpenRCT2::Date& date);
uint32_t CalculateParkSize();
int32_t CalculateParkRating();
money64 CalculateParkValue();
money64 CalculateCompanyValue();
Guest* GenerateGuest();
void ResetParkHistories(OpenRCT2::GameState_t& gameState);
void UpdateParkHistories(OpenRCT2::GameState_t& gameState);
void ParkSetForcedRating(int32_t rating); void ParkSetForcedRating(int32_t rating);
int32_t ParkGetForcedRating(); int32_t ParkGetForcedRating();
int32_t ParkIsOpen(); uint32_t ParkUpdateSize(OpenRCT2::GameState_t& gameState);
uint32_t ParkCalculateSize();
void ParkUpdateFences(const CoordsXY& coords); void ParkUpdateFences(const CoordsXY& coords);
void ParkUpdateFencesAroundTile(const CoordsXY& coords); void ParkUpdateFencesAroundTile(const CoordsXY& coords);