Use memmove for shifting

Use memmove for shifting the customer history, rename ride fields, and add back the offset comments.
This commit is contained in:
Jonathan Haas 2015-12-27 10:45:11 +01:00
parent b71c649d45
commit cf78b28adf
3 changed files with 43 additions and 47 deletions

View File

@ -1911,7 +1911,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){
peep->destination_y = y; peep->destination_y = y;
peep->destination_tolerence = 3; peep->destination_tolerence = 3;
ride->customer_counter++; ride->cur_num_customers++;
peep_on_enter_or_exit_ride(peep, peep->current_ride, 0); peep_on_enter_or_exit_ride(peep, peep->current_ride, 0);
peep->sub_state = 17; peep->sub_state = 17;
return; return;
@ -1938,7 +1938,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){
peep->destination_y = y; peep->destination_y = y;
peep->current_car = 0; peep->current_car = 0;
ride->customer_counter++; ride->cur_num_customers++;
peep_on_enter_or_exit_ride(peep, peep->current_ride, 0); peep_on_enter_or_exit_ride(peep, peep->current_ride, 0);
peep->sub_state = 14; peep->sub_state = 14;
return; return;
@ -2297,7 +2297,7 @@ static void peep_update_ride_sub_state_5(rct_peep* peep){
return; return;
vehicle->num_peeps++; vehicle->num_peeps++;
ride->customer_counter++; ride->cur_num_customers++;
vehicle->friction += seated_peep->var_41; vehicle->friction += seated_peep->var_41;
invalidate_sprite_2((rct_sprite*)seated_peep); invalidate_sprite_2((rct_sprite*)seated_peep);
@ -2312,7 +2312,7 @@ static void peep_update_ride_sub_state_5(rct_peep* peep){
} }
vehicle->num_peeps++; vehicle->num_peeps++;
ride->customer_counter++; ride->cur_num_customers++;
vehicle->friction += peep->var_41; vehicle->friction += peep->var_41;
invalidate_sprite_2((rct_sprite*)vehicle); invalidate_sprite_2((rct_sprite*)vehicle);
@ -6767,7 +6767,7 @@ static int peep_interact_with_shop(rct_peep* peep, sint16 x, sint16 y, rct_map_e
peep_window_state_update(peep); peep_window_state_update(peep);
peep->time_on_ride = 0; peep->time_on_ride = 0;
ride->customer_counter++; ride->cur_num_customers++;
if (peep->flags & PEEP_FLAGS_TRACKING){ if (peep->flags & PEEP_FLAGS_TRACKING){
RCT2_GLOBAL(0x0013CE952, rct_string_id) = peep->name_string_idx; RCT2_GLOBAL(0x0013CE952, rct_string_id) = peep->name_string_idx;
RCT2_GLOBAL(0x0013CE954, uint32) = peep->id; RCT2_GLOBAL(0x0013CE954, uint32) = peep->id;
@ -8358,7 +8358,7 @@ loc_69B221:
ride->total_profit += (price - get_shop_item_cost(shopItem)); ride->total_profit += (price - get_shop_item_cost(shopItem));
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
ride->customer_counter++; ride->cur_num_customers++;
ride->total_customers++; ride->total_customers++;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
@ -8379,7 +8379,7 @@ static bool peep_should_use_cash_machine(rct_peep *peep, int rideIndex)
rct_ride *ride = GET_RIDE(rideIndex); rct_ride *ride = GET_RIDE(rideIndex);
ride_update_satisfaction(ride, peep->happiness >> 6); ride_update_satisfaction(ride, peep->happiness >> 6);
ride->customer_counter++; ride->cur_num_customers++;
ride->total_customers++; ride->total_customers++;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
return true; return true;

View File

@ -1832,23 +1832,17 @@ static void ride_update(int rideIndex)
ride_update_station(ride, i); ride_update_station(ride, i);
// Update financial statistics // Update financial statistics
ride->statistics_tick_counter++; ride->num_customers_timeout++;
if (ride->statistics_tick_counter >= 960) { if (ride->num_customers_timeout >= 960) {
// This is meant to update about every 30 seconds // This is meant to update about every 30 seconds
ride->statistics_tick_counter = 0; ride->num_customers_timeout = 0;
ride->customer_count_history[9] = ride->customer_count_history[8]; // Shift number of customers history, start of the array is the most recent one
ride->customer_count_history[8] = ride->customer_count_history[7]; memmove(ride->num_customers + 1, ride->num_customers, 9 * sizeof(*(ride->num_customers)));
ride->customer_count_history[7] = ride->customer_count_history[6]; ride->num_customers[0] = ride->cur_num_customers;
ride->customer_count_history[6] = ride->customer_count_history[5];
ride->customer_count_history[5] = ride->customer_count_history[4]; ride->cur_num_customers = 0;
ride->customer_count_history[4] = ride->customer_count_history[3];
ride->customer_count_history[3] = ride->customer_count_history[2];
ride->customer_count_history[2] = ride->customer_count_history[1];
ride->customer_count_history[1] = ride->customer_count_history[0];
ride->customer_count_history[0] = ride->customer_counter;
ride->customer_counter = 0;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
ride->income_per_hour = ride_calculate_income_per_hour(ride); ride->income_per_hour = ride_calculate_income_per_hour(ride);
@ -5380,8 +5374,8 @@ foundRideEntry:
ride->measurement_index = 255; ride->measurement_index = 255;
ride->excitement = (ride_rating)-1; ride->excitement = (ride_rating)-1;
ride->customer_counter = 0; ride->cur_num_customers = 0;
ride->statistics_tick_counter = 0; ride->num_customers_timeout = 0;
ride->var_148 = 0; ride->var_148 = 0;
ride->price = 0; ride->price = 0;
@ -5433,17 +5427,16 @@ foundRideEntry:
} }
} }
ride->customer_counter = 0; ride->num_customers[0] = 0;
ride->customer_count_history[0] = 0; ride->num_customers[1] = 0;
ride->customer_count_history[1] = 0; ride->num_customers[2] = 0;
ride->customer_count_history[2] = 0; ride->num_customers[3] = 0;
ride->customer_count_history[3] = 0; ride->num_customers[4] = 0;
ride->customer_count_history[4] = 0; ride->num_customers[5] = 0;
ride->customer_count_history[5] = 0; ride->num_customers[6] = 0;
ride->customer_count_history[6] = 0; ride->num_customers[7] = 0;
ride->customer_count_history[7] = 0; ride->num_customers[8] = 0;
ride->customer_count_history[8] = 0; ride->num_customers[9] = 0;
ride->customer_count_history[9] = 0;
ride->value = 0xFFFF; ride->value = 0xFFFF;
ride->satisfaction = 255; ride->satisfaction = 255;
@ -7379,15 +7372,15 @@ const uint32 ride_customers_per_hour(const rct_ride *ride) {
// Calculates the number of customers for this ride in the last 5 minutes (or more correctly 9600 game ticks) // Calculates the number of customers for this ride in the last 5 minutes (or more correctly 9600 game ticks)
const uint32 ride_customers_in_last_5_minutes(const rct_ride *ride) { const uint32 ride_customers_in_last_5_minutes(const rct_ride *ride) {
uint32 sum = ride->customer_count_history[0] uint32 sum = ride->num_customers[0]
+ ride->customer_count_history[1] + ride->num_customers[1]
+ ride->customer_count_history[2] + ride->num_customers[2]
+ ride->customer_count_history[3] + ride->num_customers[3]
+ ride->customer_count_history[4] + ride->num_customers[4]
+ ride->customer_count_history[5] + ride->num_customers[5]
+ ride->customer_count_history[6] + ride->num_customers[6]
+ ride->customer_count_history[7] + ride->num_customers[7]
+ ride->customer_count_history[8] + ride->num_customers[8]
+ ride->customer_count_history[9]; + ride->num_customers[9];
return sum; return sum;
} }

View File

@ -201,9 +201,12 @@ typedef struct {
uint8 pad_11C[0x2]; uint8 pad_11C[0x2];
uint8 num_sheltered_sections; // 0x11E uint8 num_sheltered_sections; // 0x11E
uint8 var_11F; uint8 var_11F;
uint16 customer_counter; // Customer count in the current 960 game tick (about 30 seconds) interval // Customer counter in the current 960 game tick (about 30 seconds) interval
uint16 statistics_tick_counter; // Counts ticks to update customer intervals, resets each 960 game ticks. uint16 cur_num_customers; // 0x120
uint16 customer_count_history[10]; // Customer count in the last 10 * 960 game ticks // Counts ticks to update customer intervals, resets each 960 game ticks.
uint16 num_customers_timeout; // 0x122
// Customer count in the last 10 * 960 game ticks (sliding window)
uint16 num_customers[10]; // 0x124
money16 price; // 0x138 money16 price; // 0x138
sint16 var_13A; sint16 var_13A;
sint16 var_13C; sint16 var_13C;