diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 320b597772..ff19df3337 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -258,6 +258,7 @@ declare global { subscribe(hook: "network.leave", callback: (e: NetworkEventArgs) => void): IDisposable; subscribe(hook: "ride.ratings.calculate", callback: (e: RideRatingsCalculateArgs) => void): IDisposable; subscribe(hook: "action.location", callback: (e: ActionLocationArgs) => void): IDisposable; + subscribe(hook: "guest.generation", callback: (id: number) => void): IDisposable; /** * Registers a function to be called every so often in realtime, specified by the given delay. diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 0e58ab8f2b..f6dc7d7a47 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -31,6 +31,8 @@ #include "../ride/Station.h" #include "../ride/Track.h" #include "../scenario/Scenario.h" +#include "../scripting/HookEngine.h" +#include "../scripting/ScriptEngine.h" #include "../sprites.h" #include "../util/Util.h" #include "../windows/Intent.h" @@ -1767,6 +1769,22 @@ Peep* Peep::Generate(const CoordsXYZ& coords) increment_guests_heading_for_park(); +#ifdef ENABLE_SCRIPTING + auto& hookEngine = OpenRCT2::GetContext()->GetScriptEngine().GetHookEngine(); + if (hookEngine.HasSubscriptions(OpenRCT2::Scripting::HOOK_TYPE::GUEST_GENERATION)) + { + auto ctx = OpenRCT2::GetContext()->GetScriptEngine().GetContext(); + + // Create event args object + auto obj = OpenRCT2::Scripting::DukObject(ctx); + obj.Set("id", peep->sprite_index); + + // Call the subscriptions + auto e = obj.Take(); + hookEngine.Call(OpenRCT2::Scripting::HOOK_TYPE::GUEST_GENERATION, e, true); + } +#endif + return peep; } diff --git a/src/openrct2/scripting/HookEngine.cpp b/src/openrct2/scripting/HookEngine.cpp index 33b6dde3b2..266c7050d2 100644 --- a/src/openrct2/scripting/HookEngine.cpp +++ b/src/openrct2/scripting/HookEngine.cpp @@ -19,17 +19,19 @@ using namespace OpenRCT2::Scripting; HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name) { - static const std::unordered_map LookupTable( - { { "action.query", HOOK_TYPE::ACTION_QUERY }, - { "action.execute", HOOK_TYPE::ACTION_EXECUTE }, - { "interval.tick", HOOK_TYPE::INTERVAL_TICK }, - { "interval.day", HOOK_TYPE::INTERVAL_DAY }, - { "network.chat", HOOK_TYPE::NETWORK_CHAT }, - { "network.authenticate", HOOK_TYPE::NETWORK_AUTHENTICATE }, - { "network.join", HOOK_TYPE::NETWORK_JOIN }, - { "network.leave", HOOK_TYPE::NETWORK_LEAVE }, - { "ride.ratings.calculate", HOOK_TYPE::RIDE_RATINGS_CALCULATE }, - { "action.location", HOOK_TYPE::ACTION_LOCATION } }); + static const std::unordered_map LookupTable({ + { "action.query", HOOK_TYPE::ACTION_QUERY }, + { "action.execute", HOOK_TYPE::ACTION_EXECUTE }, + { "interval.tick", HOOK_TYPE::INTERVAL_TICK }, + { "interval.day", HOOK_TYPE::INTERVAL_DAY }, + { "network.chat", HOOK_TYPE::NETWORK_CHAT }, + { "network.authenticate", HOOK_TYPE::NETWORK_AUTHENTICATE }, + { "network.join", HOOK_TYPE::NETWORK_JOIN }, + { "network.leave", HOOK_TYPE::NETWORK_LEAVE }, + { "ride.ratings.calculate", HOOK_TYPE::RIDE_RATINGS_CALCULATE }, + { "action.location", HOOK_TYPE::ACTION_LOCATION }, + { "guest.generation", HOOK_TYPE::GUEST_GENERATION }, + }); auto result = LookupTable.find(name); return (result != LookupTable.end()) ? result->second : HOOK_TYPE::UNDEFINED; } diff --git a/src/openrct2/scripting/HookEngine.h b/src/openrct2/scripting/HookEngine.h index 7323737e24..ce94ec8a20 100644 --- a/src/openrct2/scripting/HookEngine.h +++ b/src/openrct2/scripting/HookEngine.h @@ -38,6 +38,7 @@ namespace OpenRCT2::Scripting NETWORK_LEAVE, RIDE_RATINGS_CALCULATE, ACTION_LOCATION, + GUEST_GENERATION, COUNT, UNDEFINED = -1, }; diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 5411420390..4332c1ddaa 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -44,7 +44,7 @@ using namespace OpenRCT2; using namespace OpenRCT2::Scripting; -static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 25; +static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 26; struct ExpressionStringifier final {