1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 15:24:30 +01:00

Load new peep loading position json format

This commit is contained in:
Ted John
2018-03-24 17:47:42 +00:00
committed by Gymnasiast
parent 04fecf64e4
commit 6616ce0a67
4 changed files with 68 additions and 30 deletions

View File

@@ -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<size_t>(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<uint16>::max())
{
std::vector<sint8> positionData;
for (size_t j = 0; j < numPositions; j++)
{
auto pos = json_integer_value(json_array_get(positions, j));
pos = Math::Clamp<sint64>(std::numeric_limits<sint8>::min(), pos, std::numeric_limits<sint8>::max());
positionData.push_back(pos);
}
_peepLoadingPositions[i] = std::move(positionData);
}
}
}
_legacyType.flags |= ObjectJsonHelpers::GetFlags<uint32>(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<uint16>(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 },

View File

@@ -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;

View File

@@ -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 */

View File

@@ -17,6 +17,7 @@
#ifndef _VEHICLE_H_
#define _VEHICLE_H_
#include <vector>
#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<sint8> peep_loading_positions;
};
#pragma pack(pop)