From c89ea44131e4d209e3827f44e5d8d98f958199c0 Mon Sep 17 00:00:00 2001 From: daveluff Date: Mon, 6 Oct 2003 22:40:37 +0000 Subject: [PATCH] Further progress towards AI/ATC dialog --- src/ATC/AIPlane.cxx | 2 +- src/ATC/ATC.cxx | 18 ++++++++++++++++++ src/ATC/ATC.hxx | 23 +++++++++++++++++------ src/ATC/tower.cxx | 3 +++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/ATC/AIPlane.cxx b/src/ATC/AIPlane.cxx index 5ce556b47..bfb83a0e9 100644 --- a/src/ATC/AIPlane.cxx +++ b/src/ATC/AIPlane.cxx @@ -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; diff --git a/src/ATC/ATC.cxx b/src/ATC/ATC.cxx index 120c00e98..4ea5e10f4 100644 --- a/src/ATC/ATC.cxx +++ b/src/ATC/ATC.cxx @@ -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) { diff --git a/src/ATC/ATC.hxx b/src/ATC/ATC.hxx index 1249e6e1f..1401cdd1a 100644 --- a/src/ATC/ATC.hxx +++ b/src/ATC/ATC.hxx @@ -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& diff --git a/src/ATC/tower.cxx b/src/ATC/tower.cxx index dee428491..689a8e92d 100644 --- a/src/ATC/tower.cxx +++ b/src/ATC/tower.cxx @@ -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