]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATC.hxx
Add David Culp's AI model manager code which is derived from David Luff's AI/ATC...
[flightgear.git] / src / ATC / ATC.hxx
index 2dda84e0bacc5d3da30e7ed87d1db707a23e4bf5..8c7210dc236a7a6aff2ee21df5588879634de1e8 100644 (file)
@@ -36,21 +36,45 @@ SG_USING_STD(ostream);
 SG_USING_STD(string);
 SG_USING_STD(ios);
 
+enum plane_type {
+       UNKNOWN,
+       GA_SINGLE,
+       GA_HP_SINGLE,
+       GA_TWIN,
+       GA_JET,
+       MEDIUM,
+       HEAVY,
+       MIL_JET
+};
+
+// PlaneRec - a structure holding ATC-centric details of planes under control
+// This might move or change eventually
+struct PlaneRec {
+       plane_type type;
+       string callsign;
+       int squawkcode;
+};
+
 // Possible types of ATC type that the radios may be tuned to.
 // INVALID implies not tuned in to anything.
 enum atc_type {
-    INVALID,
-    ATIS,
-    GROUND,
-    TOWER,
-    APPROACH,
-    DEPARTURE,
-    ENROUTE
-}; 
+       INVALID,
+       ATIS,
+       GROUND,
+       TOWER,
+       APPROACH,
+       DEPARTURE,
+       ENROUTE
+};
+
+const int ATC_NUM_TYPES = 7;
 
 // DCL - new experimental ATC data store
 struct ATCData {
        atc_type type;
+       // I've deliberately used float instead of double here to keep the size down - we'll be storing thousands of these in memory.
+       // In fact, we could probably ditch x, y and z and generate on the fly as needed.
+       // On the other hand, we'll probably end up reading this data directly from the DAFIF eventually anyway!!
        float lon, lat, elev;
        float x, y, z;
        //int freq;
@@ -61,31 +85,69 @@ struct ATCData {
        string name;
 };
 
+// perhaps we could use an FGRunway instead of this.
+// That wouldn't cache the orthopos though.
+struct RunwayDetails {
+       Point3D threshold_pos;
+       Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
+       Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
+       double hdg;             // true runway heading
+       double length;  // In *METERS*
+       double width;   // ditto
+       string rwyID;
+       int patternDirection;   // -1 for left, 1 for right
+};
+
 ostream& operator << (ostream& os, atc_type atc);
 
 class FGATC {
-
+       
 public:
-
-    virtual ~FGATC();
-
-    // Run the internal calculations
-    virtual void Update();
-
-    // Add plane to a stack
-    virtual void AddPlane(string pid);
-
-    // Remove plane from stack
-    virtual int RemovePlane();
-
-    // Indicate that this instance should output to the display if appropriate 
-    virtual void SetDisplay();
-
-    // Indicate that this instance should not output to the display
-    virtual void SetNoDisplay();
-
-    // Return the type of ATC station that the class represents
-    virtual atc_type GetType();
+       
+       FGATC();
+       virtual ~FGATC();
+       
+       // Run the internal calculations
+       // Derived classes should call this method from their own Update methods if they 
+       // wish to use the response timer functionality.
+       virtual void Update(double dt);
+       
+       // Recieve a coded callback from the ATC menu system based on the user's selection
+       virtual void ReceiveUserCallback(int code);
+       
+       // Add plane to a stack
+       virtual void AddPlane(string pid);
+       
+       // Remove plane from stack
+       virtual int RemovePlane();
+       
+       // Indicate that this instance should output to the display if appropriate 
+       virtual void SetDisplay();
+       
+       // Indicate that this instance should not output to the display
+       virtual void SetNoDisplay();
+       
+       // Generate the text of a message from its parameters and the current context.
+       virtual string GenText(const string& m, int c);
+       
+       // Returns true if OK to transmit on this frequency
+       inline bool GetFreqClear() { return freqClear; }
+       // Indicate that the frequency is in use
+       inline void SetFreqInUse() { freqClear = false; receiving = true; }
+       // Transmission to the ATC is finished and a response is required
+       void SetResponseReqd(string rid);
+       // Transmission finished - let ATC decide if a response is reqd and clear freq if necessary
+       void NotifyTransmissionFinished(string rid);
+       // Transmission finished and no response required
+       inline void ReleaseFreq() { freqClear = true; receiving = false; }      // TODO - check that the plane releasing the freq is the right one etc.
+       // The above 3 funcs under development!!
+       // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
+       // and that the tower control sets freqClear back to true following a reply.
+       // AI traffic should check FreqClear() is true prior to transmitting.
+       // The user will just have to wait for a gap in dialog as in real life.
+       
+       // Return the type of ATC station that the class represents
+       virtual atc_type GetType();
        
        // Set the core ATC data
        void SetData(ATCData* d);
@@ -112,17 +174,17 @@ public:
        inline void set_name(const string nm) {name = nm;}
        
 protected:
-
+       
        // Render a transmission
        // Outputs the transmission either on screen or as audio depending on user preference
        // The refname is a string to identify this sample to the sound manager
        // The repeating flag indicates whether the message should be repeated continuously or played once.
        void Render(string msg, string refname, bool repeating);
-
+       
        // Cease rendering a transmission.
        // Requires the sound manager refname if audio, else "".
        void NoRender(string refname);
-
+       
        double lon, lat, elev;
        double x, y, z;
        int freq;
@@ -135,6 +197,17 @@ protected:
        bool playing;           // Indicates a message in progress      
        bool voiceOK;           // Flag - true if at least one voice has loaded OK
        FGATCVoice* vPtr;
+       
+       bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
+       bool receiving;         // Flag to indicate we are receiving a transmission
+       bool responseReqd;      // Flag to indicate we should be responding to a request/report 
+       bool runResponseCounter;        // Flag to indicate the response counter should be run
+       double responseTime;    // Time to take from end of request transmission to beginning of response
+                                                       // The idea is that this will be slightly random.
+       double responseCounter;         // counter to implement the above
+       string responseID;      // ID of the plane to respond to
+       bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
+       // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
 };
 
 inline istream&
@@ -143,7 +216,7 @@ operator >> ( istream& fin, ATCData& a )
        double f;
        char ch;
        char tp;
-
+       
        fin >> tp;
        
        switch(tp) {
@@ -167,21 +240,21 @@ operator >> ( istream& fin, ATCData& a )
                a.type = INVALID;
                return fin >> skipeol;
        }
-
+       
        fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
        >> a.ident;
        
        a.name = "";
        fin >> ch;
-       a.name += ch;
+       if(ch != '"') a.name += ch;
        while(1) {
                //in >> noskipws
                fin.unsetf(ios::skipws);
                fin >> ch;
-               a.name += ch;
                if((ch == '"') || (ch == 0x0A)) {
                        break;
                }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
+               a.name += ch;
        }
        fin.setf(ios::skipws);
        //cout << "Comm name = " << a.name << '\n';