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