1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Add plugin hook for guest generation (#14107)

* Add plugin hook for guest generation

* Update api version and add ts entry
This commit is contained in:
Duncan
2021-03-26 05:49:24 +00:00
committed by GitHub
parent a4a08ea8b4
commit 177b5e1b08
5 changed files with 34 additions and 12 deletions

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -19,17 +19,19 @@ using namespace OpenRCT2::Scripting;
HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name)
{
static const std::unordered_map<std::string, HOOK_TYPE> 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<std::string, HOOK_TYPE> 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;
}

View File

@@ -38,6 +38,7 @@ namespace OpenRCT2::Scripting
NETWORK_LEAVE,
RIDE_RATINGS_CALCULATE,
ACTION_LOCATION,
GUEST_GENERATION,
COUNT,
UNDEFINED = -1,
};

View File

@@ -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
{