Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class AGMHumpRoute
- {
- // Either TrackNumber
- public int TrackNumber = -1;
- public int MarkerId;
- // Or Junction LEFT RIGHT
- public int JnId = -1;
- public AGMHumpRoute LEFT;
- public AGMHumpRoute RIGHT;
- };
- define int StateScan = 0;
- define int StateJnLeft = 1;
- define int StateJnRight = 2;
- define int StateBack = 3;
- define int StateDone = 4;
- final AGMHumpRouteScanResult Scan()
- {
- AGMHumpRoute node;
- LTrackSearch it = new LTrackSearch().DistanceLimit(400000.0f)
- .SleepAfter(1000)
- .DepthLimit(20)
- .DetectCycles(true, true)
- .FromTrackside(Owner, LTrackSearch.FORWARD, StateScan);
- while (true) {
- Log("S: "+it.State());
- switch (it.State()) {
- case StateScan: {
- if (it.MoveNextTrackside()) {
- Log("obj: "+it.CurrentTrackside().GetLocalisedName());
- AGMHumpTrackMarker marker = cast <AGMHumpTrackMarker> it.CurrentTrackside();
- if (marker and marker.HumpTrack >= 0) {
- Log("mrk: "+marker.GetLocalisedName());
- if (marker.HumpTrack > 0) {
- node = new AGMHumpRoute();
- node.TrackNumber = marker.HumpTrack;
- node.MarkerId = marker.GetId();
- }
- it.SetState(StateBack);
- }
- else if (it.CurrentJunction()) {
- int dir = it.GetArrivedDirection();
- Log("jn: '"+it.CurrentJunction().GetLocalisedName()+"', dir " + dir);
- if (dir == LTrackSearch.BACKWARD) {
- node = new AGMHumpRoute();
- node.JnId = it.CurrentJunction().GetId();
- it.SetState(StateJnLeft, (object)node);
- node = null;
- it.PushState(StateScan);
- it.SetDirection(LTrackSearch.LEFT);
- }
- }
- }
- else
- it.SetState(StateBack);
- continue;
- }
- case StateJnLeft: {
- AGMHumpRoute parent = cast <AGMHumpRoute> it.StateData();
- parent.LEFT = node;
- node = null;
- it.SetState(StateJnRight);
- it.PushState(StateScan);
- it.SetDirection(LTrackSearch.RIGHT);
- continue;
- }
- case StateJnRight: {
- AGMHumpRoute parent = cast <AGMHumpRoute> it.StateData();
- parent.RIGHT = node;
- node = parent;
- it.SetState(StateBack);
- continue;
- }
- case StateBack: {
- if (it.IsEmpty())
- break;
- it.PopState();
- continue;
- }
- default: break;
- }
- break;
- }
- AGMHumpRouteScanResult ret = new AGMHumpRouteScanResult();
- LTrackSearchStatus status = it.Status();
- ret.Root = node;
- ret.Overflow = status.Overflow;
- ret.BadJunctionIds = status.BadJunctionIds;
- ret.CyclicJunctionIds = status.CyclicJunctionIds;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement