From 6616ce0a6769e7253e0d64d10935506804175541 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 24 Mar 2018 17:47:42 +0000 Subject: [PATCH] Load new peep loading position json format --- src/openrct2/object/RideObject.cpp | 84 +++++++++++++++++++++--------- src/openrct2/peep/Peep.cpp | 6 +-- src/openrct2/ride/RideData.cpp | 2 +- src/openrct2/ride/Vehicle.h | 6 ++- 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 8406de40df..2e1da1b3ae 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -285,8 +285,11 @@ void RideObject::Load() set_vehicle_type_image_max_sizes(vehicleEntry, num_images); } } - vehicleEntry->peep_loading_positions = _peepLoadingPositions[i].data(); - vehicleEntry->peep_loading_positions_count = (uint16)_peepLoadingPositions[i].size(); + + if (!_peepLoadingPositions[i].empty()) + { + vehicleEntry->peep_loading_positions = std::move(_peepLoadingPositions[i]); + } } } } @@ -620,27 +623,6 @@ void RideObject::ReadJson(IReadObjectContext * context, const json_t * root) auto availableTrackPieces = ObjectJsonHelpers::GetJsonStringArray(json_object_get(properties, "availableTrackPieces")); _presetColours = ReadJsonCarColours(json_object_get(properties, "carColours")); - - - // Get loading positions - auto loadingPositions = json_object_get(properties, "loadingPositions"); - auto numLoadingPositions = std::min(json_array_size(loadingPositions), 4); - for (size_t i = 0; i < numLoadingPositions; i++) - { - auto positions = json_array_get(loadingPositions, i); - auto numPositions = json_array_size(positions); - if (numPositions > 0 && numPositions <= std::numeric_limits::max()) - { - std::vector positionData; - for (size_t j = 0; j < numPositions; j++) - { - auto pos = json_integer_value(json_array_get(positions, j)); - pos = Math::Clamp(std::numeric_limits::min(), pos, std::numeric_limits::max()); - positionData.push_back(pos); - } - _peepLoadingPositions[i] = std::move(positionData); - } - } } _legacyType.flags |= ObjectJsonHelpers::GetFlags(properties, { @@ -770,6 +752,61 @@ rct_ride_entry_vehicle RideObject::ReadJsonCar(const json_t * jCar) car.draw_order = ObjectJsonHelpers::GetInteger(jCar, "drawOrder"); car.num_vertical_frames_override = ObjectJsonHelpers::GetInteger(jCar, "numVerticalFramesOverride"); + auto& peepLoadingPositions = car.peep_loading_positions; + auto jLoadingPositions = json_object_get(jCar, "loadingPositions"); + if (json_is_array(jLoadingPositions)) + { + auto arr = ObjectJsonHelpers::GetJsonIntegerArray(jLoadingPositions); + for (auto x : arr) + { + peepLoadingPositions.push_back(x); + } + } + else + { + auto jLoadingWaypoints = json_object_get(jCar, "loadingWaypoints"); + if (json_is_array(jLoadingWaypoints)) + { + auto numSegments = ObjectJsonHelpers::GetInteger(jCar, "numSegments"); + if (numSegments == 8) + { + car.flags |= VEHICLE_ENTRY_FLAG_26; + peepLoadingPositions.push_back(0); + } + else if (numSegments == 4) + { + peepLoadingPositions.push_back(1); + } + else + { + peepLoadingPositions.push_back(0); + } + + size_t i; + json_t * route; + json_array_foreach(jLoadingWaypoints, i, route) + { + if (json_is_array(route)) + { + size_t j; + json_t * waypoint; + json_array_foreach(route, j, waypoint) + { + if (json_is_array(waypoint) && json_array_size(waypoint) >= 2) + { + auto x = json_integer_value(json_array_get(waypoint, 0)); + auto y = json_integer_value(json_array_get(waypoint, 1)); + peepLoadingPositions.push_back(x); + peepLoadingPositions.push_back(y); + } + } + peepLoadingPositions.push_back(0); + peepLoadingPositions.push_back(0); + } + } + } + } + auto jFrames = json_object_get(jCar, "frames"); car.sprite_flags = ObjectJsonHelpers::GetFlags(jFrames, { { "flat", VEHICLE_SPRITE_FLAG_FLAT }, @@ -816,7 +853,6 @@ rct_ride_entry_vehicle RideObject::ReadJsonCar(const json_t * jCar) { "VEHICLE_ENTRY_FLAG_VEHICLE_ANIMATION", VEHICLE_ENTRY_FLAG_VEHICLE_ANIMATION }, { "VEHICLE_ENTRY_FLAG_RIDER_ANIMATION", VEHICLE_ENTRY_FLAG_RIDER_ANIMATION }, { "VEHICLE_ENTRY_FLAG_25", VEHICLE_ENTRY_FLAG_25 }, - { "VEHICLE_ENTRY_FLAG_26", VEHICLE_ENTRY_FLAG_26 }, { "VEHICLE_ENTRY_FLAG_SLIDE_SWING", VEHICLE_ENTRY_FLAG_SLIDE_SWING }, { "VEHICLE_ENTRY_FLAG_CHAIRLIFT", VEHICLE_ENTRY_FLAG_CHAIRLIFT }, { "VEHICLE_ENTRY_FLAG_WATER_RIDE", VEHICLE_ENTRY_FLAG_WATER_RIDE }, diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 505dee189f..6a207abfe9 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -3021,7 +3021,7 @@ static void peep_update_ride_sub_state_1(rct_peep * peep) if (ride->type != RIDE_TYPE_ENTERPRISE) direction_track *= 2; - if (*vehicle_type->peep_loading_positions == 0) + if (vehicle_type->peep_loading_positions[0] == 0) { direction_track /= 2; cl = 0; @@ -3063,7 +3063,7 @@ static void peep_update_ride_sub_state_1(rct_peep * peep) sint8 load_position = 0; // Safe, in case current seat > number of loading positions - uint16 numSeatPositions = vehicle_type->peep_loading_positions_count; + auto numSeatPositions = vehicle_type->peep_loading_positions.size(); if (numSeatPositions != 0) { size_t loadPositionIndex = numSeatPositions - 1; @@ -3563,7 +3563,7 @@ static void peep_update_ride_sub_state_7(rct_peep * peep) if (ride->type != RIDE_TYPE_ENTERPRISE) station_direction *= 2; - if (*vehicle_type->peep_loading_positions == 0) + if (vehicle_type->peep_loading_positions[0] == 0) { station_direction /= 2; cl = 0; diff --git a/src/openrct2/ride/RideData.cpp b/src/openrct2/ride/RideData.cpp index df604d8573..ae67d56a62 100644 --- a/src/openrct2/ride/RideData.cpp +++ b/src/openrct2/ride/RideData.cpp @@ -1629,7 +1629,7 @@ const rct_ride_entry_vehicle CableLiftVehicle = { /* .effect_visual = */ 1, /* .draw_order = */ 14, /* .num_vertical_frames_override = */ 0, - /* .peep_loading_positions = */ nullptr + /* .peep_loading_positions = */ }; /* rct2: 0x009A0AA0 */ diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 828c173376..9301a48d03 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -17,6 +17,7 @@ #ifndef _VEHICLE_H_ #define _VEHICLE_H_ +#include #include "../common.h" #include "../world/Location.hpp" @@ -76,8 +77,9 @@ struct rct_ride_entry_vehicle { uint8 effect_visual; uint8 draw_order; uint8 num_vertical_frames_override; // 0x60 , 0x7A, A custom number that can be used rather than letting RCT2 determine it. Needs the VEHICLE_ENTRY_FLAG_OVERRIDE_NUM_VERTICAL_FRAMES flag to be set. - sint8* peep_loading_positions; // 0x61 , 0x7B - uint16 peep_loading_positions_count; + uint8 pad_61[7]; // 0x61 , 0x7B + + std::vector peep_loading_positions; }; #pragma pack(pop)