diff --git a/distribution/changelog.txt b/distribution/changelog.txt index e9b438d604..0f0bdcd81e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Feature: [#13057] Make GameAction flags accessible by plugins. - Feature: [#13376] Open custom window at specified tab. - Feature: [#13398] Add pause button to the Track Designer. +- Feature: [#13495] [Plugin] Add properties for park value, guests and company value. - Change: [#13346] Change FootpathScenery to FootpathAddition in all occurrences. - Fix: [#12895] Mechanics are called to repair rides that have already been fixed. - Fix: [#13257] Rides that are exactly the minimum objective length are not counted. diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 179c52857b..48a5b76bd5 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -1454,6 +1454,23 @@ declare global { */ entranceFee: number; + /** + * The number of guests within the park, not including any outside the park but still + * on the map. + */ + readonly guests: number; + + /** + * The park value, will be updated every 512 ticks. + */ + value: number; + + /** + * The company value, will be updated every 512 ticks. + * Calculation is: `park.value + park.cash - park.bankLoan` + */ + companyValue: number; + name: string; messages: ParkMessage[]; diff --git a/src/openrct2/scripting/ScPark.hpp b/src/openrct2/scripting/ScPark.hpp index d4ec7dcaec..dfe05052b1 100644 --- a/src/openrct2/scripting/ScPark.hpp +++ b/src/openrct2/scripting/ScPark.hpp @@ -17,6 +17,7 @@ # include "../core/String.hpp" # include "../management/Finance.h" # include "../management/NewsItem.h" +# include "../peep/Peep.h" # include "../windows/Intent.h" # include "../world/Park.h" # include "Duktape.hpp" @@ -255,9 +256,13 @@ namespace OpenRCT2::Scripting void cash_set(money32 value) { ThrowIfGameStateNotMutable(); - gCash = value; - auto intent = Intent(INTENT_ACTION_UPDATE_CASH); - context_broadcast_intent(&intent); + + if (gCash != value) + { + gCash = value; + auto intent = Intent(INTENT_ACTION_UPDATE_CASH); + context_broadcast_intent(&intent); + } } int32_t rating_get() const @@ -267,9 +272,14 @@ namespace OpenRCT2::Scripting void rating_set(int32_t value) { ThrowIfGameStateNotMutable(); - gParkRating = std::min(std::max(0, value), 999); - auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); - context_broadcast_intent(&intent); + + auto valueClamped = std::min(std::max(0, value), 999); + if (gParkRating != valueClamped) + { + gParkRating = std::min(std::max(0, value), 999); + auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); + context_broadcast_intent(&intent); + } } money32 bankLoan_get() const @@ -279,9 +289,13 @@ namespace OpenRCT2::Scripting void bankLoan_set(money32 value) { ThrowIfGameStateNotMutable(); - gBankLoan = value; - auto intent = Intent(INTENT_ACTION_UPDATE_CASH); - context_broadcast_intent(&intent); + + if (gBankLoan != value) + { + gBankLoan = value; + auto intent = Intent(INTENT_ACTION_UPDATE_CASH); + context_broadcast_intent(&intent); + } } money32 maxBankLoan_get() const @@ -291,9 +305,13 @@ namespace OpenRCT2::Scripting void maxBankLoan_set(money32 value) { ThrowIfGameStateNotMutable(); - gMaxBankLoan = value; - auto intent = Intent(INTENT_ACTION_UPDATE_CASH); - context_broadcast_intent(&intent); + + if (gMaxBankLoan != value) + { + gMaxBankLoan = value; + auto intent = Intent(INTENT_ACTION_UPDATE_CASH); + context_broadcast_intent(&intent); + } } money16 entranceFee_get() const @@ -303,7 +321,49 @@ namespace OpenRCT2::Scripting void entranceFee_set(money16 value) { ThrowIfGameStateNotMutable(); - gParkEntranceFee = value; + + if (gParkEntranceFee != value) + { + gParkEntranceFee = value; + window_invalidate_by_class(WC_PARK_INFORMATION); + } + } + + uint32_t guests_get() const + { + return gNumGuestsInPark; + } + + money32 value_get() const + { + return gParkValue; + } + void value_set(money32 value) + { + ThrowIfGameStateNotMutable(); + + if (gParkValue != value) + { + gParkValue = value; + auto intent = Intent(INTENT_ACTION_UPDATE_CASH); + context_broadcast_intent(&intent); + } + } + + money32 companyValue_get() const + { + return gCompanyValue; + } + void companyValue_set(money32 value) + { + ThrowIfGameStateNotMutable(); + + if (gCompanyValue != value) + { + gCompanyValue = value; + auto intent = Intent(INTENT_ACTION_UPDATE_CASH); + context_broadcast_intent(&intent); + } } std::string name_get() const @@ -313,7 +373,13 @@ namespace OpenRCT2::Scripting void name_set(std::string value) { ThrowIfGameStateNotMutable(); - GetContext()->GetGameState()->GetPark().Name = value; + + auto& park = GetContext()->GetGameState()->GetPark(); + if (park.Name != value) + { + park.Name = value; + gfx_invalidate_screen(); + } } bool getFlag(const std::string& key) const @@ -426,6 +492,9 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScPark::bankLoan_get, &ScPark::bankLoan_set, "bankLoan"); dukglue_register_property(ctx, &ScPark::maxBankLoan_get, &ScPark::maxBankLoan_set, "maxBankLoan"); dukglue_register_property(ctx, &ScPark::entranceFee_get, &ScPark::entranceFee_set, "entranceFee"); + dukglue_register_property(ctx, &ScPark::guests_get, nullptr, "guests"); + dukglue_register_property(ctx, &ScPark::value_get, &ScPark::value_set, "value"); + dukglue_register_property(ctx, &ScPark::companyValue_get, &ScPark::companyValue_set, "companyValue"); dukglue_register_property(ctx, &ScPark::name_get, &ScPark::name_set, "name"); dukglue_register_property(ctx, &ScPark::messages_get, &ScPark::messages_set, "messages"); dukglue_register_method(ctx, &ScPark::getFlag, "getFlag");