forked from rosebudai/OpenRCT2-Web
Add ride breakdown hook for scripting (#24243)
This commit is contained in:
9 files changed
+62
-17
No files matched your search
@@ -1,5 +1,6 @@
|
||||
0.5.1 (in development)
|
||||
------------------------------------------------------------------------
|
||||
- Feature: [#24242] [Plugin] Add ride-breakdown hooktype.
|
||||
- Fix: [#26352] Large scenery items are incorrectly labelled as 'banners' in the tile inspector.
|
||||
- Fix: [#26352] The label for path additions is using the wrong text colour in the tile inspector.
|
||||
- Fix: [#26360] Inverted Lay-down Roller Coaster helices are invisible when loading old saves.
|
||||
|
||||
Vendored
+6
@@ -514,6 +514,7 @@ declare global {
|
||||
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.breakdown", callback: (e: RideBreakdownArgs) => void): IDisposable;
|
||||
subscribe(hook: "ride.ratings.calculate", callback: (e: RideRatingsCalculateArgs) => void): IDisposable;
|
||||
subscribe(hook: "vehicle.crash", callback: (e: VehicleCrashArgs) => void): IDisposable;
|
||||
|
||||
@@ -1641,6 +1642,11 @@ declare global {
|
||||
cancel: boolean;
|
||||
}
|
||||
|
||||
interface RideBreakdownArgs {
|
||||
readonly rideId: number;
|
||||
breakdownReason: string;
|
||||
}
|
||||
|
||||
interface RideRatingsCalculateArgs {
|
||||
readonly rideId: number;
|
||||
excitement: number;
|
||||
|
||||
@@ -462,6 +462,7 @@
|
||||
<ClInclude Include="ride\Ride.h" />
|
||||
<ClInclude Include="ride\RideAudio.h" />
|
||||
<ClInclude Include="ride\RideColour.h" />
|
||||
<ClInclude Include="ride\RideBreakdownMap.h" />
|
||||
<ClInclude Include="ride\RideConstruction.h" />
|
||||
<ClInclude Include="ride\RideData.h" />
|
||||
<ClInclude Include="ride\RideEntry.h" />
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "../profiling/Profiling.h"
|
||||
#include "../rct1/RCT1.h"
|
||||
#include "../scenario/Scenario.h"
|
||||
#include "../scripting/ScriptEngine.h"
|
||||
#include "../ui/WindowManager.h"
|
||||
#include "../util/Util.h"
|
||||
#include "../windows/Intent.h"
|
||||
@@ -61,6 +62,7 @@
|
||||
#include "../world/tile_element/TrackElement.h"
|
||||
#include "CableLift.h"
|
||||
#include "RideAudio.h"
|
||||
#include "RideBreakdownMap.h"
|
||||
#include "RideConstruction.h"
|
||||
#include "RideData.h"
|
||||
#include "RideEntry.h"
|
||||
@@ -80,6 +82,7 @@
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::TrackMetadata;
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
static constexpr auto kRideModeBlockSectionedCounterpart = std::to_array(
|
||||
{
|
||||
@@ -1313,6 +1316,24 @@ void RidePrepareBreakdown(Ride& ride, Breakdown breakdownReason)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine();
|
||||
if (hookEngine.HasSubscriptions(HookType::rideBreakDown))
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
JSValue obj = JS_NewObject(ctx);
|
||||
|
||||
JS_SetPropertyStr(ctx, obj, "rideId", JS_NewInt32(ctx, ride.id.ToUnderlying()));
|
||||
|
||||
auto it = kBreakdownMap.find(breakdownReason);
|
||||
if (it != kBreakdownMap.end())
|
||||
JS_SetPropertyStr(ctx, obj, "breakdownReason", JS_NewString(ctx, it->first.data()));
|
||||
else
|
||||
JS_SetPropertyStr(ctx, obj, "breakdownReason", JS_NewString(ctx, "none"));
|
||||
|
||||
hookEngine.Call(HookType::rideBreakDown, obj, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2026 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../core/EnumMap.hpp"
|
||||
#include "Ride.h"
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
static const EnumMap<Breakdown> kBreakdownMap(
|
||||
{ { "safety_cut_out", Breakdown::safetyCutOut },
|
||||
{ "restraints_stuck_closed", Breakdown::restraintsStuckClosed },
|
||||
{ "restraints_stuck_open", Breakdown::restraintsStuckOpen },
|
||||
{ "doors_stuck_closed", Breakdown::doorsStuckClosed },
|
||||
{ "doors_stuck_open", Breakdown::doorsStuckOpen },
|
||||
{ "vehicle_malfunction", Breakdown::vehicleMalfunction },
|
||||
{ "brakes_failure", Breakdown::brakesFailure },
|
||||
{ "control_failure", Breakdown::controlFailure } });
|
||||
#endif
|
||||
@@ -34,6 +34,7 @@ static const EnumMap<HookType> HooksLookupTable(
|
||||
{ "map.changed", HookType::mapChanged },
|
||||
{ "map.save", HookType::mapSave },
|
||||
{ "park.guest.softcap.calculate", HookType::parkCalculateGuestCap },
|
||||
{ "ride.breakdown", HookType::rideBreakDown },
|
||||
});
|
||||
|
||||
HookType OpenRCT2::Scripting::GetHookType(const std::string& name)
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace OpenRCT2::Scripting
|
||||
mapChanged,
|
||||
mapSave,
|
||||
parkCalculateGuestCap,
|
||||
rideBreakDown,
|
||||
count,
|
||||
notDefined = -1,
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRCT2
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
static constexpr int32_t kPluginApiVersion = 111;
|
||||
static constexpr int32_t kPluginApiVersion = 112;
|
||||
|
||||
// Versions marking breaking changes.
|
||||
static constexpr int32_t kApiVersionPeepDeprecation = 33;
|
||||
|
||||
@@ -15,24 +15,13 @@
|
||||
#include "../../../core/EnumMap.hpp"
|
||||
#include "../../../core/UnitConversion.h"
|
||||
#include "../../../ride/Ride.h"
|
||||
#include "../../../ride/RideBreakdownMap.h"
|
||||
#include "../../../ride/RideData.h"
|
||||
#include "../../ScriptEngine.h"
|
||||
#include "../object/ScObject.hpp"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
static const EnumMap<Breakdown> BreakdownMap(
|
||||
{
|
||||
{ "safety_cut_out", Breakdown::safetyCutOut },
|
||||
{ "restraints_stuck_closed", Breakdown::restraintsStuckClosed },
|
||||
{ "restraints_stuck_open", Breakdown::restraintsStuckOpen },
|
||||
{ "doors_stuck_closed", Breakdown::doorsStuckClosed },
|
||||
{ "doors_stuck_open", Breakdown::doorsStuckOpen },
|
||||
{ "vehicle_malfunction", Breakdown::vehicleMalfunction },
|
||||
{ "brakes_failure", Breakdown::brakesFailure },
|
||||
{ "control_failure", Breakdown::controlFailure },
|
||||
});
|
||||
|
||||
void ScRide::Register(JSContext* ctx)
|
||||
{
|
||||
static constexpr JSCFunctionListEntry funcs[] = {
|
||||
@@ -787,8 +776,8 @@ namespace OpenRCT2::Scripting
|
||||
{
|
||||
return JSFromStdString(ctx, "none");
|
||||
}
|
||||
auto it = BreakdownMap.find(ride->breakdownReason);
|
||||
if (it != BreakdownMap.end())
|
||||
auto it = kBreakdownMap.find(ride->breakdownReason);
|
||||
if (it != kBreakdownMap.end())
|
||||
return JSFromStdString(ctx, std::string(it->first));
|
||||
}
|
||||
return JSFromStdString(ctx, "");
|
||||
@@ -802,8 +791,8 @@ namespace OpenRCT2::Scripting
|
||||
auto ride = GetRide(thisVal);
|
||||
if (ride != nullptr && ride->canBreakDown() && ride->status == RideStatus::open)
|
||||
{
|
||||
auto it = BreakdownMap.find(breakDown);
|
||||
if (it != BreakdownMap.end())
|
||||
auto it = kBreakdownMap.find(breakDown);
|
||||
if (it != kBreakdownMap.end())
|
||||
{
|
||||
RidePrepareBreakdown(*ride, it->second);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user