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

Fix #21507: Expose suggestedGuestMaximum via hook (#21521)

This commit is contained in:
Harry Hopkinson
2024-09-12 01:17:26 +01:00
committed by GitHub
parent 6ee282c8f9
commit 89637013e8
6 changed files with 31 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
0.4.15 (in development)
------------------------------------------------------------------------
- Feature: [#15642] Track design placement can now use contruction modifier keys (ctrl/shift).
- Feature: [#21521] [Plugin] Add hook 'park.guest.softcap.calculate' called before calculating the soft guest cap.
- Change: [#22596] Land ownership fixes described by .parkpatch files are now only considered on scenarios.
- Fix: [#2614] The colour tab of the ride window does not hide invisible cars (original bug).
- Fix: [#15406] Tunnels on steep Side-Friction track are drawn too low.

View File

@@ -515,6 +515,7 @@ declare global {
subscribe(hook: "network.chat", callback: (e: NetworkChatEventArgs) => void): IDisposable;
subscribe(hook: "network.join", callback: (e: NetworkEventArgs) => void): IDisposable;
subscribe(hook: "network.leave", callback: (e: NetworkEventArgs) => void): IDisposable;
subscribe(hook: "park.guest.softcap.calculate", callback: (e: ParkCalculateGuestCapArgs) => void): IDisposable;
subscribe(hook: "ride.ratings.calculate", callback: (e: RideRatingsCalculateArgs) => void): IDisposable;
subscribe(hook: "vehicle.crash", callback: (e: VehicleCrashArgs) => void): IDisposable;
@@ -640,6 +641,7 @@ declare global {
"network.chat" |
"network.join" |
"network.leave" |
"park.guest.softcap.calculate" |
"ride.ratings.calculate" |
"vehicle.crash";
@@ -1415,6 +1417,14 @@ declare global {
readonly crashIntoType: VehicleCrashIntoType;
}
/**
* The 'suggestedGuestMaximum' field in this interface can be used to override
* the park's suggested guest cap.
*/
interface ParkCalculateGuestCapArgs {
suggestedGuestMaximum: number;
}
/**
* APIs for the in-game date.
*/

View File

@@ -34,6 +34,7 @@ static const EnumMap<HOOK_TYPE> HooksLookupTable({
{ "map.change", HOOK_TYPE::MAP_CHANGE },
{ "map.changed", HOOK_TYPE::MAP_CHANGED },
{ "map.save", HOOK_TYPE::MAP_SAVE },
{ "park.guest.softcap.calculate", HOOK_TYPE::PARK_CALCULATE_GUEST_CAP },
});
HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name)

View File

@@ -42,6 +42,7 @@ namespace OpenRCT2::Scripting
MAP_CHANGE,
MAP_CHANGED,
MAP_SAVE,
PARK_CALCULATE_GUEST_CAP,
COUNT,
UNDEFINED = -1,
};

View File

@@ -46,7 +46,7 @@ namespace OpenRCT2
namespace OpenRCT2::Scripting
{
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 98;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 99;
// Versions marking breaking changes.
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;

View File

@@ -33,6 +33,7 @@
#include "../ride/RideData.h"
#include "../ride/ShopItem.h"
#include "../scenario/Scenario.h"
#include "../scripting/ScriptEngine.h"
#include "../util/Util.h"
#include "../windows/Intent.h"
#include "Entrance.h"
@@ -43,6 +44,7 @@
#include <type_traits>
using namespace OpenRCT2;
using namespace OpenRCT2::Scripting;
namespace OpenRCT2::Park
{
@@ -157,6 +159,21 @@ namespace OpenRCT2::Park
}
suggestedMaxGuests = std::min<uint32_t>(suggestedMaxGuests, 65535);
#ifdef ENABLE_SCRIPTING
auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine();
if (hookEngine.HasSubscriptions(HOOK_TYPE::PARK_CALCULATE_GUEST_CAP))
{
auto ctx = GetContext()->GetScriptEngine().GetContext();
auto obj = DukObject(ctx);
obj.Set("suggestedGuestMaximum", suggestedMaxGuests);
auto e = obj.Take();
hookEngine.Call(HOOK_TYPE::PARK_CALCULATE_GUEST_CAP, e, true);
suggestedMaxGuests = AsOrDefault(e["suggestedGuestMaximum"], static_cast<int32_t>(suggestedMaxGuests));
suggestedMaxGuests = std::clamp<uint16_t>(suggestedMaxGuests, 0, UINT16_MAX);
}
#endif
return suggestedMaxGuests;
}