/** * Route Manager for Rob's Moving Map package * @author Robert J Morton * @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 wpenc we; // reference to a waypoint encounter event object private boolean trace = false; private int NWR, // total number of waypoints in this route nwr, // number of waypoints so far installed CWN, // number of last waypoint in route cwn; // current waypoint number private waypnt pw, // reference to previous waypoint cw; // reference to 'current' waypoint // CONSTRUCT A NEW ROUTE route(int x, aircraft ac, butpanel bp, boolean trace) { 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 this.trace = trace; WR = new waypnt[NWR]; // array for references to 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 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 first, create: for(cwn = CWN ; cwn > 0 ; cwn--) { cw = WR[cwn]; // object reference to current waypoint pw = WR[cwn - 1]; // object reference to previous waypoint pw.setNext(cw); // current 'wp' is previous 'wp's' next 'wp' cw.setPrev(pw); // previous wp is current wp's previous wp ac.reset(pw); // set aircraft to previous waypoint // Tell this waypoint whether or not it is the destination waypoint. boolean F = false; if(cwn == CWN) F = true; cw.setDest(F); // create an encounter between 'aircraft' and current waypoint. we = new wpenc(cw,ac,false,trace); /* Bearing of previous waypoint ('aircraft') from current waypoint and distance of current waypoint from prev waypoint ('aircraft'). */ double InRad = cw.gettBrg(), D = cw.getDst(); /* if doing the last waypoint in the route, say that this waypoint's next waypoint is itself, that the distance to run after the final waypoint = 2 * turning circle diameter, that the outbound direction = runway heading of destination waypoint and that the current way- point is the destination. */ if(F) { cw.setNext(cw); cw.setDST(4 * R); cw.setOutRad(cw.getRunHdg()); } cw.setInRad(InRad); // set for drawing the approach corridor cw.setPWD(D); // tell current waypoint its distance from prev waypoint pw.setDST(D); // tell prev waypoint its distance to current waypoint 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() + π), b = R * (1 - Math.cos(a)); // half the width of this // waypoint's approach corridor if(a < 0) // make it the same sign as 'a' b = -b; 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, ie: its previous is itself and the previous waypoint's InRad is its take-off runway heading. */ if(cwn == 1) { pw.setPrev(pw); pw.setInRad(ac.getHdg()); } cw.setFrst(false); // none of these waypoints is first in the route } WR[0].setFrst(true); // tell 1st waypoint that it is first in the route } // ADVANCE THE AIRCRAFT ALONG THE CURRENTLY SELECTED ROUTE boolean advance() { // exit if current waypoint encounter still in progress if(we.enRoute()) return true; /* 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. The 'flag' indicates if this waypoint is the first or last in the route. */ if(cwn < CWN) { we = new wpenc(WR[++cwn],ac,false,trace); return true; } bp.stop(); // hit the stop button return false; // and signal termination of flight } /* Methods to reset aircraft to the start of currently selected route, to the next or previous en-route waypoint or to any specified waypoint in the current route. */ void reset() { setAircraftAt(cwn = 0); } void setNext() { if(cwn < CWN) setAircraftAt(++cwn); } void setPrev() { if(cwn > 0) setAircraftAt(--cwn); } void setThis(int x) { setAircraftAt(x); } /* REPOSITION AIRCRAFT TO A GIVEN WAYPOINT IN THE CURRENT ROUTE Set the aircraft to the specified waypoint 'x', then, provided it is not the first waypoint in the route, set the aircraft heading to the next waypoint and set up the [next] waypoint encounter event. */ private void setAircraftAt(int x) { ac.reset(cw = WR[x]); if(x > 0) ac.setHdg(cw.getOutRad()); we = new wpenc(cw,ac,true,trace); } // get object reference of currently selected route static route getCurrent() { return CR; } }