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

Method opposingTrainAtSignal

src/OpenLoco/src/Vehicles/VehicleHead.cpp:4756–4803  ·  view source on GitHub ↗

0x004AC0A3

Source from the content-addressed store, hash-verified

4754
4755 // 0x004AC0A3
4756 bool VehicleHead::opposingTrainAtSignal()
4757 {
4758 // Works out if there is an opposing train in the tile 2 ahead (i.e. waiting at a signal)
4759 // The train could be on any of the multiple connections on that tile.
4760
4761 const auto [nextPos, rotation] = World::Track::getTrackConnectionEnd(getTrackLoc(), trackAndDirection.track._data);
4762 auto tc1 = World::Track::getTrackConnections(nextPos, rotation, owner, trackType, 0, 0);
4763 if (tc1.connections.size() != 1)
4764 {
4765 return false;
4766 }
4767
4768 const auto [nextNextPos, nextRotation] = World::Track::getTrackConnectionEnd(nextPos, tc1.connections.front() & Track::AdditionalTaDFlags::basicTaDMask);
4769 auto tc2 = World::Track::getTrackConnections(nextNextPos, nextRotation, owner, trackType, 0, 0);
4770 if (tc2.connections.empty())
4771 {
4772 return false;
4773 }
4774
4775 for (auto c : tc2.connections)
4776 {
4777 TrackAndDirection::_TrackAndDirection tad{ 0, 0 };
4778 tad._data = c & Track::AdditionalTaDFlags::basicTaDMask;
4779 auto& trackSize = World::TrackData::getUnkTrack(tad._data);
4780 auto pos = nextNextPos + trackSize.pos;
4781 if (trackSize.rotationEnd < 12)
4782 {
4783 pos -= World::Pos3{ kRotationOffset[trackSize.rotationEnd], 0 };
4784 }
4785
4786 auto reverseTad = tad;
4787 reverseTad.setReversed(!tad.isReversed());
4788
4789 for (auto* v : VehicleManager::VehicleList())
4790 {
4791 Vehicle vehicle(v->head);
4792 auto* veh2 = vehicle.veh2;
4793 if (veh2->tileX == pos.x
4794 && veh2->tileY == pos.y
4795 && veh2->tileBaseZ == pos.z / World::kSmallZStep
4796 && veh2->trackAndDirection.track == reverseTad)
4797 {
4798 return true;
4799 }
4800 }
4801 }
4802 return false;
4803 }
4804
4805 struct Sub4AC884State
4806 {

Callers

nothing calls this directly

Calls 6

getTrackConnectionEndFunction · 0.85
getTrackConnectionsFunction · 0.85
sizeMethod · 0.45
emptyMethod · 0.45
setReversedMethod · 0.45
isReversedMethod · 0.45

Tested by

no test coverage detected