MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / getElTrackConnection

Function getElTrackConnection

src/OpenLoco/src/Map/Track/Track.cpp:206–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204 constexpr uint16_t kNullTad = 0xFFFFU;
205
206 static uint16_t getElTrackConnection(const World::TrackElement& elTrack, uint8_t nextRotation, uint8_t baseZ, uint8_t queryMods)
207 {
208 if (elTrack.sequenceIndex() == 0)
209 {
210 auto trackAndDirection2 = (elTrack.trackId() << 3) | elTrack.rotation();
211 if (nextRotation == TrackData::getUnkTrack(trackAndDirection2).rotationBegin)
212 {
213 const auto& trackPiece = TrackData::getTrackPiece(elTrack.trackId());
214 if (baseZ == (elTrack.baseZ() - trackPiece[0].z / 4))
215 {
216 if (elTrack.hasBridge())
217 {
218 trackAndDirection2 |= elTrack.bridge() << 9;
219 trackAndDirection2 |= AdditionalTaDFlags::hasBridge;
220 }
221
222 if ((queryMods & elTrack.mods()) != 0)
223 {
224 trackAndDirection2 |= AdditionalTaDFlags::hasMods;
225 }
226
227 if (elTrack.hasSignal())
228 {
229 auto* elSignal = elTrack.next()->as<SignalElement>();
230 if (elSignal != nullptr)
231 {
232 if (!elSignal->isAiAllocated() && !elSignal->isGhost())
233 {
234 trackAndDirection2 |= (1 << 15);
235 }
236 }
237 }
238 return trackAndDirection2;
239 }
240 }
241 }
242
243 if (!elTrack.isFlag6())
244 {
245 return kNullTad;
246 }
247
248 auto trackAndDirection2 = (elTrack.trackId() << 3) | (1 << 2) | elTrack.rotation();
249 if (nextRotation != TrackData::getUnkTrack(trackAndDirection2).rotationBegin)
250 {
251 return kNullTad;
252 }
253
254 const auto previousBaseZ = elTrack.baseZ() - (TrackData::getTrackPiece(elTrack.trackId())[elTrack.sequenceIndex()].z + TrackData::getUnkTrack(trackAndDirection2).pos.z) / 4;
255 if (previousBaseZ != baseZ)
256 {
257 return kNullTad;
258 }
259
260 if (elTrack.hasBridge())
261 {
262 trackAndDirection2 |= elTrack.bridge() << 9;
263 trackAndDirection2 |= AdditionalTaDFlags::hasBridge;

Callers 2

getTrackConnectionsFunction · 0.85
getTrackConnectionsAiFunction · 0.85

Calls 13

getTrackPieceFunction · 0.85
trackIdMethod · 0.80
baseZMethod · 0.80
isAiAllocatedMethod · 0.80
isFlag6Method · 0.80
sequenceIndexMethod · 0.45
rotationMethod · 0.45
hasBridgeMethod · 0.45
bridgeMethod · 0.45
modsMethod · 0.45
hasSignalMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected