/** * Route Manager for Rob's Moving Map package * @author Robert J Morton YE572246C * @version 18 December 1997 */ class route implements navconst { private static route CR; // reference to current route object private aircraft ac; // reference to current aircraft object private butpanel bp; // reference to the button panel object private waypnt WR[]; // array of references to waypoints in route private int NWR; // total number of waypoints in this route private int nwr; // number of waypoints so far installed private int CWN; // number of last waypoint in route private int cwn; // current waypoint number private wpenc we; // reference to a waypoint encounter event object private waypnt pw; // reference to previous waypoint private waypnt cw; // reference to 'current' waypoint route(int x, aircraft ac, butpanel bp) { // CONSTRUCT A NEW ROUTE CR = this; // reference to current route object this.ac = ac; // reference to the aircraft object this.bp = bp; // reference to the button panel object NWR = x; // set total number of waypoints in new route nwr = 0; // no waypoints installed yet WR = new waypnt[NWR]; // array for the references to the waypoints } // in new route /* ADD A GIVEN WAYPOINT TO A GIVEN ROUTE: provided there's still room, put new waypoint's object reference in next route array element. */ void AddWayPnt(waypnt w) { if(nwr < NWR) WR[nwr++] = w; } void init() { // INITIALISE THE CURRENTLY-SELECTED ROUTE // ac = aircraft.getCurrent(); [method deprecated] if(nwr < 3) return; // not enough waypoints to make a route CWN = nwr - 1; // index number of the last waypoint in the route double R = ac.getTCR(); // radius of turning circle // for each waypoint in the route except the last for(cwn = CWN ; cwn > 0 ; cwn--) { cw = WR[cwn]; // object reference to current waypoint pw = WR[cwn - 1]; // object reference to 'previous' waypoint /* Set the current waypoint as the previous waypoint's next waypoint and the previous waypoint as the current waypoint's previous waypoint then set 'aircraft' at previous waypoint. */ pw.setNext(cw); cw.setPrev(pw); ac.reset(pw); // Create an encounter between the aircraft and the current waypoint we = new wpenc(cw, ac); double // bearing of the previous waypoint ('aircraft') from current one InRad = cw.gettBrg(), // distance of current waypoint from previous waypoint ('aircraft') D = cw.getDst(); // indicates that the current waypoint is not the destination boolean isDestination = false; /* If doing the last waypoint in the route say that this waypoint's next waypoint is itself, distance to run after final waypoint = 2 * turning circle dia. The 'outbound direction = runway heading of destination waypoint. Set current waypoint as destination. */ if(cwn == CWN) { cw.setNext(cw); cw.setDST(4 * R); cw.setOutRad(cw.getRunHdg()); isDestination = true; } cw.setDest(isDestination); // current waypoint is/is not destination cw.setInRad(InRad); // set for drawing the approach corridor cw.setPWD(D); // tell current waypt distance from previous waypt pw.setDST(D); // tell previous waypt distance to current waypt double OutRad = cw.getrBrg(); // Outbound radial to next waypoint /* If close enough for Cartesian approach & turn geometry, subtract the steering offset from the inbound radial. */ if(D < cw.getRange()) OutRad += we.getStrOff(InRad); pw.setOutRad(OutRad); // set previous waypoint's outbound radial double a = ac.BipAng(InRad - cw.getOutRad() + π), // half the width of this waypoint's approach corridor b = R * (1 - Math.cos(a)); if(a < 0) b = -b; // make it the same sign as 'a' cw.setDL(b); // store it as the width for the approach corridor /* if the current waypoint is the second waypoint in the route, the previous waypoint is the first: its previous is itself. The previous waypoint's InRad is its take-off runway heading. */ if(cwn == 1) { pw.setPrev(pw); pw.setInRad(ac.getHdg()); } } } // ADVANCE THE AIRCRAFT ALONG THE CURRENTLY SELECTED ROUTE boolean advance() { if(we.enRoute()) // Exit if the current waypoint return true; // encounter is still in progress. /* If this is not the last waypoint in the route, set up next waypoint encounter event and indicate that the flight is still in progress. */ if(cwn < CWN) { we = new wpenc(WR[++cwn], ac); return true; } bp.stop(); // Hit the STOP button and signal return false; // the termination of the flight. } // Reset the aircraft to the start of the currently selected route. void reset() {setAircraftAt(cwn = 0);} // Set the aircraft to the next waypoint en-route. void setNext() { if(cwn < CWN) setAircraftAt(++cwn); } // Set the aircraft to the previous waypoint en-route. void setPrev() { if(cwn > 0) setAircraftAt(--cwn); } // Set the aircraft to a specific waypoint en-route. void setThis(int x) { setAircraftAt(x); } // REPOSITION THE AIRCRAFT TO GIVEN WAYPOINT IN THE CURRENT ROUTE private void setAircraftAt(int x) { ac.reset(cw = WR[x]); // set aircraft to given waypoint // If not at start of rout, set aircraft heading to next waypoint if(x > 0) ac.setHdg(cw.getOutRad()); we = new wpenc(cw, ac); // set up the [next] waypoint encounter event } // Get the object reference of THE currently selected route. static route getCurrent() {return CR;} }