mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #17821 from Basssiiie/plugin-tracksegment-subposition-length
[Plugin] Implement plugin getters for track and vehicle subpositions
This commit is contained in:
commit
1956b718ef
|
@ -8,6 +8,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 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: [objects#198] Add additional pirate roofs.
|
||||
|
|
|
@ -107,7 +107,7 @@ declare global {
|
|||
* The direction is between 0 and 3.
|
||||
*/
|
||||
interface CoordsXYZD extends CoordsXYZ {
|
||||
direction: number;
|
||||
direction: Direction;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,6 +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 {
|
||||
|
@ -1263,7 +1274,17 @@ 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<CoordsXYZ> {
|
||||
readonly yaw: number;
|
||||
readonly pitch: TrackSlope;
|
||||
readonly roll: TrackBanking;
|
||||
}
|
||||
|
||||
interface TrackIterator {
|
||||
|
@ -1467,6 +1488,12 @@ declare global {
|
|||
*/
|
||||
readonly remainingDistance: number;
|
||||
|
||||
/**
|
||||
* The type of subposition coordinates that this vehicle is using to find its
|
||||
* position on the track.
|
||||
*/
|
||||
readonly subposition: number;
|
||||
|
||||
/**
|
||||
* List of guest IDs ordered by seat.
|
||||
* @deprecated since version 34, use guests instead.
|
||||
|
|
|
@ -664,7 +664,7 @@ const rct_vehicle_info* Vehicle::GetMoveInfo() const
|
|||
return vehicle_get_move_info(TrackSubposition, GetTrackType(), GetTrackDirection(), track_progress);
|
||||
}
|
||||
|
||||
static uint16_t vehicle_get_move_info_size(VehicleTrackSubposition trackSubposition, track_type_t type, uint8_t direction)
|
||||
uint16_t vehicle_get_move_info_size(VehicleTrackSubposition trackSubposition, track_type_t type, uint8_t direction)
|
||||
{
|
||||
uint16_t typeAndDirection = (type << 2) | (direction & 3);
|
||||
|
||||
|
|
|
@ -526,6 +526,7 @@ enum
|
|||
Vehicle* try_get_vehicle(EntityId spriteIndex);
|
||||
void vehicle_update_all();
|
||||
void vehicle_sounds_update();
|
||||
uint16_t vehicle_get_move_info_size(VehicleTrackSubposition trackSubposition, track_type_t type, uint8_t direction);
|
||||
|
||||
void RideUpdateMeasurementsSpecialElements_Default(Ride* ride, const track_type_t trackType);
|
||||
void RideUpdateMeasurementsSpecialElements_MiniGolf(Ride* ride, const track_type_t trackType);
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace OpenRCT2
|
|||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 58;
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 59;
|
||||
|
||||
// Versions marking breaking changes.
|
||||
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;
|
||||
|
|
|
@ -75,6 +75,7 @@ namespace OpenRCT2::Scripting
|
|||
dukglue_register_property(ctx, &ScVehicle::trackLocation_get, &ScVehicle::trackLocation_set, "trackLocation");
|
||||
dukglue_register_property(ctx, &ScVehicle::trackProgress_get, nullptr, "trackProgress");
|
||||
dukglue_register_property(ctx, &ScVehicle::remainingDistance_get, nullptr, "remainingDistance");
|
||||
dukglue_register_property(ctx, &ScVehicle::subposition_get, nullptr, "subposition");
|
||||
dukglue_register_property(
|
||||
ctx, &ScVehicle::poweredAcceleration_get, &ScVehicle::poweredAcceleration_set, "poweredAcceleration");
|
||||
dukglue_register_property(ctx, &ScVehicle::poweredMaxSpeed_get, &ScVehicle::poweredMaxSpeed_set, "poweredMaxSpeed");
|
||||
|
@ -386,6 +387,12 @@ namespace OpenRCT2::Scripting
|
|||
return vehicle != nullptr ? vehicle->remaining_distance : 0;
|
||||
}
|
||||
|
||||
uint8_t ScVehicle::subposition_get() const
|
||||
{
|
||||
auto vehicle = GetVehicle();
|
||||
return vehicle != nullptr ? static_cast<uint8_t>(vehicle->TrackSubposition) : 0;
|
||||
}
|
||||
|
||||
uint8_t ScVehicle::poweredAcceleration_get() const
|
||||
{
|
||||
auto vehicle = GetVehicle();
|
||||
|
|
|
@ -77,6 +77,8 @@ namespace OpenRCT2::Scripting
|
|||
|
||||
int32_t remainingDistance_get() const;
|
||||
|
||||
uint8_t subposition_get() const;
|
||||
|
||||
uint8_t poweredAcceleration_get() const;
|
||||
void poweredAcceleration_set(uint8_t value);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
# include "../../../Context.h"
|
||||
# include "../../../ride/TrackData.h"
|
||||
# include "../../../ride/Vehicle.h"
|
||||
# include "../../ScriptEngine.h"
|
||||
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
@ -35,6 +36,8 @@ void ScTrackSegment::Register(duk_context* ctx)
|
|||
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");
|
||||
dukglue_register_method(ctx, &ScTrackSegment::getSubpositionLength, "getSubpositionLength");
|
||||
dukglue_register_method(ctx, &ScTrackSegment::getSubpositions, "getSubpositions");
|
||||
}
|
||||
|
||||
int32_t ScTrackSegment::type_get() const
|
||||
|
@ -141,4 +144,25 @@ DukValue ScTrackSegment::elements_get() const
|
|||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
uint16_t ScTrackSegment::getSubpositionLength(uint8_t trackSubposition, uint8_t direction) const
|
||||
{
|
||||
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
|
||||
|
|
|
@ -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("yaw", value.direction);
|
||||
dukSubposition.Set("pitch", value.Pitch);
|
||||
dukSubposition.Set("roll", value.bank_rotation);
|
||||
return dukSubposition.Take();
|
||||
}
|
||||
|
||||
class ScTrackSegment
|
||||
{
|
||||
private:
|
||||
|
@ -44,6 +56,8 @@ namespace OpenRCT2::Scripting
|
|||
int32_t endBank_get() const;
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue