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