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;
44 // Derived classes wishing to use the response counter should call this from their own Update(...).
45 void FGATC::Update(double dt) {
46 if(runResponseCounter) {
47 //cout << responseCounter << '\t' << responseTime << '\n';
48 if(responseCounter >= responseTime) {
49 runResponseCounter = false;
51 //cout << "RESPOND\n";
53 responseCounter += dt;
58 void FGATC::ReceiveUserCallback(int code) {
59 SG_LOG(SG_ATC, SG_WARN, "WARNING - whichever ATC class was intended to receive callback code " << code << " didn't get it!!!");
62 void FGATC::SetResponseReqd(string rid) {
65 respond = false; // TODO - this ignores the fact that more than one plane could call this before response
66 // Shouldn't happen with AI only, but user could confuse things??
68 runResponseCounter = true;
69 responseCounter = 0.0;
70 responseTime = 1.8; // TODO - randomize this slightly.
73 void FGATC::NotifyTransmissionFinished(string rid) {
77 runResponseCounter = true;
78 responseCounter = 0.0;
79 responseTime = 1.8; // TODO - randomize this slightly.
85 void FGATC::AddPlane(string pid) {
88 int FGATC::RemovePlane() {
92 void FGATC::SetDisplay() {
95 void FGATC::SetNoDisplay() {
98 atc_type FGATC::GetType() {
102 void FGATC::SetData(ATCData* d) {
115 // Render a transmission
116 // Outputs the transmission either on screen or as audio depending on user preference
117 // The refname is a string to identify this sample to the sound manager
118 // The repeating flag indicates whether the message should be repeated continuously or played once.
119 void FGATC::Render(string msg, string refname, bool repeating) {
120 #ifdef ENABLE_AUDIO_SUPPORT
121 voice = (voiceOK && fgGetBool("/sim/sound/audible")
122 && fgGetBool("/sim/sound/voice"));
125 unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
127 SGSimpleSound* simple = new SGSimpleSound(buf, len);
128 // TODO - at the moment the volume is always set off comm1
129 // and can't be changed after the transmission has started.
130 simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
131 globals->get_soundmgr()->add(simple, refname);
133 globals->get_soundmgr()->play_looped(refname);
135 globals->get_soundmgr()->play_once(refname);
140 #endif // ENABLE_AUDIO_SUPPORT
142 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
143 for(unsigned int i = 0; i < msg.length(); ++i) {
144 if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
148 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
154 // Cease rendering a transmission.
155 void FGATC::NoRender(string refname) {
158 #ifdef ENABLE_AUDIO_SUPPORT
159 globals->get_soundmgr()->stop(refname);
160 globals->get_soundmgr()->remove(refname);
163 globals->get_ATC_display()->CancelRepeatingMessage();
169 // Generate the text of a message from its parameters and the current context.
170 string FGATC::GenText(const string& m, int c) {
174 ostream& operator << (ostream& os, atc_type atc) {
176 case(INVALID): return(os << "INVALID");
177 case(ATIS): return(os << "ATIS");
178 case(GROUND): return(os << "GROUND");
179 case(TOWER): return(os << "TOWER");
180 case(APPROACH): return(os << "APPROACH");
181 case(DEPARTURE): return(os << "DEPARTURE");
182 case(ENROUTE): return(os << "ENROUTE");
184 return(os << "ERROR - Unknown switch in atc_type operator << ");