1 // Implementation of FGATC - ATC subsystem base class.
3 // Written by David Luff, started February 2002.
5 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <simgear/sound/soundmgr.hxx>
27 #include <Main/fg_props.hxx>
30 #include "ATCdisplay.hxx"
36 runResponseCounter = false;
37 _runReleaseCounter = false;
46 // Derived classes wishing to use the response counter should call this from their own Update(...).
47 void FGATC::Update(double dt) {
48 if(runResponseCounter) {
49 //cout << responseCounter << '\t' << responseTime << '\n';
50 if(responseCounter >= responseTime) {
51 runResponseCounter = false;
53 //cout << "RESPOND\n";
55 responseCounter += dt;
59 if(_runReleaseCounter) {
60 if(_releaseCounter >= _releaseTime) {
62 _runReleaseCounter = false;
64 _releaseCounter += dt;
69 void FGATC::ReceiveUserCallback(int code) {
70 SG_LOG(SG_ATC, SG_WARN, "WARNING - whichever ATC class was intended to receive callback code " << code << " didn't get it!!!");
73 void FGATC::SetResponseReqd(string rid) {
76 respond = false; // TODO - this ignores the fact that more than one plane could call this before response
77 // Shouldn't happen with AI only, but user could confuse things??
79 runResponseCounter = true;
80 responseCounter = 0.0;
81 responseTime = 1.8; // TODO - randomize this slightly.
84 void FGATC::NotifyTransmissionFinished(string rid) {
85 //cout << "Transmission finished, callsign = " << rid << '\n';
89 runResponseCounter = true;
90 responseCounter = 0.0;
91 responseTime = 1.2; // TODO - randomize this slightly, and allow it to be dependent on the transmission and how busy the ATC is.
92 respond = false; // TODO - this ignores the fact that more than one plane could call this before response
93 // Shouldn't happen with AI only, but user could confuse things??
99 void FGATC::AddPlane(string pid) {
102 int FGATC::RemovePlane() {
106 void FGATC::SetDisplay() {
109 void FGATC::SetNoDisplay() {
112 void FGATC::SetData(ATCData* d) {
125 // Render a transmission
126 // Outputs the transmission either on screen or as audio depending on user preference
127 // The refname is a string to identify this sample to the sound manager
128 // The repeating flag indicates whether the message should be repeated continuously or played once.
129 void FGATC::Render(string msg, string refname, bool repeating) {
130 #ifdef ENABLE_AUDIO_SUPPORT
131 voice = (voiceOK && fgGetBool("/sim/sound/audible")
132 && fgGetBool("/sim/sound/voice"));
135 unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
137 SGSimpleSound* simple = new SGSimpleSound(buf, len);
138 // TODO - at the moment the volume is always set off comm1
139 // and can't be changed after the transmission has started.
140 simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
141 globals->get_soundmgr()->add(simple, refname);
143 globals->get_soundmgr()->play_looped(refname);
145 globals->get_soundmgr()->play_once(refname);
150 #endif // ENABLE_AUDIO_SUPPORT
152 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
153 for(unsigned int i = 0; i < msg.length(); ++i) {
154 if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
158 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
164 // Cease rendering a transmission.
165 void FGATC::NoRender(string refname) {
168 #ifdef ENABLE_AUDIO_SUPPORT
169 globals->get_soundmgr()->stop(refname);
170 globals->get_soundmgr()->remove(refname);
173 globals->get_ATC_display()->CancelRepeatingMessage();
179 // Generate the text of a message from its parameters and the current context.
180 string FGATC::GenText(const string& m, int c) {
184 ostream& operator << (ostream& os, atc_type atc) {
186 case(INVALID): return(os << "INVALID");
187 case(ATIS): return(os << "ATIS");
188 case(GROUND): return(os << "GROUND");
189 case(TOWER): return(os << "TOWER");
190 case(APPROACH): return(os << "APPROACH");
191 case(DEPARTURE): return(os << "DEPARTURE");
192 case(ENROUTE): return(os << "ENROUTE");
194 return(os << "ERROR - Unknown switch in atc_type operator << ");