Merge pull request #2561 from HaasJona/refactor

Refactor Ride Customer History
This commit is contained in:
Duncan 2015-12-27 17:52:52 +00:00
commit 1c41b513b4
7 changed files with 153 additions and 75 deletions

View File

@ -1911,7 +1911,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){
peep->destination_y = y;
peep->destination_tolerence = 3;
ride->var_120++;
ride->cur_num_customers++;
peep_on_enter_or_exit_ride(peep, peep->current_ride, 0);
peep->sub_state = 17;
return;
@ -1938,7 +1938,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){
peep->destination_y = y;
peep->current_car = 0;
ride->var_120++;
ride->cur_num_customers++;
peep_on_enter_or_exit_ride(peep, peep->current_ride, 0);
peep->sub_state = 14;
return;
@ -2297,7 +2297,7 @@ static void peep_update_ride_sub_state_5(rct_peep* peep){
return;
vehicle->num_peeps++;
ride->var_120++;
ride->cur_num_customers++;
vehicle->friction += seated_peep->var_41;
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++;
ride->var_120++;
ride->cur_num_customers++;
vehicle->friction += peep->var_41;
invalidate_sprite_2((rct_sprite*)vehicle);
@ -6767,13 +6767,13 @@ static int peep_interact_with_shop(rct_peep* peep, sint16 x, sint16 y, rct_map_e
peep_window_state_update(peep);
peep->time_on_ride = 0;
ride->var_120++;
ride->cur_num_customers++;
if (peep->flags & PEEP_FLAGS_TRACKING){
RCT2_GLOBAL(0x0013CE952, rct_string_id) = peep->name_string_idx;
RCT2_GLOBAL(0x0013CE954, uint32) = peep->id;
RCT2_GLOBAL(0x0013CE958, rct_string_id) = ride->name;
RCT2_GLOBAL(0x0013CE95A, uint32) = ride->name_arguments;
rct_string_id string_id = ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IN_RIDE) ? 1933 : 1932;
rct_string_id string_id = ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IN_RIDE) ? STR_PEEP_TRACKING_PEEP_IS_IN_X : STR_PEEP_TRACKING_PEEP_IS_ON_X;
if (gConfigNotifications.guest_used_facility) {
news_item_add_to_queue(NEWS_ITEM_PEEP_ON_RIDE, string_id, peep->sprite_index);
}
@ -8358,7 +8358,7 @@ loc_69B221:
ride->total_profit += (price - get_shop_item_cost(shopItem));
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
ride->var_120++;
ride->cur_num_customers++;
ride->total_customers++;
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);
ride_update_satisfaction(ride, peep->happiness >> 6);
ride->var_120++;
ride->cur_num_customers++;
ride->total_customers++;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
return true;

View File

@ -275,22 +275,11 @@ money16 get_shop_hot_value(int shopItem)
money32 ride_calculate_income_per_hour(rct_ride *ride)
{
rct_ride_type *entry;
money32 incomePerHour, priceMinusCost;
money32 customersPerHour, priceMinusCost;
int currentShopItem;
entry = GET_RIDE_ENTRY(ride->subtype);
incomePerHour =
ride->var_124 +
ride->var_126 +
ride->var_128 +
ride->var_12A +
ride->var_12C +
ride->var_12E +
ride->age +
ride->running_cost +
ride->var_134 +
ride->var_136;
incomePerHour *= 12;
customersPerHour = ride_customers_per_hour(ride);
priceMinusCost = ride->price;
currentShopItem = entry->shop_item;
@ -310,8 +299,7 @@ money32 ride_calculate_income_per_hour(rct_ride *ride)
priceMinusCost /= 2;
}
incomePerHour *= priceMinusCost;
return incomePerHour;
return customersPerHour * priceMinusCost;
}
/**
@ -1844,21 +1832,17 @@ static void ride_update(int rideIndex)
ride_update_station(ride, i);
// Update financial statistics
ride->var_122++;
if (ride->var_122 >= 960) {
ride->var_122 = 0;
ride->num_customers_timeout++;
ride->var_136 = ride->var_134;
ride->var_134 = ride->running_cost;
ride->running_cost = ride->age;
ride->age = ride->var_12E;
ride->var_12E = ride->var_12C;
ride->var_12C = ride->var_12A;
ride->var_12A = ride->var_128;
ride->var_128 = ride->var_126;
ride->var_126 = ride->var_124;
ride->var_124 = ride->var_120;
ride->var_120 = 0;
if (ride->num_customers_timeout >= 960) {
// This is meant to update about every 30 seconds
ride->num_customers_timeout = 0;
// Shift number of customers history, start of the array is the most recent one
memmove(ride->num_customers + 1, ride->num_customers, 9 * sizeof(*(ride->num_customers)));
ride->num_customers[0] = ride->cur_num_customers;
ride->cur_num_customers = 0;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
ride->income_per_hour = ride_calculate_income_per_hour(ride);
@ -5390,8 +5374,8 @@ foundRideEntry:
ride->measurement_index = 255;
ride->excitement = (ride_rating)-1;
ride->var_120 = 0;
ride->var_122 = 0;
ride->cur_num_customers = 0;
ride->num_customers_timeout = 0;
ride->var_148 = 0;
ride->price = 0;
@ -5443,19 +5427,7 @@ foundRideEntry:
}
}
// The next 10 variables are treated like an array of 10 items
ride->var_124 = 0;
ride->var_124 = 0;
ride->var_126 = 0;
ride->var_128 = 0;
ride->var_12A = 0;
ride->var_12C = 0;
ride->var_12E = 0;
ride->age = 0;
ride->running_cost = 0;
ride->var_134 = 0;
ride->var_136 = 0;
memset(ride->num_customers, 0, 10 * sizeof(ride->num_customers));
ride->value = 0xFFFF;
ride->satisfaction = 255;
ride->satisfaction_time_out = 0;
@ -7382,3 +7354,23 @@ const uint8* ride_seek_available_modes(rct_ride *ride)
return availableModes;
}
// Gets the approximate value of customers per hour for this ride. Multiplies ride_customers_in_last_5_minutes() by 12.
const uint32 ride_customers_per_hour(const rct_ride *ride) {
return ride_customers_in_last_5_minutes(ride) * 12;
}
// 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) {
uint32 sum = ride->num_customers[0]
+ ride->num_customers[1]
+ ride->num_customers[2]
+ ride->num_customers[3]
+ ride->num_customers[4]
+ ride->num_customers[5]
+ ride->num_customers[6]
+ ride->num_customers[7]
+ ride->num_customers[8]
+ ride->num_customers[9];
return sum;
}

View File

@ -201,18 +201,12 @@ typedef struct {
uint8 pad_11C[0x2];
uint8 num_sheltered_sections; // 0x11E
uint8 var_11F;
sint16 var_120;
sint16 var_122;
sint16 var_124;
sint16 var_126;
sint16 var_128;
sint16 var_12A;
sint16 var_12C;
sint16 var_12E;
uint16 age; // 0x130
sint16 running_cost; // 0x132
sint16 var_134;
sint16 var_136;
// Customer counter in the current 960 game tick (about 30 seconds) interval
uint16 cur_num_customers; // 0x120
// 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
sint16 var_13A;
sint16 var_13C;
@ -1019,4 +1013,7 @@ const uint8* ride_seek_available_modes(rct_ride *ride);
void window_ride_construction_mouseup_demolish_next_piece(int x, int y, int z, int direction, int type);
const uint32 ride_customers_per_hour(const rct_ride *ride);
const uint32 ride_customers_in_last_5_minutes(const rct_ride *ride);
#endif

View File

@ -585,6 +585,100 @@ const uint8 rideUnknownData3[0x60] = {
10, // 59 LIM Launched Roller Coaster
};
// Data at 0x0097D21E
const uint8 rideBonusValue[0x60] = {
85, // 00 Spiral Roller coaster
90, // 01 Stand Up Coaster
90, // 02 Suspended Swinging
100, // 03 Inverted
60, // 04 Steel Mini Coaster
50, // 05 Mini Railroad
60, // 06 Monorail
50, // 07 Mini Suspended Coaster
40, // 08 Boat Ride
55, // 09 Wooden Wild Mine/Mouse
60, // 0a Steeplechase/Motorbike/Soap
50, // 0b Car Ride
65, // 0c Launched Freefall
75, // 0d Bobsleigh Coaster
45, // 0e Observation Tower
95, // 0f Looping Roller Coaster
55, // 10 Dinghy Slide
85, // 11 Mine Train Coaster
55, // 12 Chairlift
100, // 13 Corkscrew Roller Coaster
40, // 14 Maze
40, // 15 Spiral Slide
55, // 16 Go Karts
65, // 17 Log Flume
70, // 18 River Rapids
35, // 19 Bumper Cars
35, // 1a Pirate Ship
35, // 1b Swinging Inverter Ship
15, // 1c Food Stall
15, // 1d (none)
15, // 1e Drink Stall
15, // 1f (none)
15, // 20 Shop (all types)
45, // 21 Merry Go Round
15, // 22 Balloon Stall (maybe)
15, // 23 Information Kiosk
5, // 24 Bathroom
45, // 25 Ferris Wheel
45, // 26 Motion Simulator
45, // 27 3D Cinema
55, // 28 Topspin
30, // 29 Space Rings
70, // 2a Reverse Freefall Coaster
45, // 2b Elevator
95, // 2c Vertical Drop Roller Coaster
5, // 2d ATM
40, // 2e Twist
22, // 2f Haunted House
5, // 30 First Aid
39, // 31 Circus Show
50, // 32 Ghost Train
120, // 33 Twister Roller Coaster
105, // 34 Wooden Roller Coaster
65, // 35 Side-Friction Roller Coaster
55, // 36 Wild Mouse
100, // 37 Multi Dimension Coaster
100, // 38 (none)
100, // 39 Flying Roller Coaster
100, // 3a (none)
50, // 3b Virginia Reel
65, // 3c Splash Boats
45, // 3d Mini Helicopters
100, // 3e Lay-down Roller Coaster
60, // 3f Suspended Monorail
100, // 40 (none)
65, // 41 Reverser Roller Coaster
35, // 42 Heartline Twister Roller Coaster
23, // 43 Mini Golf
120, // 44 Giga Coaster
45, // 45 Roto-Drop
35, // 46 Flying Saucers
22, // 47 Crooked House
45, // 48 Monorail Cycles
80, // 49 Compact Inverted Coaster
60, // 4a Water Coaster
70, // 4b Air Powered Vertical Coaster
55, // 4c Inverted Hairpin Coaster
35, // 4d Magic Carpet
40, // 4e Submarine Ride
65, // 4f River Rafts
15, // 50 (none)
45, // 51 Enterprise
15, // 52 (none)
15, // 53 (none)
15, // 54 (none)
100, // 55 (none)
75, // 56 Inverted Impulse Coaster
60, // 57 Mini Roller Coaster
70, // 58 Mine Ride
55, // 59 LIM Launched Roller Coaster
};
const rct_ride_name_convention RideNameConvention[96] = {
{ 1229, 1243, 1257, 0 }, // 00 Spiral Roller coaster
{ 1229, 1243, 1257, 0 }, // 01 Stand Up Coaster

View File

@ -80,6 +80,7 @@ extern const uint8 costPerTrackPiece[0x60];
extern const uint8 rideUnknownData1[0x60];
extern const bool rideUnknownData2[0x60];
extern const uint8 rideUnknownData3[0x60];
extern const uint8 rideBonusValue[0x60];
extern const rct_ride_name_convention RideNameConvention[96];
extern const uint8 RideAvailableModes[];

View File

@ -5970,9 +5970,7 @@ static void window_ride_customer_paint(rct_window *w, rct_drawpixelinfo *dpi)
y = w->y + window_ride_customer_widgets[WIDX_PAGE_BACKGROUND].top + 4;
// Customers per hour
customersPerHour = ride->var_124 + ride->var_126 + ride->var_128 + ride->var_12A + ride->var_12C +
ride->var_12E + ride->age + ride->running_cost + ride->var_134 + ride->var_136;
customersPerHour *= 12;
customersPerHour = ride_customers_per_hour(ride);
gfx_draw_string_left(dpi, STR_CUSTOMERS_PER_HOUR, &customersPerHour, 0, x, y);
y += 10;

View File

@ -30,6 +30,7 @@
#include "../management/research.h"
#include "../peep/peep.h"
#include "../ride/ride.h"
#include "../ride/ride_data.h"
#include "../scenario.h"
#include "../world/map.h"
#include "park.h"
@ -285,12 +286,7 @@ money32 calculate_ride_value(rct_ride *ride)
return 0;
// Fair value * (...)
return (ride->value * 10) * (
ride->var_124 + ride->var_126 + ride->var_128 + ride->var_12A +
ride->var_12C + ride->var_12E + ride->age + ride->running_cost +
ride->var_134 + ride->var_136 +
*((uint8*)(0x0097D21E + (ride->type * 8))) * 4
);
return (ride->value * 10) * (ride_customers_in_last_5_minutes(ride) + rideBonusValue[ride->type] * 4);
}
/**
@ -371,7 +367,7 @@ static int park_calculate_guest_generation_probability()
continue;
// Add guest score for ride type
suggestedMaxGuests += RCT2_GLOBAL(0x0097D21E + (ride->type * 8), uint8);
suggestedMaxGuests += rideBonusValue[ride->type];
// Add ride value
if (ride->value != RIDE_VALUE_UNDEFINED) {
@ -402,7 +398,7 @@ static int park_calculate_guest_generation_probability()
continue;
// Bonus guests for good ride
suggestedMaxGuests += RCT2_GLOBAL(0x0097D21E + (ride->type * 8), uint8) * 2;
suggestedMaxGuests += rideBonusValue[ride->type] * 2;
}
}