Merge pull request #12156 from tupaschoal/coords-train-creation

Change train creation to use CoordsXYZ
This commit is contained in:
Michael Steenbeek 2020-07-14 15:54:36 +02:00 committed by GitHub
commit 5c42765d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 32 deletions

View File

@ -4322,7 +4322,7 @@ static constexpr const CoordsXY word_9A2A60[] = {
* rct2: 0x006DD90D * rct2: 0x006DD90D
*/ */
static Vehicle* vehicle_create_car( 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) int32_t* remainingDistance, TileElement* tileElement)
{ {
auto ride = get_ride(rideIndex); auto ride = get_ride(rideIndex);
@ -4392,13 +4392,11 @@ static Vehicle* vehicle_create_car(
// loc_6DDCA4: // loc_6DDCA4:
vehicle->TrackSubposition = VEHICLE_TRACK_SUBPOSITION_0; vehicle->TrackSubposition = VEHICLE_TRACK_SUBPOSITION_0;
int32_t direction = tileElement->GetDirection(); int32_t direction = tileElement->GetDirection();
x += word_9A3AB4[direction].x; auto dodgemPos = carPosition + CoordsXYZ{ word_9A3AB4[direction], 0 };
y += word_9A3AB4[direction].y; vehicle->TrackLocation = dodgemPos;
z = tileElement->GetBaseZ();
vehicle->TrackLocation = { x, y, z };
vehicle->current_station = tileElement->AsTrack()->GetStationIndex(); 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_type = tileElement->AsTrack()->GetTrackType() << 2;
vehicle->track_progress = 0; vehicle->track_progress = 0;
@ -4410,11 +4408,11 @@ static Vehicle* vehicle_create_car(
do do
{ {
vehicle->sprite_direction = scenario_rand() & 0x1E; vehicle->sprite_direction = scenario_rand() & 0x1E;
chosenLoc.y = y + (scenario_rand() & 0xFF); chosenLoc.y = dodgemPos.y + (scenario_rand() & 0xFF);
chosenLoc.x = x + (scenario_rand() & 0xFF); chosenLoc.x = dodgemPos.x + (scenario_rand() & 0xFF);
} while (vehicle->DodgemsCarWouldCollideAt(chosenLoc, nullptr)); } while (vehicle->DodgemsCarWouldCollideAt(chosenLoc, nullptr));
vehicle->MoveTo({ chosenLoc.x, chosenLoc.y, z }); vehicle->MoveTo({ chosenLoc, dodgemPos.z });
} }
else else
{ {
@ -4452,7 +4450,9 @@ static Vehicle* vehicle_create_car(
subposition = VEHICLE_TRACK_SUBPOSITION_REVERSER_RC_REAR_BOGIE; subposition = VEHICLE_TRACK_SUBPOSITION_REVERSER_RC_REAR_BOGIE;
} }
vehicle->TrackSubposition = subposition; vehicle->TrackSubposition = subposition;
vehicle->TrackLocation = { x, y, tileElement->GetBaseZ() };
auto chosenLoc = carPosition;
vehicle->TrackLocation = chosenLoc;
int32_t direction = tileElement->GetDirection(); int32_t direction = tileElement->GetDirection();
vehicle->sprite_direction = direction << 3; vehicle->sprite_direction = direction << 3;
@ -4482,14 +4482,11 @@ static Vehicle* vehicle_create_car(
} }
} }
x += word_9A2A60[direction].x; chosenLoc += CoordsXYZ{ word_9A2A60[direction], RideTypeDescriptors[ride->type].Heights.VehicleZOffset };
y += word_9A2A60[direction].y;
vehicle->current_station = tileElement->AsTrack()->GetStationIndex(); 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_type = (tileElement->AsTrack()->GetTrackType() << 2) | (vehicle->sprite_direction >> 3);
vehicle->track_progress = 31; vehicle->track_progress = 31;
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_MINI_GOLF) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_MINI_GOLF)
@ -4519,8 +4516,7 @@ static Vehicle* vehicle_create_car(
* rct2: 0x006DD84C * rct2: 0x006DD84C
*/ */
static train_ref vehicle_create_train( 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, ride_id_t rideIndex, const CoordsXYZ& trainPos, int32_t vehicleIndex, int32_t* remainingDistance, TileElement* tileElement)
TileElement* tileElement)
{ {
train_ref train = { nullptr, nullptr }; train_ref train = { nullptr, nullptr };
auto ride = get_ride(rideIndex); auto ride = get_ride(rideIndex);
@ -4529,7 +4525,7 @@ static train_ref vehicle_create_train(
for (int32_t carIndex = 0; carIndex < ride->num_cars_per_train; carIndex++) 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 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) if (car == nullptr)
break; break;
@ -4550,7 +4546,7 @@ static train_ref vehicle_create_train(
return 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); auto ride = get_ride(rideIndex);
if (ride == nullptr) if (ride == nullptr)
@ -4566,7 +4562,7 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int
{ {
remainingDistance = 0; 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) if (vehicleIndex == 0)
{ {
firstTrain = train; firstTrain = train;
@ -4679,7 +4675,7 @@ static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYEl
* *
* rct2: 0x006DD84C * 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(); ride->UpdateMaxVehicles();
if (ride->subtype == RIDE_ENTRY_INDEX_NULL) if (ride->subtype == RIDE_ENTRY_INDEX_NULL)
@ -4700,25 +4696,22 @@ static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApply
return true; return true;
} }
TileElement* tileElement = element->element; TileElement* tileElement = element.element;
int32_t x = element->x; auto vehiclePos = CoordsXYZ{ element, element.element->GetBaseZ() };
int32_t y = element->y;
int32_t z = element->element->base_height;
int32_t direction = tileElement->GetDirection(); int32_t direction = tileElement->GetDirection();
// //
if (ride->mode == RIDE_MODE_STATION_TO_STATION) if (ride->mode == RIDE_MODE_STATION_TO_STATION)
{ {
x = element->x - CoordsDirectionDelta[direction].x; vehiclePos -= CoordsXYZ{ CoordsDirectionDelta[direction], 0 };
y = element->y - CoordsDirectionDelta[direction].y;
tileElement = reinterpret_cast<TileElement*>(map_get_track_element_at({ x, y, z << 3 })); tileElement = reinterpret_cast<TileElement*>(map_get_track_element_at(vehiclePos));
z = tileElement->base_height; vehiclePos.z = tileElement->GetBaseZ();
direction = tileElement->GetDirection(); direction = tileElement->GetDirection();
} }
vehicle_create_trains(ride->id, x, y, z, tileElement); vehicle_create_trains(ride->id, vehiclePos, tileElement);
// return true; // return true;
// Initialise station departs // Initialise station departs
@ -5224,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_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; return 0;
} }
@ -5358,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_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; return 0;
} }