diff --git a/distribution/changelog.txt b/distribution/changelog.txt index d765ba49fb..c1afda516d 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -29,6 +29,7 @@ - Feature: [#14171] [Plugin] Add API for creating custom widgets. - Feature: [#14171] [Plugin] Add API for drawing graphics for custom widgets. - Feature: [#14171] [Plugin] Add click event to spinners and allow them to be held down. +- Feature: [#14252] [Plugin] Add API for vehicle g-forces. - Change: [#13346] [Plugin] Renamed FootpathScenery to FootpathAddition, fix typos. - Change: [#13857] Change Rotation Control Toggle to track element number 256 - Fix: [#4605, #11912] Water palettes are not updated properly when selected in Object Selection. diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index bca0d63753..320b597772 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -114,6 +114,14 @@ declare global { rightBottom: CoordsXY; } + /** + * Represents lateral and vertical g-forces. + */ + interface GForces { + lateralG: number; + verticalG: number; + } + /** * Represents information about the plugin such as type, name, author and version. * It also includes the entry point. @@ -1173,6 +1181,11 @@ declare global { */ trackLocation: CoordsXYZD; + /** + * The current g-forces of this car. + */ + readonly gForces: GForces; + /** * The progress on the current track piece, in steps. */ diff --git a/src/openrct2/scripting/Duktape.hpp b/src/openrct2/scripting/Duktape.hpp index 73cddc4e52..fdd7f0f327 100644 --- a/src/openrct2/scripting/Duktape.hpp +++ b/src/openrct2/scripting/Duktape.hpp @@ -12,6 +12,7 @@ #ifdef ENABLE_SCRIPTING # include "../core/Console.hpp" +# include "../ride/Vehicle.h" # include "../world/Map.h" # include @@ -408,6 +409,14 @@ namespace OpenRCT2::Scripting } } + template<> inline DukValue ToDuk(duk_context* ctx, const GForces& value) + { + DukObject dukGForces(ctx); + dukGForces.Set("lateralG", value.LateralG); + dukGForces.Set("verticalG", value.VerticalG); + return dukGForces.Take(); + } + template<> inline CoordsXYZD FromDuk(const DukValue& value) { CoordsXYZD result; diff --git a/src/openrct2/scripting/ScEntity.hpp b/src/openrct2/scripting/ScEntity.hpp index c9aded3b04..d5cb5aa1aa 100644 --- a/src/openrct2/scripting/ScEntity.hpp +++ b/src/openrct2/scripting/ScEntity.hpp @@ -270,6 +270,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScVehicle::poweredMaxSpeed_get, &ScVehicle::poweredMaxSpeed_set, "poweredMaxSpeed"); dukglue_register_property(ctx, &ScVehicle::status_get, &ScVehicle::status_set, "status"); dukglue_register_property(ctx, &ScVehicle::peeps_get, nullptr, "peeps"); + dukglue_register_property(ctx, &ScVehicle::gForces_get, nullptr, "gForces"); dukglue_register_method(ctx, &ScVehicle::travelBy, "travelBy"); } @@ -627,6 +628,18 @@ namespace OpenRCT2::Scripting return result; } + DukValue gForces_get() const + { + auto ctx = GetContext()->GetScriptEngine().GetContext(); + auto vehicle = GetVehicle(); + if (vehicle != nullptr) + { + GForces gForces = vehicle->GetGForces(); + return ToDuk(ctx, gForces); + } + return ToDuk(ctx, nullptr); + } + void travelBy(int32_t value) { ThrowIfGameStateNotMutable(); diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 1892c0d48b..00f167150c 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 = 23; +static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 24; struct ExpressionStringifier final {