diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index ce68bae60c..f15ae84873 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -649,6 +649,7 @@ declare global { "surface" | "footpath" | "track" | "small_scenery" | "wall" | "entrance" | "large_scenery" | "banner"; type Direction = 0 | 1 | 2 | 3; + type Direction8 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; type TileElement = SurfaceElement | FootpathElement | TrackElement | SmallSceneryElement | WallElement | EntranceElement @@ -1154,6 +1155,38 @@ declare global { */ readonly description: string; + /** + * The relative starting Z position. + */ + readonly beginZ: number; + + /** + * The relative starting direction. Usually 0, but will be 4 + * for diagonal pieces. + */ + readonly beginDirection: Direction8; + + /** + * The relative ending X position. + */ + readonly endX: number; + + /** + * The relative ending Y position. + */ + readonly endY: number; + + /** + * The relative ending Z position. Negative numbers indicate + * that the track ends upside down. + */ + readonly endZ: number; + + /** + * The relative ending direction. + */ + readonly endDirection: Direction8; + /** * Gets a list of the elements that make up the track segment. */ diff --git a/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp b/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp index 8b6d1d1bd4..d1c127b6c7 100644 --- a/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp +++ b/src/openrct2/scripting/bindings/ride/ScTrackSegment.cpp @@ -28,6 +28,12 @@ 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"); } int32_t ScTrackSegment::type_get() const @@ -41,6 +47,42 @@ std::string ScTrackSegment::description_get() const return language_get_string(ted.Description); } +int32_t ScTrackSegment::beginZ() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.z_begin; +} + +int32_t ScTrackSegment::beginDirection() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.rotation_begin; +} + +int32_t ScTrackSegment::endX() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.x; +} + +int32_t ScTrackSegment::endY() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.y; +} + +int32_t ScTrackSegment::endZ() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.z_end; +} + +int32_t ScTrackSegment::endDirection() const +{ + const auto& ted = GetTrackElementDescriptor(_type); + return ted.Coordinates.rotation_end; +} + 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 95449faa1e..ba0feae27f 100644 --- a/src/openrct2/scripting/bindings/ride/ScTrackSegment.h +++ b/src/openrct2/scripting/bindings/ride/ScTrackSegment.h @@ -32,6 +32,12 @@ 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; DukValue elements_get() const; };