From e627b1680cc0db3c830e97583e4f526838f3d910 Mon Sep 17 00:00:00 2001 From: Mustapha Elghoul Date: Mon, 20 Apr 2020 22:12:42 -0400 Subject: [PATCH 1/3] Part of #9473: Create 5 Vehicle::CableLiftUpdate... from cable_lift_update_... --- src/openrct2/ride/CableLift.cpp | 94 +++++++++++++++------------------ src/openrct2/ride/Vehicle.h | 5 ++ 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index bb2bab30da..3a5340f203 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -20,12 +20,6 @@ #include -static void cable_lift_update_moving_to_end_of_station(Vehicle* vehicle); -static void cable_lift_update_waiting_to_depart(Vehicle* vehicle); -static void cable_lift_update_departing(Vehicle* vehicle); -static void cable_lift_update_travelling(Vehicle* vehicle); -static void cable_lift_update_arriving(Vehicle* vehicle); - Vehicle* cable_lift_segment_create( Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head) { @@ -93,22 +87,22 @@ void Vehicle::CableLiftUpdate() switch (status) { case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: - cable_lift_update_moving_to_end_of_station(this); + CableLiftUpdateMovingToEndOfStation(); break; case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: // Stays in this state until a train puts it into next state break; case VEHICLE_STATUS_WAITING_TO_DEPART: - cable_lift_update_waiting_to_depart(this); + CableLiftUpdateWaitingToDepart(); break; case VEHICLE_STATUS_DEPARTING: - cable_lift_update_departing(this); + CableLiftUpdateDeparting(); break; case VEHICLE_STATUS_TRAVELLING: - cable_lift_update_travelling(this); + CableLiftUpdateTravelling(); break; case VEHICLE_STATUS_ARRIVING: - cable_lift_update_arriving(this); + CableLiftUpdateArriving(); break; default: break; @@ -119,47 +113,47 @@ void Vehicle::CableLiftUpdate() * * rct2: 0x006DF8A4 */ -static void cable_lift_update_moving_to_end_of_station(Vehicle* vehicle) +void Vehicle::CableLiftUpdateMovingToEndOfStation() { - if (vehicle->velocity >= -439800) - vehicle->acceleration = -2932; + if (velocity >= -439800) + acceleration = -2932; - if (vehicle->velocity < -439800) + if (velocity < -439800) { - vehicle->velocity -= vehicle->velocity / 16; - vehicle->acceleration = 0; + velocity -= velocity / 16; + acceleration = 0; } - if (!(cable_lift_update_track_motion(vehicle) & (1 << 0))) + if (!(cable_lift_update_track_motion(this) & (1 << 0))) return; - vehicle->velocity = 0; - vehicle->acceleration = 0; - vehicle->SetState(VEHICLE_STATUS_WAITING_FOR_PASSENGERS, vehicle->sub_state); + velocity = 0; + acceleration = 0; + SetState(VEHICLE_STATUS_WAITING_FOR_PASSENGERS, sub_state); } /** * * rct2: 0x006DF8F1 */ -static void cable_lift_update_waiting_to_depart(Vehicle* vehicle) +void Vehicle::CableLiftUpdateWaitingToDepart() { - if (vehicle->velocity >= -58640) - vehicle->acceleration = -14660; + if (velocity >= -58640) + acceleration = -14660; - if (vehicle->velocity < -58640) + if (velocity < -58640) { - vehicle->velocity -= vehicle->velocity / 16; - vehicle->acceleration = 0; + velocity -= velocity / 16; + acceleration = 0; } - cable_lift_update_track_motion(vehicle); + cable_lift_update_track_motion(this); // Next check to see if the second part of the cable lift // is at the front of the passenger vehicle to simulate the // cable being attached underneath the train. - Vehicle* passengerVehicle = GET_VEHICLE(vehicle->cable_lift_target); - Vehicle* cableLiftSecondPart = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + Vehicle* passengerVehicle = GET_VEHICLE(cable_lift_target); + Vehicle* cableLiftSecondPart = GET_VEHICLE(prev_vehicle_on_ride); int16_t dist_x = abs(passengerVehicle->x - cableLiftSecondPart->x); int16_t dist_y = abs(passengerVehicle->y - cableLiftSecondPart->y); @@ -167,23 +161,23 @@ static void cable_lift_update_waiting_to_depart(Vehicle* vehicle) if (dist_x + dist_y > 2) return; - vehicle->velocity = 0; - vehicle->acceleration = 0; - vehicle->SetState(VEHICLE_STATUS_DEPARTING, 0); + velocity = 0; + acceleration = 0; + SetState(VEHICLE_STATUS_DEPARTING, 0); } /** * * rct2: 0x006DF97A */ -static void cable_lift_update_departing(Vehicle* vehicle) +void Vehicle::CableLiftUpdateDeparting() { - vehicle->sub_state++; - if (vehicle->sub_state < 16) + sub_state++; + if (sub_state < 16) return; - Vehicle* passengerVehicle = GET_VEHICLE(vehicle->cable_lift_target); - vehicle->SetState(VEHICLE_STATUS_TRAVELLING, vehicle->sub_state); + Vehicle* passengerVehicle = GET_VEHICLE(cable_lift_target); + SetState(VEHICLE_STATUS_TRAVELLING, sub_state); passengerVehicle->SetState(VEHICLE_STATUS_TRAVELLING_CABLE_LIFT, passengerVehicle->sub_state); } @@ -191,32 +185,32 @@ static void cable_lift_update_departing(Vehicle* vehicle) * * rct2: 0x006DF99C */ -static void cable_lift_update_travelling(Vehicle* vehicle) +void Vehicle::CableLiftUpdateTravelling() { - Vehicle* passengerVehicle = GET_VEHICLE(vehicle->cable_lift_target); + Vehicle* passengerVehicle = GET_VEHICLE(cable_lift_target); - vehicle->velocity = std::min(passengerVehicle->velocity, 439800); - vehicle->acceleration = 0; + velocity = std::min(passengerVehicle->velocity, 439800); + acceleration = 0; if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) return; - if (!(cable_lift_update_track_motion(vehicle) & (1 << 1))) + if (!(cable_lift_update_track_motion(this) & (1 << 1))) return; - vehicle->velocity = 0; - vehicle->acceleration = 0; - vehicle->SetState(VEHICLE_STATUS_ARRIVING, 0); + velocity = 0; + acceleration = 0; + SetState(VEHICLE_STATUS_ARRIVING, 0); } /** * * rct2: 0x006DF9F0 */ -static void cable_lift_update_arriving(Vehicle* vehicle) +void Vehicle::CableLiftUpdateArriving() { - vehicle->sub_state++; - if (vehicle->sub_state >= 64) - vehicle->SetState(VEHICLE_STATUS_MOVING_TO_END_OF_STATION, vehicle->sub_state); + sub_state++; + if (sub_state >= 64) + SetState(VEHICLE_STATUS_MOVING_TO_END_OF_STATION, sub_state); } static bool sub_6DF01A_loop(Vehicle* vehicle) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 8582a79f02..ff6a60177e 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -350,6 +350,11 @@ 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 CableLiftUpdateMovingToEndOfStation(); + void CableLiftUpdateWaitingToDepart(); + void CableLiftUpdateDeparting(); + void CableLiftUpdateTravelling(); + void CableLiftUpdateArriving(); }; struct train_ref From b38bf7a438108f5710fbdaa455779dbe13ccf00e Mon Sep 17 00:00:00 2001 From: Mustapha Elghoul Date: Mon, 20 Apr 2020 22:52:22 -0400 Subject: [PATCH 2/3] Grouped Alike Functions in Vehicle.h --- src/openrct2/ride/Vehicle.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index ff6a60177e..91c7f86df6 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -312,6 +312,11 @@ private: uint16_t GetSoundPriority() const; rct_vehicle_sound_params CreateSoundParam(uint16_t priority) const; void CableLiftUpdate(); + void CableLiftUpdateMovingToEndOfStation(); + void CableLiftUpdateWaitingToDepart(); + void CableLiftUpdateDeparting(); + void CableLiftUpdateTravelling(); + void CableLiftUpdateArriving(); void UpdateMovingToEndOfStation(); void UpdateWaitingForPassengers(); void UpdateWaitingToDepart(); @@ -350,11 +355,6 @@ 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 CableLiftUpdateMovingToEndOfStation(); - void CableLiftUpdateWaitingToDepart(); - void CableLiftUpdateDeparting(); - void CableLiftUpdateTravelling(); - void CableLiftUpdateArriving(); }; struct train_ref From 38630eeb59331e0956f4d38ce5c3c2fb9df0647c Mon Sep 17 00:00:00 2001 From: Mustapha Elghoul Date: Tue, 21 Apr 2020 16:51:00 -0400 Subject: [PATCH 3/3] Update dist_x and dist_y to camelCase. (1 >> 1) to VEHICLE_UPDATE_MOTION_TRACK_FLAG_1, and (1 >> 0) to VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION --- src/openrct2/ride/CableLift.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 3a5340f203..684995969f 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -124,7 +124,7 @@ void Vehicle::CableLiftUpdateMovingToEndOfStation() acceleration = 0; } - if (!(cable_lift_update_track_motion(this) & (1 << 0))) + if (!(cable_lift_update_track_motion(this) & VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION)) return; velocity = 0; @@ -155,10 +155,10 @@ void Vehicle::CableLiftUpdateWaitingToDepart() Vehicle* passengerVehicle = GET_VEHICLE(cable_lift_target); Vehicle* cableLiftSecondPart = GET_VEHICLE(prev_vehicle_on_ride); - int16_t dist_x = abs(passengerVehicle->x - cableLiftSecondPart->x); - int16_t dist_y = abs(passengerVehicle->y - cableLiftSecondPart->y); + int16_t distX = abs(passengerVehicle->x - cableLiftSecondPart->x); + int16_t distY = abs(passengerVehicle->y - cableLiftSecondPart->y); - if (dist_x + dist_y > 2) + if (distX + distY > 2) return; velocity = 0; @@ -194,7 +194,7 @@ void Vehicle::CableLiftUpdateTravelling() if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) return; - if (!(cable_lift_update_track_motion(this) & (1 << 1))) + if (!(cable_lift_update_track_motion(this) & VEHICLE_UPDATE_MOTION_TRACK_FLAG_1)) return; velocity = 0;