diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 4a69b03d5a..9a2763b525 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1792,7 +1792,7 @@ void peep_decrement_num_riders(rct_peep * peep) { Ride * ride = get_ride(peep->current_ride); - ride->num_riders--; + ride->num_riders = std::max(0, ride->num_riders - 1); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; } } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 36425fb03a..ef59e89a46 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -49,6 +49,7 @@ #include "../world/Entrance.h" #include "../world/MapAnimation.h" #include "../world/Park.h" +#include "../world/Sprite.h" class ObjectLoadException : public std::runtime_error { @@ -471,7 +472,7 @@ public: void ImportRides() { - for (uint16 index = 0; index < RCT12_MAX_RIDES_IN_PARK; index++) + for (uint8 index = 0; index < RCT12_MAX_RIDES_IN_PARK; index++) { auto src = &_s6.rides[index]; auto dst = get_ride(index); @@ -482,12 +483,12 @@ public: } else { - ImportRide(dst, src); + ImportRide(dst, src, index); } } } - void ImportRide(Ride * dst, const rct2_ride * src) + void ImportRide(Ride * dst, const rct2_ride * src, const uint8 rideIndex) { memset(dst, 0, sizeof(Ride)); @@ -629,7 +630,21 @@ public: dst->popularity = src->popularity; dst->popularity_time_out = src->popularity_time_out; dst->popularity_next = src->popularity_next; - dst->num_riders = src->num_riders; + + // The number of riders might have overflown or underflow. Re-calculate the value. + uint16 numRiders = 0; + for (const rct_sprite sprite : _s6.sprites) + { + if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP) + { + if (sprite.peep.state == PEEP_STATE_ON_RIDE && sprite.peep.current_ride == rideIndex) + { + numRiders++; + } + } + } + dst->num_riders = numRiders; + dst->music_tune_id = src->music_tune_id; dst->slide_in_use = src->slide_in_use; // Includes maze_tiles diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 56fe0ec205..f4e0999327 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -268,7 +268,7 @@ typedef struct Ride { uint8 popularity; // 0x158 uint8 popularity_time_out; // 0x159 Updated every purchase and ?possibly by time? uint8 popularity_next; // 0x15A When timeout reached this will be the next popularity - uint8 num_riders; // 0x15B + uint8 num_riders_rct2; // 0x15B uint8 music_tune_id; // 0x15C uint8 slide_in_use; // 0x15D union { @@ -341,7 +341,8 @@ typedef struct Ride { uint8 pad_1FD; // 0x1FD uint16 cable_lift; // 0x1FE uint16 queue_length[MAX_STATIONS]; // 0x200 - uint8 pad_208[0x58]; // 0x208 + uint16 num_riders; // 0x208 + uint8 pad_210[0x56]; // 0x210 } Ride; assert_struct_size(Ride, 0x260);