From 307523610e72432341bc8c8ac677d57517e067be Mon Sep 17 00:00:00 2001 From: kendfrey Date: Wed, 2 Oct 2024 05:49:43 -0400 Subject: [PATCH] Add Park.generateGuest() to plugin API (#22883) Co-authored-by: Tulio Leao --- contributors.md | 1 + distribution/changelog.txt | 1 + distribution/openrct2.d.ts | 6 ++++++ src/openrct2/scripting/ScriptEngine.h | 2 +- src/openrct2/scripting/bindings/world/ScPark.cpp | 9 +++++++++ src/openrct2/scripting/bindings/world/ScPark.hpp | 2 ++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contributors.md b/contributors.md index b550ebbf88..8fbb93306a 100644 --- a/contributors.md +++ b/contributors.md @@ -122,6 +122,7 @@ Appreciation for contributors who have provided substantial work, but are no lon * Arnold Zhou (mrmagic2020) - Various plugin additions, new game option, misc. * John Dolph (johnwdolph) - Ride music UI, misc. * Harry Hopkinson (Harry-Hopkinson) - Added Cheat for guests ignoring price of rides and stalls. +* Kendall Frey (kendfrey) - Add plugin API for spawning guests ## Bug fixes & Refactors * Claudio Tiecher (janclod) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 9a169a34b9..2ec8d26bdb 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -6,6 +6,7 @@ - Feature: [#22694] Park graphs have tooltips and can be resized like finance graphs. - Feature: [#22758] The table of ‘real’ peep names can now be changed using Peep Names objects. - Feature: [#22842] [Plugin] Expose large scenery object tiles to the plugin API. +- Feature: [#22883] [Plugin] Add plugin API for spawning guests. - Improved: [#22470] Android: automatically detect RCT2 installs in /sdcard/rct2. - Improved: [#22735] The map generator has a redesigned interface that is much more user friendly. - Improved: [#22777] Add long flat-to-steep track pieces to the Wooden and Classic Wooden Roller Coasters. diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 507fd782f4..f4a42020a6 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -3840,6 +3840,12 @@ declare global { */ readonly guestGenerationProbability: number; + /** + * Spawns a new guest at a random peep spawn point. + * Note: The "guest.generation" hook will be called before this function returns. + */ + generateGuest(): Guest; + /** * The average amount of cash guests will spawn with. */ diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 7f800d1d0b..fb79961d21 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 100; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 101; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 066d5c04a6..91a497da87 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -22,6 +22,7 @@ # include "../../../world/Park.h" # include "../../Duktape.hpp" # include "../../ScriptEngine.h" +# include "../entity/ScGuest.hpp" # include "ScParkMessage.hpp" namespace OpenRCT2::Scripting @@ -148,6 +149,13 @@ namespace OpenRCT2::Scripting return GetGameState().GuestGenerationProbability; } + DukValue ScPark::generateGuest() + { + ThrowIfGameStateNotMutable(); + auto guest = Park::GenerateGuest(); + return GetObjectAsDukValue(_context, std::make_shared(guest->Id)); + } + money64 ScPark::guestInitialCash_get() const { return GetGameState().GuestInitialCash; @@ -428,6 +436,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScPark::guests_get, nullptr, "guests"); dukglue_register_property(ctx, &ScPark::suggestedGuestMaximum_get, nullptr, "suggestedGuestMaximum"); dukglue_register_property(ctx, &ScPark::guestGenerationProbability_get, nullptr, "guestGenerationProbability"); + dukglue_register_method(ctx, &ScPark::generateGuest, "generateGuest"); dukglue_register_property(ctx, &ScPark::guestInitialCash_get, nullptr, "guestInitialCash"); dukglue_register_property(ctx, &ScPark::guestInitialHappiness_get, nullptr, "guestInitialHappiness"); dukglue_register_property(ctx, &ScPark::guestInitialHunger_get, nullptr, "guestInitialHunger"); diff --git a/src/openrct2/scripting/bindings/world/ScPark.hpp b/src/openrct2/scripting/bindings/world/ScPark.hpp index 10a41b528d..bf590bdefe 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.hpp +++ b/src/openrct2/scripting/bindings/world/ScPark.hpp @@ -49,6 +49,8 @@ namespace OpenRCT2::Scripting int32_t guestGenerationProbability_get() const; + DukValue generateGuest(); + money64 guestInitialCash_get() const; uint8_t guestInitialHappiness_get() const;