diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index f9ff5e0ffd..34f4367804 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -565,7 +565,7 @@ bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords) break; case ViewportInteractionItem::Ride: tileElement = { info.Loc, info.Element }; - ride_modify(&tileElement); + ride_modify(tileElement); break; case ViewportInteractionItem::Scenery: ViewportInteractionRemoveScenery(info.Element, info.Loc); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 286ea015a7..ece91b05e3 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2666,15 +2666,18 @@ void Ride::ChainQueues() const * * rct2: 0x006D3319 */ -static ResultWithMessage ride_check_block_brakes(CoordsXYE* input, CoordsXYE* output) +static ResultWithMessage RideCheckBlockBrakes(const CoordsXYE& input, CoordsXYE* output) { - RideId rideIndex = input->element->AsTrack()->GetRideIndex(); + if (input.element == nullptr || input.element->GetType() != TileElementType::Track) + return { false }; + + RideId rideIndex = input.element->AsTrack()->GetRideIndex(); rct_window* w = window_find_by_class(WC_RIDE_CONSTRUCTION); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == rideIndex) ride_construction_invalidate_current_track(); track_circuit_iterator it; - track_circuit_iterator_begin(&it, *input); + track_circuit_iterator_begin(&it, input); while (track_circuit_iterator_next(&it)) { if (it.current.element->AsTrack()->GetTrackType() == TrackElemType::BlockBrakes) @@ -3817,7 +3820,7 @@ void Ride::ConstructMissingEntranceOrExit() const CoordsXYE trackElement; ride_try_get_origin_element(this, &trackElement); ride_find_track_gap(this, &trackElement, &trackElement); - int32_t ok = ride_modify(&trackElement); + int32_t ok = ride_modify(trackElement); if (ok == 0) { return; @@ -3833,12 +3836,15 @@ void Ride::ConstructMissingEntranceOrExit() const * * rct2: 0x006B528A */ -static void ride_scroll_to_track_error(CoordsXYE* trackElement) +static void ride_scroll_to_track_error(const CoordsXYE& trackElement) { + if (trackElement.element == nullptr) + return; + auto* w = window_get_main(); if (w != nullptr) { - window_scroll_to_location(*w, { *trackElement, trackElement->element->GetBaseZ() }); + window_scroll_to_location(*w, { trackElement, trackElement.element->GetBaseZ() }); ride_modify(trackElement); } } @@ -3921,17 +3927,17 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying) if (ride_find_track_gap(this, &trackElement, &problematicTrackElement) && (newStatus != RideStatus::Simulating || IsBlockSectioned())) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_IS_NOT_A_COMPLETE_CIRCUIT }; } } if (IsBlockSectioned()) { - auto blockBrakeCheck = ride_check_block_brakes(&trackElement, &problematicTrackElement); + auto blockBrakeCheck = RideCheckBlockBrakes(trackElement, &problematicTrackElement); if (!blockBrakeCheck.Successful) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, blockBrakeCheck.Message }; } } @@ -3943,7 +3949,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying) { if (ride_check_track_contains_inversions(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN }; } } @@ -3951,7 +3957,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying) { if (ride_check_track_contains_banked(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN }; } } @@ -3966,13 +3972,13 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying) if (!ride_check_station_length(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_STATION_NOT_LONG_ENOUGH }; } if (!ride_check_start_and_end_is_station(&trackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS }; } } @@ -4056,17 +4062,17 @@ ResultWithMessage Ride::Open(bool isApplying) { if (ride_find_track_gap(this, &trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_IS_NOT_A_COMPLETE_CIRCUIT }; } } if (IsBlockSectioned()) { - auto blockBrakeCheck = ride_check_block_brakes(&trackElement, &problematicTrackElement); + auto blockBrakeCheck = RideCheckBlockBrakes(trackElement, &problematicTrackElement); if (!blockBrakeCheck.Successful) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, blockBrakeCheck.Message }; } } @@ -4078,7 +4084,7 @@ ResultWithMessage Ride::Open(bool isApplying) { if (ride_check_track_contains_inversions(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN }; } } @@ -4086,7 +4092,7 @@ ResultWithMessage Ride::Open(bool isApplying) { if (ride_check_track_contains_banked(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN }; } } @@ -4101,13 +4107,13 @@ ResultWithMessage Ride::Open(bool isApplying) if (!ride_check_station_length(&trackElement, &problematicTrackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_STATION_NOT_LONG_ENOUGH }; } if (!ride_check_start_and_end_is_station(&trackElement)) { - ride_scroll_to_track_error(&problematicTrackElement); + ride_scroll_to_track_error(problematicTrackElement); return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS }; } } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 1a09b3929b..77382f6b6d 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -141,7 +141,7 @@ void ride_construct(Ride* ride) ride_find_track_gap(ride, &trackElement, &trackElement); rct_window* w = window_get_main(); - if (w != nullptr && ride_modify(&trackElement)) + if (w != nullptr && ride_modify(trackElement)) window_scroll_to_location(*w, { trackElement, trackElement.element->GetBaseZ() }); } else @@ -985,9 +985,9 @@ static bool ride_modify_maze(const CoordsXYE& tileElement) * * rct2: 0x006CC056 */ -bool ride_modify(CoordsXYE* input) +bool ride_modify(const CoordsXYE& input) { - auto tileElement = *input; + auto tileElement = input; if (tileElement.element == nullptr) return false; diff --git a/src/openrct2/ride/RideConstruction.h b/src/openrct2/ride/RideConstruction.h index 8e8d43c9b9..2d805b0a36 100644 --- a/src/openrct2/ride/RideConstruction.h +++ b/src/openrct2/ride/RideConstruction.h @@ -88,7 +88,7 @@ void ride_construction_set_default_next_piece(); void ride_select_next_section(); void ride_select_previous_section(); -bool ride_modify(CoordsXYE* input); +bool ride_modify(const CoordsXYE& input); CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenCoordsXY& screenCoords);