]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.cxx
Set the initial log-level back to info
[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 #include <Main/fgfs.hxx>
22 #include <Main/fg_props.hxx>
23 #include <Sound/soundmgr.hxx>
24
25 #include "ATC.hxx"
26 #include "ATCdisplay.hxx"
27
28 FGATC::~FGATC() {
29 }
30
31 void FGATC::Update(double dt) {
32 }
33
34 void FGATC::AddPlane(string pid) {
35 }
36
37 int FGATC::RemovePlane() {
38     return 0;
39 }
40
41 void FGATC::SetDisplay() {
42 }
43
44 void FGATC::SetNoDisplay() {
45 }
46
47 atc_type FGATC::GetType() {
48     return INVALID;
49 }
50
51 void FGATC::SetData(ATCData* d) {
52         lon = d->lon;
53         lat = d->lat;
54         elev = d->elev;
55         x = d->x;
56         y = d->y;
57         z = d->z;
58         range = d->range;
59         ident = d->ident;
60         name = d->name;
61         freq = d->freq;
62 }
63
64 // Render a transmission
65 // Outputs the transmission either on screen or as audio depending on user preference
66 // The refname is a string to identify this sample to the sound manager
67 // The repeating flag indicates whether the message should be repeated continuously or played once.
68 void FGATC::Render(string msg, string refname, bool repeating) {
69 #ifdef ENABLE_AUDIO_SUPPORT
70         voice = (voiceOK && fgGetBool("/sim/sound/audible")
71                  && fgGetBool("/sim/sound/voice"));
72         if(voice) {
73                 int len;
74                 unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
75                 if(voice) {
76                         FGSimpleSound* simple = new FGSimpleSound(buf, len);
77                         // TODO - at the moment the volume is always set off comm1 
78                         // and can't be changed after the transmission has started.
79                         simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
80                         globals->get_soundmgr()->add(simple, refname);
81                         if(repeating) {
82                                 globals->get_soundmgr()->play_looped(refname);
83                         } else {
84                                 globals->get_soundmgr()->play_once(refname);
85                         }
86                 }
87                 delete[] buf;
88         }
89 #endif  // ENABLE_AUDIO_SUPPORT
90         if(!voice) {
91                 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
92                 for(unsigned int i = 0; i < msg.length(); ++i) {
93                         if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
94                                 msg[i] = ' ';
95                         }
96                 }
97                 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
98         }
99         playing = true; 
100 }
101
102
103 // Cease rendering a transmission.
104 void FGATC::NoRender(string refname) {
105         if(playing) {
106                 if(voice) {
107 #ifdef ENABLE_AUDIO_SUPPORT             
108                         globals->get_soundmgr()->stop(refname);
109                         globals->get_soundmgr()->remove(refname);
110 #endif
111                 } else {
112                         globals->get_ATC_display()->CancelRepeatingMessage();
113                 }
114                 playing = false;
115         }
116 }
117
118 ostream& operator << (ostream& os, atc_type atc) {
119     switch(atc) {
120     case(INVALID):
121         return(os << "INVALID");
122     case(ATIS):
123         return(os << "ATIS");
124     case(GROUND):
125         return(os << "GROUND");
126     case(TOWER):
127         return(os << "TOWER");
128     case(APPROACH):
129         return(os << "APPROACH");
130     case(DEPARTURE):
131         return(os << "DEPARTURE");
132     case(ENROUTE):
133         return(os << "ENROUTE");
134     }
135     return(os << "ERROR - Unknown switch in atc_type operator << ");
136 }