]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Parse route files by Durk Talsma.
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
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 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #if defined(FX) && defined(XMESA)
29 bool global_fullscreen = true;
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <math.h>            // rint()
35 #include <stdio.h>
36 #include <stdlib.h>          // atof(), atoi()
37 #include <string.h>
38
39 #include STL_STRING
40
41 #include <simgear/constants.h>
42 #include <simgear/debug/logstream.hxx>
43 #include <simgear/misc/fgstream.hxx>
44 #include <simgear/misc/props.hxx>
45 #include <simgear/timing/sg_time.hxx>
46
47 #include <Include/general.hxx>
48 #include <Airports/simple.hxx>
49 #include <Cockpit/cockpit.hxx>
50 #include <FDM/flight.hxx>
51 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
52 #ifdef FG_NETWORK_OLK
53 #  include <NetworkOLK/network.h>
54 #endif
55
56 #include "fg_init.hxx"
57 #include "globals.hxx"
58 #include "options.hxx"
59
60 FG_USING_STD(string);
61 FG_USING_NAMESPACE(std);
62
63 // from main.cxx
64 extern void fgReshape( int width, int height );
65
66 inline double
67 atof( const string& str )
68 {
69
70 #ifdef __MWERKS__ 
71     // -dw- if ::atof is called, then we get an infinite loop
72     return std::atof( str.c_str() );
73 #else
74     return ::atof( str.c_str() );
75 #endif
76 }
77
78 inline int
79 atoi( const string& str )
80 {
81 #ifdef __MWERKS__ 
82     // -dw- if ::atoi is called, then we get an infinite loop
83     return std::atoi( str.c_str() );
84 #else
85     return ::atoi( str.c_str() );
86 #endif
87 }
88
89
90 // Defined the shared options class here
91 // FGOptions current_options;
92
93
94 // Constructor
95 FGOptions::FGOptions() :
96     // starting longitude in degrees (west = -)
97     // starting latitude in degrees (south = -)
98
99     // Default initial position is Globe, AZ (P13)
100     lon(-110.6642444),
101     lat(  33.3528917),
102
103     // North of the city of Globe
104     // lon(-110.7),
105     // lat(  33.4),
106
107     // North of the city of Globe
108     // lon(-110.742578),
109     // lat(  33.507122),
110
111     // Near where I used to live in Globe, AZ
112     // lon(-110.766000),
113     // lat(  33.377778),
114
115     // 10125 Jewell St. NE
116     // lon(-93.15),
117     // lat( 45.15),
118
119     // Near KHSP (Hot Springs, VA)
120     // lon(-79.8338964 + 0.01),
121     // lat( 37.9514564 + 0.008),
122
123     // (SEZ) SEDONA airport
124     // lon(-111.7884614 + 0.01),
125     // lat(  34.8486289 - 0.015),
126
127     // Jim Brennon's Kingmont Observatory
128     // lon(-121.1131667),
129     // lat(  38.8293917),
130
131     // Huaras, Peru (S09d 31.871'  W077d 31.498')
132     // lon(-77.5249667),
133     // lat( -9.5311833),
134  
135     // Eclipse Watching w73.5 n10 (approx) 18:00 UT
136     // lon(-73.5),
137     // lat( 10.0),
138
139     // Timms Hill (WI)
140     // lon(-90.1953055556),
141     // lat( 45.4511388889),
142
143     // starting altitude in meters (this will be reset to ground level
144     // if it is lower than the terrain
145     altitude(-9999.0),
146
147     // Initial Orientation
148     heading(270.0),      // heading (yaw) angle in degress (Psi)
149     roll(0.0),           // roll angle in degrees (Phi)
150     pitch(0.424),        // pitch angle in degrees (Theta)
151
152     // Initialize current options velocities to 0.0
153     speedset(FG_VC),
154     uBody(0.0), vBody(0.0), wBody(0.0), 
155     vNorth(0.0),vEast(0.0), vDown(0.0),
156     vkcas(0.0), mach(0.0),
157
158     // Miscellaneous
159     game_mode(0),
160     splash_screen(1),
161     intro_music(1),
162     mouse_pointer(0),
163     control_mode(FG_JOYSTICK),
164     auto_coordination(FG_AUTO_COORD_NOT_SPECIFIED),
165
166     // Features
167     hud_status(0),
168     panel_status(1),
169     sound(1),
170     anti_alias_hud(0),
171
172     // Flight Model options
173     flight_model( FGInterface::FG_LARCSIM ),
174     aircraft( "c172" ),
175     model_hz( NEW_DEFAULT_MODEL_HZ ),
176     speed_up( 1 ),
177     trim(0),
178
179     // Rendering options
180     fog(FG_FOG_NICEST),  // nicest
181     clouds(true),
182     clouds_asl(5000*FEET_TO_METER),
183     fullscreen(0),
184     shading(1),
185     skyblend(1),
186     textures(1),
187     wireframe(0),
188     xsize(800),
189     ysize(600),
190     bpp(16),
191     view_mode(FG_VIEW_PILOT),
192     default_view_offset(0),
193
194     // Scenery options
195     tile_diameter(5),
196
197     // HUD options
198     units(FG_UNITS_FEET),
199     tris_or_culled(0),
200         
201     // Time options
202     time_offset(0),
203
204     network_olk(false)
205 {
206     // set initial values/defaults
207     time_offset_type = FG_TIME_SYS_OFFSET;
208     char* envp = ::getenv( "FG_ROOT" );
209
210     if ( envp != NULL ) {
211         // fg_root could be anywhere, so default to environmental
212         // variable $FG_ROOT if it is set.
213         fg_root = envp;
214     } else {
215         // Otherwise, default to a random compiled-in location if
216         // $FG_ROOT is not set.  This can still be overridden from the
217         // command line or a config file.
218
219 #if defined( WIN32 )
220         fg_root = "\\FlightGear";
221 #elif defined( macintosh )
222         fg_root = "";
223 #else
224         fg_root = PKGLIBDIR;
225 #endif
226     }
227
228     // set a possibly independent location for scenery data
229     envp = ::getenv( "FG_SCENERY" );
230
231     if ( envp != NULL ) {
232         // fg_root could be anywhere, so default to environmental
233         // variable $FG_ROOT if it is set.
234         fg_scenery = envp;
235     } else {
236         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
237         fg_scenery = "";
238     }
239
240     airport_id = "KPAO";        // default airport id
241     net_id = "Johnney";         // default pilot's name
242
243     // initialize port config string list
244     channel_options_list.clear();
245 }
246
247 void 
248 FGOptions::toggle_panel() {
249     
250     bool freeze = globals->get_freeze();
251
252     if( !freeze )
253         globals->set_freeze(true);
254     
255     if( panel_status ) {
256         panel_status = false;
257         if ( current_panel != NULL )
258           current_panel->setVisibility(false);
259     } else {
260         panel_status = true;
261         if ( current_panel != NULL )
262           current_panel->setVisibility(true);
263     }
264
265     fgReshape( xsize, ysize);
266
267     if( !freeze )
268         globals->set_freeze( false );
269 }
270
271 double
272 FGOptions::parse_time(const string& time_in) {
273     char *time_str, num[256];
274     double hours, minutes, seconds;
275     double result = 0.0;
276     int sign = 1;
277     int i;
278
279     time_str = (char *)time_in.c_str();
280
281     // printf("parse_time(): %s\n", time_str);
282
283     // check for sign
284     if ( strlen(time_str) ) {
285         if ( time_str[0] == '+' ) {
286             sign = 1;
287             time_str++;
288         } else if ( time_str[0] == '-' ) {
289             sign = -1;
290             time_str++;
291         }
292     }
293     // printf("sign = %d\n", sign);
294
295     // get hours
296     if ( strlen(time_str) ) {
297         i = 0;
298         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
299             num[i] = time_str[0];
300             time_str++;
301             i++;
302         }
303         if ( time_str[0] == ':' ) {
304             time_str++;
305         }
306         num[i] = '\0';
307         hours = atof(num);
308         // printf("hours = %.2lf\n", hours);
309
310         result += hours;
311     }
312
313     // get minutes
314     if ( strlen(time_str) ) {
315         i = 0;
316         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
317             num[i] = time_str[0];
318             time_str++;
319             i++;
320         }
321         if ( time_str[0] == ':' ) {
322             time_str++;
323         }
324         num[i] = '\0';
325         minutes = atof(num);
326         // printf("minutes = %.2lf\n", minutes);
327
328         result += minutes / 60.0;
329     }
330
331     // get seconds
332     if ( strlen(time_str) ) {
333         i = 0;
334         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
335             num[i] = time_str[0];
336             time_str++;
337             i++;
338         }
339         num[i] = '\0';
340         seconds = atof(num);
341         // printf("seconds = %.2lf\n", seconds);
342
343         result += seconds / 3600.0;
344     }
345
346     return(sign * result);
347 }
348
349
350 long int FGOptions::parse_date( const string& date)
351 {
352     struct tm gmt;
353     char * date_str, num[256];
354     int i;
355     // initialize to zero
356     gmt.tm_sec = 0;
357     gmt.tm_min = 0;
358     gmt.tm_hour = 0;
359     gmt.tm_mday = 0;
360     gmt.tm_mon = 0;
361     gmt.tm_year = 0;
362     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
363     date_str = (char *)date.c_str();
364     // get year
365     if ( strlen(date_str) ) {
366         i = 0;
367         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
368             num[i] = date_str[0];
369             date_str++;
370             i++;
371         }
372         if ( date_str[0] == ':' ) {
373             date_str++;
374         }
375         num[i] = '\0';
376         gmt.tm_year = atoi(num) - 1900;
377     }
378     // get month
379     if ( strlen(date_str) ) {
380         i = 0;
381         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
382             num[i] = date_str[0];
383             date_str++;
384             i++;
385         }
386         if ( date_str[0] == ':' ) {
387             date_str++;
388         }
389         num[i] = '\0';
390         gmt.tm_mon = atoi(num) -1;
391     }
392     // get day
393     if ( strlen(date_str) ) {
394         i = 0;
395         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
396             num[i] = date_str[0];
397             date_str++;
398             i++;
399         }
400         if ( date_str[0] == ':' ) {
401             date_str++;
402         }
403         num[i] = '\0';
404         gmt.tm_mday = atoi(num);
405     }
406     // get hour
407     if ( strlen(date_str) ) {
408         i = 0;
409         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
410             num[i] = date_str[0];
411             date_str++;
412             i++;
413         }
414         if ( date_str[0] == ':' ) {
415             date_str++;
416         }
417         num[i] = '\0';
418         gmt.tm_hour = atoi(num);
419     }
420     // get minute
421     if ( strlen(date_str) ) {
422         i = 0;
423         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
424             num[i] = date_str[0];
425             date_str++;
426             i++;
427         }
428         if ( date_str[0] == ':' ) {
429             date_str++;
430         }
431         num[i] = '\0';
432         gmt.tm_min = atoi(num);
433     }
434     // get second
435     if ( strlen(date_str) ) {
436         i = 0;
437         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
438             num[i] = date_str[0];
439             date_str++;
440             i++;
441         }
442         if ( date_str[0] == ':' ) {
443             date_str++;
444         }
445         num[i] = '\0';
446         gmt.tm_sec = atoi(num);
447     }
448     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
449                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
450     //printf ("Date is %s\n", ctime(&theTime));
451     //printf ("in seconds that is %d\n", theTime);
452     //exit(1);
453     return (theTime);
454 }
455
456
457 // parse degree in the form of [+/-]hhh:mm:ss
458 void FGOptions::parse_control( const string& mode ) {
459     if ( mode == "joystick" ) {
460         control_mode = FG_JOYSTICK;
461     } else if ( mode == "mouse" ) {
462         control_mode = FG_MOUSE;
463     } else {
464         control_mode = FG_KEYBOARD;
465     }
466 }
467
468
469 /// parse degree in the form of [+/-]hhh:mm:ss
470 double
471 FGOptions::parse_degree( const string& degree_str) {
472     double result = parse_time( degree_str );
473
474     // printf("Degree = %.4f\n", result);
475
476     return(result);
477 }
478
479
480 // parse time offset command line option
481 int
482 FGOptions::parse_time_offset( const string& time_str) {
483     int result;
484
485     // printf("time offset = %s\n", time_str);
486
487 #ifdef HAVE_RINT
488     result = (int)rint(parse_time(time_str) * 3600.0);
489 #else
490     result = (int)(parse_time(time_str) * 3600.0);
491 #endif
492
493     // printf("parse_time_offset(): %d\n", result);
494
495     return( result );
496 }
497
498
499 // Parse --tile-diameter=n type option 
500
501 int
502 FGOptions::parse_tile_radius( const string& arg ) {
503     int radius = atoi( arg );
504
505     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
506     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
507
508     // printf("parse_tile_radius(): radius = %d\n", radius);
509
510     return(radius);
511 }
512
513
514 // Parse --fdm=abcdefg type option 
515 int
516 FGOptions::parse_fdm( const string& fm ) {
517     // cout << "fdm = " << fm << endl;
518
519     if ( fm == "ada" ) {
520         return FGInterface::FG_ADA;
521     } else if ( fm == "balloon" ) {
522         return FGInterface::FG_BALLOONSIM;
523     } else if ( fm == "external" ) {
524         return FGInterface::FG_EXTERNAL;
525     } else if ( fm == "jsb" ) {
526         return FGInterface::FG_JSBSIM;
527     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
528         return FGInterface::FG_LARCSIM;
529     } else if ( fm == "magic" ) {
530         return FGInterface::FG_MAGICCARPET;
531     } else {
532         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
533         exit(-1);
534     }
535
536     // we'll never get here, but it makes the compiler happy.
537     return -1;
538 }
539
540
541 // Parse --fov=x.xx type option 
542 double
543 FGOptions::parse_fov( const string& arg ) {
544     double fov = atof(arg);
545
546     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
547     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
548
549     globals->get_current_view()->set_fov( fov );
550
551     // printf("parse_fov(): result = %.4f\n", fov);
552
553     return fov;
554 }
555
556
557 // Parse I/O channel option
558 //
559 // Format is "--protocol=medium,direction,hz,medium_options,..."
560 //
561 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
562 //   medium = { serial, socket, file, etc. }
563 //   direction = { in, out, bi }
564 //   hz = number of times to process channel per second (floating
565 //        point values are ok.
566 //
567 // Serial example "--nmea=serial,dir,hz,device,baud" where
568 // 
569 //  device = OS device name of serial line to be open()'ed
570 //  baud = {300, 1200, 2400, ..., 230400}
571 //
572 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
573 // 
574 //  machine = machine name or ip address if client (leave empty if server)
575 //  port = port, leave empty to let system choose
576 //  style = tcp or udp
577 //
578 // File example "--garmin=file,dir,hz,filename" where
579 // 
580 //  filename = file system file name
581
582 bool 
583 FGOptions::parse_channel( const string& type, const string& channel_str ) {
584     // cout << "Channel string = " << channel_str << endl;
585
586     channel_options_list.push_back( type + "," + channel_str );
587
588     return true;
589 }
590
591
592 // Parse --wp=ID[,alt]
593 bool FGOptions::parse_wp( const string& arg ) {
594     string id, alt_str;
595     double alt = 0.0;
596
597     int pos = arg.find( "@" );
598     if ( pos != string::npos ) {
599         id = arg.substr( 0, pos );
600         alt_str = arg.substr( pos + 1 );
601         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
602         alt = atof( alt_str.c_str() );
603         if ( units == FG_UNITS_FEET ) {
604             alt *= FEET_TO_METER;
605         }
606     } else {
607         id = arg;
608     }
609
610     FGAirport a;
611     if ( fgFindAirportID( id, &a ) ) {
612         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
613         globals->get_route()->add_waypoint( wp );
614
615         return true;
616     } else {
617         return false;
618     }
619 }
620
621
622 // Parse --flight-plan=[file]
623 bool FGOptions::parse_flightplan(const string& arg)
624 {
625     fg_gzifstream infile(arg.c_str());
626     if (!infile) {
627         return false;
628     }
629     while ( true ) {
630         string line;
631 #ifdef GETLINE_NEEDS_TERMINATOR
632         getline( infile, line, '\n' );
633 #elif defined( macintosh )
634         getline( infile, line, '\r' );
635 #else
636         getline( infile, line );
637 #endif
638         if ( infile.eof() ) {
639             break;
640         }
641         parse_wp(line);
642     }
643
644     return true;
645 }
646
647
648 // Parse a single option
649 int FGOptions::parse_option( const string& arg ) {
650     // General Options
651     if ( (arg == "--help") || (arg == "-h") ) {
652         // help/usage request
653         return(FG_OPTIONS_HELP);
654     } else if ( arg == "--disable-game-mode") {
655         game_mode = false;
656     } else if ( arg == "--enable-game-mode" ) {
657         game_mode = true;
658     } else if ( arg == "--disable-splash-screen" ) {
659         splash_screen = false;
660     } else if ( arg == "--enable-splash-screen" ) {
661         splash_screen = true;
662     } else if ( arg == "--disable-intro-music" ) {
663         intro_music = false;
664     } else if ( arg == "--enable-intro-music" ) {
665         intro_music = true;
666     } else if ( arg == "--disable-mouse-pointer" ) {
667         mouse_pointer = 1;
668     } else if ( arg == "--enable-mouse-pointer" ) {
669         mouse_pointer = 2;
670     } else if ( arg == "--disable-freeze" ) {
671         globals->set_freeze( false );
672     } else if ( arg == "--enable-freeze" ) {
673         globals->set_freeze( true );
674     } else if ( arg == "--disable-anti-alias-hud" ) {
675         anti_alias_hud = false; 
676     } else if ( arg == "--enable-anti-alias-hud" ) {
677         anti_alias_hud = true;  
678     } else if ( arg.find( "--control=") != string::npos ) {
679         parse_control( arg.substr(10) );
680     } else if ( arg == "--disable-auto-coordination" ) {
681         auto_coordination = FG_AUTO_COORD_DISABLED;     
682     } else if ( arg == "--enable-auto-coordination" ) {
683         auto_coordination = FG_AUTO_COORD_ENABLED;      
684     } else if ( arg == "--disable-hud" ) {
685         hud_status = false;     
686         current_properties.setBoolValue("/sim/hud/visibility", false);
687     } else if ( arg == "--enable-hud" ) {
688         hud_status = true;      
689         current_properties.setBoolValue("/sim/hud/visibility", true);
690     } else if ( arg == "--disable-panel" ) {
691         panel_status = false;
692         current_properties.setBoolValue("/sim/panel/visibility", false);
693         if ( current_panel != NULL )
694           current_panel->setVisibility(false);
695     } else if ( arg == "--enable-panel" ) {
696         panel_status = true;
697         current_properties.setBoolValue("/sim/panel/visibility", true);
698         if ( current_panel != NULL )
699             current_panel->setVisibility(true);
700     } else if ( arg == "--disable-sound" ) {
701         sound = false;
702     } else if ( arg == "--enable-sound" ) {
703         sound = true;
704     } else if ( arg.find( "--airport-id=") != string::npos ) {
705         airport_id = arg.substr( 13 );
706         current_properties.setStringValue("/position/airport-id", airport_id);
707     } else if ( arg.find( "--lon=" ) != string::npos ) {
708         lon = parse_degree( arg.substr(6) );
709         airport_id = "";
710         current_properties.setDoubleValue("/position/longitude", lon);
711         current_properties.setStringValue("/position/airport-id", airport_id);
712     } else if ( arg.find( "--lat=" ) != string::npos ) {
713         lat = parse_degree( arg.substr(6) );
714         airport_id = "";
715         current_properties.setDoubleValue("/position/latitude", lat);
716         current_properties.setStringValue("/position/airport-id", airport_id);
717     } else if ( arg.find( "--altitude=" ) != string::npos ) {
718         if ( units == FG_UNITS_FEET ) {
719             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
720         } else {
721             altitude = atof( arg.substr(11) );
722         }
723         current_properties.setDoubleValue("/position/altitude", altitude);
724     } else if ( arg.find( "--uBody=" ) != string::npos ) {
725         speedset = FG_VTUVW;
726         if ( units == FG_UNITS_FEET ) {
727             uBody = atof( arg.substr(8) );
728         } else {
729             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
730         }
731         //current_properties.setDoubleValue("/velocities/speed-north", uBody);
732     } else if ( arg.find( "--vBody=" ) != string::npos ) {
733         speedset = FG_VTUVW;
734         if ( units == FG_UNITS_FEET ) {
735             vBody = atof( arg.substr(8) );
736         } else {
737             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
738         }
739         //current_properties.setDoubleValue("/velocities/speed-east", vBody);
740     } else if ( arg.find( "--wBody=" ) != string::npos ) {
741         speedset = FG_VTUVW;
742         if ( units == FG_UNITS_FEET ) {
743             wBody = atof( arg.substr(8) );
744         } else {
745             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
746         }
747     } else if ( arg.find( "--vNorth=" ) != string::npos ) {
748         speedset = FG_VTNED;
749         if ( units == FG_UNITS_FEET ) {
750             vNorth = atof( arg.substr(9) );
751         } else {
752             vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
753         }
754         current_properties.setDoubleValue("/velocities/speed-north", vNorth);
755     } else if ( arg.find( "--vEast=" ) != string::npos ) {
756         speedset = FG_VTNED;
757         if ( units == FG_UNITS_FEET ) {
758             vEast = atof( arg.substr(8) );
759         } else {
760             vEast = atof( arg.substr(8) ) * FEET_TO_METER;
761         }
762         current_properties.setDoubleValue("/velocities/speed-east", vEast);
763     } else if ( arg.find( "--vDown=" ) != string::npos ) {
764         speedset = FG_VTNED;
765         if ( units == FG_UNITS_FEET ) {
766             vDown = atof( arg.substr(8) );
767         } else {
768             vDown = atof( arg.substr(8) ) * FEET_TO_METER;
769         }
770         current_properties.setDoubleValue("/velocities/speed-down", vDown);
771     } else if ( arg.find( "--vc=" ) != string::npos) {
772         speedset = FG_VC;
773         vkcas=atof( arg.substr(5) );
774         cout << "Got vc: " << vkcas << endl;
775     } else if ( arg.find( "--mach=" ) != string::npos) {
776         speedset = FG_MACH;
777         mach=atof( arg.substr(7) );
778     } else if ( arg.find( "--heading=" ) != string::npos ) {
779         heading = atof( arg.substr(10) );
780         current_properties.setDoubleValue("/orientation/heading", heading);
781     } else if ( arg.find( "--roll=" ) != string::npos ) {
782         roll = atof( arg.substr(7) );
783         current_properties.setDoubleValue("/orientation/roll", roll);
784     } else if ( arg.find( "--pitch=" ) != string::npos ) {
785         pitch = atof( arg.substr(8) );
786         current_properties.setDoubleValue("/orientation/pitch", pitch);
787     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
788         fg_root = arg.substr( 10 );
789     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
790         fg_scenery = arg.substr( 13 );
791     } else if ( arg.find( "--fdm=" ) != string::npos ) {
792         flight_model = parse_fdm( arg.substr(6) );
793         current_properties.setIntValue("/sim/flight-model", flight_model);
794     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
795         set_trim_mode(1);
796     } else {
797         set_trim_mode(0);
798     }        
799     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
800         aircraft = arg.substr(11);
801         current_properties.setStringValue("/sim/aircraft", aircraft);
802     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
803         aircraft_dir =  arg.substr(15); //  (UIUC)
804     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
805         model_hz = atoi( arg.substr(11) );
806     } else if ( arg.find( "--speed=" ) != string::npos ) {
807         speed_up = atoi( arg.substr(8) );
808     } else if ( arg.find( "--notrim") != string::npos) {
809         trim=-1;
810     } else if ( arg == "--fog-disable" ) {
811         fog = FG_FOG_DISABLED;  
812     } else if ( arg == "--fog-fastest" ) {
813         fog = FG_FOG_FASTEST;   
814     } else if ( arg == "--fog-nicest" ) {
815         fog = FG_FOG_NICEST;    
816     } else if ( arg == "--disable-clouds" ) {
817         clouds = false; 
818     } else if ( arg == "--enable-clouds" ) {
819         clouds = true;  
820     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
821         if ( units == FG_UNITS_FEET ) {
822             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
823         } else {
824             clouds_asl = atof( arg.substr(13) );
825         }
826     } else if ( arg.find( "--fov=" ) != string::npos ) {
827         parse_fov( arg.substr(6) );
828     } else if ( arg == "--disable-fullscreen" ) {
829         fullscreen = false;     
830     } else if ( arg== "--enable-fullscreen") {
831         fullscreen = true;      
832     } else if ( arg == "--shading-flat") {
833         shading = 0;    
834     } else if ( arg == "--shading-smooth") {
835         shading = 1;    
836     } else if ( arg == "--disable-skyblend") {
837         skyblend = false;       
838     } else if ( arg== "--enable-skyblend" ) {
839         skyblend = true;        
840     } else if ( arg == "--disable-textures" ) {
841         textures = false;       
842     } else if ( arg == "--enable-textures" ) {
843         textures = true;
844     } else if ( arg == "--disable-wireframe" ) {
845         wireframe = false;      
846     } else if ( arg == "--enable-wireframe" ) {
847         wireframe = true;
848     } else if ( arg.find( "--geometry=" ) != string::npos ) {
849         bool geometry_ok = true;
850         string geometry = arg.substr( 11 );
851         string::size_type i = geometry.find('x');
852
853         if (i != string::npos) {
854             xsize = atoi(geometry.substr(0, i));
855             ysize = atoi(geometry.substr(i+1));
856             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
857         } else {
858             geometry_ok = false;
859         }
860
861         if ( xsize <= 0 || ysize <= 0 ) {
862             xsize = 640;
863             ysize = 480;
864             geometry_ok = false;
865         }
866
867         if ( !geometry_ok ) {
868             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
869             FG_LOG( FG_GENERAL, FG_ALERT,
870                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
871         }
872     } else if ( arg.find( "--bpp=" ) != string::npos ) {
873         string bits_per_pix = arg.substr( 6 );
874         if ( bits_per_pix == "16" ) {
875             bpp = 16;
876         } else if ( bits_per_pix == "24" ) {
877             bpp = 24;
878         } else if ( bits_per_pix == "32" ) {
879             bpp = 32;
880         }
881     } else if ( arg == "--units-feet" ) {
882         units = FG_UNITS_FEET;  
883     } else if ( arg == "--units-meters" ) {
884         units = FG_UNITS_METERS;        
885     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
886         tile_radius = parse_tile_radius( arg.substr(14) );
887         tile_diameter = tile_radius * 2 + 1;
888     } else if ( arg.find( "--time-offset" ) != string::npos ) {
889         time_offset = parse_time_offset( (arg.substr(14)) );
890         //time_offset_type = FG_TIME_SYS_OFFSET;
891     } else if ( arg.find( "--time-match-real") != string::npos ) {
892       //time_offset = parse_time_offset(arg.substr(18));
893         time_offset_type = FG_TIME_SYS_OFFSET;
894     } else if ( arg.find( "--time-match-local") != string::npos ) {
895       //time_offset = parse_time_offset(arg.substr(18));
896         time_offset_type = FG_TIME_LAT_OFFSET;
897     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
898         time_offset = parse_date( (arg.substr(17)) );
899         time_offset_type = FG_TIME_SYS_ABSOLUTE;
900     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
901         time_offset = parse_date( (arg.substr(17)) );
902         time_offset_type = FG_TIME_LAT_ABSOLUTE;
903     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
904         time_offset = parse_date( (arg.substr(17)) );
905         time_offset_type = FG_TIME_GMT_ABSOLUTE;
906
907     } else if ( arg == "--hud-tris" ) {
908         tris_or_culled = 0;     
909     } else if ( arg == "--hud-culled" ) {
910         tris_or_culled = 1;
911     } else if ( arg.find( "--native=" ) != string::npos ) {
912         parse_channel( "native", arg.substr(9) );
913     } else if ( arg.find( "--garmin=" ) != string::npos ) {
914         parse_channel( "garmin", arg.substr(9) );
915     } else if ( arg.find( "--nmea=" ) != string::npos ) {
916         parse_channel( "nmea", arg.substr(7) );
917     } else if ( arg.find( "--props=" ) != string::npos ) {
918         parse_channel( "props", arg.substr(8) );
919     } else if ( arg.find( "--pve=" ) != string::npos ) {
920         parse_channel( "pve", arg.substr(6) );
921     } else if ( arg.find( "--ray=" ) != string::npos ) {
922         parse_channel( "ray", arg.substr(6) );
923     } else if ( arg.find( "--rul=" ) != string::npos ) {
924         parse_channel( "rul", arg.substr(6) );
925     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
926         parse_channel( "joyclient", arg.substr(12) );
927 #ifdef FG_NETWORK_OLK
928     } else if ( arg == "--disable-network-olk" ) {
929         network_olk = false;    
930     } else if ( arg== "--enable-network-olk") {
931         network_olk = true;     
932     } else if ( arg == "--net-hud" ) {
933         net_hud_display = 1;    
934     } else if ( arg.find( "--net-id=") != string::npos ) {
935         net_id = arg.substr( 9 );
936 #endif
937     } else if ( arg.find( "--prop:" ) == 0 ) {
938         string assign = arg.substr(7);
939         int pos = assign.find('=');
940         if (pos == arg.npos || pos == 0) {
941             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
942             return FG_OPTIONS_ERROR;
943         }
944         string name = assign.substr(0, pos);
945         string value = assign.substr(pos + 1);
946         current_properties.setStringValue(name.c_str(), value);
947         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
948                << name << " to \"" << value << '"');
949     // $$$ begin - added VS Renganathan, 14 Oct 2K
950     // for multi-window outside window imagery
951     } else if ( arg.find( "--view-offset=" ) != string::npos ) {
952         string woffset = arg.substr( 14 );
953         if ( woffset == "LEFT" ) {
954                default_view_offset = M_PI * 0.25;
955         } else if ( woffset == "RIGHT" ) {
956             default_view_offset = M_PI * 1.75;
957         } else if ( woffset == "CENTER" ) {
958             default_view_offset = 0.00;
959         } else {
960             default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
961         }
962         FGViewerRPH *pilot_view =
963             (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
964         pilot_view->set_view_offset( default_view_offset );
965         pilot_view->set_goal_view_offset( default_view_offset );
966     // $$$ end - added VS Renganathan, 14 Oct 2K
967     } else if ( arg.find( "--wp=" ) != string::npos ) {
968         parse_wp( arg.substr( 5 ) );
969     } else if ( arg.find( "--flight-plan=") != string::npos) {
970         parse_flightplan ( arg.substr (14) );
971     } else {
972         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
973         return FG_OPTIONS_ERROR;
974     }
975     
976     return FG_OPTIONS_OK;
977 }
978
979
980 // Scan the command line options for an fg_root definition and set
981 // just that.
982 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
983     int i = 1;
984
985     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
986
987     while ( i < argc ) {
988         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
989
990         string arg = argv[i];
991         if ( arg.find( "--fg-root=" ) != string::npos ) {
992             fg_root = arg.substr( 10 );
993         }
994
995         i++;
996     }
997     
998     return FG_OPTIONS_OK;
999 }
1000
1001
1002 // Scan the config file for an fg_root definition and set just that.
1003 int FGOptions::scan_config_file_for_root( const string& path ) {
1004     fg_gzifstream in( path );
1005     if ( !in.is_open() )
1006         return(FG_OPTIONS_ERROR);
1007
1008     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1009
1010     in >> skipcomment;
1011 #ifndef __MWERKS__
1012     while ( ! in.eof() ) {
1013 #else
1014     char c = '\0';
1015     while ( in.get(c) && c != '\0' ) {
1016         in.putback(c);
1017 #endif
1018         string line;
1019
1020 #ifdef GETLINE_NEEDS_TERMINATOR
1021         getline( in, line, '\n' );
1022 #elif defined( macintosh )
1023         getline( in, line, '\r' );
1024 #else
1025         getline( in, line );
1026 #endif
1027
1028         if ( line.find( "--fg-root=" ) != string::npos ) {
1029             fg_root = line.substr( 10 );
1030         }
1031
1032         in >> skipcomment;
1033     }
1034
1035     return FG_OPTIONS_OK;
1036 }
1037
1038
1039 // Parse the command line options
1040 int FGOptions::parse_command_line( int argc, char **argv ) {
1041     int i = 1;
1042     int result;
1043
1044     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1045
1046     while ( i < argc ) {
1047         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1048
1049         result = parse_option(argv[i]);
1050         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1051             return(result);
1052         }
1053
1054         i++;
1055     }
1056     
1057     return FG_OPTIONS_OK;
1058 }
1059
1060
1061 // Parse config file options
1062 int FGOptions::parse_config_file( const string& path ) {
1063     fg_gzifstream in( path );
1064     if ( !in.is_open() )
1065         return(FG_OPTIONS_ERROR);
1066
1067     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1068
1069     in >> skipcomment;
1070 #ifndef __MWERKS__
1071     while ( ! in.eof() ) {
1072 #else
1073     char c = '\0';
1074     while ( in.get(c) && c != '\0' ) {
1075         in.putback(c);
1076 #endif
1077         string line;
1078
1079 #ifdef GETLINE_NEEDS_TERMINATOR
1080         getline( in, line, '\n' );
1081 #elif defined( macintosh )
1082         getline( in, line, '\r' );
1083 #else
1084         getline( in, line );
1085 #endif
1086
1087         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1088             FG_LOG( FG_GENERAL, FG_ALERT, 
1089                     "Config file parse error: " << path << " '" 
1090                     << line << "'" );
1091             exit(-1);
1092         }
1093         in >> skipcomment;
1094     }
1095
1096     return FG_OPTIONS_OK;
1097 }
1098
1099
1100 // Print usage message
1101 void FGOptions::usage ( void ) {
1102     cout << "Usage: fg [ options ... ]" << endl;
1103     cout << endl;
1104
1105     cout << "General Options:" << endl;
1106     cout << "\t--help -h:  print usage" << endl;
1107     cout << "\t--fg-root=path:  specify the root path for all the data files"
1108          << endl;
1109     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
1110          << " data." << endl
1111          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1112     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
1113     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
1114     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
1115     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
1116     cout << "\t--disable-intro-music:  disable introduction music" << endl;
1117     cout << "\t--enable-intro-music:  enable introduction music" << endl;
1118     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
1119     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
1120          << endl;
1121     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1122     cout << "\t--disable-freeze:  start out in an running state" << endl;
1123     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
1124     cout << "\t--control=mode:  primary control mode " 
1125          << "(joystick, keyboard, mouse)" << endl;
1126     cout << endl;
1127
1128     cout << "Features:" << endl;
1129     cout << "\t--disable-hud:  disable heads up display" << endl;
1130     cout << "\t--enable-hud:  enable heads up display" << endl;
1131     cout << "\t--disable-panel:  disable instrument panel" << endl;
1132     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
1133     cout << "\t--disable-sound:  disable sound effects" << endl;
1134     cout << "\t--enable-sound:  enable sound effects" << endl;
1135     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
1136     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
1137     cout << endl;
1138  
1139     cout << "Flight Model:" << endl;
1140     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
1141     cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1142          << endl;
1143     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
1144     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
1145          << endl;
1146     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
1147     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
1148     cout << endl;
1149     //(UIUC)
1150     cout <<"Aircraft model directory:" << endl;
1151     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1152     cout << endl;
1153
1154     cout << "Initial Position and Orientation:" << endl;
1155     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
1156          << endl;
1157     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
1158          << endl;
1159     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
1160          << endl;
1161     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
1162     cout << "\t\t(unless --units-meters specified" << endl;
1163     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
1164          << endl;
1165     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
1166     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
1167     cout << "\t--uBody=feet per second:  velocity along the body X axis"
1168          << endl;
1169     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
1170          << endl;
1171     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
1172          << endl;
1173     cout << "\t\t(unless --units-meters specified" << endl;
1174     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1175     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1176     cout << endl;
1177
1178     cout << "Rendering Options:" << endl;
1179     cout << "\t--fog-disable:  disable fog/haze" << endl;
1180     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
1181     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
1182     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
1183     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
1184     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1185     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1186          << endl;
1187     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1188     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1189     cout << "\t--shading-flat:  enable flat shading" << endl;
1190     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1191     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1192     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1193     cout << "\t--disable-textures:  disable textures" << endl;
1194     cout << "\t--enable-textures:  enable textures" << endl;
1195     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1196     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1197     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1198          << endl;
1199     cout << "\t--view-offset=xxx:  set the default forward view direction"
1200          << endl;
1201     cout << "\t\tas an offset from straight ahead.  Allowable values are"
1202          << endl;
1203     cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1204     cout << endl;
1205
1206     cout << "Scenery Options:" << endl;
1207     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1208     cout << endl;
1209
1210     cout << "Hud Options:" << endl;
1211     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1212     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1213     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1214     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1215          << endl;
1216     cout << endl;
1217         
1218     cout << "Time Options:" << endl;
1219     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1220     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1221          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1222     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1223          << "\t\tFlightGear time" << endl;   
1224     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1225          << "\t\tdate/time. Uses your system time " << endl;
1226     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1227          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1228     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1229          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1230 #ifdef FG_NETWORK_OLK
1231     cout << endl;
1232
1233     cout << "Network Options:" << endl;
1234     cout << "\t--enable-network-olk:  enable Multipilot mode" << endl;
1235     cout << "\t--disable-network-olk:  disable Multipilot mode (default)" << endl;
1236     cout << "\t--net-hud:  Hud displays network info" << endl;
1237     cout << "\t--net-id=name:  specify your own callsign" << endl;
1238 #endif
1239
1240     cout << endl;
1241     cout << "Route/Way Point Options:" << endl;
1242     cout << "\t--wp=ID[@alt]:  specify a waypoint for the GC autopilot" << endl;
1243     cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1244          << endl;
1245     cout << "\t\tinstances of --wp=" << endl;
1246     cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1247 }
1248
1249
1250 // Destructor
1251 FGOptions::~FGOptions( void ) {
1252 }