mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-17 03:53:07 +01:00
Merge pull request #17821 from Basssiiie/plugin-tracksegment-subposition-length
[Plugin] Implement plugin getters for track and vehicle subpositions
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user