diff --git a/src/ride.c b/src/ride.c index 0e21718909..da87ccce29 100644 --- a/src/ride.c +++ b/src/ride.c @@ -26,6 +26,7 @@ #include "staff.h" #include "sprite.h" #include "ride.h" +#include "ride_data.h" #include "scenario.h" #include "sprite.h" #include "peep.h" @@ -699,7 +700,7 @@ void ride_measurement_update(rct_ride_measurement *measurement) verticalG = clamp(-127, verticalG / 8, 127); lateralG = clamp(-127, lateralG / 8, 127); - if (RCT2_GLOBAL(0x00F663AC, uint32) & 1) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, uint32) & 1) { verticalG = (verticalG + measurement->vertical[measurement->current_item]) / 2; lateralG = (lateralG + measurement->lateral[measurement->current_item]) / 2; } @@ -711,7 +712,7 @@ void ride_measurement_update(rct_ride_measurement *measurement) velocity = min(abs((vehicle->velocity * 5) >> 16), 255); altitude = min(vehicle->z / 8, 255); - if (RCT2_GLOBAL(0x00F663AC, uint32) & 1) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, uint32) & 1) { velocity = (velocity + measurement->velocity[measurement->current_item]) / 2; altitude = (altitude + measurement->altitude[measurement->current_item]) / 2; } @@ -719,7 +720,7 @@ void ride_measurement_update(rct_ride_measurement *measurement) measurement->velocity[measurement->current_item] = velocity & 0xFF; measurement->altitude[measurement->current_item] = altitude & 0xFF; - if (RCT2_GLOBAL(0x00F663AC, uint32) & 1) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, uint32) & 1) { measurement->current_item++; measurement->num_items = max(measurement->num_items, measurement->current_item); } @@ -771,4 +772,75 @@ void ride_measurements_update() } } +} + +/** + * + * rct2: 0x006B66D9 + */ +rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message) +{ + rct_ride *ride; + rct_ride_measurement *measurement; + uint32 lruTicks; + int i, lruIndex; + + ride = GET_RIDE(rideIndex); + + // Check if ride type supports data logging + if (!(RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8), uint32) & 0x200)) { + if (message != NULL) *message = STR_DATA_LOGGING_NOT_AVAILABLE_FOR_THIS_TYPE_OF_RIDE; + return NULL; + } + + // Check if a measurement already exists for this ride + for (i = 0; i < MAX_RIDE_MEASUREMENTS; i++) { + measurement = GET_RIDE_MEASUREMENT(i); + if (measurement->ride_index == i) + goto use_measurement; + } + + // Find a free measurement + for (i = 0; i < MAX_RIDE_MEASUREMENTS; i++) { + measurement = GET_RIDE_MEASUREMENT(i); + if (measurement->ride_index == 255) + goto new_measurement; + } + + // Use last recently used measurement for some other ride + lruIndex = 0; + lruTicks = 0xFFFFFFFF; + for (i = 0; i < MAX_RIDE_MEASUREMENTS; i++) { + measurement = GET_RIDE_MEASUREMENT(i); + + if (measurement->last_use_tick <= lruTicks) { + lruTicks = measurement->last_use_tick; + lruIndex = i; + } + } + + i = lruIndex; + measurement = GET_RIDE_MEASUREMENT(i); + ride->measurement_index = 255; + +new_measurement: + measurement->ride_index = rideIndex; + ride->measurement_index = i; + measurement->flags = 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8), uint32) & 0x80) + measurement->flags |= RIDE_MEASUREMENT_FLAG_G_FORCES; + measurement->num_items = 0; + measurement->current_item = 0; + +use_measurement: + measurement->last_use_tick = RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, uint32); + if (measurement->flags & 1) { + if (message != NULL) *message = 0; + return measurement; + } else { + RCT2_GLOBAL(0x013CE952, uint16) = RideNameConvention[ride->type].vehicle_name; + RCT2_GLOBAL(0x013CE952 + 2, uint16) = RideNameConvention[ride->type].station_name; + if (message != NULL) *message = STR_DATA_LOGGING_WILL_START_WHEN_NEXT_LEAVES; + return NULL; + } } \ No newline at end of file diff --git a/src/ride.h b/src/ride.h index 7f3d0e0e53..34b040a707 100644 --- a/src/ride.h +++ b/src/ride.h @@ -106,7 +106,9 @@ typedef struct { uint8 min_waiting_time; // 0x0CE uint8 max_waiting_time; // 0x0CF uint8 var_0D0; - uint8 pad_0D1[0x7]; + uint8 pad_0D1[0x3]; + uint8 measurement_index; // 0x0D4 + uint8 pad_0D5[0x3]; sint32 max_speed; // 0x0D8 sint32 average_speed; // 0x0DC uint8 pad_0E0[0x4]; @@ -199,8 +201,8 @@ typedef struct { */ typedef struct { uint8 ride_index; // 0x0000 - uint8 flags; - uint8 pad_02[4]; + uint8 flags; // 0x0001 + uint32 last_use_tick; // 0x0002 uint16 num_items; // 0x0006 uint16 current_item; // 0x0008 uint8 vehicle_index; // 0x000A @@ -549,5 +551,6 @@ vehicle_colour ride_get_vehicle_colour(rct_ride *ride, int vehicleIndex); rct_ride_type *ride_get_entry(rct_ride *ride); uint8 *get_ride_entry_indices_for_ride_type(uint8 rideType); void ride_measurements_update(); +rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message); #endif diff --git a/src/string_ids.h b/src/string_ids.h index 49d8eced3d..9cf960b8f6 100644 --- a/src/string_ids.h +++ b/src/string_ids.h @@ -474,6 +474,8 @@ enum { STR_BUILD_THIS = 1407, STR_COST_LABEL = 1408, + STR_DATA_LOGGING_NOT_AVAILABLE_FOR_THIS_TYPE_OF_RIDE = 1412, + STR_DATA_LOGGING_WILL_START_WHEN_NEXT_LEAVES = 1413, STR_LOGGING_DATA_FROM_TIP = 1422, STR_QUEUE_LINE_PATH_TIP = 1423, STR_FOOTPATH_TIP = 1424, diff --git a/src/window_ride.c b/src/window_ride.c index d937d0f05e..4b80aa6f4f 100644 --- a/src/window_ride.c +++ b/src/window_ride.c @@ -4612,28 +4612,6 @@ enum { GRAPH_LATERAL }; -/** - * - * rct2: 0x006B66D9 - */ -rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message) -{ - int eax, ebx, ecx, edx, esi, edi, ebp; - edx = rideIndex; - - RCT2_CALLFUNC_X(0x006B66D9, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - eax &= 0xFFFF; - - if ((eax & 0xFF) < 10) { - eax &= 0xFF; - return GET_RIDE_MEASUREMENT(eax); - } else { - if (message != NULL) - *message = eax; - return NULL; - } -} - /** * * rct2: 0x006AE8A6