Port more functions to Ride struct (#9119)

This commit is contained in:
Michael Steenbeek 2019-04-20 22:22:39 +02:00 committed by GitHub
parent 42a1a8704d
commit 5a906b2378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 147 additions and 140 deletions

View File

@ -1320,7 +1320,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo* dpi, rct_window* w)
Ride* ride = get_ride(w->number); Ride* ride = get_ride(w->number);
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
if (rideEntry->flags & RIDE_ENTRY_FLAG_VEHICLE_TAB_SCALE_HALF) if (rideEntry->flags & RIDE_ENTRY_FLAG_VEHICLE_TAB_SCALE_HALF)
{ {
clipDPI.zoom_level = 1; clipDPI.zoom_level = 1;
@ -1856,7 +1856,7 @@ static void window_ride_init_viewport(rct_window* w)
{ {
focus.sprite.sprite_id = ride->vehicles[eax]; focus.sprite.sprite_id = ride->vehicles[eax];
rct_ride_entry* ride_entry = get_ride_entry_by_ride(ride); rct_ride_entry* ride_entry = ride->GetRideEntry();
if (ride_entry && ride_entry->tab_vehicle != 0) if (ride_entry && ride_entry->tab_vehicle != 0)
{ {
rct_vehicle* vehicle = GET_VEHICLE(focus.sprite.sprite_id); rct_vehicle* vehicle = GET_VEHICLE(focus.sprite.sprite_id);
@ -2250,7 +2250,7 @@ static void window_ride_show_ride_type_dropdown(rct_window* w, rct_widget* widge
static void populate_vehicle_type_dropdown(Ride* ride) static void populate_vehicle_type_dropdown(Ride* ride)
{ {
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
bool selectionShouldBeExpanded; bool selectionShouldBeExpanded;
int32_t rideTypeIterator, rideTypeIteratorMax; int32_t rideTypeIterator, rideTypeIteratorMax;
@ -2882,7 +2882,7 @@ static void window_ride_vehicle_mousedown(rct_window* w, rct_widgetindex widgetI
ride->SetNumCarsPerVehicle(ride->num_cars_per_train + 1); ride->SetNumCarsPerVehicle(ride->num_cars_per_train + 1);
break; break;
case WIDX_VEHICLE_CARS_PER_TRAIN_DECREASE: case WIDX_VEHICLE_CARS_PER_TRAIN_DECREASE:
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
if (ride->num_cars_per_train > rideEntry->zero_cars + 1) if (ride->num_cars_per_train > rideEntry->zero_cars + 1)
ride->SetNumCarsPerVehicle(ride->num_cars_per_train - 1); ride->SetNumCarsPerVehicle(ride->num_cars_per_train - 1);
break; break;
@ -2947,7 +2947,7 @@ static void window_ride_vehicle_invalidate(rct_window* w)
window_ride_set_pressed_tab(w); window_ride_set_pressed_tab(w);
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
set_format_arg(0, rct_string_id, ride->name); set_format_arg(0, rct_string_id, ride->name);
set_format_arg(2, uint32_t, ride->name_arguments); set_format_arg(2, uint32_t, ride->name_arguments);
@ -3042,7 +3042,7 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi)
window_ride_draw_tab_images(dpi, w); window_ride_draw_tab_images(dpi, w);
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
x = w->x + 8; x = w->x + 8;
y = w->y + 64; y = w->y + 64;
@ -3104,7 +3104,7 @@ static rct_vehicle_paintinfo _sprites_to_draw[144];
static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
{ {
Ride* ride = get_ride(w->number); Ride* ride = get_ride(w->number);
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
// Background // Background
gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width, dpi->y + dpi->height, PALETTE_INDEX_12); gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width, dpi->y + dpi->height, PALETTE_INDEX_12);
@ -3534,7 +3534,7 @@ static void window_ride_operating_invalidate(rct_window* w)
} }
// Number of circuits // Number of circuits
if (ride_can_have_multiple_circuits(ride)) if (ride->CanHaveMultipleCircuits())
{ {
window_ride_operating_widgets[WIDX_OPERATE_NUMBER_OF_CIRCUITS_LABEL].type = WWT_LABEL; window_ride_operating_widgets[WIDX_OPERATE_NUMBER_OF_CIRCUITS_LABEL].type = WWT_LABEL;
window_ride_operating_widgets[WIDX_OPERATE_NUMBER_OF_CIRCUITS].type = WWT_SPINNER; window_ride_operating_widgets[WIDX_OPERATE_NUMBER_OF_CIRCUITS].type = WWT_SPINNER;
@ -4364,7 +4364,7 @@ static void window_ride_colour_mousedown(rct_window* w, rct_widgetindex widgetIn
rct_string_id stringId; rct_string_id stringId;
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
colourSchemeIndex = w->ride_colour; colourSchemeIndex = w->ride_colour;
dropdownWidget = widget - 1; dropdownWidget = widget - 1;
@ -4633,7 +4633,7 @@ static void window_ride_colour_invalidate(rct_window* w)
window_ride_set_pressed_tab(w); window_ride_set_pressed_tab(w);
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
set_format_arg(0, rct_string_id, ride->name); set_format_arg(0, rct_string_id, ride->name);
set_format_arg(2, uint32_t, ride->name_arguments); set_format_arg(2, uint32_t, ride->name_arguments);
@ -4849,7 +4849,7 @@ static void window_ride_colour_paint(rct_window* w, rct_drawpixelinfo* dpi)
rct_ride_entry* rideEntry; rct_ride_entry* rideEntry;
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
window_draw_widgets(w, dpi); window_draw_widgets(w, dpi);
window_ride_draw_tab_images(dpi, w); window_ride_draw_tab_images(dpi, w);
@ -4958,7 +4958,7 @@ static void window_ride_colour_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
vehicle_colour vehicleColour; vehicle_colour vehicleColour;
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
vehiclePreviewWidget = &window_ride_colour_widgets[WIDX_VEHICLE_PREVIEW]; vehiclePreviewWidget = &window_ride_colour_widgets[WIDX_VEHICLE_PREVIEW];
vehicleColour = ride_get_vehicle_colour(ride, w->vehicleIndex); vehicleColour = ride_get_vehicle_colour(ride, w->vehicleIndex);
@ -6465,7 +6465,7 @@ static void window_ride_income_invalidate(rct_window* w)
set_format_arg(0, rct_string_id, ride->name); set_format_arg(0, rct_string_id, ride->name);
set_format_arg(2, uint32_t, ride->name_arguments); set_format_arg(2, uint32_t, ride->name_arguments);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
// Primary item // Primary item
w->pressed_widgets &= ~(1 << WIDX_PRIMARY_PRICE_SAME_THROUGHOUT_PARK); w->pressed_widgets &= ~(1 << WIDX_PRIMARY_PRICE_SAME_THROUGHOUT_PARK);
@ -6563,7 +6563,7 @@ static void window_ride_income_paint(rct_window* w, rct_drawpixelinfo* dpi)
window_ride_draw_tab_images(dpi, w); window_ride_draw_tab_images(dpi, w);
ride = get_ride(w->number); ride = get_ride(w->number);
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
x = w->x + window_ride_income_widgets[WIDX_PAGE_BACKGROUND].left + 4; x = w->x + window_ride_income_widgets[WIDX_PAGE_BACKGROUND].left + 4;
y = w->y + window_ride_income_widgets[WIDX_PAGE_BACKGROUND].top + 33; y = w->y + window_ride_income_widgets[WIDX_PAGE_BACKGROUND].top + 33;
@ -6820,14 +6820,14 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi)
// Queue time // Queue time
if (gRideClassifications[ride->type] == RIDE_CLASS_RIDE) if (gRideClassifications[ride->type] == RIDE_CLASS_RIDE)
{ {
queueTime = ride_get_max_queue_time(ride); queueTime = ride->GetMaxQueueTime();
stringId = queueTime == 1 ? STR_QUEUE_TIME_MINUTE : STR_QUEUE_TIME_MINUTES; stringId = queueTime == 1 ? STR_QUEUE_TIME_MINUTE : STR_QUEUE_TIME_MINUTES;
y += gfx_draw_string_left_wrapped(dpi, &queueTime, x, y, 308, stringId, COLOUR_BLACK); y += gfx_draw_string_left_wrapped(dpi, &queueTime, x, y, 308, stringId, COLOUR_BLACK);
y += 5; y += 5;
} }
// Primary shop items sold // Primary shop items sold
shopItem = get_ride_entry_by_ride(ride)->shop_item; shopItem = ride->GetRideEntry()->shop_item;
if (shopItem != SHOP_ITEM_NONE) if (shopItem != SHOP_ITEM_NONE)
{ {
set_format_arg(0, rct_string_id, ShopItemStringIds[shopItem].plural); set_format_arg(0, rct_string_id, ShopItemStringIds[shopItem].plural);
@ -6838,7 +6838,7 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi)
// Secondary shop items sold / on-ride photos sold // Secondary shop items sold / on-ride photos sold
shopItem = (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) ? RidePhotoItems[ride->type] shopItem = (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) ? RidePhotoItems[ride->type]
: get_ride_entry_by_ride(ride)->shop_item_secondary; : ride->GetRideEntry()->shop_item_secondary;
if (shopItem != SHOP_ITEM_NONE) if (shopItem != SHOP_ITEM_NONE)
{ {
set_format_arg(0, rct_string_id, ShopItemStringIds[shopItem].plural); set_format_arg(0, rct_string_id, ShopItemStringIds[shopItem].plural);

View File

@ -2526,7 +2526,7 @@ void window_ride_construction_update_active_elements_impl()
void window_ride_construction_update_enabled_track_pieces() void window_ride_construction_update_enabled_track_pieces()
{ {
Ride* ride = get_ride(_currentRideIndex); Ride* ride = get_ride(_currentRideIndex);
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
int32_t rideType = (_currentTrackAlternative & RIDE_TYPE_ALTERNATIVE_TRACK_TYPE) ? RideData4[ride->type].alternate_type int32_t rideType = (_currentTrackAlternative & RIDE_TYPE_ALTERNATIVE_TRACK_TYPE) ? RideData4[ride->type].alternate_type
: ride->type; : ride->type;

View File

@ -695,7 +695,7 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
} }
break; break;
case INFORMATION_TYPE_QUEUE_LENGTH: case INFORMATION_TYPE_QUEUE_LENGTH:
set_format_arg(2, uint16_t, ride_get_total_queue_length(ride)); set_format_arg(2, uint16_t, ride->GetTotalQueueLength());
formatSecondary = STR_QUEUE_EMPTY; formatSecondary = STR_QUEUE_EMPTY;
{ {
uint16_t arg; uint16_t arg;
@ -708,7 +708,7 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
} }
break; break;
case INFORMATION_TYPE_QUEUE_TIME: case INFORMATION_TYPE_QUEUE_TIME:
set_format_arg(2, uint16_t, ride_get_max_queue_time(ride)); set_format_arg(2, uint16_t, ride->GetMaxQueueTime());
formatSecondary = STR_QUEUE_TIME_LABEL; formatSecondary = STR_QUEUE_TIME_LABEL;
{ {
uint16_t arg; uint16_t arg;
@ -906,7 +906,7 @@ void window_ride_list_refresh_list(rct_window* w)
while (--current_list_position >= 0) while (--current_list_position >= 0)
{ {
otherRide = get_ride(w->list_item_positions[current_list_position]); otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride_get_total_queue_length(ride) <= ride_get_total_queue_length(otherRide)) if (ride->GetTotalQueueLength() <= otherRide->GetTotalQueueLength())
break; break;
window_bubble_list_item(w, current_list_position); window_bubble_list_item(w, current_list_position);
@ -916,7 +916,7 @@ void window_ride_list_refresh_list(rct_window* w)
while (--current_list_position >= 0) while (--current_list_position >= 0)
{ {
otherRide = get_ride(w->list_item_positions[current_list_position]); otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride_get_max_queue_time(ride) <= ride_get_max_queue_time(otherRide)) if (ride->GetMaxQueueTime() <= otherRide->GetMaxQueueTime())
break; break;
window_bubble_list_item(w, current_list_position); window_bubble_list_item(w, current_list_position);

View File

@ -260,7 +260,7 @@ void GameState::UpdateLogic()
map_restore_provisional_elements(); map_restore_provisional_elements();
vehicle_update_all(); vehicle_update_all();
sprite_misc_update_all(); sprite_misc_update_all();
ride_update_all(); Ride::UpdateAll();
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR)) if (!(gScreenFlags & SCREEN_FLAGS_EDITOR))
{ {

View File

@ -260,7 +260,7 @@ private:
Ride* ride = get_ride(rideIndex); Ride* ride = get_ride(rideIndex);
if (ride != nullptr) if (ride != nullptr)
{ {
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
if (rideEntry != nullptr) if (rideEntry != nullptr)
{ {
int32_t maxHeight = rideEntry->max_height; int32_t maxHeight = rideEntry->max_height;

View File

@ -3736,7 +3736,7 @@ static void peep_update_ride_no_free_vehicle_rejoin_queue(Peep* peep, Ride* ride
peep->SetState(PEEP_STATE_QUEUING_FRONT); peep->SetState(PEEP_STATE_QUEUING_FRONT);
peep->sub_state = PEEP_RIDE_AT_ENTRANCE; peep->sub_state = PEEP_RIDE_AT_ENTRANCE;
ride_queue_insert_guest_at_front(ride, peep->current_ride_station, peep); ride->QueueInsertGuestAtFront(peep->current_ride_station, peep);
} }
/** /**

View File

@ -205,7 +205,6 @@ static void ride_breakdown_status_update(Ride* ride);
static void ride_breakdown_update(Ride* ride); static void ride_breakdown_update(Ride* ride);
static void ride_call_closest_mechanic(Ride* ride); static void ride_call_closest_mechanic(Ride* ride);
static void ride_call_mechanic(Ride* ride, Peep* mechanic, int32_t forInspection); static void ride_call_mechanic(Ride* ride, Peep* mechanic, int32_t forInspection);
static void ride_chairlift_update(Ride* ride);
static void ride_entrance_exit_connected(Ride* ride); static void ride_entrance_exit_connected(Ride* ride);
static void ride_set_name_to_vehicle_default(Ride* ride, rct_ride_entry* rideEntry); static void ride_set_name_to_vehicle_default(Ride* ride, rct_ride_entry* rideEntry);
static int32_t ride_get_new_breakdown_problem(Ride* ride); static int32_t ride_get_new_breakdown_problem(Ride* ride);
@ -213,8 +212,6 @@ static void ride_inspection_update(Ride* ride);
static void ride_mechanic_status_update(Ride* ride, int32_t mechanicStatus); static void ride_mechanic_status_update(Ride* ride, int32_t mechanicStatus);
static void ride_music_update(Ride* ride); static void ride_music_update(Ride* ride);
static void ride_shop_connected(Ride* ride); static void ride_shop_connected(Ride* ride);
static void ride_spiral_slide_update(Ride* ride);
static void ride_update(Ride* ride);
void loc_6DDF9C(Ride* ride, TileElement* tileElement); void loc_6DDF9C(Ride* ride, TileElement* tileElement);
Ride* get_ride(int32_t index) Ride* get_ride(int32_t index)
@ -263,16 +260,16 @@ rct_ride_measurement* get_ride_measurement(int32_t index)
return &gRideMeasurements[index]; return &gRideMeasurements[index];
} }
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride) rct_ride_entry* Ride::GetRideEntry() const
{ {
rct_ride_entry* type = get_ride_entry(ride->subtype); rct_ride_entry* rideEntry = get_ride_entry(subtype);
if (type == nullptr) if (rideEntry == nullptr)
{ {
char oldname[128]; char oldname[128];
format_string(oldname, 128, ride->name, &ride->name_arguments); format_string(oldname, 128, name, &name_arguments);
log_error("Invalid ride subtype for ride %s", oldname); log_error("Invalid ride subtype for ride %s", oldname);
} }
return type; return rideEntry;
} }
/** /**
@ -344,29 +341,29 @@ int32_t ride_get_count()
return count; return count;
} }
int32_t ride_get_total_queue_length(Ride* ride) int32_t Ride::GetTotalQueueLength() const
{ {
int32_t i, queueLength = 0; int32_t i, queueLength = 0;
for (i = 0; i < MAX_STATIONS; i++) for (i = 0; i < MAX_STATIONS; i++)
if (!ride_get_entrance_location(ride, i).isNull()) if (!ride_get_entrance_location(this, i).isNull())
queueLength += ride->stations[i].QueueLength; queueLength += stations[i].QueueLength;
return queueLength; return queueLength;
} }
int32_t ride_get_max_queue_time(Ride* ride) int32_t Ride::GetMaxQueueTime() const
{ {
uint8_t i, queueTime = 0; uint8_t i, queueTime = 0;
for (i = 0; i < MAX_STATIONS; i++) for (i = 0; i < MAX_STATIONS; i++)
if (!ride_get_entrance_location(ride, i).isNull()) if (!ride_get_entrance_location(this, i).isNull())
queueTime = std::max(queueTime, ride->stations[i].QueueTime); queueTime = std::max(queueTime, stations[i].QueueTime);
return (int32_t)queueTime; return (int32_t)queueTime;
} }
Peep* ride_get_queue_head_guest(Ride* ride, int32_t stationIndex) Peep* Ride::GetQueueHeadGuest(int32_t stationIndex) const
{ {
Peep* peep; Peep* peep;
Peep* result = nullptr; Peep* result = nullptr;
uint16_t spriteIndex = ride->stations[stationIndex].LastPeepInQueue; uint16_t spriteIndex = stations[stationIndex].LastPeepInQueue;
while ((peep = try_get_guest(spriteIndex)) != nullptr) while ((peep = try_get_guest(spriteIndex)) != nullptr)
{ {
spriteIndex = peep->next_in_queue; spriteIndex = peep->next_in_queue;
@ -375,36 +372,35 @@ Peep* ride_get_queue_head_guest(Ride* ride, int32_t stationIndex)
return result; return result;
} }
static void ride_update_queue_length(Ride* ride, int32_t stationIndex) void Ride::UpdateQueueLength(int32_t stationIndex)
{ {
uint16_t count = 0; uint16_t count = 0;
Peep* peep; Peep* peep;
uint16_t spriteIndex = ride->stations[stationIndex].LastPeepInQueue; uint16_t spriteIndex = stations[stationIndex].LastPeepInQueue;
while ((peep = try_get_guest(spriteIndex)) != nullptr) while ((peep = try_get_guest(spriteIndex)) != nullptr)
{ {
spriteIndex = peep->next_in_queue; spriteIndex = peep->next_in_queue;
count++; count++;
} }
ride->stations[stationIndex].QueueLength = count; stations[stationIndex].QueueLength = count;
} }
void ride_queue_insert_guest_at_front(Ride* ride, int32_t stationIndex, Peep* peep) void Ride::QueueInsertGuestAtFront(int32_t stationIndex, Peep* peep)
{ {
assert(ride != nullptr);
assert(stationIndex < MAX_STATIONS); assert(stationIndex < MAX_STATIONS);
assert(peep != nullptr); assert(peep != nullptr);
peep->next_in_queue = SPRITE_INDEX_NULL; peep->next_in_queue = SPRITE_INDEX_NULL;
Peep* queueHeadGuest = ride_get_queue_head_guest(ride, peep->current_ride_station); Peep* queueHeadGuest = GetQueueHeadGuest(peep->current_ride_station);
if (queueHeadGuest == nullptr) if (queueHeadGuest == nullptr)
{ {
ride->stations[peep->current_ride_station].LastPeepInQueue = peep->sprite_index; stations[peep->current_ride_station].LastPeepInQueue = peep->sprite_index;
} }
else else
{ {
queueHeadGuest->next_in_queue = peep->sprite_index; queueHeadGuest->next_in_queue = peep->sprite_index;
} }
ride_update_queue_length(ride, peep->current_ride_station); UpdateQueueLength(peep->current_ride_station);
} }
/** /**
@ -440,16 +436,16 @@ void ride_update_favourited_stat()
* *
* rct2: 0x006AC3AB * rct2: 0x006AC3AB
*/ */
static money32 ride_calculate_income_per_hour(Ride* ride) money32 Ride::CalculateIncomePerHour() const
{ {
// Get entry by ride to provide better reporting // Get entry by ride to provide better reporting
rct_ride_entry* entry = get_ride_entry_by_ride(ride); rct_ride_entry* entry = GetRideEntry();
if (entry == nullptr) if (entry == nullptr)
{ {
return 0; return 0;
} }
money32 customersPerHour = ride_customers_per_hour(ride); money32 customersPerHour = ride_customers_per_hour(this);
money32 priceMinusCost = ride_get_price(ride); money32 priceMinusCost = ride_get_price(this);
int32_t currentShopItem = entry->shop_item; int32_t currentShopItem = entry->shop_item;
if (currentShopItem != SHOP_ITEM_NONE) if (currentShopItem != SHOP_ITEM_NONE)
@ -457,12 +453,11 @@ static money32 ride_calculate_income_per_hour(Ride* ride)
priceMinusCost -= get_shop_item_cost(currentShopItem); priceMinusCost -= get_shop_item_cost(currentShopItem);
} }
currentShopItem = (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) ? RidePhotoItems[ride->type] currentShopItem = (lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) ? RidePhotoItems[type] : entry->shop_item_secondary;
: entry->shop_item_secondary;
if (currentShopItem != SHOP_ITEM_NONE) if (currentShopItem != SHOP_ITEM_NONE)
{ {
priceMinusCost += ride->price_secondary; priceMinusCost += price_secondary;
priceMinusCost -= get_shop_item_cost(currentShopItem); priceMinusCost -= get_shop_item_cost(currentShopItem);
if (entry->shop_item != SHOP_ITEM_NONE) if (entry->shop_item != SHOP_ITEM_NONE)
@ -953,23 +948,23 @@ int32_t ride_get_total_time(Ride* ride)
return totalTime; return totalTime;
} }
int32_t ride_can_have_multiple_circuits(Ride* ride) bool Ride::CanHaveMultipleCircuits() const
{ {
if (!(RideData4[ride->type].flags & RIDE_TYPE_FLAG4_ALLOW_MULTIPLE_CIRCUITS)) if (!(RideData4[type].flags & RIDE_TYPE_FLAG4_ALLOW_MULTIPLE_CIRCUITS))
return 0; return false;
// Only allow circuit or launch modes // Only allow circuit or launch modes
if (ride->mode != RIDE_MODE_CONTINUOUS_CIRCUIT && ride->mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE if (mode != RIDE_MODE_CONTINUOUS_CIRCUIT && mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE
&& ride->mode != RIDE_MODE_POWERED_LAUNCH_PASSTROUGH) && mode != RIDE_MODE_POWERED_LAUNCH_PASSTROUGH)
{ {
return 0; return false;
} }
// Must have no more than one vehicle and one station // Must have no more than one vehicle and one station
if (ride->num_vehicles > 1 || ride->num_stations > 1) if (num_vehicles > 1 || num_stations > 1)
return 0; return false;
return 1; return true;
} }
#pragma region Initialisation functions #pragma region Initialisation functions
@ -1014,7 +1009,7 @@ void reset_all_ride_build_dates()
static int32_t ride_check_if_construction_allowed(Ride* ride) static int32_t ride_check_if_construction_allowed(Ride* ride)
{ {
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
if (rideEntry == nullptr) if (rideEntry == nullptr)
{ {
context_show_error(STR_INVALID_RIDE_TYPE, STR_CANT_EDIT_INVALID_RIDE_TYPE); context_show_error(STR_INVALID_RIDE_TYPE, STR_CANT_EDIT_INVALID_RIDE_TYPE);
@ -1974,7 +1969,7 @@ int32_t ride_modify(CoordsXYE* input)
{ {
return 0; return 0;
} }
rideEntry = get_ride_entry_by_ride(ride); rideEntry = ride->GetRideEntry();
if ((rideEntry == nullptr) || !ride_check_if_construction_allowed(ride)) if ((rideEntry == nullptr) || !ride_check_if_construction_allowed(ride))
return 0; return 0;
@ -2117,7 +2112,7 @@ int32_t ride_initialise_construction_window(Ride* ride)
* *
* rct2: 0x006ABE4C * rct2: 0x006ABE4C
*/ */
void ride_update_all() void Ride::UpdateAll()
{ {
Ride* ride; Ride* ride;
int32_t i; int32_t i;
@ -2135,7 +2130,7 @@ void ride_update_all()
// Update rides // Update rides
FOR_ALL_RIDES (i, ride) FOR_ALL_RIDES (i, ride)
ride_update(ride); ride->Update();
ride_music_update_final(); ride_music_update_final();
} }
@ -2144,63 +2139,63 @@ void ride_update_all()
* *
* rct2: 0x006ABE73 * rct2: 0x006ABE73
*/ */
static void ride_update(Ride* ride) void Ride::Update()
{ {
if (ride->vehicle_change_timeout != 0) if (vehicle_change_timeout != 0)
ride->vehicle_change_timeout--; vehicle_change_timeout--;
ride_music_update(ride); ride_music_update(this);
// Update stations // Update stations
if (ride->type != RIDE_TYPE_MAZE) if (type != RIDE_TYPE_MAZE)
for (int32_t i = 0; i < MAX_STATIONS; i++) for (int32_t i = 0; i < MAX_STATIONS; i++)
ride_update_station(ride, i); ride_update_station(this, i);
// Update financial statistics // Update financial statistics
ride->num_customers_timeout++; num_customers_timeout++;
if (ride->num_customers_timeout >= 960) if (num_customers_timeout >= 960)
{ {
// This is meant to update about every 30 seconds // This is meant to update about every 30 seconds
ride->num_customers_timeout = 0; num_customers_timeout = 0;
// Shift number of customers history, start of the array is the most recent one // Shift number of customers history, start of the array is the most recent one
for (int32_t i = CUSTOMER_HISTORY_SIZE - 1; i > 0; i--) for (int32_t i = CUSTOMER_HISTORY_SIZE - 1; i > 0; i--)
{ {
ride->num_customers[i] = ride->num_customers[i - 1]; num_customers[i] = num_customers[i - 1];
} }
ride->num_customers[0] = ride->cur_num_customers; num_customers[0] = cur_num_customers;
ride->cur_num_customers = 0; cur_num_customers = 0;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER;
ride->income_per_hour = ride_calculate_income_per_hour(ride); income_per_hour = CalculateIncomePerHour();
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
if (ride->upkeep_cost != MONEY16_UNDEFINED) if (upkeep_cost != MONEY16_UNDEFINED)
ride->profit = (ride->income_per_hour - ((money32)ride->upkeep_cost * 16)); profit = (income_per_hour - ((money32)upkeep_cost * 16));
} }
// Ride specific updates // Ride specific updates
if (ride->type == RIDE_TYPE_CHAIRLIFT) if (type == RIDE_TYPE_CHAIRLIFT)
ride_chairlift_update(ride); UpdateChairlift();
else if (ride->type == RIDE_TYPE_SPIRAL_SLIDE) else if (type == RIDE_TYPE_SPIRAL_SLIDE)
ride_spiral_slide_update(ride); UpdateSpiralSlide();
ride_breakdown_update(ride); ride_breakdown_update(this);
// Various things include news messages // Various things include news messages
if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_DUE_INSPECTION)) if (lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_DUE_INSPECTION))
if (((gCurrentTicks >> 1) & 255) == (uint32_t)ride->id) if (((gCurrentTicks >> 1) & 255) == (uint32_t)id)
ride_breakdown_status_update(ride); ride_breakdown_status_update(this);
ride_inspection_update(ride); ride_inspection_update(this);
if (ride->status == RIDE_STATUS_TESTING && gConfigGeneral.no_test_crashes) if (status == RIDE_STATUS_TESTING && gConfigGeneral.no_test_crashes)
{ {
for (int32_t i = 0; i < ride->num_vehicles; i++) for (int32_t i = 0; i < num_vehicles; i++)
{ {
uint16_t spriteIndex = ride->vehicles[i]; uint16_t spriteIndex = vehicles[i];
if (spriteIndex == SPRITE_INDEX_NULL) if (spriteIndex == SPRITE_INDEX_NULL)
continue; continue;
@ -2208,9 +2203,9 @@ static void ride_update(Ride* ride)
if (vehicle->status == VEHICLE_STATUS_CRASHED || vehicle->status == VEHICLE_STATUS_CRASHING) if (vehicle->status == VEHICLE_STATUS_CRASHED || vehicle->status == VEHICLE_STATUS_CRASHING)
{ {
ride_set_status(ride, RIDE_STATUS_CLOSED); ride_set_status(this, RIDE_STATUS_CLOSED);
ride_set_status(ride, RIDE_STATUS_CLOSED); ride_set_status(this, RIDE_STATUS_CLOSED);
ride_set_status(ride, RIDE_STATUS_TESTING); ride_set_status(this, RIDE_STATUS_TESTING);
break; break;
} }
} }
@ -2221,29 +2216,29 @@ static void ride_update(Ride* ride)
* *
* rct2: 0x006AC489 * rct2: 0x006AC489
*/ */
static void ride_chairlift_update(Ride* ride) void Ride::UpdateChairlift()
{ {
int32_t x, y, z; int32_t x, y, z;
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) if (!(lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK))
return; return;
if ((ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) if ((lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED))
&& ride->breakdown_reason_pending == 0) && breakdown_reason_pending == 0)
return; return;
uint16_t old_chairlift_bullwheel_rotation = ride->chairlift_bullwheel_rotation >> 14; uint16_t old_chairlift_bullwheel_rotation = chairlift_bullwheel_rotation >> 14;
ride->chairlift_bullwheel_rotation += ride->speed * 2048; chairlift_bullwheel_rotation += speed * 2048;
if (old_chairlift_bullwheel_rotation == ride->speed / 8) if (old_chairlift_bullwheel_rotation == speed / 8)
return; return;
x = ride->chairlift_bullwheel_location[0].x * 32; x = chairlift_bullwheel_location[0].x * 32;
y = ride->chairlift_bullwheel_location[0].y * 32; y = chairlift_bullwheel_location[0].y * 32;
z = ride->chairlift_bullwheel_z[0] * 8; z = chairlift_bullwheel_z[0] * 8;
map_invalidate_tile_zoom1(x, y, z, z + (4 * 8)); map_invalidate_tile_zoom1(x, y, z, z + (4 * 8));
x = ride->chairlift_bullwheel_location[1].x * 32; x = chairlift_bullwheel_location[1].x * 32;
y = ride->chairlift_bullwheel_location[1].y * 32; y = chairlift_bullwheel_location[1].y * 32;
z = ride->chairlift_bullwheel_z[1] * 8; z = chairlift_bullwheel_z[1] * 8;
map_invalidate_tile_zoom1(x, y, z, z + (4 * 8)); map_invalidate_tile_zoom1(x, y, z, z + (4 * 8));
} }
@ -2319,19 +2314,19 @@ static constexpr const LocationXY16 ride_spiral_slide_main_tile_offset[][4] = {
* *
* rct2: 0x006AC545 * rct2: 0x006AC545
*/ */
static void ride_spiral_slide_update(Ride* ride) void Ride::UpdateSpiralSlide()
{ {
if (gCurrentTicks & 3) if (gCurrentTicks & 3)
return; return;
if (ride->slide_in_use == 0) if (slide_in_use == 0)
return; return;
ride->spiral_slide_progress++; spiral_slide_progress++;
if (ride->spiral_slide_progress >= 48) if (spiral_slide_progress >= 48)
{ {
ride->slide_in_use--; slide_in_use--;
Peep* peep = GET_PEEP(ride->slide_peep); Peep* peep = GET_PEEP(slide_peep);
peep->destination_x++; peep->destination_x++;
} }
@ -2339,13 +2334,13 @@ static void ride_spiral_slide_update(Ride* ride)
// Invalidate something related to station start // Invalidate something related to station start
for (int32_t i = 0; i < MAX_STATIONS; i++) for (int32_t i = 0; i < MAX_STATIONS; i++)
{ {
if (ride->stations[i].Start.xy == RCT_XY8_UNDEFINED) if (stations[i].Start.xy == RCT_XY8_UNDEFINED)
continue; continue;
int32_t x = ride->stations[i].Start.x; int32_t x = stations[i].Start.x;
int32_t y = ride->stations[i].Start.y; int32_t y = stations[i].Start.y;
TileElement* tileElement = ride_get_station_start_track_element(ride, i); TileElement* tileElement = ride_get_station_start_track_element(this, i);
if (tileElement == nullptr) if (tileElement == nullptr)
continue; continue;
@ -2573,7 +2568,7 @@ bool Ride::CanBreakDown() const
return false; return false;
} }
rct_ride_entry* entry = get_ride_entry_by_ride(this); rct_ride_entry* entry = GetRideEntry();
if (entry == nullptr || entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN) if (entry == nullptr || entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN)
{ {
return false; return false;
@ -7540,7 +7535,7 @@ bool Ride::IsRide() const
} }
} }
money16 ride_get_price(Ride* ride) money16 ride_get_price(const Ride* ride)
{ {
if (gParkFlags & PARK_FLAGS_NO_MONEY) if (gParkFlags & PARK_FLAGS_NO_MONEY)
return 0; return 0;

View File

@ -352,6 +352,14 @@ struct Ride
uint16_t holes; uint16_t holes;
uint8_t sheltered_eighths; uint8_t sheltered_eighths;
private:
void Update();
void UpdateChairlift();
void UpdateSpiralSlide();
void UpdateQueueLength(int32_t stationIndex);
money32 CalculateIncomePerHour() const;
public:
bool CanBreakDown() const; bool CanBreakDown() const;
bool IsRide() const; bool IsRide() const;
void Renew(); void Renew();
@ -373,12 +381,23 @@ struct Ride
bool IsPoweredLaunched() const; bool IsPoweredLaunched() const;
bool IsBlockSectioned() const; bool IsBlockSectioned() const;
bool CanHaveMultipleCircuits() const;
void StopGuestsQueuing(); void StopGuestsQueuing();
uint8_t GetDefaultMode() const; uint8_t GetDefaultMode() const;
void SetColourPreset(uint8_t index); void SetColourPreset(uint8_t index);
rct_ride_entry* GetRideEntry() const;
int32_t GetTotalQueueLength() const;
int32_t GetMaxQueueTime() const;
void QueueInsertGuestAtFront(int32_t stationIndex, Peep* peep);
Peep* GetQueueHeadGuest(int32_t stationIndex) const;
static void UpdateAll();
}; };
#pragma pack(push, 1) #pragma pack(push, 1)
@ -1024,14 +1043,9 @@ extern uint8_t gLastEntranceStyle;
ride_id_t ride_get_empty_slot(); ride_id_t ride_get_empty_slot();
int32_t ride_get_count(); int32_t ride_get_count();
int32_t ride_get_total_queue_length(Ride* ride);
int32_t ride_get_max_queue_time(Ride* ride);
Peep* ride_get_queue_head_guest(Ride* ride, int32_t stationIndex);
void ride_queue_insert_guest_at_front(Ride* ride, int32_t stationIndex, Peep* peep);
void ride_init_all(); void ride_init_all();
void reset_all_ride_build_dates(); void reset_all_ride_build_dates();
void ride_update_favourited_stat(); void ride_update_favourited_stat();
void ride_update_all();
void ride_check_all_reachable(); void ride_check_all_reachable();
void ride_update_satisfaction(Ride* ride, uint8_t happiness); void ride_update_satisfaction(Ride* ride, uint8_t happiness);
void ride_update_popularity(Ride* ride, uint8_t pop_amount); void ride_update_popularity(Ride* ride, uint8_t pop_amount);
@ -1047,12 +1061,10 @@ Staff* ride_get_mechanic(Ride* ride);
Staff* ride_get_assigned_mechanic(Ride* ride); Staff* ride_get_assigned_mechanic(Ride* ride);
int32_t ride_get_total_length(Ride* ride); int32_t ride_get_total_length(Ride* ride);
int32_t ride_get_total_time(Ride* ride); int32_t ride_get_total_time(Ride* ride);
int32_t ride_can_have_multiple_circuits(Ride* ride);
TrackColour ride_get_track_colour(Ride* ride, int32_t colourScheme); TrackColour ride_get_track_colour(Ride* ride, int32_t colourScheme);
vehicle_colour ride_get_vehicle_colour(Ride* ride, int32_t vehicleIndex); vehicle_colour ride_get_vehicle_colour(Ride* ride, int32_t vehicleIndex);
int32_t ride_get_unused_preset_vehicle_colour(uint8_t ride_sub_type); int32_t ride_get_unused_preset_vehicle_colour(uint8_t ride_sub_type);
void ride_set_vehicle_colours_to_random_preset(Ride* ride, uint8_t preset_index); void ride_set_vehicle_colours_to_random_preset(Ride* ride, uint8_t preset_index);
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride);
uint8_t* get_ride_entry_indices_for_ride_type(uint8_t rideType); uint8_t* get_ride_entry_indices_for_ride_type(uint8_t rideType);
void reset_type_to_ride_entry_index_map(IObjectManager& objectManager); void reset_type_to_ride_entry_index_map(IObjectManager& objectManager);
void ride_measurement_clear(Ride* ride); void ride_measurement_clear(Ride* ride);
@ -1177,7 +1189,7 @@ rct_vehicle* ride_get_broken_vehicle(Ride* ride);
void window_ride_construction_do_station_check(); void window_ride_construction_do_station_check();
void window_ride_construction_do_entrance_exit_check(); void window_ride_construction_do_entrance_exit_check();
money16 ride_get_price(Ride* ride); money16 ride_get_price(const Ride* ride);
TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tolerance); TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tolerance);
bool ride_has_adjacent_station(Ride* ride); bool ride_has_adjacent_station(Ride* ride);

View File

@ -122,7 +122,7 @@ static void paint_magic_carpet_vehicle(
paint_session* session, Ride* ride, uint8_t direction, uint32_t swingImageId, LocationXYZ16 offset, LocationXYZ16 bbOffset, paint_session* session, Ride* ride, uint8_t direction, uint32_t swingImageId, LocationXYZ16 offset, LocationXYZ16 bbOffset,
LocationXYZ16 bbSize) LocationXYZ16 bbSize)
{ {
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
uint32_t vehicleImageId = rideEntry->vehicles[0].base_image_id + direction; uint32_t vehicleImageId = rideEntry->vehicles[0].base_image_id + direction;
// Vehicle // Vehicle

View File

@ -34,7 +34,7 @@ static void paint_motionsimulator_vehicle(
paint_session* session, int8_t offsetX, int8_t offsetY, uint8_t direction, int32_t height, const TileElement* tileElement) paint_session* session, int8_t offsetX, int8_t offsetY, uint8_t direction, int32_t height, const TileElement* tileElement)
{ {
Ride* ride = get_ride(tileElement->AsTrack()->GetRideIndex()); Ride* ride = get_ride(tileElement->AsTrack()->GetRideIndex());
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride); rct_ride_entry* rideEntry = ride->GetRideEntry();
const TileElement* savedTileElement = static_cast<const TileElement*>(session->CurrentlyDrawnItem); const TileElement* savedTileElement = static_cast<const TileElement*>(session->CurrentlyDrawnItem);

View File

@ -139,14 +139,14 @@ rct_ride_entry* get_ride_entry(int index)
return gRideEntries[index]; return gRideEntries[index];
} }
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride) rct_ride_entry* Ride::GetRideEntry() const
{ {
rct_ride_entry* type = get_ride_entry(ride->subtype); rct_ride_entry* rideEntry = get_ride_entry(subtype);
if (type == nullptr) if (rideEntry == nullptr)
{ {
log_error("Invalid ride subtype for ride"); log_error("Invalid ride subtype for ride");
} }
return type; return rideEntry;
} }
rct_sprite* get_sprite(size_t sprite_idx) rct_sprite* get_sprite(size_t sprite_idx)