From bf1e3412a585a699d3c4eee78198800a31516636 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 30 Apr 2022 16:09:01 +0100 Subject: [PATCH] Add extra fields to TrackSegment --- distribution/openrct2.d.ts | 53 +++++++++++++++---- .../bindings/ride/ScTrackSegment.cpp | 31 ++++++----- .../scripting/bindings/ride/ScTrackSegment.h | 13 ++--- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index f15ae84873..e302de5566 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -1160,17 +1160,27 @@ declare global { */ readonly beginZ: number; - /** - * The relative starting direction. Usually 0, but will be 4 - * for diagonal pieces. - */ + /** + * The relative starting direction. Usually 0, but will be 4 + * for diagonal segments. + */ readonly beginDirection: Direction8; + /** + * The slope angle the segment starts with. + */ + readonly beginAngle: number; + + /** + * The kind of banking the segment starts with. + */ + readonly beginBank: TrackBanking; + /** * The relative ending X position. */ readonly endX: number; - + /** * The relative ending Y position. */ @@ -1180,12 +1190,30 @@ declare global { * The relative ending Z position. Negative numbers indicate * that the track ends upside down. */ - readonly endZ: number; + readonly endZ: number; /** * The relative ending direction. */ - readonly endDirection: Direction8; + readonly endDirection: Direction8; + + + /** + * The slope angle the segment ends with. + */ + readonly endAngle: number; + + /** + * The kind of banking the segment ends with. + */ + readonly endBank: TrackBanking; + + /** + * The length of the segment in RCT track length units. + * + * *1 metre = 1 / (2 ^ 16)* + */ + readonly length: number; /** * Gets a list of the elements that make up the track segment. @@ -1193,7 +1221,14 @@ declare global { readonly elements: TrackSegmentElement[]; } - interface TrackSegmentElement implements CoordsXYZ { + enum TrackBanking { + None = 0, + Left = 2, + Right = 4, + UpsideDown = 15 + } + + interface TrackSegmentElement extends CoordsXYZ { } interface TrackIterator { @@ -1201,7 +1236,7 @@ declare global { * The position and direction of the current track segment. Usually this is the position of the * element of the segment, however for some segments, it may be offset. */ - readonly position: CoordsXYZD; + readonly position: CoordsXYZD; /** * The current track segment. diff --git a/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp b/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp index d1c127b6c7..384e42fd56 100644 --- a/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp +++ b/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp @@ -28,12 +28,13 @@ void ScTrackSegment::Register(duk_context* ctx) dukglue_register_property(ctx, &ScTrackSegment::type_get, nullptr, "type"); dukglue_register_property(ctx, &ScTrackSegment::description_get, nullptr, "description"); dukglue_register_property(ctx, &ScTrackSegment::elements_get, nullptr, "elements"); - dukglue_register_property(ctx, &ScTrackSegment::beginZ, nullptr, "beginZ"); - dukglue_register_property(ctx, &ScTrackSegment::beginDirection, nullptr, "beginDirection"); - dukglue_register_property(ctx, &ScTrackSegment::endX, nullptr, "endX"); - dukglue_register_property(ctx, &ScTrackSegment::endY, nullptr, "endY"); - dukglue_register_property(ctx, &ScTrackSegment::endZ, nullptr, "endZ"); - dukglue_register_property(ctx, &ScTrackSegment::endDirection, nullptr, "endDirection"); + dukglue_register_property(ctx, &ScTrackSegment::beginZ_get, nullptr, "beginZ"); + dukglue_register_property(ctx, &ScTrackSegment::beginDirection_get, nullptr, "beginDirection"); + dukglue_register_property(ctx, &ScTrackSegment::endX_get, nullptr, "endX"); + dukglue_register_property(ctx, &ScTrackSegment::endY_get, nullptr, "endY"); + dukglue_register_property(ctx, &ScTrackSegment::endZ_get, nullptr, "endZ"); + dukglue_register_property(ctx, &ScTrackSegment::endDirection_get, nullptr, "endDirection"); + dukglue_register_property(ctx, &ScTrackSegment::length_get, nullptr, "length"); } int32_t ScTrackSegment::type_get() const @@ -47,42 +48,48 @@ std::string ScTrackSegment::description_get() const return language_get_string(ted.Description); } -int32_t ScTrackSegment::beginZ() const +int32_t ScTrackSegment::beginZ_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.z_begin; } -int32_t ScTrackSegment::beginDirection() const +int32_t ScTrackSegment::beginDirection_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.rotation_begin; } -int32_t ScTrackSegment::endX() const +int32_t ScTrackSegment::endX_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.x; } -int32_t ScTrackSegment::endY() const +int32_t ScTrackSegment::endY_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.y; } -int32_t ScTrackSegment::endZ() const +int32_t ScTrackSegment::endZ_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.z_end; } -int32_t ScTrackSegment::endDirection() const +int32_t ScTrackSegment::endDirection_get() const { const auto& ted = GetTrackElementDescriptor(_type); return ted.Coordinates.rotation_end; } +int32_t ScTrackSegment::length_get() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.PieceLength; +} + DukValue ScTrackSegment::elements_get() const { auto& scriptEngine = GetContext()->GetScriptEngine(); diff --git a/src/openrct2/scripting/bindings/ride/ScTrackSegment.h b/src/openrct2/scripting/bindings/ride/ScTrackSegment.h index ba0feae27f..f89d4125a1 100644 --- a/src/openrct2/scripting/bindings/ride/ScTrackSegment.h +++ b/src/openrct2/scripting/bindings/ride/ScTrackSegment.h @@ -32,12 +32,13 @@ namespace OpenRCT2::Scripting private: int32_t type_get() const; std::string description_get() const; - int32_t beginZ() const; - int32_t beginDirection() const; - int32_t endX() const; - int32_t endY() const; - int32_t endZ() const; - int32_t endDirection() const; + int32_t beginZ_get() const; + int32_t beginDirection_get() const; + int32_t endX_get() const; + int32_t endY_get() const; + int32_t endZ_get() const; + int32_t endDirection_get() const; + int32_t length_get() const; DukValue elements_get() const; };