Refactor ride track checking code to use constrefs

This commit is contained in:
Gymnasiast 2022-12-17 17:34:00 +01:00
parent a4f7ca4682
commit 4923847f39
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
3 changed files with 29 additions and 29 deletions

View File

@ -2721,12 +2721,12 @@ static ResultWithMessage RideCheckBlockBrakes(const CoordsXYE& input, CoordsXYE*
* @returns true if an inversion track piece is found, otherwise false. * @returns true if an inversion track piece is found, otherwise false.
* rct2: 0x006CB149 * rct2: 0x006CB149
*/ */
static bool ride_check_track_contains_inversions(CoordsXYE* input, CoordsXYE* output) static bool ride_check_track_contains_inversions(const CoordsXYE& input, CoordsXYE* output)
{ {
if (input->element == nullptr) if (input.element == nullptr)
return false; return false;
const auto* trackElement = input->element->AsTrack(); const auto* trackElement = input.element->AsTrack();
if (trackElement == nullptr) if (trackElement == nullptr)
return false; return false;
@ -2747,7 +2747,7 @@ static bool ride_check_track_contains_inversions(CoordsXYE* input, CoordsXYE* ou
bool moveSlowIt = true; bool moveSlowIt = true;
track_circuit_iterator it, slowIt; track_circuit_iterator it, slowIt;
track_circuit_iterator_begin(&it, *input); track_circuit_iterator_begin(&it, input);
slowIt = it; slowIt = it;
while (track_circuit_iterator_next(&it)) while (track_circuit_iterator_next(&it))
@ -2781,12 +2781,12 @@ static bool ride_check_track_contains_inversions(CoordsXYE* input, CoordsXYE* ou
* @returns true if a banked track piece is found, otherwise false. * @returns true if a banked track piece is found, otherwise false.
* rct2: 0x006CB1D3 * rct2: 0x006CB1D3
*/ */
static bool ride_check_track_contains_banked(CoordsXYE* input, CoordsXYE* output) static bool ride_check_track_contains_banked(const CoordsXYE& input, CoordsXYE* output)
{ {
if (input->element == nullptr) if (input.element == nullptr)
return false; return false;
const auto* trackElement = input->element->AsTrack(); const auto* trackElement = input.element->AsTrack();
if (trackElement == nullptr) if (trackElement == nullptr)
return false; return false;
@ -2807,7 +2807,7 @@ static bool ride_check_track_contains_banked(CoordsXYE* input, CoordsXYE* output
bool moveSlowIt = true; bool moveSlowIt = true;
track_circuit_iterator it, slowIt; track_circuit_iterator it, slowIt;
track_circuit_iterator_begin(&it, *input); track_circuit_iterator_begin(&it, input);
slowIt = it; slowIt = it;
while (track_circuit_iterator_next(&it)) while (track_circuit_iterator_next(&it))
@ -2838,18 +2838,18 @@ static bool ride_check_track_contains_banked(CoordsXYE* input, CoordsXYE* output
* *
* rct2: 0x006CB25D * rct2: 0x006CB25D
*/ */
static int32_t ride_check_station_length(CoordsXYE* input, CoordsXYE* output) static int32_t ride_check_station_length(const CoordsXYE& input, CoordsXYE* output)
{ {
rct_window* w = window_find_by_class(WindowClass::RideConstruction); rct_window* w = window_find_by_class(WindowClass::RideConstruction);
if (w != nullptr && _rideConstructionState != RideConstructionState::State0 if (w != nullptr && _rideConstructionState != RideConstructionState::State0
&& _currentRideIndex == input->element->AsTrack()->GetRideIndex()) && _currentRideIndex == input.element->AsTrack()->GetRideIndex())
{ {
ride_construction_invalidate_current_track(); ride_construction_invalidate_current_track();
} }
output->x = input->x; output->x = input.x;
output->y = input->y; output->y = input.y;
output->element = input->element; output->element = input.element;
track_begin_end trackBeginEnd; track_begin_end trackBeginEnd;
while (track_block_get_previous(*output, &trackBeginEnd)) while (track_block_get_previous(*output, &trackBeginEnd))
{ {
@ -2893,11 +2893,11 @@ static int32_t ride_check_station_length(CoordsXYE* input, CoordsXYE* output)
* *
* rct2: 0x006CB2DA * rct2: 0x006CB2DA
*/ */
static bool ride_check_start_and_end_is_station(CoordsXYE* input) static bool ride_check_start_and_end_is_station(const CoordsXYE& input)
{ {
CoordsXYE trackBack, trackFront; CoordsXYE trackBack, trackFront;
RideId rideIndex = input->element->AsTrack()->GetRideIndex(); RideId rideIndex = input.element->AsTrack()->GetRideIndex();
auto ride = get_ride(rideIndex); auto ride = get_ride(rideIndex);
if (ride == nullptr) if (ride == nullptr)
return false; return false;
@ -3952,7 +3952,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying)
rct_ride_entry* rideType = get_ride_entry(subtype); rct_ride_entry* rideType = get_ride_entry(subtype);
if (rideType->flags & RIDE_ENTRY_FLAG_NO_INVERSIONS) if (rideType->flags & RIDE_ENTRY_FLAG_NO_INVERSIONS)
{ {
if (ride_check_track_contains_inversions(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN };
@ -3960,7 +3960,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying)
} }
if (rideType->flags & RIDE_ENTRY_FLAG_NO_BANKED_TRACK) if (rideType->flags & RIDE_ENTRY_FLAG_NO_BANKED_TRACK)
{ {
if (ride_check_track_contains_banked(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN };
@ -3975,13 +3975,13 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying)
return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS }; return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };
} }
if (!ride_check_station_length(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_STATION_NOT_LONG_ENOUGH };
} }
if (!ride_check_start_and_end_is_station(&trackElement)) 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 }; return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };
@ -4088,7 +4088,7 @@ ResultWithMessage Ride::Open(bool isApplying)
rct_ride_entry* rideEntry = get_ride_entry(subtype); rct_ride_entry* rideEntry = get_ride_entry(subtype);
if (rideEntry->flags & RIDE_ENTRY_FLAG_NO_INVERSIONS) if (rideEntry->flags & RIDE_ENTRY_FLAG_NO_INVERSIONS)
{ {
if (ride_check_track_contains_inversions(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN };
@ -4096,7 +4096,7 @@ ResultWithMessage Ride::Open(bool isApplying)
} }
if (rideEntry->flags & RIDE_ENTRY_FLAG_NO_BANKED_TRACK) if (rideEntry->flags & RIDE_ENTRY_FLAG_NO_BANKED_TRACK)
{ {
if (ride_check_track_contains_banked(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_TRACK_UNSUITABLE_FOR_TYPE_OF_TRAIN };
@ -4111,13 +4111,13 @@ ResultWithMessage Ride::Open(bool isApplying)
return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS }; return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };
} }
if (!ride_check_station_length(&trackElement, &problematicTrackElement)) 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 }; return { false, STR_STATION_NOT_LONG_ENOUGH };
} }
if (!ride_check_start_and_end_is_station(&trackElement)) 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 }; return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };

View File

@ -482,13 +482,13 @@ bool track_circuit_iterators_match(const track_circuit_iterator* firstIt, const
&& firstIt->current.x == secondIt->current.x && firstIt->current.y == secondIt->current.y); && firstIt->current.x == secondIt->current.x && firstIt->current.y == secondIt->current.y);
} }
void track_get_back(CoordsXYE* input, CoordsXYE* output) void track_get_back(const CoordsXYE& input, CoordsXYE* output)
{ {
CoordsXYE lastTrack; CoordsXYE lastTrack;
track_begin_end currentTrack; track_begin_end currentTrack;
bool result; bool result;
lastTrack = *input; lastTrack = input;
do do
{ {
result = track_block_get_previous(lastTrack, &currentTrack); result = track_block_get_previous(lastTrack, &currentTrack);
@ -502,13 +502,13 @@ void track_get_back(CoordsXYE* input, CoordsXYE* output)
*output = lastTrack; *output = lastTrack;
} }
void track_get_front(CoordsXYE* input, CoordsXYE* output) void track_get_front(const CoordsXYE& input, CoordsXYE* output)
{ {
CoordsXYE lastTrack, currentTrack; CoordsXYE lastTrack, currentTrack;
int32_t z, direction; int32_t z, direction;
bool result; bool result;
lastTrack = *input; lastTrack = input;
do do
{ {
result = track_block_get_next(&lastTrack, &currentTrack, &z, &direction); result = track_block_get_next(&lastTrack, &currentTrack, &z, &direction);

View File

@ -619,8 +619,8 @@ bool track_circuit_iterator_previous(track_circuit_iterator* it);
bool track_circuit_iterator_next(track_circuit_iterator* it); bool track_circuit_iterator_next(track_circuit_iterator* it);
bool track_circuit_iterators_match(const track_circuit_iterator* firstIt, const track_circuit_iterator* secondIt); bool track_circuit_iterators_match(const track_circuit_iterator* firstIt, const track_circuit_iterator* secondIt);
void track_get_back(CoordsXYE* input, CoordsXYE* output); void track_get_back(const CoordsXYE& input, CoordsXYE* output);
void track_get_front(CoordsXYE* input, CoordsXYE* output); void track_get_front(const CoordsXYE& input, CoordsXYE* output);
bool track_element_is_covered(track_type_t trackElementType); bool track_element_is_covered(track_type_t trackElementType);
bool track_type_is_station(track_type_t trackType); bool track_type_is_station(track_type_t trackType);