// transmissionlist.cxx -- transmission management class // // Written by Alexander Kappes, started March 2002. // Based on navlist.cxx by Curtis Olson, started April 2000. // // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id$ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "transmissionlist.hxx" #include static puDialogBox *ATCMenuBox = 0; static puFrame *ATCMenuFrame = 0; static puText *ATCMenuBoxMessage = 0; FGTransmissionList *current_transmissionlist; // Constructor FGTransmissionList::FGTransmissionList( void ) { } // Destructor FGTransmissionList::~FGTransmissionList( void ) { } /* // ============================================================================ // init menu window // ============================================================================ void mkATCMenuInit (void) { int dx = 400; int dy = 100; int y = (fgGetInt("/sim/startup/ysize") - 10 - dy); ATCMenuBox = new puDialogBox (10, y); { ATCMenuFrame = new puFrame (0,0,400,100); ATCMenuBoxMessage = new puText (10, 70); ATCMenuBoxMessage -> setLabel (""); } fgSetBool("/sim/atc/menu",false); fgSetBool("/sim/atc/opt1",false); fgSetBool("/sim/atc/opt2",false); fgSetBool("/sim/atc/opt3",false); fgSetBool("/sim/atc/opt4",false); fgSetBool("/sim/atc/opt5",false); fgSetBool("/sim/atc/opt6",false); fgSetBool("/sim/atc/opt7",false); fgSetBool("/sim/atc/opt8",false); fgSetBool("/sim/atc/opt9",false); fgSetBool("/sim/atc/opt0",false); } // ATC Menu Message Box void mkATCMenu ( const char *txt ) { ATCMenuBoxMessage = new puText (10, 70); ATCMenuBoxMessage->setLabel( txt ); FG_PUSH_PUI_DIALOG( ATCMenuBox ); } */ // load default.transmissions bool FGTransmissionList::init( SGPath path ) { FGTransmission a; transmissionlist_station.erase( transmissionlist_station.begin(), transmissionlist_station.end() ); sg_gzifstream in( path.str() ); if ( !in.is_open() ) { SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() ); exit(-1); } // read in each line of the file // in >> skipeol; // in >> skipcomment; #ifdef __MWERKS__ char c = 0; while ( in.get(c) && c != '\0' ) { in.putback(c); in >> a; if ( a.get_type() != '[' ) { transmissionlist_code[a.get_station()].push_back(a); } in >> skipcomment; } #else double min = 100000; double max = 0; while ( ! in.eof() ) { in >> a; transmissionlist_station[a.get_station()].push_back(a); in >> skipcomment; if ( a.get_station() < min ) { min = a.get_station(); } if ( a.get_station() > max ) { max = a.get_station(); } cout << a.get_station() << " " << a.get_code().c1 << " " << a.get_code().c2 << " " << a.get_code().c3 << " " << a.get_transtext() << " " << a.get_menutext() << endl; } #endif // init ATC menu fgSetBool("/sim/atc/menu",false); return true; } // query the database for the specified station type; // for station see FlightGear/ATC/default.transmissions bool FGTransmissionList::query_station( const int &station, FGTransmission *t, int max_trans, int &num_trans ) { transmission_list_type tmissions = transmissionlist_station[station]; transmission_list_iterator current = tmissions.begin(); transmission_list_iterator last = tmissions.end(); for ( ; current != last ; ++current ) { if (num_trans < max_trans) { t[num_trans] = *current; num_trans += 1; } else { cout << "Transmissionlist error: Too many transmissions" << endl; } } if ( num_trans != 0 ) return true; else { cout << "No transmission with station " << station << "found." << endl; string empty; return false; } } string FGTransmissionList::gen_text(const int &station, const TransCode code, const TransPar &tpars, const bool ttext ) { const int cmax = 100; string message; char tag[4]; char crej = '@'; char mes[cmax]; char dum[cmax]; char buf[10]; char *pos; int len; FGTransmission t; // if (current_transmissionlist->query_station( station, &t ) ) { transmission_list_type tmissions = transmissionlist_station[station]; transmission_list_iterator current = tmissions.begin(); transmission_list_iterator last = tmissions.end(); for ( ; current != last ; ++current ) { if ( current->get_code().c1 == code.c1 && current->get_code().c2 == code.c2 && current->get_code().c3 == code.c3 ) { if ( ttext ) message = current->get_transtext(); else message = current->get_menutext(); strcpy( &mes[0], message.c_str() ); while ( strchr(&mes[0], crej) != NULL ) { pos = strchr( &mes[0], crej ); bcopy(pos, &tag, 3); tag[3] = '\0'; int i; len = 0; for ( i=0; i