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