1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-14 19:42:38 +01:00

Merge pull request #6269 from Gymnasiast/small-cleanup

Slightly refactor loading of vehicle entries
This commit is contained in:
Michael Steenbeek
2017-09-14 15:17:04 +02:00
committed by GitHub
3 changed files with 83 additions and 50 deletions

View File

@@ -136,57 +136,16 @@ void RideObject::Load()
_legacyType.vehicle_preset_list = &_presetColours;
sint32 cur_vehicle_images_offset = _legacyType.images_offset + 3;
for (sint32 i = 0; i < 4; i++)
for (sint32 i = 0; i < RCT2_MAX_VEHICLES_PER_RIDE_ENTRY; i++)
{
rct_ride_entry_vehicle * vehicleEntry = &_legacyType.vehicles[i];
if (vehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_FLAT)
{
sint32 al = 1;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SWINGING)
{
al = 13;
if ((vehicleEntry->flags & (VEHICLE_ENTRY_FLAG_21 | VEHICLE_ENTRY_FLAG_27)) != (VEHICLE_ENTRY_FLAG_21 | VEHICLE_ENTRY_FLAG_27))
{
al = 7;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_21))
{
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_27))
{
al = 5;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_25)
{
al = 3;
}
}
}
}
}
vehicleEntry->var_03 = al;
// 0x6DE90B
al = 0x20;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_14))
{
al = 1;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_23)
{
if (vehicleEntry->var_11 != 6)
{
al = 2;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_7))
{
al = 4;
}
}
}
}
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_12)
{
al = vehicleEntry->special_frames;
}
vehicleEntry->var_02 = al;
// RCT2 calculates var_02 and var_03 and overwrites these properties on the vehicle entry.
// Immediately afterwards, the two were multiplied in order to calculate var_16 and were never used again.
// This has been changed to use the calculation results directly - var_02 and var_03 are no longer set.
// 0x6DE946
vehicleEntry->var_16 = vehicleEntry->var_02 * vehicleEntry->var_03;
vehicleEntry->var_16 = CalculateVar02(vehicleEntry) * CalculateVar03(vehicleEntry);
vehicleEntry->base_image_id = cur_vehicle_images_offset;
sint32 image_index = vehicleEntry->base_image_id;
@@ -504,3 +463,74 @@ void RideObject::PerformFixes()
_legacyType.enabledTrackPieces &= ~(1ULL << TRACK_SLOPE_STEEP);
}
}
uint8 RideObject::CalculateVar02(const rct_ride_entry_vehicle * vehicleEntry)
{
// 0x6DE90B
uint8 newVar02;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_HAS_SPECIAL_FRAMES)
{
newVar02 = vehicleEntry->special_frames;
}
else
{
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_14))
{
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_23 && vehicleEntry->var_11 != 6)
{
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_7))
{
newVar02 = 4;
}
else
{
newVar02 = 2;
}
}
else
{
newVar02 = 1;
}
}
else
{
newVar02 = 32;
}
}
return newVar02;
}
uint8 RideObject::CalculateVar03(const rct_ride_entry_vehicle * vehicleEntry)
{
uint8 newVar03;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SWINGING)
{
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_21) && !(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_27))
{
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_25)
{
newVar03 = 3;
}
else
{
newVar03 = 5;
}
}
else if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_21) || !(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_27))
{
newVar03 = 7;
}
else
{
newVar03 = 13;
}
}
else
{
newVar03 = 1;
}
return newVar03;
}

View File

@@ -51,4 +51,7 @@ public:
private:
void ReadLegacyVehicle(IReadObjectContext * context, IStream * stream, rct_ride_entry_vehicle * vehicle);
void PerformFixes();
static uint8 CalculateVar02(const rct_ride_entry_vehicle * vehicleEntry);
static uint8 CalculateVar03(const rct_ride_entry_vehicle * vehicleEntry);
};

View File

@@ -34,8 +34,8 @@ assert_struct_size(rct_vehicle_colour, 2);
*/
typedef struct rct_ride_entry_vehicle {
uint16 rotation_frame_mask; // 0x00 , 0x1A
uint8 var_02; // 0x02 , 0x1C
uint8 var_03; // 0x03 , 0x1D
uint8 var_02; // 0x02 , 0x1C, Appears to be unused, except as a temporary variable in RCT2 (not needed for OpenRCT2)
uint8 var_03; // 0x03 , 0x1D, Appears to be unused, except as a temporary variable in RCT2 (not needed for OpenRCT2)
uint32 spacing; // 0x04 , 0x1E
uint16 car_friction; // 0x08 , 0x22
sint8 tab_height; // 0x0A , 0x24
@@ -74,7 +74,7 @@ typedef struct rct_ride_entry_vehicle {
uint8 car_visual; // 0x5D , 0x77
uint8 effect_visual;
uint8 draw_order;
uint8 special_frames; // 0x60 , 0x7A
uint8 special_frames; // 0x60 , 0x7A, A custom number that can be used rather than letting RCT2 determine it. Needs the VEHICLE_ENTRY_FLAG_HAS_SPECIAL_FRAMES flag to be set.
sint8* peep_loading_positions; // 0x61 , 0x7B
#ifdef NO_RCT2
uint16 peep_loading_positions_count;
@@ -232,7 +232,7 @@ enum {
VEHICLE_ENTRY_FLAG_ENABLE_ADDITIONAL_COLOUR_2 = 1 << 9,
VEHICLE_ENTRY_FLAG_10 = 1 << 10,
VEHICLE_ENTRY_FLAG_11 = 1 << 11,
VEHICLE_ENTRY_FLAG_12 = 1 << 12,
VEHICLE_ENTRY_FLAG_HAS_SPECIAL_FRAMES = 1 << 12, // Setting this will cause the game to set vehicleEntry->var_02 to vehicleEntry->special_frames, rather than determining it itself.
VEHICLE_ENTRY_FLAG_13 = 1 << 13,
VEHICLE_ENTRY_FLAG_14 = 1 << 14,
VEHICLE_ENTRY_FLAG_15 = 1 << 15,