diff --git a/contributors.md b/contributors.md index 6f72111d05..b319c8bd3d 100644 --- a/contributors.md +++ b/contributors.md @@ -119,7 +119,7 @@ Appreciation for contributors who have provided substantial work, but are no lon * Tiago Reul (reul) - Misc. * Fredrik Tegnell (fredriktegnell) - Misc. * Alex Parisi (alex-parisi) - Added API for returning metadata from all registered plugins. -* Arnold Zhou (mrmagic2020) - Added plugin API for getting and setting guests' favourite rides, new game option, misc. +* Arnold Zhou (mrmagic2020) - Various plugin additions, new game option, misc. ## Bug fixes & Refactors * Claudio Tiecher (janclod) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 2a4fc131f9..c543c7f82c 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -10,6 +10,7 @@ - Feature: [#22085] [Plugin] The result of actions that create banners now includes the bannerIndex. - Feature: [#22087] [Plugin] Expose guests’ favourite rides to the plugin API. - Feature: [#22140] Add option to automatically close dropdown menus if Enlarged UI is enabled. +- Feature: [#22150] [Plugin] Expose monthly expenditure history to the plugin API. - Improved: [#19870] Allow using new colours in UI themes. - Improved: [#21853] Dropdowns now automatically use multiple columns if they are too tall for the screen. - Improved: [#21981] Rendering performance of the map window has been improved considerably. diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index b9f93dabec..3ad16189b7 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -3799,6 +3799,14 @@ declare global { postMessage(message: string): void; postMessage(message: ParkMessageDesc): void; + + /** + * Gets the monthly expenditure history for a given type. + * Index 0 represents the current month, index 1 the previous month, etc. + * The maximum length of the array is 16. + * @param type The type of expenditure to get. + */ + getMonthlyExpenditure(type: ExpenditureType): number[] } interface Research { diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 753e983f13..f54e969390 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -47,7 +47,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 92; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 93; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; @@ -262,6 +262,9 @@ namespace OpenRCT2::Scripting IntervalHandle AddInterval(const std::shared_ptr& plugin, int32_t delay, bool repeat, DukValue&& callback); void RemoveInterval(const std::shared_ptr& plugin, IntervalHandle handle); + static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType); + static ExpenditureType StringToExpenditureType(std::string_view expenditureType); + # ifndef DISABLE_NETWORK void AddSocket(const std::shared_ptr& socket); # endif @@ -289,8 +292,6 @@ namespace OpenRCT2::Scripting void ProcessREPL(); void RemoveCustomGameActions(const std::shared_ptr& plugin); [[nodiscard]] GameActions::Result DukToGameActionResult(const DukValue& d); - static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType); - static ExpenditureType StringToExpenditureType(std::string_view expenditureType); void InitSharedStorage(); void LoadSharedStorage(); diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 8fe213753e..4c1dadf217 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -12,6 +12,7 @@ # include "ScPark.hpp" # include "../../../Context.h" +# include "../../../Date.h" # include "../../../GameState.h" # include "../../../common.h" # include "../../../core/String.hpp" @@ -401,6 +402,23 @@ namespace OpenRCT2::Scripting } } + std::vector ScPark::getMonthlyExpenditure(const std::string& expenditureType) const + { + auto recordedMonths = std::clamp( + GetDate().GetMonthsElapsed() + 1, static_cast(0), static_cast(kExpenditureTableMonthCount)); + std::vector result(recordedMonths, 0); + auto type = ScriptEngine::StringToExpenditureType(expenditureType); + if (type != ExpenditureType::Count) + { + auto& gameState = GetGameState(); + for (size_t i = 0; i < recordedMonths; ++i) + { + result[i] = gameState.ExpenditureTable[i][EnumValue(type)]; + } + } + return result; + } + void ScPark::Register(duk_context* ctx) { dukglue_register_property(ctx, &ScPark::cash_get, &ScPark::cash_set, "cash"); @@ -432,6 +450,7 @@ namespace OpenRCT2::Scripting dukglue_register_method(ctx, &ScPark::getFlag, "getFlag"); dukglue_register_method(ctx, &ScPark::setFlag, "setFlag"); dukglue_register_method(ctx, &ScPark::postMessage, "postMessage"); + dukglue_register_method(ctx, &ScPark::getMonthlyExpenditure, "getMonthlyExpenditure"); } } // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/bindings/world/ScPark.hpp b/src/openrct2/scripting/bindings/world/ScPark.hpp index a8f9454805..2ffa992b40 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.hpp +++ b/src/openrct2/scripting/bindings/world/ScPark.hpp @@ -98,6 +98,8 @@ namespace OpenRCT2::Scripting void postMessage(DukValue message); + std::vector getMonthlyExpenditure(const std::string& expenditureType) const; + static void Register(duk_context* ctx); }; } // namespace OpenRCT2::Scripting