MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / RideGetStartOfTrack

Function RideGetStartOfTrack

src/openrct2/ride/Ride.cpp:3925–3964  ·  view source on GitHub ↗

* Given a track element of the ride, find the start of the track. * It has to do this as a backwards loop in case this is an incomplete track. */

Source from the content-addressed store, hash-verified

3923 * It has to do this as a backwards loop in case this is an incomplete track.
3924 */
3925void RideGetStartOfTrack(CoordsXYE* output)
3926{
3927 TrackBeginEnd trackBeginEnd;
3928 CoordsXYE trackElement = *output;
3929 if (trackBlockGetPrevious(trackElement, &trackBeginEnd))
3930 {
3931 TileElement* initial_map = trackElement.element;
3932 TrackBeginEnd slowIt = trackBeginEnd;
3933 bool moveSlowIt = true;
3934 do
3935 {
3936 // Because we are working backwards, begin_element is the section at the end of a piece of track, whereas
3937 // begin_x and begin_y are the coordinates at the start of a piece of track, so we need to pass end_x and
3938 // end_y
3939 CoordsXYE lastGood = {
3940 /* .x = */ trackBeginEnd.end_x,
3941 /* .y = */ trackBeginEnd.end_y,
3942 /* .element = */ trackBeginEnd.begin_element,
3943 };
3944
3945 if (!trackBlockGetPrevious(
3946 { trackBeginEnd.end_x, trackBeginEnd.end_y, trackBeginEnd.begin_element }, &trackBeginEnd))
3947 {
3948 trackElement = lastGood;
3949 break;
3950 }
3951
3952 moveSlowIt = !moveSlowIt;
3953 if (moveSlowIt)
3954 {
3955 if (!trackBlockGetPrevious({ slowIt.end_x, slowIt.end_y, slowIt.begin_element }, &slowIt)
3956 || slowIt.begin_element == trackBeginEnd.begin_element)
3957 {
3958 break;
3959 }
3960 }
3961 } while (initial_map != trackBeginEnd.begin_element);
3962 }
3963 *output = trackElement;
3964}
3965
3966/**
3967 *

Callers 3

RideGetRefundPriceFunction · 0.85

Calls 1

trackBlockGetPreviousFunction · 0.85

Tested by

no test coverage detected