mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Refactor ride_find_track_gap() to Ride::FindTrackGap()
This commit is contained in:
@@ -732,31 +732,31 @@ bool track_block_get_previous(const CoordsXYE& trackPos, track_begin_end* outTra
|
||||
* bx result y
|
||||
* esi input / output map element
|
||||
*/
|
||||
int32_t ride_find_track_gap(const Ride* ride, CoordsXYE* input, CoordsXYE* output)
|
||||
bool Ride::FindTrackGap(const CoordsXYE& input, CoordsXYE* output) const
|
||||
{
|
||||
if (ride == nullptr || input == nullptr || input->element == nullptr || input->element->GetType() != TileElementType::Track)
|
||||
return 0;
|
||||
if (input.element == nullptr || input.element->GetType() != TileElementType::Track)
|
||||
return false;
|
||||
|
||||
const auto& rtd = ride->GetRideTypeDescriptor();
|
||||
const auto& rtd = GetRideTypeDescriptor();
|
||||
if (rtd.HasFlag(RIDE_TYPE_FLAG_IS_MAZE))
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
rct_window* w = window_find_by_class(WindowClass::RideConstruction);
|
||||
if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == ride->id)
|
||||
if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == id)
|
||||
{
|
||||
ride_construction_invalidate_current_track();
|
||||
}
|
||||
|
||||
bool moveSlowIt = true;
|
||||
track_circuit_iterator it = {};
|
||||
track_circuit_iterator_begin(&it, *input);
|
||||
track_circuit_iterator_begin(&it, input);
|
||||
track_circuit_iterator slowIt = it;
|
||||
while (track_circuit_iterator_next(&it))
|
||||
{
|
||||
if (!track_is_connected_by_shape(it.last.element, it.current.element))
|
||||
{
|
||||
*output = it.current;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
// #2081: prevent an infinite loop
|
||||
moveSlowIt = !moveSlowIt;
|
||||
@@ -766,17 +766,17 @@ int32_t ride_find_track_gap(const Ride* ride, CoordsXYE* input, CoordsXYE* outpu
|
||||
if (track_circuit_iterators_match(&it, &slowIt))
|
||||
{
|
||||
*output = it.current;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!it.looped)
|
||||
{
|
||||
*output = it.last;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Ride::FormatStatusTo(Formatter& ft) const
|
||||
@@ -3824,7 +3824,7 @@ void Ride::ConstructMissingEntranceOrExit() const
|
||||
|
||||
CoordsXYE trackElement;
|
||||
ride_try_get_origin_element(this, &trackElement);
|
||||
ride_find_track_gap(this, &trackElement, &trackElement);
|
||||
FindTrackGap(trackElement, &trackElement);
|
||||
int32_t ok = ride_modify(trackElement);
|
||||
if (ok == 0)
|
||||
{
|
||||
@@ -3930,8 +3930,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying)
|
||||
|
||||
if (mode == RideMode::ContinuousCircuit || IsBlockSectioned())
|
||||
{
|
||||
if (ride_find_track_gap(this, &trackElement, &problematicTrackElement)
|
||||
&& (newStatus != RideStatus::Simulating || IsBlockSectioned()))
|
||||
if (FindTrackGap(trackElement, &problematicTrackElement) && (newStatus != RideStatus::Simulating || IsBlockSectioned()))
|
||||
{
|
||||
ride_scroll_to_track_error(problematicTrackElement);
|
||||
return { false, STR_TRACK_IS_NOT_A_COMPLETE_CIRCUIT };
|
||||
@@ -3971,7 +3970,7 @@ ResultWithMessage Ride::Test(RideStatus newStatus, bool isApplying)
|
||||
|
||||
if (mode == RideMode::StationToStation)
|
||||
{
|
||||
if (!ride_find_track_gap(this, &trackElement, &problematicTrackElement))
|
||||
if (!FindTrackGap(trackElement, &problematicTrackElement))
|
||||
{
|
||||
return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };
|
||||
}
|
||||
@@ -4067,7 +4066,7 @@ ResultWithMessage Ride::Open(bool isApplying)
|
||||
|
||||
if (mode == RideMode::Race || mode == RideMode::ContinuousCircuit || IsBlockSectioned())
|
||||
{
|
||||
if (ride_find_track_gap(this, &trackElement, &problematicTrackElement))
|
||||
if (FindTrackGap(trackElement, &problematicTrackElement))
|
||||
{
|
||||
ride_scroll_to_track_error(problematicTrackElement);
|
||||
return { false, STR_TRACK_IS_NOT_A_COMPLETE_CIRCUIT };
|
||||
@@ -4107,7 +4106,7 @@ ResultWithMessage Ride::Open(bool isApplying)
|
||||
|
||||
if (mode == RideMode::StationToStation)
|
||||
{
|
||||
if (!ride_find_track_gap(this, &trackElement, &problematicTrackElement))
|
||||
if (!FindTrackGap(trackElement, &problematicTrackElement))
|
||||
{
|
||||
return { false, STR_RIDE_MUST_START_AND_END_WITH_STATIONS };
|
||||
}
|
||||
|
||||
@@ -397,6 +397,8 @@ public:
|
||||
|
||||
bool HasRecolourableShopItems() const;
|
||||
bool HasStation() const;
|
||||
|
||||
bool FindTrackGap(const CoordsXYE& input, CoordsXYE* output) const;
|
||||
};
|
||||
void UpdateSpiralSlide(Ride& ride);
|
||||
void UpdateChairlift(Ride& ride);
|
||||
@@ -1009,7 +1011,6 @@ void ride_update_favourited_stat();
|
||||
void ride_check_all_reachable();
|
||||
|
||||
bool ride_try_get_origin_element(const Ride* ride, CoordsXYE* output);
|
||||
int32_t ride_find_track_gap(const Ride* ride, CoordsXYE* input, CoordsXYE* output);
|
||||
void ride_construct(Ride* ride);
|
||||
void ride_clear_blocked_tiles(Ride* ride);
|
||||
Staff* ride_get_mechanic(Ride* ride);
|
||||
|
||||
@@ -135,7 +135,7 @@ void ride_construct(Ride* ride)
|
||||
CoordsXYE trackElement;
|
||||
if (ride_try_get_origin_element(ride, &trackElement))
|
||||
{
|
||||
ride_find_track_gap(ride, &trackElement, &trackElement);
|
||||
ride->FindTrackGap(trackElement, &trackElement);
|
||||
|
||||
rct_window* w = window_get_main();
|
||||
if (w != nullptr && ride_modify(trackElement))
|
||||
@@ -1035,7 +1035,7 @@ bool ride_modify(const CoordsXYE& input)
|
||||
if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_CANNOT_HAVE_GAPS))
|
||||
{
|
||||
CoordsXYE endOfTrackElement{};
|
||||
if (ride_find_track_gap(ride, &tileElement, &endOfTrackElement))
|
||||
if (ride->FindTrackGap(tileElement, &endOfTrackElement))
|
||||
tileElement = endOfTrackElement;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user