Skip to content

Commit

Permalink
Expose vehicle.trackType to scripting (OpenRCT2#22272)
Browse files Browse the repository at this point in the history
Co-authored-by: Guy Sviry <guy@axissecurity.com>
  • Loading branch information
guysv and Guy Sviry authored Jul 25, 2024
1 parent 06bb987 commit 30a555d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion distribution/openrct2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/scripting/ScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions src/openrct2/scripting/bindings/entity/ScVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,13 @@ namespace OpenRCT2::Scripting
auto vehicle = GetVehicle();
if (vehicle != nullptr)
{
auto coords = CoordsXYZD(vehicle->TrackLocation, vehicle->GetTrackDirection());
return ToDuk<CoordsXYZD>(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);
}
Expand All @@ -395,9 +400,12 @@ namespace OpenRCT2::Scripting
auto vehicle = GetVehicle();
if (vehicle != nullptr)
{
auto coords = FromDuk<CoordsXYZD>(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));
}
}

Expand Down Expand Up @@ -515,7 +523,6 @@ namespace OpenRCT2::Scripting
vehicle->MoveRelativeDistance(value);
}
}

} // namespace OpenRCT2::Scripting

#endif

0 comments on commit 30a555d

Please sign in to comment.