1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Implement plugin getter for subposition coordinates

This commit is contained in:
Bas
2022-08-19 22:10:46 +02:00
parent 7b5aeece59
commit 8c39881353
4 changed files with 51 additions and 6 deletions

View File

@@ -6,7 +6,7 @@
- Feature: [#16662] Show a warning message when g2.dat is mismatched.
- Feature: [#17107] Ride operating settings can be set via text input.
- Feature: [#17638] Added Zero G rolls, medium loops and large corkscrews to the Hybrid and Single-Rail coasters.
- Feature: [#17821] [Plugin] Add API for track subposition length and vehicle subposition.
- Feature: [#17821] [Plugin] Add API for track subpositions and vehicle subposition.
- Feature: [#17877] Add three real-life flying roller coaster colour schemes.
- Feature: [#17900] Add “Classic Wooden Coaster” with shallow banked turns.
- Feature: [#6570, #10860, #17929] Fully support RollerCoaster Tycoon Classic as a RCT2 base install path.

View File

@@ -884,7 +884,7 @@ declare global {
readonly imageId: number;
readonly spriteNumImages: number;
}
/**
* Represents the sprite groups of a vehicle
*/
@@ -915,7 +915,7 @@ declare global {
readonly restraintAnimation?: SpriteGroup;
readonly curvedLiftHill?: SpriteGroup;
}
/**
* Represents a defined vehicle within a Ride object definition.
*/
@@ -1244,11 +1244,17 @@ declare global {
* Gets a list of the elements that make up the track segment.
*/
readonly elements: TrackSegmentElement[];
/**
* Gets a length of the subpositions list for this track segment.
*/
getSubpositionLength(subpositionType: number, direction: Direction): number;
/**
* Gets all of the subpositions for this track segment. These subpositions are used for the
* pathing of vehicles when moving along the track.
*/
getSubpositions(subpositionType: number, direction: Direction): TrackSubposition[];
}
enum TrackSlope {
@@ -1268,7 +1274,16 @@ declare global {
UpsideDown = 15
}
interface TrackSegmentElement extends CoordsXYZ {
interface TrackSegmentElement extends Readonly<CoordsXYZ> {
}
/**
* A single subposition on a track piece. These subpositions are used for the pathing of vehicles
* when moving along the track.
*/
interface TrackSubposition extends Readonly<CoordsXYZD> {
readonly angle: TrackSlope;
readonly banking: TrackBanking;
}
interface TrackIterator {
@@ -1473,7 +1488,7 @@ declare global {
readonly remainingDistance: number;
/**
* The type of subposition coordinates that this vehicle is using to find its
* The type of subposition coordinates that this vehicle is using to find its
* position on the track.
*/
readonly subposition: number;

View File

@@ -37,6 +37,7 @@ void ScTrackSegment::Register(duk_context* ctx)
dukglue_register_property(ctx, &ScTrackSegment::endDirection_get, nullptr, "endDirection");
dukglue_register_property(ctx, &ScTrackSegment::length_get, nullptr, "length");
dukglue_register_method(ctx, &ScTrackSegment::getSubpositionLength, "getSubpositionLength");
dukglue_register_method(ctx, &ScTrackSegment::getSubpositions, "getSubpositions");
}
int32_t ScTrackSegment::type_get() const
@@ -148,4 +149,20 @@ uint16_t ScTrackSegment::getSubpositionLength(uint8_t trackSubposition, uint8_t
return vehicle_get_move_info_size(static_cast<VehicleTrackSubposition>(trackSubposition), _type, direction);
}
std::vector<DukValue> ScTrackSegment::getSubpositions(uint8_t trackSubposition, uint8_t direction) const
{
const auto ctx = GetContext()->GetScriptEngine().GetContext();
const uint16_t size = getSubpositionLength(trackSubposition, direction);
const uint16_t typeAndDirection = (_type << 2) | (direction & 3);
std::vector<DukValue> result;
for (auto idx = 0; idx < size; idx++)
{
result.push_back(ToDuk<rct_vehicle_info>(
ctx, gTrackVehicleInfo[static_cast<uint8_t>(trackSubposition)][typeAndDirection]->info[idx]));
}
return result;
}
#endif

View File

@@ -19,6 +19,18 @@
namespace OpenRCT2::Scripting
{
template<> inline DukValue ToDuk(duk_context* ctx, const rct_vehicle_info& value)
{
DukObject dukSubposition(ctx);
dukSubposition.Set("x", value.x);
dukSubposition.Set("y", value.y);
dukSubposition.Set("z", value.z);
dukSubposition.Set("direction", value.direction);
dukSubposition.Set("angle", value.Pitch);
dukSubposition.Set("banking", value.bank_rotation);
return dukSubposition.Take();
}
class ScTrackSegment
{
private:
@@ -45,6 +57,7 @@ namespace OpenRCT2::Scripting
int32_t length_get() const;
DukValue elements_get() const;
uint16_t getSubpositionLength(uint8_t trackSubposition, uint8_t direction) const;
std::vector<DukValue> getSubpositions(uint8_t trackSubposition, uint8_t direction) const;
};
} // namespace OpenRCT2::Scripting