From 30a555d3c20e05fb1253fecf50f63748283e7b0d Mon Sep 17 00:00:00 2001 From: Guy Sviry <32539816+guysv@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:27:15 +0300 Subject: [PATCH] Expose vehicle.trackType to scripting (#22272) Co-authored-by: Guy Sviry --- distribution/changelog.txt | 1 + distribution/openrct2.d.ts | 9 ++++++++- src/openrct2/scripting/ScriptEngine.h | 2 +- .../scripting/bindings/entity/ScVehicle.cpp | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index bf3e2883d438..101ec19b276e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -5,6 +5,7 @@ - Feature: [#22172] [Plugin] Expose ride satisfaction ratings to the plugin API. - Feature: [#22184] [Plugin] Expose staff statistics to the plugin API. - Feature: [#22213] [Plugin] Allow plugins to focus on textboxes in custom windows. +- Feature: [#22272] [Plugin] Expose ride vehicle's current track type via car trackLocation. - Feature: [#22301] Loading save games or scenarios now indicates loading progress. - Feature: [OpenMusic#54] Added Progressive ride music style (feat. Approaching Nirvana). - Improved: [#22361] Add additional colour preset for the Observation Tower. diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index d32549bc1497..37ea4aed9c5b 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -117,6 +117,13 @@ declare global { direction: Direction; } + /** + * A track piece coordinate and type within the game. + */ + interface CarTrackLocation extends CoordsXYZD { + trackType: number; + } + /** * A rectangular area specified using two coordinates. */ @@ -2558,7 +2565,7 @@ declare global { /** * The location and direction of where the car is on the track. */ - trackLocation: CoordsXYZD; + trackLocation: CarTrackLocation; /** * The current g-forces of this car. diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 68e083b57441..0fe438d3c6a3 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 96; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 97; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp index c62818b158ff..1d8462fa3d77 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp @@ -384,8 +384,13 @@ namespace OpenRCT2::Scripting auto vehicle = GetVehicle(); if (vehicle != nullptr) { - auto coords = CoordsXYZD(vehicle->TrackLocation, vehicle->GetTrackDirection()); - return ToDuk(ctx, coords); + DukObject dukCoords(ctx); + dukCoords.Set("x", vehicle->TrackLocation.x); + dukCoords.Set("y", vehicle->TrackLocation.y); + dukCoords.Set("z", vehicle->TrackLocation.z); + dukCoords.Set("direction", vehicle->GetTrackDirection()); + dukCoords.Set("trackType", vehicle->GetTrackType()); + return dukCoords.Take(); } return ToDuk(ctx, nullptr); } @@ -395,9 +400,12 @@ namespace OpenRCT2::Scripting auto vehicle = GetVehicle(); if (vehicle != nullptr) { - auto coords = FromDuk(value); - vehicle->TrackLocation = CoordsXYZ(coords.x, coords.y, coords.z); - vehicle->SetTrackDirection(coords.direction); + auto x = AsOrDefault(value["x"], 0); + auto y = AsOrDefault(value["y"], 0); + auto z = AsOrDefault(value["z"], 0); + vehicle->TrackLocation = CoordsXYZ(x, y, z); + vehicle->SetTrackDirection(AsOrDefault(value["direction"], 0)); + vehicle->SetTrackType(AsOrDefault(value["trackType"], 0)); } } @@ -515,7 +523,6 @@ namespace OpenRCT2::Scripting vehicle->MoveRelativeDistance(value); } } - } // namespace OpenRCT2::Scripting #endif