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