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

Function roadPathing

src/OpenLoco/src/Vehicles/VehicleHead.cpp:5326–5424  ·  view source on GitHub ↗

0x0047DFD0

Source from the content-addressed store, hash-verified

5324
5325 // 0x0047DFD0
5326 static uint16_t roadPathing(VehicleHead& head, const World::Pos3 pos, const Track::RoadConnections& rc, const uint8_t requiredMods, const uint8_t queryMods, const uint32_t allowedStationTypes, bool isSecondRun, Sub4AC3D3State& state)
5327 {
5328 // ROAD only
5329
5330 state.hadNewResult = 0;
5331 // isSecondRun is a second run flag
5332 if (!isSecondRun)
5333 {
5334 state.result.signalState = RouteSignalState::null;
5335 }
5336
5337 // 0x01136438
5338 uint32_t randVal = gPrng1().randNext();
5339
5340 const auto companyId = head.owner;
5341 const auto roadObjId = head.trackType;
5342
5343 // TODO: Lots of similar code to track
5344 auto orders = head.getCurrentOrders();
5345 auto curOrder = orders.begin();
5346 auto* stationOrder = curOrder->as<OrderStation>();
5347 auto* routeOrder = curOrder->as<OrderRouteWaypoint>();
5348 if (stationOrder != nullptr || routeOrder != nullptr)
5349 {
5350 Sub4AC94FTarget target{};
5351 if (stationOrder != nullptr)
5352 {
5353 // 0x0047E0F3
5354 target.stationId = stationOrder->getStation();
5355 auto* station = StationManager::get(target.stationId);
5356 target.pos = World::Pos3{ station->x, station->y, station->z };
5357 }
5358 else
5359 {
5360 // 0x0047E033
5361 target.stationId = StationId::null;
5362 target.pos = routeOrder->getWaypoint();
5363 target.tad = (routeOrder->getTrackId() << 3) | routeOrder->getDirection();
5364 const auto& trackSize = TrackData::getUnkRoad(target.tad);
5365 target.reversePos = target.pos + trackSize.pos;
5366 if (trackSize.rotationEnd < 12)
5367 {
5368 target.reversePos -= World::Pos3{ World::kRotationOffset[trackSize.rotationEnd], 0 };
5369 }
5370 target.reverseTad = target.tad ^ (1U << 2); // Reverse
5371 }
5372 // 0x004AC5F5
5373
5374 uint32_t bestConnection = 0;
5375 for (auto i = 0U; i < rc.connections.size(); ++i)
5376 {
5377 const auto connection = rc.connections[i] & World::Track::AdditionalTaDFlags::basicRaDWithSignalMask;
5378 const auto connectionTad = connection & World::Track::AdditionalTaDFlags::basicRaDMask;
5379
5380 if ((pos == target.pos && connectionTad == target.tad)
5381 || (pos == target.reversePos && connectionTad == target.reverseTad))
5382 {
5383 state.result.signalState = RouteSignalState::noSignals;

Callers 2

sub_47DA8DFunction · 0.85
roadPathingShouldReverseFunction · 0.85

Calls 12

roadTargetedPathingFunction · 0.85
roadAimlessWanderPathingFunction · 0.85
getCurrentOrdersMethod · 0.80
getStationMethod · 0.80
getWaypointMethod · 0.80
getTrackIdMethod · 0.80
getFunction · 0.50
randNextMethod · 0.45
beginMethod · 0.45
getDirectionMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected