1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 04:23:20 +01:00

Add plugin API for vehicle g-forces

This commit is contained in:
Felix
2021-03-06 23:25:26 +01:00
parent 58c3426747
commit 78785fffbe
3 changed files with 35 additions and 0 deletions

View File

@@ -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.
@@ -1153,6 +1161,11 @@ declare global {
*/
trackLocation: CoordsXYZD;
/**
* The current g-forces of this car.
*/
gForces: GForces;
/**
* The progress on the current track piece, in steps.
*/

View File

@@ -13,6 +13,7 @@
# include "../core/Console.hpp"
# include "../world/Map.h"
# include "../ride/Vehicle.h"
# include <cstdio>
# include <dukglue/dukglue.h>
@@ -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;

View File

@@ -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<GForces>(ctx, gForces);
}
return ToDuk(ctx, nullptr);
}
void travelBy(int32_t value)
{
ThrowIfGameStateNotMutable();