1 // transmissionlist.cxx -- transmission management class
3 // Written by Alexander Kappes, started March 2002.
4 // Based on navlist.cxx by Curtis Olson, started April 2000.
6 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <strings.h> // bcopy()
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/misc/sgstream.hxx>
33 #include <simgear/math/sg_geodesy.hxx>
35 #include "transmissionlist.hxx"
39 static puDialogBox *ATCMenuBox = 0;
40 static puFrame *ATCMenuFrame = 0;
41 static puText *ATCMenuBoxMessage = 0;
43 FGTransmissionList *current_transmissionlist;
47 FGTransmissionList::FGTransmissionList( void ) {
52 FGTransmissionList::~FGTransmissionList( void ) {
56 // ============================================================================
58 // ============================================================================
59 void mkATCMenuInit (void)
63 int y = (fgGetInt("/sim/startup/ysize") - 10 - dy);
64 ATCMenuBox = new puDialogBox (10, y);
66 ATCMenuFrame = new puFrame (0,0,400,100);
67 ATCMenuBoxMessage = new puText (10, 70);
68 ATCMenuBoxMessage -> setLabel ("");
70 fgSetBool("/sim/atc/menu",false);
71 fgSetBool("/sim/atc/opt1",false);
72 fgSetBool("/sim/atc/opt2",false);
73 fgSetBool("/sim/atc/opt3",false);
74 fgSetBool("/sim/atc/opt4",false);
75 fgSetBool("/sim/atc/opt5",false);
76 fgSetBool("/sim/atc/opt6",false);
77 fgSetBool("/sim/atc/opt7",false);
78 fgSetBool("/sim/atc/opt8",false);
79 fgSetBool("/sim/atc/opt9",false);
80 fgSetBool("/sim/atc/opt0",false);
83 // ATC Menu Message Box
84 void mkATCMenu ( const char *txt )
86 ATCMenuBoxMessage = new puText (10, 70);
87 ATCMenuBoxMessage->setLabel( txt );
89 FG_PUSH_PUI_DIALOG( ATCMenuBox );
93 // load default.transmissions
94 bool FGTransmissionList::init( SGPath path ) {
97 transmissionlist_station.erase( transmissionlist_station.begin(), transmissionlist_station.end() );
99 sg_gzifstream in( path.str() );
100 if ( !in.is_open() ) {
101 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
105 // read in each line of the file
108 // in >> skipcomment;
113 while ( in.get(c) && c != '\0' ) {
116 if ( a.get_type() != '[' ) {
117 transmissionlist_code[a.get_station()].push_back(a);
127 while ( ! in.eof() ) {
129 transmissionlist_station[a.get_station()].push_back(a);
133 if ( a.get_station() < min ) {
134 min = a.get_station();
136 if ( a.get_station() > max ) {
137 max = a.get_station();
139 cout << a.get_station() << " " << a.get_code().c1 << " " << a.get_code().c2 << " "
140 << a.get_code().c3 << " " << a.get_transtext()
141 << " " << a.get_menutext() << endl;
147 fgSetBool("/sim/atc/menu",false);
152 // query the database for the specified station type;
153 // for station see FlightGear/ATC/default.transmissions
154 bool FGTransmissionList::query_station( const int &station, FGTransmission *t,
155 int max_trans, int &num_trans )
157 transmission_list_type tmissions = transmissionlist_station[station];
158 transmission_list_iterator current = tmissions.begin();
159 transmission_list_iterator last = tmissions.end();
161 for ( ; current != last ; ++current ) {
162 if (num_trans < max_trans) {
163 t[num_trans] = *current;
167 cout << "Transmissionlist error: Too many transmissions" << endl;
171 if ( num_trans != 0 ) return true;
173 cout << "No transmission with station " << station << "found." << endl;
179 string FGTransmissionList::gen_text(const int &station, const TransCode code,
180 const TransPar &tpars, const bool ttext )
182 const int cmax = 100;
193 // if (current_transmissionlist->query_station( station, &t ) ) {
194 transmission_list_type tmissions = transmissionlist_station[station];
195 transmission_list_iterator current = tmissions.begin();
196 transmission_list_iterator last = tmissions.end();
198 for ( ; current != last ; ++current ) {
199 if ( current->get_code().c1 == code.c1 &&
200 current->get_code().c2 == code.c2 &&
201 current->get_code().c3 == code.c3 ) {
203 if ( ttext ) message = current->get_transtext();
204 else message = current->get_menutext();
205 strcpy( &mes[0], message.c_str() );
207 while ( strchr(&mes[0], crej) != NULL ) {
208 pos = strchr( &mes[0], crej );
213 for ( i=0; i<cmax; i++ ) {
214 if ( mes[i] == crej ) {
219 strncpy( &dum[0], &mes[0], len );
222 if ( strcmp ( tag, "@ST" ) == 0 )
223 strcat( &dum[0], tpars.station.c_str() );
224 else if ( strcmp ( tag, "@AP" ) == 0 )
225 strcat( &dum[0], tpars.airport.c_str() );
226 else if ( strcmp ( tag, "@CS" ) == 0 )
227 strcat( &dum[0], tpars.callsign.c_str() );
228 else if ( strcmp ( tag, "@TD" ) == 0 ) {
229 if ( tpars.tdir == 1 ) {
231 strcat( &dum[0], &buf[0] );
234 char buf[] = "right";
235 strcat( &dum[0], &buf[0] );
238 else if ( strcmp ( tag, "@HE" ) == 0 ) {
240 sprintf( buf, "%i", (int)(tpars.heading) );
241 strcat( &dum[0], &buf[0] );
243 else if ( strcmp ( tag, "@VD" ) == 0 ) {
244 if ( tpars.VDir == 1 ) {
245 char buf[] = "Descent and maintain";
246 strcat( &dum[0], &buf[0] );
248 else if ( tpars.VDir == 2 ) {
249 char buf[] = "Maintain";
250 strcat( &dum[0], &buf[0] );
252 else if ( tpars.VDir == 3 ) {
253 char buf[] = "Climb and maintain";
254 strcat( &dum[0], &buf[0] );
257 else if ( strcmp ( tag, "@AL" ) == 0 ) {
259 sprintf( buf, "%i", (int)(tpars.alt) );
260 strcat( &dum[0], &buf[0] );
262 else if ( strcmp ( tag, "@MI" ) == 0 ) {
264 sprintf( buf, "%3.1f", tpars.miles );
265 strcat( &dum[0], &buf[0] );
267 else if ( strcmp ( tag, "@FR" ) == 0 ) {
269 sprintf( buf, "%6.2f", tpars.freq );
270 strcat( &dum[0], &buf[0] );
272 else if ( strcmp ( tag, "@RW" ) == 0 )
273 strcat( &dum[0], tpars.runway.c_str() );
275 cout << "Tag " << tag << " not found" << endl;
278 strcat( &dum[0], &mes[len+3] );
279 strcpy( &mes[0], &dum[0] );
282 //cout << mes << endl;
286 if ( mes != "" ) return mes;
287 else return "No transmission found";