]> git.mxchange.org Git - flightgear.git/commitdiff
Further progress towards AI/ATC dialog
authordaveluff <daveluff>
Mon, 6 Oct 2003 22:40:37 +0000 (22:40 +0000)
committerdaveluff <daveluff>
Mon, 6 Oct 2003 22:40:37 +0000 (22:40 +0000)
src/ATC/AIPlane.cxx
src/ATC/ATC.cxx
src/ATC/ATC.hxx
src/ATC/tower.cxx

index 5ce556b472705ca157670acf127749eacf8c2729..bfb83a0e926bda89f15f98f6adcacb09f4d9ba2b 100644 (file)
@@ -52,7 +52,7 @@ FGAIPlane::~FGAIPlane() {
 void FGAIPlane::Update(double dt) {
        if(_pending) {
                if(tuned_station) {
-                       if(tuned_station->FreqClear()) {
+                       if(tuned_station->GetFreqClear()) {
                                _pending = false;
                                _transmit = true;
                                _transmitting = false;
index 120c00e98d50f444b7d9933b9227e1982544bd48..4ea5e10f44929a52934e375878dd52f87c53ac19 100644 (file)
@@ -36,7 +36,25 @@ FGATC::FGATC() {
 FGATC::~FGATC() {
 }
 
+// Derived classes wishing to use the response counter should call this from their own Update(...).
 void FGATC::Update(double dt) {
+       if(responseReqd) {
+               if(responseCounter >= responseTime) {
+                       responseReqd = false;
+                       respond = true;
+               } else {
+                       responseCounter += dt;
+               }
+       }
+}
+
+void FGATC::SetResponseReqd(string rid) {
+       responseReqd = true;
+       respond = false;        // TODO - this ignores the fact that more than one plane could call this before response
+                                               // Shouldn't happen with AI only, but user could confuse things??
+       responseID = rid;
+       responseCounter = 0.0;
+       responseTime = 2.5;             // TODO - randomize this slightly.
 }
 
 void FGATC::AddPlane(string pid) {
index 1249e6e1f44fa6b357880fa2628816c993ea8b43..1401cdd1ad7223d05dbcfc3b48181a58a539262c 100644 (file)
@@ -99,13 +99,15 @@ ostream& operator << (ostream& os, atc_type atc);
 
 class FGATC {
        
-       public:
+public:
        
        FGATC();
        virtual ~FGATC();
        
        // Run the internal calculations
-       virtual void Update(double dt);
+       // Derived classes should call this method from their own Update methods if they 
+       // wish to use the response timer functionality.
+       void Update(double dt);
        
        // Add plane to a stack
        virtual void AddPlane(string pid);
@@ -120,10 +122,12 @@ class FGATC {
        virtual void SetNoDisplay();
        
        // Returns true if OK to transmit on this frequency
-       inline bool FreqClear() { return freqClear; }
+       inline bool GetFreqClear() { return freqClear; }
        // Indicate that the frequency is in use
-       inline void FreqInUse() { freqClear = false; }
-       // Under development!!
+       inline void SetFreqInUse() { freqClear = false; }
+       // Transmission to the ATC is finished and a response is required
+       void SetResponseReqd(string rid);
+       // 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.
@@ -156,7 +160,7 @@ class FGATC {
        inline const char* get_name() {return name.c_str();}
        inline void set_name(const string nm) {name = nm;}
        
-       protected:
+protected:
        
        // Render a transmission
        // Outputs the transmission either on screen or as audio depending on user preference
@@ -182,6 +186,13 @@ class FGATC {
        FGATCVoice* vPtr;
        
        bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
+       bool responseReqd;      // Flag to indicate we should be responding to a request/report 
+       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&
index dee428491a096d13e8e87db66ea279b6bfcf7e43..689a8e92de7591bf069ec8f709075e584249bf87 100644 (file)
@@ -736,6 +736,9 @@ void FGTower::Update(double dt) {
        if(update_count >= update_count_max) {
                update_count = 0;
        }
+       
+       // Call the base class update for the response time handling.
+       FGATC::Update(dt);
 
        if(ident == "KEMT") {   
                // For AI debugging convienience - may be removed