Add nullptr checks for get_ride in libopenrct2ui (#9795)

This commit is contained in:
Ted John 2019-08-09 08:06:25 +01:00 committed by GitHub
parent ab7b17fc4e
commit 93789b9034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 528 additions and 361 deletions

View File

@ -372,18 +372,14 @@ public:
case INTENT_ACTION_INVALIDATE_VEHICLE_WINDOW:
{
rct_vehicle* vehicle = static_cast<rct_vehicle*>(intent.GetPointerExtra(INTENT_EXTRA_VEHICLE));
int32_t viewVehicleIndex;
Ride* ride;
rct_window* w;
w = window_find_by_number(WC_RIDE, vehicle->ride);
auto vehicle = static_cast<rct_vehicle*>(intent.GetPointerExtra(INTENT_EXTRA_VEHICLE));
auto w = window_find_by_number(WC_RIDE, vehicle->ride);
if (w == nullptr)
return;
ride = get_ride(vehicle->ride);
viewVehicleIndex = w->ride.view - 1;
if (viewVehicleIndex < 0 || viewVehicleIndex >= ride->num_vehicles)
auto ride = get_ride(vehicle->ride);
auto viewVehicleIndex = w->ride.view - 1;
if (ride == nullptr || viewVehicleIndex < 0 || viewVehicleIndex >= ride->num_vehicles)
return;
if (vehicle->sprite_index != ride->vehicles[viewVehicleIndex])

View File

@ -231,7 +231,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
ride = get_ride(sprite->vehicle.ride);
if (ride->status == RIDE_STATUS_CLOSED)
if (ride != nullptr && ride->status == RIDE_STATUS_CLOSED)
{
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ride->FormatNameTo(gMapTooltipFormatArgs + 2);
@ -246,6 +246,9 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
ride = get_ride(tile_element_get_ride_index(tileElement));
if (ride == nullptr)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
if (ride->status != RIDE_STATUS_CLOSED)
return info->type;

View File

@ -354,6 +354,7 @@ static void window_banner_viewport_rotate(rct_window* w)
w, w->x + viewportWidget->left + 1, w->y + viewportWidget->top + 1, (viewportWidget->right - viewportWidget->left) - 1,
(viewportWidget->bottom - viewportWidget->top) - 1, 0, view_x, view_y, view_z, 0, SPRITE_INDEX_NULL);
w->viewport->flags = gConfigGeneral.always_show_gridlines ? VIEWPORT_FLAG_GRIDLINES : 0;
if (w->viewport != nullptr)
w->viewport->flags = gConfigGeneral.always_show_gridlines ? VIEWPORT_FLAG_GRIDLINES : 0;
window_invalidate(w);
}

View File

@ -1068,15 +1068,15 @@ static void window_editor_objective_options_rides_scrollgetheight(
*/
static void window_editor_objective_options_rides_scrollmousedown(rct_window* w, int32_t scrollIndex, int32_t x, int32_t y)
{
Ride* ride;
int32_t i;
i = y / 12;
auto i = y / 12;
if (i < 0 || i >= w->no_list_items)
return;
ride = get_ride(w->list_item_positions[i]);
ride->lifecycle_flags ^= RIDE_LIFECYCLE_INDESTRUCTIBLE;
auto ride = get_ride(w->list_item_positions[i]);
if (ride != nullptr)
{
ride->lifecycle_flags ^= RIDE_LIFECYCLE_INDESTRUCTIBLE;
}
window_invalidate(w);
}
@ -1165,17 +1165,20 @@ static void window_editor_objective_options_rides_scrollpaint(rct_window* w, rct
// Checkbox mark
auto ride = get_ride(w->list_item_positions[i]);
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE)
if (ride != nullptr)
{
gCurrentFontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK
: FONT_SPRITE_BASE_MEDIUM_DARK;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, 2, y);
}
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE)
{
gCurrentFontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK
: FONT_SPRITE_BASE_MEDIUM_DARK;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, 2, y);
}
// Ride name
uint32_t args[32]{};
ride->FormatNameTo(args);
gfx_draw_string_left(dpi, stringId, args, COLOUR_BLACK, 15, y);
// Ride name
uint32_t args[32]{};
ride->FormatNameTo(args);
gfx_draw_string_left(dpi, stringId, args, COLOUR_BLACK, 15, y);
}
}
}

