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

Function findSignalOnTrack

src/OpenLoco/src/Vehicles/Routing.cpp:197–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195 constexpr auto kNullTransformFunction = [](const RoutingResults&) {};
196
197 static std::optional<std::pair<World::SignalElement*, World::TrackElement*>> findSignalOnTrack(const World::Pos3& signalLoc, const TrackAndDirection::_TrackAndDirection trackAndDirection, const uint8_t trackType, const uint8_t index)
198 {
199 auto tile = World::TileManager::get(signalLoc);
200 for (auto& el : tile)
201 {
202 if (el.baseZ() != signalLoc.z / 4)
203 {
204 continue;
205 }
206
207 auto* elTrack = el.as<TrackElement>();
208 if (elTrack == nullptr)
209 {
210 continue;
211 }
212
213 if (!elTrack->hasSignal())
214 {
215 continue;
216 }
217
218 if (elTrack->rotation() != trackAndDirection.cardinalDirection())
219 {
220 continue;
221 }
222
223 if (elTrack->sequenceIndex() != index)
224 {
225 continue;
226 }
227
228 if (elTrack->trackObjectId() != trackType)
229 {
230 continue;
231 }
232
233 if (elTrack->trackId() != trackAndDirection.id())
234 {
235 continue;
236 }
237 return std::make_pair(elTrack->next()->as<SignalElement>(), elTrack);
238 }
239 return std::nullopt;
240 }
241
242 // 0x0048963F but only when flags are 0xXXXX_XXXA
243 SignalStateFlags getSignalState(const World::Pos3& loc, const TrackAndDirection::_TrackAndDirection trackAndDirection, const uint8_t trackType, uint32_t flags)

Callers 2

getSignalStateFunction · 0.85
setSignalStateFunction · 0.85

Calls 10

baseZMethod · 0.80
trackObjectIdMethod · 0.80
trackIdMethod · 0.80
getFunction · 0.50
hasSignalMethod · 0.45
rotationMethod · 0.45
cardinalDirectionMethod · 0.45
sequenceIndexMethod · 0.45
idMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected