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

Function trackGetPreviousBlock

src/openrct2/ride/TrackIteration.cpp:130–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128 }
129
130 TrackElement* trackGetPreviousBlock(CoordsXYZ& location, TileElement* tileElement)
131 {
132 CoordsXYZ startLocation = location;
133 TrackBeginEnd trackBeginEnd, slowTrackBeginEnd;
134 TileElement slowTileElement = *tileElement;
135 bool counter = true;
136 CoordsXY slowLocation = location;
137 do
138 {
139 if (!trackBlockGetPrevious({ location, tileElement }, &trackBeginEnd))
140 {
141 return nullptr;
142 }
143 if (trackBeginEnd.begin_x == startLocation.x && trackBeginEnd.begin_y == startLocation.y
144 && tileElement == trackBeginEnd.begin_element)
145 {
146 return nullptr;
147 }
148
149 location.x = trackBeginEnd.end_x;
150 location.y = trackBeginEnd.end_y;
151 location.z = trackBeginEnd.begin_z;
152 tileElement = trackBeginEnd.begin_element;
153
154 // #2081: prevent infinite loop
155 counter = !counter;
156 if (counter)
157 {
158 trackBlockGetPrevious({ slowLocation, &slowTileElement }, &slowTrackBeginEnd);
159 slowLocation.x = slowTrackBeginEnd.end_x;
160 slowLocation.y = slowTrackBeginEnd.end_y;
161 slowTileElement = *(slowTrackBeginEnd.begin_element);
162 if (slowLocation == location && slowTileElement.getBaseZ() == tileElement->getBaseZ()
163 && slowTileElement.getType() == tileElement->getType()
164 && slowTileElement.getDirection() == tileElement->getDirection())
165 {
166 return nullptr;
167 }
168 }
169 } while (!(trackBeginEnd.begin_element->asTrack()->IsBlockStart()));
170
171 // Get the start of the track block instead of the end
172 location = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z };
173 auto trackOrigin = OpenRCT2::MapGetTrackElementAtOfTypeSeq(
174 location, trackBeginEnd.begin_element->asTrack()->GetTrackType(), 0);
175 if (trackOrigin == nullptr)
176 {
177 return nullptr;
178 }
179
180 return trackOrigin->asTrack();
181 }
182
183 /**
184 *

Callers 2

Calls 8

trackBlockGetPreviousFunction · 0.85
IsBlockStartMethod · 0.80
getBaseZMethod · 0.45
getTypeMethod · 0.45
getDirectionMethod · 0.45
asTrackMethod · 0.45
GetTrackTypeMethod · 0.45

Tested by

no test coverage detected