View File

@ -1950,7 +1950,8 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item
break;
case SHOP_ITEM_PHOTO:
ride = get_ride(peep->photo1_ride_ref);
ride->FormatNameTo(gCommonFormatArgs + 6);
if (ride != nullptr)
ride->FormatNameTo(gCommonFormatArgs + 6);
break;
case SHOP_ITEM_UMBRELLA:
set_format_arg(0, uint32_t, SPRITE_ID_PALETTE_COLOUR_1(peep->umbrella_colour) | ShopItems[item].Image);
@ -1965,8 +1966,11 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item
break;
case VOUCHER_TYPE_RIDE_FREE:
ride = get_ride(peep->voucher_arguments);
set_format_arg(6, rct_string_id, STR_PEEP_INVENTORY_VOUCHER_RIDE_FREE);
ride->FormatNameTo(gCommonFormatArgs + 8);
if (ride != nullptr)
{
set_format_arg(6, rct_string_id, STR_PEEP_INVENTORY_VOUCHER_RIDE_FREE);
ride->FormatNameTo(gCommonFormatArgs + 8);
}
break;
case VOUCHER_TYPE_PARK_ENTRY_HALF_PRICE:
set_format_arg(6, rct_string_id, STR_PEEP_INVENTORY_VOUCHER_PARK_ENTRY_HALF_PRICE);
@ -1987,15 +1991,18 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item
break;
case SHOP_ITEM_PHOTO2:
ride = get_ride(peep->photo2_ride_ref);
ride->FormatNameTo(gCommonFormatArgs + 6);
if (ride != nullptr)
ride->FormatNameTo(gCommonFormatArgs + 6);
break;
case SHOP_ITEM_PHOTO3:
ride = get_ride(peep->photo3_ride_ref);
ride->FormatNameTo(gCommonFormatArgs + 6);
if (ride != nullptr)
ride->FormatNameTo(gCommonFormatArgs + 6);
break;
case SHOP_ITEM_PHOTO4:
ride = get_ride(peep->photo4_ride_ref);
ride->FormatNameTo(gCommonFormatArgs + 6);
if (ride != nullptr)
ride->FormatNameTo(gCommonFormatArgs + 6);
break;
}

View File

@ -1602,11 +1602,13 @@ static uint16_t map_window_get_pixel_colour_ride(CoordsXY c)
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)
break;
ride = get_ride(tileElement->AsEntrance()->GetRideIndex());
colourA = RideKeyColours[RideColourKey[ride->type]];
if (ride != nullptr)
colourA = RideKeyColours[RideColourKey[ride->type]];
break;
case TILE_ELEMENT_TYPE_TRACK:
ride = get_ride(tileElement->AsTrack()->GetRideIndex());
colourA = RideKeyColours[RideColourKey[ride->type]];
if (ride != nullptr)
colourA = RideKeyColours[RideColourKey[ride->type]];
break;
}
} while (!(tileElement++)->IsLastForTile());

View File

@ -170,18 +170,21 @@ static void window_maze_construction_close(rct_window* w)
hide_gridlines();
auto ride = get_ride(_currentRideIndex);
if (ride->overall_view.xy == RCT_XY8_UNDEFINED)
if (ride != nullptr)
{
int32_t savedPausedState = gGamePaused;
gGamePaused = 0;
ride_action_modify(ride, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED);
gGamePaused = savedPausedState;
}
else
{
auto intent = Intent(WC_RIDE);
intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id);
context_open_intent(&intent);
if (ride->overall_view.xy == RCT_XY8_UNDEFINED)
{
int32_t savedPausedState = gGamePaused;
gGamePaused = 0;
ride_action_modify(ride, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED);
gGamePaused = savedPausedState;
}
else
{
auto intent = Intent(WC_RIDE);
intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id);
context_open_intent(&intent);
}
}
}
@ -376,8 +379,8 @@ static void window_maze_construction_entrance_tooldown(int32_t x, int32_t y, rct
audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
Ride* ride = get_ride(rideIndex);
if (ride_are_all_possible_entrances_and_exits_built(ride))
auto ride = get_ride(rideIndex);
if (ride != nullptr && ride_are_all_possible_entrances_and_exits_built(ride))
{
tool_cancel();
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK))

