0x004AC3D3 pos.x : ax pos.y : cx pos.z : dx tc : 0x0113609C as legacy connections requiredMods : 0x0113601A queryMods : 0x0113601B isSecondRun : dx & 0x8000 state : see above return ebx
| 5960 | // state : see above |
| 5961 | // return ebx |
| 5962 | static uint16_t trackPathing(VehicleHead& head, const World::Pos3 pos, const Track::TrackConnections& tc, const uint8_t requiredMods, const uint8_t queryMods, bool isSecondRun, Sub4AC3D3State& state) |
| 5963 | { |
| 5964 | // TRACK only |
| 5965 | |
| 5966 | state.hadNewResult = 0; |
| 5967 | // isSecondRun is a second run flag |
| 5968 | if (!isSecondRun) |
| 5969 | { |
| 5970 | state.result.signalState = RouteSignalState::null; |
| 5971 | } |
| 5972 | |
| 5973 | // 0x01136438 |
| 5974 | uint32_t randVal = 0U; |
| 5975 | if (Tutorial::state() == Tutorial::State::none) |
| 5976 | { |
| 5977 | randVal = gPrng1().randNext(); |
| 5978 | } |
| 5979 | |
| 5980 | const auto companyId = head.owner; |
| 5981 | const auto trackType = head.trackType; |
| 5982 | |
| 5983 | auto orders = head.getCurrentOrders(); |
| 5984 | auto curOrder = orders.begin(); |
| 5985 | auto* stationOrder = curOrder->as<OrderStation>(); |
| 5986 | auto* routeOrder = curOrder->as<OrderRouteWaypoint>(); |
| 5987 | if (stationOrder != nullptr || routeOrder != nullptr) |
| 5988 | { |
| 5989 | Sub4AC94FTarget target{}; |
| 5990 | if (stationOrder != nullptr) |
| 5991 | { |
| 5992 | // 0x004AC504 |
| 5993 | target.stationId = stationOrder->getStation(); |
| 5994 | auto* station = StationManager::get(target.stationId); |
| 5995 | target.pos = World::Pos3{ station->x, station->y, station->z }; |
| 5996 | } |
| 5997 | else |
| 5998 | { |
| 5999 | // 0x004AC441 |
| 6000 | target.stationId = StationId::null; |
| 6001 | target.pos = routeOrder->getWaypoint(); |
| 6002 | target.tad = (routeOrder->getTrackId() << 3) | routeOrder->getDirection(); |
| 6003 | const auto& trackSize = TrackData::getUnkTrack(target.tad); |
| 6004 | target.reversePos = target.pos + trackSize.pos; |
| 6005 | if (trackSize.rotationEnd < 12) |
| 6006 | { |
| 6007 | target.reversePos -= World::Pos3{ World::kRotationOffset[trackSize.rotationEnd], 0 }; |
| 6008 | } |
| 6009 | target.reverseTad = target.tad ^ (1U << 2); // Reverse |
| 6010 | } |
| 6011 | // 0x004AC5F5 |
| 6012 | |
| 6013 | uint32_t bestConnection = 0; |
| 6014 | for (auto i = 0U; i < tc.connections.size(); ++i) |
| 6015 | { |
| 6016 | const auto connection = tc.connections[i] & World::Track::AdditionalTaDFlags::basicTaDWithSignalMask; |
| 6017 | const auto connectionTad = connection & World::Track::AdditionalTaDFlags::basicTaDMask; |
| 6018 | |
| 6019 | if ((pos == target.pos && connectionTad == target.tad) |
no test coverage detected