]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.cxx
Rationalisation of the ATC popup dialog code - moved it all over to AK's dynamic...
[flightgear.git] / src / ATC / ATC.cxx
1 // Implementation of FGATC - ATC subsystem base class.
2 //
3 // Written by David Luff, started February 2002.
4 //
5 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
6 //
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.
11 //
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.
16 //
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.
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <simgear/sound/soundmgr.hxx>
26
27 #include <Main/fg_props.hxx>
28
29 #include "ATC.hxx"
30 #include "ATCdisplay.hxx"
31
32 FGATC::FGATC() {
33         freqClear = true;
34         receiving = false;
35         respond = false;
36         runResponseCounter = false;
37         responseID = "";
38         responseReqd = false;
39 }
40
41 FGATC::~FGATC() {
42 }
43
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;
50                         respond = true;
51                         //cout << "RESPOND\n";
52                 } else {
53                         responseCounter += dt;
54                 }
55         }
56 }
57
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!!!");
60 }
61
62 void FGATC::SetResponseReqd(string rid) {
63         receiving = false;
64         responseReqd = true;
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??
67         responseID = rid;
68         responseCounter = 0.0;
69         responseTime = 2.5;             // TODO - randomize this slightly.
70 }
71
72 void FGATC::NotifyTransmissionFinished(string rid) {
73         receiving = false;
74         responseID = rid;
75         if(responseReqd) {
76                 runResponseCounter = true;
77                 responseCounter = 0.0;
78                 responseTime = 2.5;             // TODO - randomize this slightly.
79         } else {
80                 freqClear = true;
81         }
82 }
83
84 void FGATC::AddPlane(string pid) {
85 }
86
87 int FGATC::RemovePlane() {
88         return 0;
89 }
90
91 void FGATC::SetDisplay() {
92 }
93
94 void FGATC::SetNoDisplay() {
95 }
96
97 atc_type FGATC::GetType() {
98         return INVALID;
99 }
100
101 void FGATC::SetData(ATCData* d) {
102         lon = d->lon;
103         lat = d->lat;
104         elev = d->elev;
105         x = d->x;
106         y = d->y;
107         z = d->z;
108         range = d->range;
109         ident = d->ident;
110         name = d->name;
111         freq = d->freq;
112 }
113
114 // Render a transmission
115 // Outputs the transmission either on screen or as audio depending on user preference
116 // The refname is a string to identify this sample to the sound manager
117 // The repeating flag indicates whether the message should be repeated continuously or played once.
118 void FGATC::Render(string msg, string refname, bool repeating) {
119         #ifdef ENABLE_AUDIO_SUPPORT
120         voice = (voiceOK && fgGetBool("/sim/sound/audible")
121         && fgGetBool("/sim/sound/voice"));
122         if(voice) {
123                 int len;
124                 unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
125                 if(voice) {
126                         SGSimpleSound* simple = new SGSimpleSound(buf, len);
127                         // TODO - at the moment the volume is always set off comm1 
128                         // and can't be changed after the transmission has started.
129                         simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
130                         globals->get_soundmgr()->add(simple, refname);
131                         if(repeating) {
132                                 globals->get_soundmgr()->play_looped(refname);
133                         } else {
134                                 globals->get_soundmgr()->play_once(refname);
135                         }
136                 }
137                 delete[] buf;
138         }
139         #endif  // ENABLE_AUDIO_SUPPORT
140         if(!voice) {
141                 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
142                 for(unsigned int i = 0; i < msg.length(); ++i) {
143                         if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
144                                 msg[i] = ' ';
145                         }
146                 }
147                 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
148         }
149         playing = true; 
150 }
151
152
153 // Cease rendering a transmission.
154 void FGATC::NoRender(string refname) {
155         if(playing) {
156                 if(voice) {
157                         #ifdef ENABLE_AUDIO_SUPPORT             
158                         globals->get_soundmgr()->stop(refname);
159                         globals->get_soundmgr()->remove(refname);
160                         #endif
161                 } else {
162                         globals->get_ATC_display()->CancelRepeatingMessage();
163                 }
164                 playing = false;
165         }
166 }
167
168 ostream& operator << (ostream& os, atc_type atc) {
169         switch(atc) {
170                 case(INVALID):    return(os << "INVALID");
171                 case(ATIS):       return(os << "ATIS");
172                 case(GROUND):     return(os << "GROUND");
173                 case(TOWER):      return(os << "TOWER");
174                 case(APPROACH):   return(os << "APPROACH");
175                 case(DEPARTURE):  return(os << "DEPARTURE");
176                 case(ENROUTE):    return(os << "ENROUTE");
177         }
178         return(os << "ERROR - Unknown switch in atc_type operator << ");
179 }