From 79217409382e4bf295842bce2cee2706f3c851fc Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 8 Jul 2020 09:44:21 -0300 Subject: [PATCH 1/4] Use CoordsXYZ on vehicle_create_car --- src/openrct2/ride/Ride.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 95b88ecbb1..82b7c04ba6 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4322,7 +4322,7 @@ static constexpr const CoordsXY word_9A2A60[] = { * rct2: 0x006DD90D */ static Vehicle* vehicle_create_car( - ride_id_t rideIndex, int32_t vehicleEntryIndex, int32_t carIndex, int32_t vehicleIndex, int32_t x, int32_t y, int32_t z, + ride_id_t rideIndex, int32_t vehicleEntryIndex, int32_t carIndex, int32_t vehicleIndex, const CoordsXYZ& carPosition, int32_t* remainingDistance, TileElement* tileElement) { auto ride = get_ride(rideIndex); @@ -4392,13 +4392,11 @@ static Vehicle* vehicle_create_car( // loc_6DDCA4: vehicle->TrackSubposition = VEHICLE_TRACK_SUBPOSITION_0; int32_t direction = tileElement->GetDirection(); - x += word_9A3AB4[direction].x; - y += word_9A3AB4[direction].y; - z = tileElement->GetBaseZ(); - vehicle->TrackLocation = { x, y, z }; + auto dodgemPos = CoordsXYZ{ CoordsXY{ carPosition } + word_9A3AB4[direction], tileElement->GetBaseZ() }; + vehicle->TrackLocation = dodgemPos; vehicle->current_station = tileElement->AsTrack()->GetStationIndex(); - z += RideTypeDescriptors[ride->type].Heights.VehicleZOffset; + dodgemPos.z += RideTypeDescriptors[ride->type].Heights.VehicleZOffset; vehicle->track_type = tileElement->AsTrack()->GetTrackType() << 2; vehicle->track_progress = 0; @@ -4410,11 +4408,11 @@ static Vehicle* vehicle_create_car( do { vehicle->sprite_direction = scenario_rand() & 0x1E; - chosenLoc.y = y + (scenario_rand() & 0xFF); - chosenLoc.x = x + (scenario_rand() & 0xFF); + chosenLoc.y = dodgemPos.y + (scenario_rand() & 0xFF); + chosenLoc.x = dodgemPos.x + (scenario_rand() & 0xFF); } while (vehicle->DodgemsCarWouldCollideAt(chosenLoc, nullptr)); - vehicle->MoveTo({ chosenLoc.x, chosenLoc.y, z }); + vehicle->MoveTo({ chosenLoc, dodgemPos.z }); } else { @@ -4452,7 +4450,9 @@ static Vehicle* vehicle_create_car( subposition = VEHICLE_TRACK_SUBPOSITION_REVERSER_RC_REAR_BOGIE; } vehicle->TrackSubposition = subposition; - vehicle->TrackLocation = { x, y, tileElement->GetBaseZ() }; + + auto chosenLoc = CoordsXYZ{ CoordsXY{ carPosition }, tileElement->GetBaseZ() }; + vehicle->TrackLocation = chosenLoc; int32_t direction = tileElement->GetDirection(); vehicle->sprite_direction = direction << 3; @@ -4482,14 +4482,11 @@ static Vehicle* vehicle_create_car( } } - x += word_9A2A60[direction].x; - y += word_9A2A60[direction].y; + chosenLoc += CoordsXYZ{ word_9A2A60[direction], RideTypeDescriptors[ride->type].Heights.VehicleZOffset }; vehicle->current_station = tileElement->AsTrack()->GetStationIndex(); - z = tileElement->GetBaseZ(); - z += RideTypeDescriptors[ride->type].Heights.VehicleZOffset; - vehicle->MoveTo({ x, y, z }); + vehicle->MoveTo(chosenLoc); vehicle->track_type = (tileElement->AsTrack()->GetTrackType() << 2) | (vehicle->sprite_direction >> 3); vehicle->track_progress = 31; if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_MINI_GOLF) @@ -4529,7 +4526,8 @@ static train_ref vehicle_create_train( for (int32_t carIndex = 0; carIndex < ride->num_cars_per_train; carIndex++) { auto vehicle = ride_entry_get_vehicle_at_position(ride->subtype, ride->num_cars_per_train, carIndex); - auto car = vehicle_create_car(rideIndex, vehicle, carIndex, vehicleIndex, x, y, z, remainingDistance, tileElement); + auto car = vehicle_create_car( + rideIndex, vehicle, carIndex, vehicleIndex, { x, y, z }, remainingDistance, tileElement); if (car == nullptr) break; From 47db30f1d703ee90ba38cae1bfe070b4cae490e4 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 8 Jul 2020 09:50:47 -0300 Subject: [PATCH 2/4] Use CoordsXYZ on vehicle_create_train --- src/openrct2/ride/Ride.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 82b7c04ba6..524f3b878d 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4516,8 +4516,7 @@ static Vehicle* vehicle_create_car( * rct2: 0x006DD84C */ static train_ref vehicle_create_train( - ride_id_t rideIndex, int32_t x, int32_t y, int32_t z, int32_t vehicleIndex, int32_t* remainingDistance, - TileElement* tileElement) + ride_id_t rideIndex, const CoordsXYZ& trainPos, int32_t vehicleIndex, int32_t* remainingDistance, TileElement* tileElement) { train_ref train = { nullptr, nullptr }; auto ride = get_ride(rideIndex); @@ -4526,8 +4525,7 @@ static train_ref vehicle_create_train( for (int32_t carIndex = 0; carIndex < ride->num_cars_per_train; carIndex++) { auto vehicle = ride_entry_get_vehicle_at_position(ride->subtype, ride->num_cars_per_train, carIndex); - auto car = vehicle_create_car( - rideIndex, vehicle, carIndex, vehicleIndex, { x, y, z }, remainingDistance, tileElement); + auto car = vehicle_create_car(rideIndex, vehicle, carIndex, vehicleIndex, trainPos, remainingDistance, tileElement); if (car == nullptr) break; @@ -4564,7 +4562,7 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int { remainingDistance = 0; } - train_ref train = vehicle_create_train(rideIndex, x, y, z, vehicleIndex, &remainingDistance, tileElement); + train_ref train = vehicle_create_train(rideIndex, { x, y, z }, vehicleIndex, &remainingDistance, tileElement); if (vehicleIndex == 0) { firstTrain = train; From de8bb169de7cae3d1ab127bfa2adefb7d7fb0883 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 8 Jul 2020 10:03:13 -0300 Subject: [PATCH 3/4] Use CoordsXYZ on vehicle_create_trains --- src/openrct2/ride/Ride.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 524f3b878d..369056ed09 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4392,7 +4392,7 @@ static Vehicle* vehicle_create_car( // loc_6DDCA4: vehicle->TrackSubposition = VEHICLE_TRACK_SUBPOSITION_0; int32_t direction = tileElement->GetDirection(); - auto dodgemPos = CoordsXYZ{ CoordsXY{ carPosition } + word_9A3AB4[direction], tileElement->GetBaseZ() }; + auto dodgemPos = carPosition + CoordsXYZ{ word_9A3AB4[direction], 0 }; vehicle->TrackLocation = dodgemPos; vehicle->current_station = tileElement->AsTrack()->GetStationIndex(); @@ -4451,7 +4451,7 @@ static Vehicle* vehicle_create_car( } vehicle->TrackSubposition = subposition; - auto chosenLoc = CoordsXYZ{ CoordsXY{ carPosition }, tileElement->GetBaseZ() }; + auto chosenLoc = carPosition; vehicle->TrackLocation = chosenLoc; int32_t direction = tileElement->GetDirection(); @@ -4546,7 +4546,7 @@ static train_ref vehicle_create_train( return train; } -static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int32_t z, TileElement* tileElement) +static void vehicle_create_trains(ride_id_t rideIndex, const CoordsXYZ& trainsPos, TileElement* tileElement) { auto ride = get_ride(rideIndex); if (ride == nullptr) @@ -4562,7 +4562,7 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int { remainingDistance = 0; } - train_ref train = vehicle_create_train(rideIndex, { x, y, z }, vehicleIndex, &remainingDistance, tileElement); + train_ref train = vehicle_create_train(rideIndex, trainsPos, vehicleIndex, &remainingDistance, tileElement); if (vehicleIndex == 0) { firstTrain = train; @@ -4697,24 +4697,21 @@ static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApply } TileElement* tileElement = element->element; - int32_t x = element->x; - int32_t y = element->y; - int32_t z = element->element->base_height; + auto vehiclePos = CoordsXYZ{ *element, element->element->GetBaseZ() }; int32_t direction = tileElement->GetDirection(); // if (ride->mode == RIDE_MODE_STATION_TO_STATION) { - x = element->x - CoordsDirectionDelta[direction].x; - y = element->y - CoordsDirectionDelta[direction].y; + vehiclePos -= CoordsXYZ{ CoordsDirectionDelta[direction], 0 }; - tileElement = reinterpret_cast(map_get_track_element_at({ x, y, z << 3 })); + tileElement = reinterpret_cast(map_get_track_element_at(vehiclePos)); - z = tileElement->base_height; + vehiclePos.z = tileElement->GetBaseZ(); direction = tileElement->GetDirection(); } - vehicle_create_trains(ride->id, x, y, z, tileElement); + vehicle_create_trains(ride->id, vehiclePos, tileElement); // return true; // Initialise station departs From 0758d0fe5c7dcb3aff04197f5765e4fc86993c87 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 8 Jul 2020 10:04:46 -0300 Subject: [PATCH 4/4] Prefer reference on ride_create_vehicles parameter --- src/openrct2/ride/Ride.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 369056ed09..947adf3833 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4675,7 +4675,7 @@ static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYEl * * rct2: 0x006DD84C */ -static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApplying) +static bool ride_create_vehicles(Ride* ride, const CoordsXYE& element, int32_t isApplying) { ride->UpdateMaxVehicles(); if (ride->subtype == RIDE_ENTRY_INDEX_NULL) @@ -4696,8 +4696,8 @@ static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApply return true; } - TileElement* tileElement = element->element; - auto vehiclePos = CoordsXYZ{ *element, element->element->GetBaseZ() }; + TileElement* tileElement = element.element; + auto vehiclePos = CoordsXYZ{ element, element.element->GetBaseZ() }; int32_t direction = tileElement->GetDirection(); // @@ -5217,7 +5217,7 @@ int32_t ride_is_valid_for_test(Ride* ride, int32_t status, bool isApplying) if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_NO_VEHICLES) && !(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) { - if (!ride_create_vehicles(ride, &trackElement, isApplying)) + if (!ride_create_vehicles(ride, trackElement, isApplying)) { return 0; } @@ -5351,7 +5351,7 @@ int32_t ride_is_valid_for_open(Ride* ride, int32_t goingToBeOpen, bool isApplyin if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_NO_VEHICLES) && !(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) { - if (!ride_create_vehicles(ride, &trackElement, isApplying)) + if (!ride_create_vehicles(ride, trackElement, isApplying)) { return 0; }