From 8b4b1c6561b407359dc3198dfc09ee2737bc27d2 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 9 Aug 2026 15:46:06 +0200 Subject: [PATCH] Refactor VEHICLE_VEHICLE_* to two enum classes --- src/openrct2-ui/windows/RideConstruction.cpp | 3 +- src/openrct2/object/RideObject.cpp | 18 ++++---- src/openrct2/paint/entity/Paint.Vehicle.cpp | 28 ++++++------ .../vehicle/Vehicle.LaunchedFreefall.cpp | 2 +- .../vehicle/Vehicle.ObservationTower.cpp | 2 +- .../paint/vehicle/Vehicle.RotoDrop.cpp | 2 +- .../paint/vehicle/Vehicle.Submarine.cpp | 2 +- .../paint/vehicle/Vehicle.VirginiaReel.cpp | 2 +- src/openrct2/paint/vehicle/VehiclePaint.cpp | 14 +++--- src/openrct2/ride/CarEntry.h | 8 ++-- src/openrct2/ride/RideData.cpp | 4 +- src/openrct2/ride/Vehicle.h | 43 +++++++++++-------- .../scripting/bindings/object/ScObject.hpp | 4 +- 13 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 58920efef6..8a6bb582c9 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2797,7 +2797,8 @@ namespace OpenRCT2::Ui::Windows // Non-default vehicle visuals do not use this system, so we have to assume it supports all the track pieces. auto& firstCar = currentRideEntry->Cars[0]; - if ((firstCar.PaintStyle != VEHICLE_VISUAL_DEFAULT && firstCar.PaintStyle != VEHICLE_VISUAL_SPINNING_CARS) + if ((firstCar.paintStyle != VehiclePaintStyle::standard + && firstCar.paintStyle != VehiclePaintStyle::spinningCars) || firstCar.flags.hasAny(CarEntryFlag::isChairlift, CarEntryFlag::useSlideSwing)) { disabledGroups.reset(); diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 4332f55c89..bf8bbd2f8c 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -446,11 +446,11 @@ namespace OpenRCT2 car.double_sound_frequency = stream->ReadValue(); car.powered_acceleration = stream->ReadValue(); car.powered_max_speed = stream->ReadValue(); - car.PaintStyle = stream->ReadValue(); + car.paintStyle = stream->ReadValue(); // Since this animation style may be replaced with a generic spinner system, make sure it gets limited to just our port. - if (car.PaintStyle == VEHICLE_VISUAL_SPINNING_CARS) - car.PaintStyle = VEHICLE_VISUAL_DEFAULT; - car.effect_visual = stream->ReadValue(); + if (car.paintStyle == VehiclePaintStyle::spinningCars) + car.paintStyle = VehiclePaintStyle::standard; + car.effectVisual = stream->ReadValue(); car.draw_order = stream->ReadValue(); car.num_vertical_frames_override = stream->ReadValue(); stream->Seek(4, STREAM_SEEK_CURRENT); @@ -596,7 +596,7 @@ namespace OpenRCT2 car.spriteHeightNegative = 1; car.spriteHeightPositive = 1; car.flags = { CarEntryFlag::hasSpinning }; - car.PaintStyle = VEHICLE_VISUAL_FLAT_RIDE_OR_CAR_RIDE; + car.paintStyle = VehiclePaintStyle::flatRideOrCarRide; car.friction_sound_id = Audio::SoundId::null; car.soundRange = SoundRange::none; car.draw_order = 6; @@ -765,15 +765,15 @@ namespace OpenRCT2 car.double_sound_frequency = Json::GetNumber(jCar["doubleSoundFrequency"]); car.powered_acceleration = Json::GetNumber(jCar["poweredAcceleration"]); car.powered_max_speed = Json::GetNumber(jCar["poweredMaxSpeed"]); - car.PaintStyle = Json::GetNumber(jCar["carVisual"]); + car.paintStyle = Json::GetEnum(jCar["carVisual"], VehiclePaintStyle::standard); // Since this animation style may be replaced with a generic spinner system, make sure it gets limited to just our port. - if (car.PaintStyle == VEHICLE_VISUAL_SPINNING_CARS + if (car.paintStyle == VehiclePaintStyle::spinningCars && (GetIdentifier() != "rct1.ride.spinning_cars" || _legacyType.ride_type[0] != RIDE_TYPE_CLASSIC_MINI_ROLLER_COASTER)) { - car.PaintStyle = VEHICLE_VISUAL_DEFAULT; + car.paintStyle = VehiclePaintStyle::standard; } - car.effect_visual = Json::GetNumber(jCar["effectVisual"], 1); + car.effectVisual = Json::GetEnum(jCar["effectVisual"], EffectVisual::unknown1); car.draw_order = Json::GetNumber(jCar["drawOrder"]); car.num_vertical_frames_override = Json::GetNumber(jCar["numVerticalFramesOverride"]); diff --git a/src/openrct2/paint/entity/Paint.Vehicle.cpp b/src/openrct2/paint/entity/Paint.Vehicle.cpp index d6975c6e87..9775ec168c 100644 --- a/src/openrct2/paint/entity/Paint.Vehicle.cpp +++ b/src/openrct2/paint/entity/Paint.Vehicle.cpp @@ -55,47 +55,49 @@ void PaintVehicle(PaintSession& session, const Vehicle& vehicle, int32_t imageDi carEntry = &rideEntry->Cars[carEntryIndex]; } - switch (carEntry->PaintStyle) + switch (carEntry->paintStyle) { - case VEHICLE_VISUAL_DEFAULT: + case VehiclePaintStyle::standard: VehicleVisualDefault(session, imageDirection, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_LAUNCHED_FREEFALL: + case VehiclePaintStyle::launchedFreefall: VehicleVisualLaunchedFreefall( session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_OBSERVATION_TOWER: + case VehiclePaintStyle::observationTower: VehicleVisualObservationTower( session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_RIVER_RAPIDS: + case VehiclePaintStyle::riverRapids: VehicleVisualRiverRapids(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_MINI_GOLF_PLAYER: + case VehiclePaintStyle::miniGolfPlayer: VehicleVisualMiniGolfPlayer(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle); break; - case VEHICLE_VISUAL_MINI_GOLF_BALL: + case VehiclePaintStyle::miniGolfBall: VehicleVisualMiniGolfBall(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle); break; - case VEHICLE_VISUAL_REVERSER: + case VehiclePaintStyle::reverser: VehicleVisualReverser(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_SPLASH_BOATS_OR_WATER_COASTER: + case VehiclePaintStyle::splashBoatsOrWaterCoaster: VehicleVisualSplashBoatsOrWaterCoaster( session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_ROTO_DROP: + case VehiclePaintStyle::rotoDrop: VehicleVisualRotoDrop(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_VIRGINIA_REEL: + case VehiclePaintStyle::virginiaReel: VehicleVisualVirginiaReel(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_SUBMARINE: + case VehiclePaintStyle::submarine: VehicleVisualSubmarine(session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; - case VEHICLE_VISUAL_SPINNING_CARS: + case VehiclePaintStyle::spinningCars: VehicleVisualClassicMiniSpinning( session, vehicle.x, imageDirection, vehicle.y, vehicle.z + zOffset, &vehicle, carEntry); break; + default: + break; } } diff --git a/src/openrct2/paint/vehicle/Vehicle.LaunchedFreefall.cpp b/src/openrct2/paint/vehicle/Vehicle.LaunchedFreefall.cpp index e08e068400..a1262dfcb5 100644 --- a/src/openrct2/paint/vehicle/Vehicle.LaunchedFreefall.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.LaunchedFreefall.cpp @@ -76,6 +76,6 @@ namespace OpenRCT2 } } - assert(carEntry->effect_visual == 1); + assert(carEntry->effectVisual == EffectVisual::unknown1); } } // namespace OpenRCT2 diff --git a/src/openrct2/paint/vehicle/Vehicle.ObservationTower.cpp b/src/openrct2/paint/vehicle/Vehicle.ObservationTower.cpp index 26d315d078..e9a0011025 100644 --- a/src/openrct2/paint/vehicle/Vehicle.ObservationTower.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.ObservationTower.cpp @@ -68,6 +68,6 @@ namespace OpenRCT2 PaintAddImageAsParent(session, imageId0, { 0, 0, z }, { { -11, -11, z + 1 }, { 2, 2, 41 } }); PaintAddImageAsParent(session, imageId1, { 0, 0, z }, { { -5, -5, z + 1 }, { 16, 16, 41 } }); - assert(carEntry->effect_visual == 1); + assert(carEntry->effectVisual == EffectVisual::unknown1); } } // namespace OpenRCT2 diff --git a/src/openrct2/paint/vehicle/Vehicle.RotoDrop.cpp b/src/openrct2/paint/vehicle/Vehicle.RotoDrop.cpp index 2f40f8543c..4aca6b0282 100644 --- a/src/openrct2/paint/vehicle/Vehicle.RotoDrop.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.RotoDrop.cpp @@ -81,7 +81,7 @@ namespace OpenRCT2 } } - assert(carEntry->effect_visual == 1); + assert(carEntry->effectVisual == EffectVisual::unknown1); // Although called in original code, effect_visual (splash effects) are not used for many rides and does not make sense // so it was taken out } diff --git a/src/openrct2/paint/vehicle/Vehicle.Submarine.cpp b/src/openrct2/paint/vehicle/Vehicle.Submarine.cpp index df8d5817a5..115b6d0f62 100644 --- a/src/openrct2/paint/vehicle/Vehicle.Submarine.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.Submarine.cpp @@ -62,6 +62,6 @@ namespace OpenRCT2 PaintAddImageAsParent( session, imageId1, { 0, 0, z }, { { bb.offset_x, bb.offset_y, bb.offset_z + z - 10 }, { bb.length_x, bb.length_y, 2 } }); - assert(carEntry->effect_visual == 1); + assert(carEntry->effectVisual == EffectVisual::unknown1); } } // namespace OpenRCT2 diff --git a/src/openrct2/paint/vehicle/Vehicle.VirginiaReel.cpp b/src/openrct2/paint/vehicle/Vehicle.VirginiaReel.cpp index 3b590253d6..60f2789c79 100644 --- a/src/openrct2/paint/vehicle/Vehicle.VirginiaReel.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.VirginiaReel.cpp @@ -83,6 +83,6 @@ namespace OpenRCT2 } } - assert(carEntry->effect_visual == 1); + assert(carEntry->effectVisual == EffectVisual::unknown1); } } // namespace OpenRCT2 diff --git a/src/openrct2/paint/vehicle/VehiclePaint.cpp b/src/openrct2/paint/vehicle/VehiclePaint.cpp index ab03b23d87..42d6ae4f6a 100644 --- a/src/openrct2/paint/vehicle/VehiclePaint.cpp +++ b/src/openrct2/paint/vehicle/VehiclePaint.cpp @@ -4660,23 +4660,25 @@ static void vehicle_visual_splash5_effect(PaintSession& session, const int32_t z void VehicleVisualSplashEffect(PaintSession& session, const int32_t z, const Vehicle* vehicle, const CarEntry* carEntry) { - switch (carEntry->effect_visual) + switch (carEntry->effectVisual) { - case VEHICLE_VISUAL_SPLASH1_EFFECT: + case EffectVisual::splash1Effect: vehicle_visual_splash1_effect(session, z, vehicle); break; - case VEHICLE_VISUAL_SPLASH2_EFFECT: + case EffectVisual::splash2Effect: vehicle_visual_splash2_effect(session, z, vehicle); break; - case VEHICLE_VISUAL_SPLASH3_EFFECT: + case EffectVisual::splash3Effect: vehicle_visual_splash3_effect(session, z, vehicle); break; - case VEHICLE_VISUAL_SPLASH4_EFFECT: + case EffectVisual::splash4Effect: vehicle_visual_splash4_effect(session, z, vehicle); break; - case VEHICLE_VISUAL_SPLASH5_EFFECT: + case EffectVisual::splash5Effect: vehicle_visual_splash5_effect(session, z, vehicle); break; + default: + break; } } diff --git a/src/openrct2/ride/CarEntry.h b/src/openrct2/ride/CarEntry.h index 57c8f72eae..12c702306a 100644 --- a/src/openrct2/ride/CarEntry.h +++ b/src/openrct2/ride/CarEntry.h @@ -25,8 +25,10 @@ namespace OpenRCT2::Audio namespace OpenRCT2 { + enum class EffectVisual : uint8_t; enum class SoundRange : uint8_t; -} + enum class VehiclePaintStyle : uint8_t; +} // namespace OpenRCT2 enum class CarEntryAnimation : uint8_t { @@ -219,8 +221,8 @@ struct CarEntry uint8_t double_sound_frequency; // (Doubles the velocity when working out the sound frequency {used on go karts}) uint8_t powered_acceleration; uint8_t powered_max_speed; - uint8_t PaintStyle; - uint8_t effect_visual; + OpenRCT2::VehiclePaintStyle paintStyle; + OpenRCT2::EffectVisual effectVisual; uint8_t draw_order; uint8_t num_vertical_frames_override; // A custom number that can be used rather than letting RCT2 determine it. // Needs the overrideNumberOfVerticalFrames CarEntryFlag to be set. diff --git a/src/openrct2/ride/RideData.cpp b/src/openrct2/ride/RideData.cpp index a5e410cbd4..415b95cc14 100644 --- a/src/openrct2/ride/RideData.cpp +++ b/src/openrct2/ride/RideData.cpp @@ -191,8 +191,8 @@ namespace OpenRCT2 .double_sound_frequency = 0, .powered_acceleration = 0, .powered_max_speed = 0, - .PaintStyle = 0, - .effect_visual = 1, + .paintStyle = VehiclePaintStyle::standard, + .effectVisual = EffectVisual::unknown1, .draw_order = 14, .num_vertical_frames_override = 0, .peep_loading_waypoint_segments = 0, diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index f8e5672eca..6024602ca0 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -457,26 +457,31 @@ namespace OpenRCT2 enteringReturnPosition, }; - enum + enum class VehiclePaintStyle : uint8_t { - VEHICLE_VISUAL_DEFAULT, - VEHICLE_VISUAL_FLAT_RIDE_OR_CAR_RIDE, - VEHICLE_VISUAL_LAUNCHED_FREEFALL, - VEHICLE_VISUAL_OBSERVATION_TOWER, - VEHICLE_VISUAL_RIVER_RAPIDS, - VEHICLE_VISUAL_MINI_GOLF_PLAYER, - VEHICLE_VISUAL_MINI_GOLF_BALL, - VEHICLE_VISUAL_REVERSER, - VEHICLE_VISUAL_SPLASH_BOATS_OR_WATER_COASTER, - VEHICLE_VISUAL_ROTO_DROP, - VEHICLE_VISUAL_SPLASH1_EFFECT, - VEHICLE_VISUAL_SPLASH2_EFFECT, - VEHICLE_VISUAL_SPLASH3_EFFECT, - VEHICLE_VISUAL_SPLASH4_EFFECT, - VEHICLE_VISUAL_SPLASH5_EFFECT, - VEHICLE_VISUAL_VIRGINIA_REEL, - VEHICLE_VISUAL_SUBMARINE, - VEHICLE_VISUAL_SPINNING_CARS, + standard, + flatRideOrCarRide, + launchedFreefall, + observationTower, + riverRapids, + miniGolfPlayer, + miniGolfBall, + reverser, + splashBoatsOrWaterCoaster, + rotoDrop, + virginiaReel = 15, + submarine, + spinningCars, + }; + + enum class EffectVisual : uint8_t + { + unknown1 = 1, + splash1Effect = 10, + splash2Effect, + splash3Effect, + splash4Effect, + splash5Effect, }; enum : uint32_t diff --git a/src/openrct2/scripting/bindings/object/ScObject.hpp b/src/openrct2/scripting/bindings/object/ScObject.hpp index 753a69c5d5..d058628e47 100644 --- a/src/openrct2/scripting/bindings/object/ScObject.hpp +++ b/src/openrct2/scripting/bindings/object/ScObject.hpp @@ -387,13 +387,13 @@ namespace OpenRCT2::Scripting static JSValue carVisual_get(JSContext* ctx, JSValue thisVal) { auto carEntry = GetEntry(thisVal); - return JS_NewUint32(ctx, carEntry != nullptr ? carEntry->PaintStyle : 0); + return JS_NewUint32(ctx, carEntry != nullptr ? EnumValue(carEntry->paintStyle) : 0); } static JSValue effectVisual_get(JSContext* ctx, JSValue thisVal) { auto carEntry = GetEntry(thisVal); - return JS_NewUint32(ctx, carEntry != nullptr ? carEntry->effect_visual : 0); + return JS_NewUint32(ctx, carEntry != nullptr ? EnumValue(carEntry->effectVisual) : 0); } static JSValue drawOrder_get(JSContext* ctx, JSValue thisVal)