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