diff --git a/distribution/changelog.txt b/distribution/changelog.txt index cd4d2fbc96..eae850c95d 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -26,6 +26,7 @@ - Fix: [#11438] Freeze when shrinking map size. - Fix: [#12895] Mechanics are called to repair rides that have already been fixed. - Fix: [#13102] Underflow on height chart (Ride measurements). +- Fix: [#13234] Incorrect vehicle mass after using Remove All Guests cheat. - Fix: [#13236] New ride type appears as new vehicle type in research. - Fix: [#13257] Rides that are exactly the minimum objective length are not counted. - Fix: [#13334] Uninitialised variables in CustomTabDesc. diff --git a/src/openrct2/actions/SetCheatAction.cpp b/src/openrct2/actions/SetCheatAction.cpp index 23addb6928..c07ca57822 100644 --- a/src/openrct2/actions/SetCheatAction.cpp +++ b/src/openrct2/actions/SetCheatAction.cpp @@ -644,7 +644,11 @@ void SetCheatAction::RemoveAllGuests() const auto peep = TryGetEntity(peepInTrainIndex); if (peep != nullptr) { - vehicle->mass -= peep->Mass; + if ((peep->State == PeepState::OnRide && peep->RideSubState == PeepRideSubState::OnRide) + || (peep->State == PeepState::LeavingRide && peep->RideSubState == PeepRideSubState::LeaveVehicle)) + { + vehicle->ApplyMass(-peep->Mass); + } } peepInTrainIndex = SPRITE_INDEX_NULL; } diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index ae099a48f4..5f8dcfaf3f 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -3836,7 +3836,7 @@ void Guest::UpdateRideEnterVehicle() vehicle->num_peeps++; ride->cur_num_customers++; - vehicle->mass += seatedGuest->Mass; + vehicle->ApplyMass(seatedGuest->Mass); seatedGuest->MoveTo({ LOCATION_NULL, 0, 0 }); seatedGuest->SetState(PeepState::OnRide); seatedGuest->GuestTimeOnRide = 0; @@ -3848,7 +3848,7 @@ void Guest::UpdateRideEnterVehicle() vehicle->num_peeps++; ride->cur_num_customers++; - vehicle->mass += Mass; + vehicle->ApplyMass(Mass); vehicle->Invalidate(); MoveTo({ LOCATION_NULL, 0, 0 }); @@ -3897,7 +3897,7 @@ void Guest::UpdateRideLeaveVehicle() ActionSpriteImageOffset = 0; vehicle->num_peeps--; - vehicle->mass -= Mass; + vehicle->ApplyMass(-Mass); vehicle->Invalidate(); if (ride_station >= MAX_STATIONS) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bf7e023ddb..a8ed2e8b5e 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -825,6 +825,11 @@ uint16_t Vehicle::GetTrackProgress() const return vehicle_get_move_info_size(TrackSubposition, GetTrackType(), GetTrackDirection()); } +void Vehicle::ApplyMass(int16_t appliedMass) +{ + mass = std::clamp(mass + appliedMass, 1, std::numeric_limits::max()); +} + void Vehicle::MoveRelativeDistance(int32_t distance) { remaining_distance += distance; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 99fa1a03c7..db97d5c6ef 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -371,6 +371,7 @@ struct Vehicle : SpriteBase { update_flags |= flag; } + void ApplyMass(int16_t appliedMass); private: bool SoundCanPlay() const;