View File

@ -94,19 +94,31 @@ static uint8_t window_new_campaign_shop_items[64];
static int32_t ride_value_compare(const void* a, const void* b)
{
Ride *rideA, *rideB;
auto valueA = 0;
auto rideA = get_ride(*((uint8_t*)a));
if (rideA != nullptr)
valueA = rideA->value;
rideA = get_ride(*((uint8_t*)a));
rideB = get_ride(*((uint8_t*)b));
return rideB->value - rideA->value;
auto valueB = 0;
auto rideB = get_ride(*((uint8_t*)b));
if (rideB != nullptr)
valueB = rideB->value;
return valueB - valueA;
}
static int32_t ride_name_compare(const void* a, const void* b)
{
std::string rideAName;
auto rideA = get_ride(*((uint8_t*)a));
if (rideA != nullptr)
rideAName = rideA->GetName();
std::string rideBName;
auto rideB = get_ride(*((uint8_t*)b));
auto rideAName = rideA->GetName();
auto rideBName = rideB->GetName();
if (rideB != nullptr)
rideBName = rideB->GetName();
return _strcmpi(rideAName.c_str(), rideBName.c_str());
}

File diff suppressed because it is too large Load Diff

View File

@ -522,8 +522,9 @@ rct_window* window_ride_construction_open()
ride_id_t rideIndex = _currentRideIndex;
close_ride_window_for_construction(rideIndex);
rct_window* w;
Ride* ride = get_ride(rideIndex);
auto ride = get_ride(rideIndex);
if (ride == nullptr)
return nullptr;
_stationConstructed = ride->num_stations != 0;
_deferClose = false;
@ -533,7 +534,7 @@ rct_window* window_ride_construction_open()
return context_open_window_view(WV_MAZE_CONSTRUCTION);
}
w = window_create(0, 29, 166, 394, &window_ride_construction_events, WC_RIDE_CONSTRUCTION, WF_NO_AUTO_CLOSE);
auto w = window_create(0, 29, 166, 394, &window_ride_construction_events, WC_RIDE_CONSTRUCTION, WF_NO_AUTO_CLOSE);
w->widgets = window_ride_construction_widgets;
w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_LEFT_CURVE_VERY_SMALL) | (1ULL << WIDX_LEFT_CURVE_SMALL)
@ -1950,8 +1951,12 @@ static void window_ride_construction_mouseup_demolish(rct_window* w)
}
else
{
_stationConstructed = get_ride(w->number)->num_stations != 0;
window_ride_construction_mouseup_demolish_next_piece(x, y, z, direction, type);
auto ride = get_ride(w->number);
if (ride != nullptr)
{
_stationConstructed = ride->num_stations != 0;
window_ride_construction_mouseup_demolish_next_piece(x, y, z, direction, type);
}
}
});
@ -1980,7 +1985,7 @@ static void window_ride_construction_entrance_click(rct_window* w)
if (tool_set(w, WIDX_ENTRANCE, TOOL_CROSSHAIR))
{
auto ride = get_ride(_currentRideIndex);
if (!ride_try_get_origin_element(ride, nullptr))
if (ride != nullptr && !ride_try_get_origin_element(ride, nullptr))
{
ride_initialise_construction_window(ride);
}
@ -2037,7 +2042,9 @@ static void window_ride_construction_exit_click(rct_window* w)
*/
static void window_ride_construction_update(rct_window* w)
{
Ride* ride = get_ride(_currentRideIndex);
auto ride = get_ride(_currentRideIndex);
if (ride == nullptr)
return;
// Close construction window if ride is not closed,
// editing ride while open will cause many issues until properly handled
@ -2338,12 +2345,11 @@ static void window_ride_construction_draw_track_piece(
rct_window* w, rct_drawpixelinfo* dpi, ride_id_t rideIndex, int32_t trackType, int32_t trackDirection, int32_t unknown,
int32_t width, int32_t height)
{
const rct_preview_track* trackBlock;
Ride* ride;
auto ride = get_ride(rideIndex);
if (ride == nullptr)
return;
ride = get_ride(rideIndex);
trackBlock = get_track_def_from_ride(ride, trackType);
auto trackBlock = get_track_def_from_ride(ride, trackType);
while ((trackBlock + 1)->index != 0xFF)
trackBlock++;
@ -2395,13 +2401,12 @@ static void sub_6CBCE2(
rct_drawpixelinfo* dpi, ride_id_t rideIndex, int32_t trackType, int32_t trackDirection, int32_t edx, int32_t originX,
int32_t originY, int32_t originZ)
{
Ride* ride;
const rct_preview_track* trackBlock;
paint_session* session = paint_session_alloc(dpi, 0);
trackDirection &= 3;
ride = get_ride(rideIndex);
auto ride = get_ride(rideIndex);
if (ride == nullptr)
return;
int16_t preserveMapSizeUnits = gMapSizeUnits;
int16_t preserveMapSizeMinus2 = gMapSizeMinus2;
@ -2413,7 +2418,7 @@ static void sub_6CBCE2(
gMapSize = 256;
gMapSizeMaxXY = (256 * 32) - 1;
trackBlock = get_track_def_from_ride(ride, trackType);
auto trackBlock = get_track_def_from_ride(ride, trackType);
while (trackBlock->index != 255)
{
auto quarterTile = trackBlock->var_08.Rotate(trackDirection);
@ -2518,14 +2523,16 @@ void window_ride_construction_update_active_elements_impl()
*/
void window_ride_construction_update_enabled_track_pieces()
{
Ride* ride = get_ride(_currentRideIndex);
rct_ride_entry* rideEntry = ride->GetRideEntry();
int32_t rideType = (_currentTrackAlternative & RIDE_TYPE_ALTERNATIVE_TRACK_TYPE) ? RideData4[ride->type].alternate_type
: ride->type;
auto ride = get_ride(_currentRideIndex);
if (ride == nullptr)
return;
auto rideEntry = ride->GetRideEntry();
if (rideEntry == nullptr)
return;
int32_t rideType = (_currentTrackAlternative & RIDE_TYPE_ALTERNATIVE_TRACK_TYPE) ? RideData4[ride->type].alternate_type
: ride->type;
if (gCheatsEnableAllDrawableTrackPieces)
{
_enabledRidePieces = RideTypePossibleTrackConfigurations[rideType];
@ -3362,14 +3369,14 @@ static void window_ride_construction_show_special_track_dropdown(rct_window* w,
rct_string_id trackPieceStringId = RideConfigurationStringIds[trackPiece];
if (trackPieceStringId == STR_RAPIDS)
{
Ride* ride = get_ride(_currentRideIndex);
if (ride->type == RIDE_TYPE_CAR_RIDE)
auto ride = get_ride(_currentRideIndex);
if (ride != nullptr && ride->type == RIDE_TYPE_CAR_RIDE)
trackPieceStringId = STR_LOG_BUMPS;
}
if (trackPieceStringId == STR_SPINNING_CONTROL_TOGGLE_TRACK)
{
Ride* ride = get_ride(_currentRideIndex);
if (ride->type != RIDE_TYPE_STEEL_WILD_MOUSE)
auto ride = get_ride(_currentRideIndex);
if (ride != nullptr && ride->type != RIDE_TYPE_STEEL_WILD_MOUSE)
trackPieceStringId = STR_BOOSTER;
}
gDropdownItemsFormat[i] = trackPieceStringId;
@ -3755,7 +3762,10 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
tool_cancel();
Ride* ride = get_ride(_currentRideIndex);
auto ride = get_ride(_currentRideIndex);
if (ride == nullptr)
return;
if (_trackPlaceZ == 0)
{
const rct_preview_track* trackBlock = get_track_def_from_ride(ride, _currentTrackPieceType);
@ -3927,8 +3937,8 @@ static void ride_construction_tooldown_entrance_exit(int32_t screenX, int32_t sc
audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
Ride* ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride_are_all_possible_entrances_and_exits_built(ride))
auto ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride != nullptr && ride_are_all_possible_entrances_and_exits_built(ride))
{
tool_cancel();
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK))

View File

@ -798,11 +798,14 @@ void window_ride_list_refresh_list(rct_window* w)
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
auto strB = otherRide->GetName();
if (_strcmpi(strA.c_str(), strB.c_str()) >= 0)
break;
if (otherRide != nullptr)
{
auto strB = otherRide->GetName();
if (_strcmpi(strA.c_str(), strB.c_str()) >= 0)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
}
@ -810,140 +813,182 @@ void window_ride_list_refresh_list(rct_window* w)
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->popularity * 4 <= otherRide->popularity * 4)
break;
if (otherRide != nullptr)
{
if (ride->popularity * 4 <= otherRide->popularity * 4)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_SATISFACTION:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->satisfaction * 5 <= otherRide->satisfaction * 5)
break;
if (otherRide != nullptr)
{
if (ride->satisfaction * 5 <= otherRide->satisfaction * 5)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_PROFIT:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->profit <= otherRide->profit)
break;
if (otherRide != nullptr)
{
if (ride->profit <= otherRide->profit)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_TOTAL_CUSTOMERS:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->total_customers <= otherRide->total_customers)
break;
if (otherRide != nullptr)
{
if (ride->total_customers <= otherRide->total_customers)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_TOTAL_PROFIT:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->total_profit <= otherRide->total_profit)
break;
if (otherRide != nullptr)
{
if (ride->total_profit <= otherRide->total_profit)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_CUSTOMERS:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride_customers_per_hour(ride) <= ride_customers_per_hour(otherRide))
break;
if (otherRide != nullptr)
{
if (ride_customers_per_hour(ride) <= ride_customers_per_hour(otherRide))
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_AGE:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->build_date <= otherRide->build_date)
break;
if (otherRide != nullptr)
{
if (ride->build_date <= otherRide->build_date)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_INCOME:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->income_per_hour <= otherRide->income_per_hour)
break;
if (otherRide != nullptr)
{
if (ride->income_per_hour <= otherRide->income_per_hour)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_RUNNING_COST:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->upkeep_cost <= otherRide->upkeep_cost)
break;
if (otherRide != nullptr)
{
if (ride->upkeep_cost <= otherRide->upkeep_cost)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_QUEUE_LENGTH:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->GetTotalQueueLength() <= otherRide->GetTotalQueueLength())
break;
if (otherRide != nullptr)
{
if (ride->GetTotalQueueLength() <= otherRide->GetTotalQueueLength())
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_QUEUE_TIME:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->GetMaxQueueTime() <= otherRide->GetMaxQueueTime())
break;
if (otherRide != nullptr)
{
if (ride->GetMaxQueueTime() <= otherRide->GetMaxQueueTime())
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_RELIABILITY:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->reliability_percentage <= otherRide->reliability_percentage)
break;
if (otherRide != nullptr)
{
if (ride->reliability_percentage <= otherRide->reliability_percentage)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_DOWN_TIME:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->downtime <= otherRide->downtime)
break;
if (otherRide != nullptr)
{
if (ride->downtime <= otherRide->downtime)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
case INFORMATION_TYPE_GUESTS_FAVOURITE:
while (--current_list_position >= 0)
{
auto otherRide = get_ride(w->list_item_positions[current_list_position]);
if (ride->guests_favourite <= otherRide->guests_favourite)
break;
if (otherRide != nullptr)
{
if (ride->guests_favourite <= otherRide->guests_favourite)
break;
window_bubble_list_item(w, current_list_position);
window_bubble_list_item(w, current_list_position);
}
}
break;
}

View File

@ -370,8 +370,8 @@ static void window_sign_viewport_rotate(rct_window* w)
viewport_create(
w, w->x + viewportWidget->left + 1, w->y + viewportWidget->top + 1, (viewportWidget->right - viewportWidget->left) - 1,
(viewportWidget->bottom - viewportWidget->top) - 1, 0, view_x, view_y, view_z, 0, SPRITE_INDEX_NULL);
w->viewport->flags = gConfigGeneral.always_show_gridlines ? VIEWPORT_FLAG_GRIDLINES : 0;
if (w->viewport != nullptr)
w->viewport->flags = gConfigGeneral.always_show_gridlines ? VIEWPORT_FLAG_GRIDLINES : 0;
window_invalidate(w);
}

View File

@ -4416,12 +4416,19 @@ static rct_vehicle* vehicle_create_car(
ride_id_t rideIndex, int32_t vehicleEntryIndex, int32_t carIndex, int32_t vehicleIndex, int32_t x, int32_t y, int32_t z,
int32_t* remainingDistance, TileElement* tileElement)
{
Ride* ride = get_ride(rideIndex);
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
rct_ride_entry_vehicle* vehicleEntry = &rideEntry->vehicles[vehicleEntryIndex];
int32_t edx;
auto ride = get_ride(rideIndex);
if (ride == nullptr)
return nullptr;
auto rideEntry = ride->GetRideEntry();
if (rideEntry == nullptr)
return nullptr;
auto vehicleEntry = &rideEntry->vehicles[vehicleEntryIndex];
auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle;
if (vehicle == nullptr)
return nullptr;
rct_vehicle* vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle;
vehicle->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE;
vehicle->ride = rideIndex;
vehicle->ride_subtype = ride->subtype;
@ -4429,7 +4436,7 @@ static rct_vehicle* vehicle_create_car(
vehicle->vehicle_type = vehicleEntryIndex;
vehicle->type = carIndex == 0 ? VEHICLE_TYPE_HEAD : VEHICLE_TYPE_TAIL;
vehicle->var_44 = ror32(vehicleEntry->spacing, 10) & 0xFFFF;
edx = vehicleEntry->spacing >> 1;
auto edx = vehicleEntry->spacing >> 1;
*remainingDistance -= edx;
vehicle->remaining_distance = *remainingDistance;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_GO_KART))
@ -4615,9 +4622,11 @@ static train_ref vehicle_create_train(
{
for (int32_t carIndex = 0; carIndex < ride->num_cars_per_train; carIndex++)
{
const uint8_t vehicle = ride_entry_get_vehicle_at_position(ride->subtype, ride->num_cars_per_train, carIndex);
rct_vehicle* car = vehicle_create_car(
rideIndex, vehicle, carIndex, vehicleIndex, x, y, z, remainingDistance, tileElement);
auto vehicle = ride_entry_get_vehicle_at_position(ride->subtype, ride->num_cars_per_train, carIndex);
auto car = vehicle_create_car(rideIndex, vehicle, carIndex, vehicleIndex, x, y, z, remainingDistance, tileElement);
if (car == nullptr)
break;
if (carIndex == 0)
{
train.head = car;

View File

@ -1147,12 +1147,15 @@ int32_t track_get_actual_bank_2(int32_t rideType, bool isInverted, int32_t bank)
int32_t track_get_actual_bank_3(rct_vehicle* vehicle, TileElement* tileElement)
{
auto trackType = tileElement->AsTrack()->GetTrackType();
auto bankStart = TrackDefinitions[trackType].bank_start;
auto ride = get_ride(tileElement->AsTrack()->GetRideIndex());
if (ride == nullptr)
return bankStart;
bool isInverted = ((vehicle->update_flags & VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES) > 0)
^ tileElement->AsTrack()->IsInverted();
int32_t trackType = tileElement->AsTrack()->GetTrackType();
int32_t rideType = get_ride(tileElement->AsTrack()->GetRideIndex())->type;
int32_t bankStart = TrackDefinitions[trackType].bank_start;
return track_get_actual_bank_2(rideType, isInverted, bankStart);
return track_get_actual_bank_2(ride->type, isInverted, bankStart);
}
bool track_element_is_station(TileElement* trackElement)

View File

@ -1933,9 +1933,6 @@ static SoundIdVolume sub_6D7AC0(SoundId currentSoundId, uint8_t currentVolume, S
*/
static void vehicle_update(rct_vehicle* vehicle)
{
Ride* ride;
rct_ride_entry* rideEntry;
// The cable lift uses the ride type of NULL
if (vehicle->ride_subtype == RIDE_TYPE_NULL)
{
@ -1943,11 +1940,14 @@ static void vehicle_update(rct_vehicle* vehicle)
return;
}
rideEntry = get_ride_entry(vehicle->ride_subtype);
auto rideEntry = get_ride_entry(vehicle->ride_subtype);
if (rideEntry == nullptr)
return;
rct_ride_entry_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type];
auto ride = get_ride(vehicle->ride);
if (ride == nullptr)
return;
ride = get_ride(vehicle->ride);
if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING)
vehicle_update_measurements(vehicle);
@ -1955,6 +1955,7 @@ static void vehicle_update(rct_vehicle* vehicle)
if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN))
{
_vehicleBreakdown = ride->breakdown_reason_pending;
auto vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type];
if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT)
{
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE)