]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATC.hxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[flightgear.git] / src / ATC / ATC.hxx
index 1401cdd1ad7223d05dbcfc3b48181a58a539262c..cd4ab84db04ac2ffee48e571045fbb2b7dad077d 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef _FG_ATC_HXX
 #define _FG_ATC_HXX
 
+#include <simgear/constants.h>
 #include <simgear/compiler.h>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
@@ -65,7 +66,9 @@ enum atc_type {
        APPROACH,
        DEPARTURE,
        ENROUTE
-}; 
+};
+
+const int ATC_NUM_TYPES = 7;
 
 // DCL - new experimental ATC data store
 struct ATCData {
@@ -93,6 +96,7 @@ struct RunwayDetails {
        double length;  // In *METERS*
        double width;   // ditto
        string rwyID;
+       int patternDirection;   // -1 for left, 1 for right
 };
 
 ostream& operator << (ostream& os, atc_type atc);
@@ -107,7 +111,10 @@ public:
        // Run the internal calculations
        // Derived classes should call this method from their own Update methods if they 
        // wish to use the response timer functionality.
-       void Update(double dt);
+       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);
@@ -116,17 +123,24 @@ public:
        virtual int RemovePlane();
        
        // Indicate that this instance should output to the display if appropriate 
-       virtual void SetDisplay();
+       inline void SetDisplay() { _display = true; }
        
        // Indicate that this instance should not output to the display
-       virtual void SetNoDisplay();
+       inline void SetNoDisplay() { _display = false; }
+       
+       // 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; }
+       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.
@@ -134,7 +148,7 @@ public:
        // 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();
+       inline atc_type GetType() { return _type; }
        
        // Set the core ATC data
        void SetData(ATCData* d);
@@ -155,10 +169,10 @@ public:
        inline void set_freq(const int fq) {freq = fq;}
        inline int get_range() const { return range; }
        inline void set_range(const int rg) {range = rg;}
-       inline const char* get_ident() { return ident.c_str(); }
-       inline void set_ident(const string id) {ident = id;}
-       inline const char* get_name() {return name.c_str();}
-       inline void set_name(const string nm) {name = nm;}
+       inline string get_ident() { return ident; }
+       inline void set_ident(const string id) { ident = id; }
+       inline string get_name() { return name; }
+       inline void set_name(const string nm) { name = nm; }
        
 protected:
        
@@ -166,33 +180,65 @@ protected:
        // 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);
+       void Render(string msg, string refname = "", bool repeating = false);
        
-       // Cease rendering a transmission.
+       // Cease rendering all transmission from this station.
        // Requires the sound manager refname if audio, else "".
        void NoRender(string refname);
        
+       // Transmit a message when channel becomes free of other dialog
+    void Transmit(int callback_code = 0);
+       
+       // Transmit a message if channel becomes free within timeout (seconds). timeout of zero implies no limit
+       void ConditionalTransmit(double timeout, int callback_code = 0);
+       
+       // Transmit regardless of other dialog on the channel eg emergency
+       void ImmediateTransmit(int callback_code = 0);
+       
+       virtual void ProcessCallback(int code);
+       
        double lon, lat, elev;
        double x, y, z;
        int freq;
        int range;
        string ident;           // Code of the airport its at.
        string name;            // Name transmitted in the broadcast.
+       atc_type _type;
        
        // Rendering related stuff
-       bool voice;                     // Flag - true if we are using voice
-       bool playing;           // Indicates a message in progress      
-       bool voiceOK;           // Flag - true if at least one voice has loaded OK
-       FGATCVoice* vPtr;
-       
+       bool _voice;                    // Flag - true if we are using voice
+       bool _playing;          // Indicates a message in progress      
+       bool _voiceOK;          // Flag - true if at least one voice has loaded OK
+       FGATCVoice* _vPtr;
+
+       string pending_transmission;    // derived classes set this string before calling Transmit(...) 
        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(...)
+       bool _runReleaseCounter;        // A timer for releasing the frequency after giving the message enough time to display
+       double _releaseTime;
+       double _releaseCounter;
+       
+       bool _display;          // Flag to indicate whether we should be outputting to the ATC display.
+       bool _displaying;               // Flag to indicate whether we are outputting to the ATC display.
+       
+private:
+       // Transmission timing stuff.
+       bool _pending;
+       double _timeout;
+       int _callback_code;     // A callback code to be notified and processed by the derived classes
+                                               // A value of zero indicates no callback required
+       bool _transmit;         // we are to transmit
+       bool _transmitting;     // we are transmitting
+       double _counter;
+       double _max_count;
 };
 
 inline istream&
@@ -231,15 +277,15 @@ operator >> ( istream& fin, ATCData& a )
        
        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';