From c88695a29c0cd34ad5e276ae3d3c1a0e6ec8a66b Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Sun, 19 Apr 2020 00:53:59 -0300 Subject: [PATCH 1/7] Part of #9473: Create Vehicle::UpdateDodgemsCollision Converted from vehicle_update_dodgems_collision --- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 32 ++++++++++++++++---------------- src/openrct2/ride/Vehicle.h | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index bdfd7c0608..532134992d 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4402,7 +4402,7 @@ static Vehicle* vehicle_create_car( vehicle->sprite_direction = scenario_rand() & 0x1E; chosenLoc.y = y + (scenario_rand() & 0xFF); chosenLoc.x = x + (scenario_rand() & 0xFF); - } while (vehicle_update_dodgems_collision(vehicle, chosenLoc.x, chosenLoc.y, nullptr)); + } while (vehicle->UpdateDodgemsCollision(chosenLoc.x, chosenLoc.y, nullptr)); sprite_move(chosenLoc.x, chosenLoc.y, z, vehicle); } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 60010e0712..c355d77acf 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6283,7 +6283,7 @@ int32_t Vehicle::UpdateMotionDodgems() location.x += Unk9A36C4[oldCollisionDirection + 1].x; location.y += Unk9A36C4[oldCollisionDirection + 1].y; - if (!vehicle_update_dodgems_collision(this, location.x, location.y, &collideSprite)) + if (!UpdateDodgemsCollision(location.x, location.y, &collideSprite)) { Invalidate(); sprite_move(location.x, location.y, location.z, this); @@ -6312,7 +6312,7 @@ int32_t Vehicle::UpdateMotionDodgems() location.x += Unk9A36C4[direction].x; location.y += Unk9A36C4[direction].y; - if (vehicle_update_dodgems_collision(this, location.x, location.y, &collideSprite)) + if (UpdateDodgemsCollision(location.x, location.y, &collideSprite)) break; remaining_distance -= Unk9A36C4[direction].distance; @@ -6393,26 +6393,26 @@ int32_t Vehicle::UpdateMotionDodgems() * * rct2: 0x006DD365 */ -bool vehicle_update_dodgems_collision(Vehicle* vehicle, int16_t x, int16_t y, uint16_t* spriteId) +bool Vehicle::UpdateDodgemsCollision(int16_t curX, int16_t curY, uint16_t* spriteId) { - uint16_t bp = (vehicle->var_44 * 30) >> 9; - uint32_t trackType = vehicle->track_type >> 2; + uint16_t bp = (var_44 * 30) >> 9; + uint32_t trackType = track_type >> 2; - int16_t rideLeft = vehicle->TrackLocation.x + DodgemsTrackSize[trackType].left; - int16_t rideRight = vehicle->TrackLocation.x + DodgemsTrackSize[trackType].right; - int16_t rideTop = vehicle->TrackLocation.y + DodgemsTrackSize[trackType].top; - int16_t rideBottom = vehicle->TrackLocation.y + DodgemsTrackSize[trackType].bottom; + int16_t rideLeft = TrackLocation.x + DodgemsTrackSize[trackType].left; + int16_t rideRight = TrackLocation.x + DodgemsTrackSize[trackType].right; + int16_t rideTop = TrackLocation.y + DodgemsTrackSize[trackType].top; + int16_t rideBottom = TrackLocation.y + DodgemsTrackSize[trackType].bottom; - if (x - bp < rideLeft || y - bp < rideTop || x + bp > rideRight || y + bp > rideBottom) + if (curX - bp < rideLeft || curY - bp < rideTop || curX + bp > rideRight || curY + bp > rideBottom) { if (spriteId != nullptr) *spriteId = SPRITE_INDEX_NULL; return true; } - auto location = CoordsXY{ x, y }; + auto location = CoordsXY{ curX, curY }; - ride_id_t rideIndex = vehicle->ride; + ride_id_t rideIndex = ride; for (auto xy_offset : SurroundingTiles) { location += xy_offset; @@ -6423,7 +6423,7 @@ bool vehicle_update_dodgems_collision(Vehicle* vehicle, int16_t x, int16_t y, ui Vehicle* vehicle2 = GET_VEHICLE(spriteIdx); spriteIdx = vehicle2->next_in_quadrant; - if (vehicle2 == vehicle) + if (vehicle2 == this) continue; if (vehicle2->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) @@ -6432,15 +6432,15 @@ bool vehicle_update_dodgems_collision(Vehicle* vehicle, int16_t x, int16_t y, ui if (vehicle2->ride != rideIndex) continue; - int32_t distX = abs(x - vehicle2->x); + int32_t distX = abs(curX - vehicle2->x); if (distX > 32768) continue; - int32_t distY = abs(y - vehicle2->y); + int32_t distY = abs(curY - vehicle2->y); if (distY > 32768) continue; - int32_t ecx = (vehicle->var_44 + vehicle2->var_44) / 2; + int32_t ecx = (var_44 + vehicle2->var_44) / 2; ecx *= 30; ecx >>= 8; if (std::max(distX, distY) < ecx) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 22b443ea57..988c123b8d 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -305,6 +305,7 @@ struct Vehicle : SpriteBase void SetState(VEHICLE_STATUS vehicleStatus, uint8_t subState = 0); bool IsGhost() const; void UpdateSoundParams(std::vector& vehicleSoundParamsList) const; + bool UpdateDodgemsCollision(int16_t x, int16_t y, uint16_t* spriteId); int32_t UpdateTrackMotion(int32_t* outStation); private: @@ -564,7 +565,6 @@ Vehicle* vehicle_get_head(const Vehicle* vehicle); Vehicle* vehicle_get_tail(const Vehicle* vehicle); const rct_vehicle_info* vehicle_get_move_info(int32_t trackSubposition, int32_t typeAndDirection, int32_t offset); uint16_t vehicle_get_move_info_size(int32_t trackSubposition, int32_t typeAndDirection); -bool vehicle_update_dodgems_collision(Vehicle* vehicle, int16_t x, int16_t y, uint16_t* spriteId); extern Vehicle* gCurrentVehicle; extern StationIndex _vehicleStationIndex; From 90cd90e738493dc48bb211048101934379be9967 Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Sun, 19 Apr 2020 01:14:41 -0300 Subject: [PATCH 2/7] Part of #9473: Create Vehicle::Entry Converted from vehicle_get_vehicle_entry --- src/openrct2/ride/Ride.cpp | 4 ++-- src/openrct2/ride/Vehicle.cpp | 44 +++++++++++++++++------------------ src/openrct2/ride/Vehicle.h | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 532134992d..f69bb28d30 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4740,7 +4740,7 @@ static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApply { Vehicle* vehicle = GET_VEHICLE(ride->vehicles[i]); - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_DODGEM_CAR_PLACEMENT)) { @@ -7483,7 +7483,7 @@ void fix_invalid_vehicle_sprite_sizes() break; } - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { break; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index c355d77acf..c533970399 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -4260,7 +4260,7 @@ void Vehicle::UpdateMotionBoatHire() _vehicleVelocityF64E08 = velocity; _vehicleVelocityF64E0C = (velocity >> 10) * 42; - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(this); + auto vehicleEntry = Entry(); if (vehicleEntry == nullptr) { return; @@ -6461,7 +6461,7 @@ bool Vehicle::UpdateDodgemsCollision(int16_t curX, int16_t curY, uint16_t* sprit */ static void vehicle_update_track_motion_up_stop_check(Vehicle* vehicle) { - auto vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { return; @@ -6596,7 +6596,7 @@ static void check_and_apply_block_section_stop_site(Vehicle* vehicle) if (ride == nullptr) return; - auto vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) return; @@ -6884,7 +6884,7 @@ static void vehicle_update_swinging_car(Vehicle* vehicle) vehicle->var_4E += dword_F64E08 >> swingAmount; } - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { return; @@ -7068,7 +7068,7 @@ static void vehicle_update_spinning_car(Vehicle* vehicle) return; } - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { return; @@ -7203,7 +7203,7 @@ void Vehicle::UpdateAdditionalAnimation() uint32_t eax; uint32_t* curVar_C8 = reinterpret_cast(&var_C8); - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(this); + auto vehicleEntry = Entry(); if (vehicleEntry == nullptr) { return; @@ -7594,7 +7594,7 @@ static bool vehicle_update_motion_collision_detection( if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_1) return false; - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + auto vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { return false; @@ -7662,11 +7662,11 @@ static bool vehicle_update_motion_collision_detection( if (collideVehicle->ride_subtype == RIDE_TYPE_NULL) continue; - rct_ride_entry_vehicle* collideType = vehicle_get_vehicle_entry(collideVehicle); - if (collideType == nullptr) + auto collideVehicleEntry = collideVehicle->Entry(); + if (collideVehicleEntry == nullptr) continue; - if (!(collideType->flags & VEHICLE_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION)) + if (!(collideVehicleEntry->flags & VEHICLE_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION)) continue; uint32_t x_diff = abs(collideVehicle->x - x); @@ -7691,7 +7691,7 @@ static bool vehicle_update_motion_collision_detection( if (x_diff + y_diff >= ecx) continue; - if (!(collideType->flags & VEHICLE_ENTRY_FLAG_GO_KART)) + if (!(collideVehicleEntry->flags & VEHICLE_ENTRY_FLAG_GO_KART)) { mayCollide = true; break; @@ -7805,7 +7805,7 @@ static void vehicle_reverse_reverser_car(Vehicle* vehicle) */ static void sub_6DBF3E(Vehicle* vehicle) { - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + rct_ride_entry_vehicle* vehicleEntry = vehicle->Entry(); vehicle->acceleration = vehicle->acceleration / _vehicleUnkF64E10; if (vehicle->TrackSubposition == VEHICLE_TRACK_SUBPOSITION_CHAIRLIFT_GOING_BACK) @@ -8011,7 +8011,7 @@ loc_6DB41D: vehicle->TrackLocation = location; // TODO check if getting the vehicle entry again is necessary - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + rct_ride_entry_vehicle* vehicleEntry = vehicle->Entry(); if (vehicleEntry == nullptr) { return false; @@ -8101,7 +8101,7 @@ loc_6DAEB9: if (track_progress == 80) { vehicle_type ^= 1; - vehicleEntry = vehicle_get_vehicle_entry(this); + vehicleEntry = Entry(); } if (_vehicleVelocityF64E08 >= 0x40000) { @@ -8173,7 +8173,7 @@ loc_6DAEB9: if (track_progress == 32) { vehicle_type = vehicleEntry->log_flume_reverser_vehicle_type; - vehicleEntry = vehicle_get_vehicle_entry(this); + vehicleEntry = Entry(); } } else @@ -8653,7 +8653,7 @@ static int32_t vehicle_update_track_motion_mini_golf(Vehicle* vehicle, int32_t* return 0; rct_ride_entry* rideEntry = get_ride_entry(vehicle->ride_subtype); - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + rct_ride_entry_vehicle* vehicleEntry = vehicle->Entry(); TileElement* tileElement = nullptr; @@ -9506,7 +9506,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) return 0; rct_ride_entry* rideEntry = get_ride_entry(ride_subtype); - rct_ride_entry_vehicle* vehicleEntry = vehicle_get_vehicle_entry(this); + auto vehicleEntry = Entry(); if (vehicleEntry == nullptr) { @@ -9540,7 +9540,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) while (spriteId != SPRITE_INDEX_NULL) { Vehicle* car = GET_VEHICLE(spriteId); - vehicleEntry = vehicle_get_vehicle_entry(car); + vehicleEntry = car->Entry(); if (vehicleEntry == nullptr) { goto loc_6DBF3E; @@ -9643,7 +9643,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) // loc_6DC144 vehicle = gCurrentVehicle; - vehicleEntry = vehicle_get_vehicle_entry(vehicle); + vehicleEntry = vehicle->Entry(); // eax int32_t totalAcceleration = 0; // ebp @@ -9755,14 +9755,14 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) return regs.eax; } -rct_ride_entry_vehicle* vehicle_get_vehicle_entry(const Vehicle* vehicle) +rct_ride_entry_vehicle* Vehicle::Entry() const { - rct_ride_entry* rideEntry = get_ride_entry(vehicle->ride_subtype); + rct_ride_entry* rideEntry = get_ride_entry(ride_subtype); if (rideEntry == nullptr) { return nullptr; } - return &rideEntry->vehicles[vehicle->vehicle_type]; + return &rideEntry->vehicles[vehicle_type]; } int32_t vehicle_get_total_num_peeps(const Vehicle* vehicle) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 988c123b8d..2947a2ca39 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -307,6 +307,7 @@ struct Vehicle : SpriteBase void UpdateSoundParams(std::vector& vehicleSoundParamsList) const; bool UpdateDodgemsCollision(int16_t x, int16_t y, uint16_t* spriteId); int32_t UpdateTrackMotion(int32_t* outStation); + rct_ride_entry_vehicle* Entry() const; private: bool SoundCanPlay() const; @@ -555,7 +556,6 @@ void vehicle_sounds_update(); GForces vehicle_get_g_forces(const Vehicle* vehicle); void vehicle_set_map_toolbar(const Vehicle* vehicle); int32_t vehicle_is_used_in_pairs(const Vehicle* vehicle); -rct_ride_entry_vehicle* vehicle_get_vehicle_entry(const Vehicle* vehicle); int32_t vehicle_get_total_num_peeps(const Vehicle* vehicle); void vehicle_invalidate_window(Vehicle* vehicle); void vehicle_update_test_finish(Vehicle* vehicle); From d69cc1c877dab38ae1efe807ae16c7df69f5c10d Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Sun, 19 Apr 2020 01:28:23 -0300 Subject: [PATCH 3/7] Part of #9473: Create Vehicle::TrainHead and Vehicle::TrainTail Converted from vehicle_get_head and vehicle_get_tail --- src/openrct2-ui/windows/Ride.cpp | 2 +- src/openrct2/drawing/LightFX.cpp | 10 +++++----- src/openrct2/ride/CableLift.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 18 ++++++++++-------- src/openrct2/ride/Vehicle.h | 4 ++-- src/openrct2/ride/VehiclePaint.cpp | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 8ff2edc189..eaefc167e2 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1696,7 +1696,7 @@ rct_window* window_ride_open_track(TileElement* tileElement) */ rct_window* window_ride_open_vehicle(Vehicle* vehicle) { - Vehicle* headVehicle = vehicle_get_head(vehicle); + Vehicle* headVehicle = vehicle->TrainHead(); uint16_t headVehicleSpriteIndex = headVehicle->sprite_index; auto ride = get_ride(headVehicle->ride); if (ride == nullptr) diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 09561ec1c2..fe8aefd11e 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -725,7 +725,7 @@ void lightfx_add_lights_magic_vehicle(const Vehicle* vehicle) break; case RIDE_TYPE_MINE_TRAIN_COASTER: case RIDE_TYPE_GHOST_TRAIN: - if (vehicle == vehicle_get_head(vehicle)) + if (vehicle == vehicle->TrainHead()) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; @@ -748,7 +748,7 @@ void lightfx_add_lights_magic_vehicle(const Vehicle* vehicle) case RIDE_TYPE_SPLASH_BOATS: case RIDE_TYPE_WATER_COASTER: { - Vehicle* vehicle_draw = vehicle_get_head(vehicle); + Vehicle* vehicle_draw = vehicle->TrainHead(); if (vehicle_draw->next_vehicle_on_train != SPRITE_INDEX_NULL) { vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); @@ -770,7 +770,7 @@ void lightfx_add_lights_magic_vehicle(const Vehicle* vehicle) lightfx_add_3d_light( vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); - if (vehicle == vehicle_get_head(vehicle)) + if (vehicle == vehicle->TrainHead()) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; @@ -783,7 +783,7 @@ void lightfx_add_lights_magic_vehicle(const Vehicle* vehicle) vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } - if (vehicle == vehicle_get_tail(vehicle)) + if (vehicle == vehicle->TrainTail()) { place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; @@ -798,7 +798,7 @@ void lightfx_add_lights_magic_vehicle(const Vehicle* vehicle) } break; case RIDE_TYPE_MINIATURE_RAILWAY: - if (vehicle == vehicle_get_head(vehicle)) + if (vehicle == vehicle->TrainHead()) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index b138c4fabf..016ab0e5db 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -377,7 +377,7 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift) Vehicle* frontVehicle = cableLift; if (cableLift->velocity < 0) { - frontVehicle = vehicle_get_tail(cableLift); + frontVehicle = cableLift->TrainTail(); } _vehicleFrontVehicle = frontVehicle; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index c533970399..7186859aa2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6180,8 +6180,9 @@ void vehicle_set_map_toolbar(const Vehicle* vehicle) } } -Vehicle* vehicle_get_head(const Vehicle* vehicle) +Vehicle* Vehicle::TrainHead() const { + const Vehicle* vehicle = this; Vehicle* prevVehicle; for (;;) @@ -6198,8 +6199,9 @@ Vehicle* vehicle_get_head(const Vehicle* vehicle) return const_cast(vehicle); } -Vehicle* vehicle_get_tail(const Vehicle* vehicle) +Vehicle* Vehicle::TrainTail() const { + const Vehicle* vehicle = this; uint16_t spriteIndex; while ((spriteIndex = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL) @@ -8293,7 +8295,7 @@ loc_6DB967: remaining_distance = -1; // Might need to be bp rather than this, but hopefully not - Vehicle* head = vehicle_get_head(GET_VEHICLE(regs.bp)); + auto head = (GET_VEHICLE(regs.bp))->TrainHead(); regs.eax = abs(velocity - head->velocity); if (!(rideEntry->flags & RIDE_ENTRY_FLAG_DISABLE_COLLISION_CRASHES)) @@ -8664,7 +8666,7 @@ static int32_t vehicle_update_track_motion_mini_golf(Vehicle* vehicle, int32_t* _vehicleVelocityF64E0C = (vehicle->velocity >> 10) * 42; if (_vehicleVelocityF64E08 < 0) { - vehicle = vehicle_get_tail(vehicle); + vehicle = vehicle->TrainTail(); } _vehicleFrontVehicle = vehicle; @@ -9530,7 +9532,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) Vehicle* vehicle = this; if (_vehicleVelocityF64E08 < 0) { - vehicle = vehicle_get_tail(vehicle); + vehicle = vehicle->TrainTail(); } // This will be the front vehicle even when traveling // backwards. @@ -9795,7 +9797,7 @@ void vehicle_invalidate_window(Vehicle* vehicle) void Vehicle::UpdateCrossings() const { - if (vehicle_get_head(this) != this) + if (TrainHead() != this) { return; } @@ -9808,11 +9810,11 @@ void Vehicle::UpdateCrossings() const if (travellingForwards) { frontVehicle = this; - backVehicle = vehicle_get_tail(this); + backVehicle = TrainTail(); } else { - frontVehicle = vehicle_get_tail(this); + frontVehicle = TrainTail(); backVehicle = this; } diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 2947a2ca39..3680698d4f 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -308,6 +308,8 @@ struct Vehicle : SpriteBase bool UpdateDodgemsCollision(int16_t x, int16_t y, uint16_t* spriteId); int32_t UpdateTrackMotion(int32_t* outStation); rct_ride_entry_vehicle* Entry() const; + Vehicle* TrainHead() const; + Vehicle* TrainTail() const; private: bool SoundCanPlay() const; @@ -561,8 +563,6 @@ void vehicle_invalidate_window(Vehicle* vehicle); void vehicle_update_test_finish(Vehicle* vehicle); void vehicle_test_reset(Vehicle* vehicle); void vehicle_peep_easteregg_here_we_are(const Vehicle* vehicle); -Vehicle* vehicle_get_head(const Vehicle* vehicle); -Vehicle* vehicle_get_tail(const Vehicle* vehicle); const rct_vehicle_info* vehicle_get_move_info(int32_t trackSubposition, int32_t typeAndDirection, int32_t offset); uint16_t vehicle_get_move_info_size(int32_t trackSubposition, int32_t typeAndDirection); diff --git a/src/openrct2/ride/VehiclePaint.cpp b/src/openrct2/ride/VehiclePaint.cpp index ac472c8fe5..a3893f709e 100644 --- a/src/openrct2/ride/VehiclePaint.cpp +++ b/src/openrct2/ride/VehiclePaint.cpp @@ -2976,7 +2976,7 @@ static void vehicle_visual_splash1_effect(paint_session* session, int32_t z, con { return; } - if (vehicle_get_head(vehicle)->velocity <= 0x50000) + if (vehicle->TrainHead()->velocity <= 0x50000) { return; } From 53f6bd8340f6174edf6eac5a6769bcb03ad6ee66 Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Sun, 19 Apr 2020 01:33:05 -0300 Subject: [PATCH 4/7] Part of #9473: Create Vehicle::PeepEasterEggHereWeAre Converted from vehicle_peep_easteregg_here_we_are --- src/openrct2/ride/Vehicle.cpp | 13 +++++++------ src/openrct2/ride/Vehicle.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7186859aa2..ae07ea0a5b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2974,18 +2974,19 @@ static bool vehicle_can_depart_synchronised(Vehicle* vehicle) * * rct2: 0x006D9EB0 */ -void vehicle_peep_easteregg_here_we_are(const Vehicle* vehicle) +void Vehicle::PeepEasterEggHereWeAre() const { + const Vehicle* vehicle = this; uint16_t spriteId = vehicle->sprite_index; do { vehicle = GET_VEHICLE(spriteId); for (int32_t i = 0; i < vehicle->num_peeps; ++i) { - Peep* peep = GET_PEEP(vehicle->peep[i]); - if (peep->peep_flags & PEEP_FLAGS_HERE_WE_ARE) + Peep* curPeep = GET_PEEP(vehicle->peep[i]); + if (curPeep->peep_flags & PEEP_FLAGS_HERE_WE_ARE) { - peep->InsertNewThought(PEEP_THOUGHT_TYPE_HERE_WE_ARE, peep->current_ride); + curPeep->InsertNewThought(PEEP_THOUGHT_TYPE_HERE_WE_ARE, curPeep->current_ride); } } } while ((spriteId = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL); @@ -3172,7 +3173,7 @@ void Vehicle::UpdateDeparting() } sub_state = 1; - vehicle_peep_easteregg_here_we_are(this); + PeepEasterEggHereWeAre(); if (rideEntry->flags & RIDE_ENTRY_FLAG_PLAY_DEPART_SOUND) { @@ -4156,7 +4157,7 @@ void Vehicle::UpdateTravellingCableLift() } sub_state = 1; - vehicle_peep_easteregg_here_we_are(this); + PeepEasterEggHereWeAre(); if (!(curRide->lifecycle_flags & RIDE_LIFECYCLE_TESTED)) { if (update_flags & VEHICLE_UPDATE_FLAG_TESTING) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 3680698d4f..3eed9f4733 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -360,6 +360,7 @@ private: bool CurrentTowerElementIsTop(); bool UpdateTrackMotionForwards(rct_ride_entry_vehicle* vehicleEntry, Ride* curRide, rct_ride_entry* rideEntry); bool UpdateTrackMotionBackwards(rct_ride_entry_vehicle* vehicleEntry, Ride* curRide, rct_ride_entry* rideEntry); + void PeepEasterEggHereWeAre() const; }; struct train_ref @@ -562,7 +563,6 @@ int32_t vehicle_get_total_num_peeps(const Vehicle* vehicle); void vehicle_invalidate_window(Vehicle* vehicle); void vehicle_update_test_finish(Vehicle* vehicle); void vehicle_test_reset(Vehicle* vehicle); -void vehicle_peep_easteregg_here_we_are(const Vehicle* vehicle); const rct_vehicle_info* vehicle_get_move_info(int32_t trackSubposition, int32_t typeAndDirection, int32_t offset); uint16_t vehicle_get_move_info_size(int32_t trackSubposition, int32_t typeAndDirection); From 4389670939112f52cbfcd0b16066bcb9c704e3e1 Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Sun, 26 Apr 2020 18:30:00 -0300 Subject: [PATCH 5/7] Improve names in UpdateDodgemsCollision --- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 40 ++++++++++++++++++++--------------- src/openrct2/ride/Vehicle.h | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index f69bb28d30..5d32811d6f 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4402,7 +4402,7 @@ static Vehicle* vehicle_create_car( vehicle->sprite_direction = scenario_rand() & 0x1E; chosenLoc.y = y + (scenario_rand() & 0xFF); chosenLoc.x = x + (scenario_rand() & 0xFF); - } while (vehicle->UpdateDodgemsCollision(chosenLoc.x, chosenLoc.y, nullptr)); + } while (vehicle->DodgemsCarWouldCollideAt(chosenLoc, nullptr)); sprite_move(chosenLoc.x, chosenLoc.y, z, vehicle); } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index ae07ea0a5b..a14173d973 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6286,7 +6286,7 @@ int32_t Vehicle::UpdateMotionDodgems() location.x += Unk9A36C4[oldCollisionDirection + 1].x; location.y += Unk9A36C4[oldCollisionDirection + 1].y; - if (!UpdateDodgemsCollision(location.x, location.y, &collideSprite)) + if (!DodgemsCarWouldCollideAt(location, &collideSprite)) { Invalidate(); sprite_move(location.x, location.y, location.z, this); @@ -6315,7 +6315,7 @@ int32_t Vehicle::UpdateMotionDodgems() location.x += Unk9A36C4[direction].x; location.y += Unk9A36C4[direction].y; - if (UpdateDodgemsCollision(location.x, location.y, &collideSprite)) + if (DodgemsCarWouldCollideAt(location, &collideSprite)) break; remaining_distance -= Unk9A36C4[direction].distance; @@ -6396,24 +6396,30 @@ int32_t Vehicle::UpdateMotionDodgems() * * rct2: 0x006DD365 */ -bool Vehicle::UpdateDodgemsCollision(int16_t curX, int16_t curY, uint16_t* spriteId) +static bool wouldCollideWithDodgemsTrackEdge( + CoordsXY coords, CoordsXY trackLocation, uint32_t trackType, uint16_t dodgemsCarRadius) +{ + int16_t rideLeft = trackLocation.x + DodgemsTrackSize[trackType].left; + int16_t rideRight = trackLocation.x + DodgemsTrackSize[trackType].right; + int16_t rideTop = trackLocation.y + DodgemsTrackSize[trackType].top; + int16_t rideBottom = trackLocation.y + DodgemsTrackSize[trackType].bottom; + + return coords.x - dodgemsCarRadius < rideLeft || coords.y - dodgemsCarRadius < rideTop + || coords.x + dodgemsCarRadius > rideRight || coords.y + dodgemsCarRadius > rideBottom; +} + +bool Vehicle::DodgemsCarWouldCollideAt(CoordsXY coords, uint16_t* collidedWith) const { - uint16_t bp = (var_44 * 30) >> 9; uint32_t trackType = track_type >> 2; - int16_t rideLeft = TrackLocation.x + DodgemsTrackSize[trackType].left; - int16_t rideRight = TrackLocation.x + DodgemsTrackSize[trackType].right; - int16_t rideTop = TrackLocation.y + DodgemsTrackSize[trackType].top; - int16_t rideBottom = TrackLocation.y + DodgemsTrackSize[trackType].bottom; - - if (curX - bp < rideLeft || curY - bp < rideTop || curX + bp > rideRight || curY + bp > rideBottom) + if (wouldCollideWithDodgemsTrackEdge(coords, TrackLocation, trackType, (var_44 * 30) >> 9)) { - if (spriteId != nullptr) - *spriteId = SPRITE_INDEX_NULL; + if (collidedWith != nullptr) + *collidedWith = SPRITE_INDEX_NULL; return true; } - auto location = CoordsXY{ curX, curY }; + auto location = coords; ride_id_t rideIndex = ride; for (auto xy_offset : SurroundingTiles) @@ -6435,11 +6441,11 @@ bool Vehicle::UpdateDodgemsCollision(int16_t curX, int16_t curY, uint16_t* sprit if (vehicle2->ride != rideIndex) continue; - int32_t distX = abs(curX - vehicle2->x); + int32_t distX = abs(coords.x - vehicle2->x); if (distX > 32768) continue; - int32_t distY = abs(curY - vehicle2->y); + int32_t distY = abs(coords.y - vehicle2->y); if (distY > 32768) continue; @@ -6448,8 +6454,8 @@ bool Vehicle::UpdateDodgemsCollision(int16_t curX, int16_t curY, uint16_t* sprit ecx >>= 8; if (std::max(distX, distY) < ecx) { - if (spriteId != nullptr) - *spriteId = vehicle2->sprite_index; + if (collidedWith != nullptr) + *collidedWith = vehicle2->sprite_index; return true; } } diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 3eed9f4733..ff48adaf5d 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -305,7 +305,7 @@ struct Vehicle : SpriteBase void SetState(VEHICLE_STATUS vehicleStatus, uint8_t subState = 0); bool IsGhost() const; void UpdateSoundParams(std::vector& vehicleSoundParamsList) const; - bool UpdateDodgemsCollision(int16_t x, int16_t y, uint16_t* spriteId); + bool DodgemsCarWouldCollideAt(CoordsXY coords, uint16_t* spriteId) const; int32_t UpdateTrackMotion(int32_t* outStation); rct_ride_entry_vehicle* Entry() const; Vehicle* TrainHead() const; From 864a40e22c84a59493044c6b93c9937c08d96b44 Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Thu, 30 Apr 2020 20:56:19 -0300 Subject: [PATCH 6/7] Use const& in wouldCollideWithDodgemsTrackEdge --- src/openrct2/ride/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index a14173d973..5c25fbeee2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6397,7 +6397,7 @@ int32_t Vehicle::UpdateMotionDodgems() * rct2: 0x006DD365 */ static bool wouldCollideWithDodgemsTrackEdge( - CoordsXY coords, CoordsXY trackLocation, uint32_t trackType, uint16_t dodgemsCarRadius) + const CoordsXY& coords, const CoordsXY& trackLocation, uint32_t trackType, uint16_t dodgemsCarRadius) { int16_t rideLeft = trackLocation.x + DodgemsTrackSize[trackType].left; int16_t rideRight = trackLocation.x + DodgemsTrackSize[trackType].right; From 83d88c09390c8cc14549d3deab0f564a11658787 Mon Sep 17 00:00:00 2001 From: hdpoliveira Date: Thu, 30 Apr 2020 21:03:05 -0300 Subject: [PATCH 7/7] Use const& in DodgemsCarWouldCollideAt --- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/ride/Vehicle.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 5c25fbeee2..c589d4b728 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6408,7 +6408,7 @@ static bool wouldCollideWithDodgemsTrackEdge( || coords.x + dodgemsCarRadius > rideRight || coords.y + dodgemsCarRadius > rideBottom; } -bool Vehicle::DodgemsCarWouldCollideAt(CoordsXY coords, uint16_t* collidedWith) const +bool Vehicle::DodgemsCarWouldCollideAt(const CoordsXY& coords, uint16_t* collidedWith) const { uint32_t trackType = track_type >> 2; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index ff48adaf5d..f126d87d43 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -305,7 +305,7 @@ struct Vehicle : SpriteBase void SetState(VEHICLE_STATUS vehicleStatus, uint8_t subState = 0); bool IsGhost() const; void UpdateSoundParams(std::vector& vehicleSoundParamsList) const; - bool DodgemsCarWouldCollideAt(CoordsXY coords, uint16_t* spriteId) const; + bool DodgemsCarWouldCollideAt(const CoordsXY& coords, uint16_t* spriteId) const; int32_t UpdateTrackMotion(int32_t* outStation); rct_ride_entry_vehicle* Entry() const; Vehicle* TrainHead() const;