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