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; }