]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
src/GUI/gui.cxx:
[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         current_properties.setBoolValue("/sim/hud/visibility", false);
667     } else if ( arg == "--enable-hud" ) {
668         hud_status = true;      
669         current_properties.setBoolValue("/sim/hud/visibility", true);
670     } else if ( arg == "--disable-panel" ) {
671         panel_status = false;
672         current_properties.setBoolValue("/sim/panel/visibility", false);
673         if ( current_panel != NULL )
674           current_panel->setVisibility(false);
675     } else if ( arg == "--enable-panel" ) {
676         panel_status = true;
677         current_properties.setBoolValue("/sim/panel/visibility", true);
678         if ( current_panel != NULL )
679             current_panel->setVisibility(true);
680         // fov *= 0.4232; /* NO!!! */
681     } else if ( arg == "--disable-sound" ) {
682         sound = false;
683     } else if ( arg == "--enable-sound" ) {
684         sound = true;
685     } else if ( arg.find( "--airport-id=") != string::npos ) {
686         airport_id = arg.substr( 13 );
687         current_properties.setStringValue("/position/airport-id", airport_id);
688     } else if ( arg.find( "--lon=" ) != string::npos ) {
689         lon = parse_degree( arg.substr(6) );
690         airport_id = "";
691         current_properties.setDoubleValue("/position/longitude", lon);
692         current_properties.setStringValue("/position/airport-id", airport_id);
693     } else if ( arg.find( "--lat=" ) != string::npos ) {
694         lat = parse_degree( arg.substr(6) );
695         airport_id = "";
696         current_properties.setDoubleValue("/position/latitude", lat);
697         current_properties.setStringValue("/position/airport-id", airport_id);
698     } else if ( arg.find( "--altitude=" ) != string::npos ) {
699         if ( units == FG_UNITS_FEET ) {
700             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
701         } else {
702             altitude = atof( arg.substr(11) );
703         }
704         current_properties.setDoubleValue("/position/altitude", altitude);
705     } else if ( arg.find( "--uBody=" ) != string::npos ) {
706         speedset = FG_VTUVW;
707         if ( units == FG_UNITS_FEET ) {
708             uBody = atof( arg.substr(8) );
709         } else {
710             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
711         }
712         //current_properties.setDoubleValue("/velocities/speed-north", uBody);
713     } else if ( arg.find( "--vBody=" ) != string::npos ) {
714         speedset = FG_VTUVW;
715         if ( units == FG_UNITS_FEET ) {
716             vBody = atof( arg.substr(8) );
717         } else {
718             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
719         }
720         //current_properties.setDoubleValue("/velocities/speed-east", vBody);
721     } else if ( arg.find( "--wBody=" ) != string::npos ) {
722         speedset = FG_VTUVW;
723         if ( units == FG_UNITS_FEET ) {
724             wBody = atof( arg.substr(8) );
725         } else {
726             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
727         }
728     } else if ( arg.find( "--vNorth=" ) != string::npos ) {
729         speedset = FG_VTNED;
730         if ( units == FG_UNITS_FEET ) {
731             vNorth = atof( arg.substr(9) );
732         } else {
733             vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
734         }
735         current_properties.setDoubleValue("/velocities/speed-north", vNorth);
736     } else if ( arg.find( "--vEast=" ) != string::npos ) {
737         speedset = FG_VTNED;
738         if ( units == FG_UNITS_FEET ) {
739             vEast = atof( arg.substr(8) );
740         } else {
741             vEast = atof( arg.substr(8) ) * FEET_TO_METER;
742         }
743         current_properties.setDoubleValue("/velocities/speed-east", vEast);
744     } else if ( arg.find( "--vDown=" ) != string::npos ) {
745         speedset = FG_VTNED;
746         if ( units == FG_UNITS_FEET ) {
747             vDown = atof( arg.substr(8) );
748         } else {
749             vDown = atof( arg.substr(8) ) * FEET_TO_METER;
750         }
751         current_properties.setDoubleValue("/velocities/speed-down", vDown);
752     } else if ( arg.find( "--vc=" ) != string::npos) {
753         speedset = FG_VC;
754         vkcas=atof( arg.substr(5) );
755         cout << "Got vc: " << vkcas << endl;
756     } else if ( arg.find( "--mach=" ) != string::npos) {
757         speedset = FG_MACH;
758         mach=atof( arg.substr(7) );
759     } else if ( arg.find( "--heading=" ) != string::npos ) {
760         heading = atof( arg.substr(10) );
761         current_properties.setDoubleValue("/orientation/heading", heading);
762     } else if ( arg.find( "--roll=" ) != string::npos ) {
763         roll = atof( arg.substr(7) );
764         current_properties.setDoubleValue("/orientation/roll", roll);
765     } else if ( arg.find( "--pitch=" ) != string::npos ) {
766         pitch = atof( arg.substr(8) );
767         current_properties.setDoubleValue("/orientation/pitch", pitch);
768     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
769         fg_root = arg.substr( 10 );
770     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
771         fg_scenery = arg.substr( 13 );
772     } else if ( arg.find( "--fdm=" ) != string::npos ) {
773         flight_model = parse_fdm( arg.substr(6) );
774         current_properties.setIntValue("/sim/flight-model", flight_model);
775     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
776         set_trim_mode(1);
777     } else {
778         set_trim_mode(0);
779     }        
780     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
781         aircraft = arg.substr(11);
782         current_properties.setStringValue("/sim/aircraft", aircraft);
783     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
784         aircraft_dir =  arg.substr(15); //  (UIUC)
785     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
786         model_hz = atoi( arg.substr(11) );
787     } else if ( arg.find( "--speed=" ) != string::npos ) {
788         speed_up = atoi( arg.substr(8) );
789     } else if ( arg.find( "--notrim") != string::npos) {
790         trim=-1;
791     } else if ( arg == "--fog-disable" ) {
792         fog = FG_FOG_DISABLED;  
793     } else if ( arg == "--fog-fastest" ) {
794         fog = FG_FOG_FASTEST;   
795     } else if ( arg == "--fog-nicest" ) {
796         fog = FG_FOG_NICEST;    
797     } else if ( arg == "--disable-clouds" ) {
798         clouds = false; 
799     } else if ( arg == "--enable-clouds" ) {
800         clouds = true;  
801     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
802         if ( units == FG_UNITS_FEET ) {
803             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
804         } else {
805             clouds_asl = atof( arg.substr(13) );
806         }
807     } else if ( arg.find( "--fov=" ) != string::npos ) {
808         fov = parse_fov( arg.substr(6) );
809     } else if ( arg == "--disable-fullscreen" ) {
810         fullscreen = false;     
811     } else if ( arg== "--enable-fullscreen") {
812         fullscreen = true;      
813     } else if ( arg == "--shading-flat") {
814         shading = 0;    
815     } else if ( arg == "--shading-smooth") {
816         shading = 1;    
817     } else if ( arg == "--disable-skyblend") {
818         skyblend = false;       
819     } else if ( arg== "--enable-skyblend" ) {
820         skyblend = true;        
821     } else if ( arg == "--disable-textures" ) {
822         textures = false;       
823     } else if ( arg == "--enable-textures" ) {
824         textures = true;
825     } else if ( arg == "--disable-wireframe" ) {
826         wireframe = false;      
827     } else if ( arg == "--enable-wireframe" ) {
828         wireframe = true;
829     } else if ( arg.find( "--geometry=" ) != string::npos ) {
830         bool geometry_ok = true;
831         string geometry = arg.substr( 11 );
832         string::size_type i = geometry.find('x');
833
834         if (i != string::npos) {
835             xsize = atoi(geometry.substr(0, i));
836             ysize = atoi(geometry.substr(i+1));
837             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
838         } else {
839             geometry_ok = false;
840         }
841
842         if ( xsize <= 0 || ysize <= 0 ) {
843             xsize = 640;
844             ysize = 480;
845             geometry_ok = false;
846         }
847
848         if ( !geometry_ok ) {
849             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
850             FG_LOG( FG_GENERAL, FG_ALERT,
851                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
852         }
853     } else if ( arg.find( "--bpp=" ) != string::npos ) {
854         string bits_per_pix = arg.substr( 6 );
855         if ( bits_per_pix == "16" ) {
856             bpp = 16;
857         } else if ( bits_per_pix == "24" ) {
858             bpp = 24;
859         } else if ( bits_per_pix == "32" ) {
860             bpp = 32;
861         }
862     } else if ( arg == "--units-feet" ) {
863         units = FG_UNITS_FEET;  
864     } else if ( arg == "--units-meters" ) {
865         units = FG_UNITS_METERS;        
866     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
867         tile_radius = parse_tile_radius( arg.substr(14) );
868         tile_diameter = tile_radius * 2 + 1;
869     } else if ( arg.find( "--time-offset" ) != string::npos ) {
870         time_offset = parse_time_offset( (arg.substr(14)) );
871         //time_offset_type = FG_TIME_SYS_OFFSET;
872     } else if ( arg.find( "--time-match-real") != string::npos ) {
873       //time_offset = parse_time_offset(arg.substr(18));
874         time_offset_type = FG_TIME_SYS_OFFSET;
875     } else if ( arg.find( "--time-match-local") != string::npos ) {
876       //time_offset = parse_time_offset(arg.substr(18));
877         time_offset_type = FG_TIME_LAT_OFFSET;
878     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
879         time_offset = parse_date( (arg.substr(17)) );
880         time_offset_type = FG_TIME_SYS_ABSOLUTE;
881     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
882         time_offset = parse_date( (arg.substr(17)) );
883         time_offset_type = FG_TIME_LAT_ABSOLUTE;
884     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
885         time_offset = parse_date( (arg.substr(17)) );
886         time_offset_type = FG_TIME_GMT_ABSOLUTE;
887
888     } else if ( arg == "--hud-tris" ) {
889         tris_or_culled = 0;     
890     } else if ( arg == "--hud-culled" ) {
891         tris_or_culled = 1;
892     } else if ( arg.find( "--native=" ) != string::npos ) {
893         parse_channel( "native", arg.substr(9) );
894     } else if ( arg.find( "--garmin=" ) != string::npos ) {
895         parse_channel( "garmin", arg.substr(9) );
896     } else if ( arg.find( "--nmea=" ) != string::npos ) {
897         parse_channel( "nmea", arg.substr(7) );
898     } else if ( arg.find( "--props=" ) != string::npos ) {
899         parse_channel( "props", arg.substr(8) );
900     } else if ( arg.find( "--pve=" ) != string::npos ) {
901         parse_channel( "pve", arg.substr(6) );
902     } else if ( arg.find( "--ray=" ) != string::npos ) {
903         parse_channel( "ray", arg.substr(6) );
904     } else if ( arg.find( "--rul=" ) != string::npos ) {
905         parse_channel( "rul", arg.substr(6) );
906     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
907         parse_channel( "joyclient", arg.substr(12) );
908 #ifdef FG_NETWORK_OLK
909     } else if ( arg == "--disable-network-olk" ) {
910         network_olk = false;    
911     } else if ( arg== "--enable-network-olk") {
912         network_olk = true;     
913     } else if ( arg == "--net-hud" ) {
914         net_hud_display = 1;    
915     } else if ( arg.find( "--net-id=") != string::npos ) {
916         net_id = arg.substr( 9 );
917 #endif
918     } else if ( arg.find( "--prop:" ) == 0 ) {
919         string assign = arg.substr(7);
920         int pos = assign.find('=');
921         if (pos == arg.npos || pos == 0) {
922             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
923             return FG_OPTIONS_ERROR;
924         }
925         string name = assign.substr(0, pos);
926         string value = assign.substr(pos + 1);
927         current_properties.setStringValue(name.c_str(), value);
928         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
929                << name << " to \"" << value << '"');
930     // $$$ begin - added VS Renganathan, 14 Oct 2K
931     // for multi-window outside window imagery
932     } else if ( arg.find( "--view-offset=" ) != string::npos ) {
933         string woffset = arg.substr( 14 );
934         if ( woffset == "LEFT" ) {
935                default_view_offset = M_PI * 0.25;
936         } else if ( woffset == "RIGHT" ) {
937             default_view_offset = M_PI * 1.75;
938         } else if ( woffset == "CENTER" ) {
939             default_view_offset = 0.00;
940         } else {
941             default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
942         }
943         FGViewerRPH *pilot_view =
944             (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
945         pilot_view->set_view_offset( default_view_offset );
946         pilot_view->set_goal_view_offset( default_view_offset );
947     // $$$ end - added VS Renganathan, 14 Oct 2K
948     } else if ( arg.find( "--wp=" ) != string::npos ) {
949         parse_wp( arg.substr( 5 ) );
950     } else {
951         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
952         return FG_OPTIONS_ERROR;
953     }
954     
955     return FG_OPTIONS_OK;
956 }
957
958
959 // Scan the command line options for an fg_root definition and set
960 // just that.
961 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
962     int i = 1;
963
964     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
965
966     while ( i < argc ) {
967         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
968
969         string arg = argv[i];
970         if ( arg.find( "--fg-root=" ) != string::npos ) {
971             fg_root = arg.substr( 10 );
972         }
973
974         i++;
975     }
976     
977     return FG_OPTIONS_OK;
978 }
979
980
981 // Scan the config file for an fg_root definition and set just that.
982 int FGOptions::scan_config_file_for_root( const string& path ) {
983     fg_gzifstream in( path );
984     if ( !in.is_open() )
985         return(FG_OPTIONS_ERROR);
986
987     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
988
989     in >> skipcomment;
990 #ifndef __MWERKS__
991     while ( ! in.eof() ) {
992 #else
993     char c = '\0';
994     while ( in.get(c) && c != '\0' ) {
995         in.putback(c);
996 #endif
997         string line;
998
999 #ifdef GETLINE_NEEDS_TERMINATOR
1000         getline( in, line, '\n' );
1001 #elif defined( macintosh )
1002         getline( in, line, '\r' );
1003 #else
1004         getline( in, line );
1005 #endif
1006
1007         if ( line.find( "--fg-root=" ) != string::npos ) {
1008             fg_root = line.substr( 10 );
1009         }
1010
1011         in >> skipcomment;
1012     }
1013
1014     return FG_OPTIONS_OK;
1015 }
1016
1017
1018 // Parse the command line options
1019 int FGOptions::parse_command_line( int argc, char **argv ) {
1020     int i = 1;
1021     int result;
1022
1023     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1024
1025     while ( i < argc ) {
1026         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1027
1028         result = parse_option(argv[i]);
1029         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1030             return(result);
1031         }
1032
1033         i++;
1034     }
1035     
1036     return FG_OPTIONS_OK;
1037 }
1038
1039
1040 // Parse config file options
1041 int FGOptions::parse_config_file( const string& path ) {
1042     fg_gzifstream in( path );
1043     if ( !in.is_open() )
1044         return(FG_OPTIONS_ERROR);
1045
1046     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1047
1048     in >> skipcomment;
1049 #ifndef __MWERKS__
1050     while ( ! in.eof() ) {
1051 #else
1052     char c = '\0';
1053     while ( in.get(c) && c != '\0' ) {
1054         in.putback(c);
1055 #endif
1056         string line;
1057
1058 #ifdef GETLINE_NEEDS_TERMINATOR
1059         getline( in, line, '\n' );
1060 #elif defined( macintosh )
1061         getline( in, line, '\r' );
1062 #else
1063         getline( in, line );
1064 #endif
1065
1066         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1067             FG_LOG( FG_GENERAL, FG_ALERT, 
1068                     "Config file parse error: " << path << " '" 
1069                     << line << "'" );
1070             exit(-1);
1071         }
1072         in >> skipcomment;
1073     }
1074
1075     return FG_OPTIONS_OK;
1076 }
1077
1078
1079 // Print usage message
1080 void FGOptions::usage ( void ) {
1081     cout << "Usage: fg [ options ... ]" << endl;
1082     cout << endl;
1083
1084     cout << "General Options:" << endl;
1085     cout << "\t--help -h:  print usage" << endl;
1086     cout << "\t--fg-root=path:  specify the root path for all the data files"
1087          << endl;
1088     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
1089          << " data." << endl
1090          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1091     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
1092     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
1093     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
1094     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
1095     cout << "\t--disable-intro-music:  disable introduction music" << endl;
1096     cout << "\t--enable-intro-music:  enable introduction music" << endl;
1097     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
1098     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
1099          << endl;
1100     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1101     cout << "\t--disable-freeze:  start out in an running state" << endl;
1102     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
1103     cout << "\t--control=mode:  primary control mode " 
1104          << "(joystick, keyboard, mouse)" << endl;
1105     cout << endl;
1106
1107     cout << "Features:" << endl;
1108     cout << "\t--disable-hud:  disable heads up display" << endl;
1109     cout << "\t--enable-hud:  enable heads up display" << endl;
1110     cout << "\t--disable-panel:  disable instrument panel" << endl;
1111     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
1112     cout << "\t--disable-sound:  disable sound effects" << endl;
1113     cout << "\t--enable-sound:  enable sound effects" << endl;
1114     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
1115     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
1116     cout << endl;
1117  
1118     cout << "Flight Model:" << endl;
1119     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
1120     cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1121          << endl;
1122     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
1123     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
1124          << endl;
1125     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
1126     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
1127     cout << endl;
1128     //(UIUC)
1129     cout <<"Aircraft model directory:" << endl;
1130     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1131     cout << endl;
1132
1133     cout << "Initial Position and Orientation:" << endl;
1134     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
1135          << endl;
1136     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
1137          << endl;
1138     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
1139          << endl;
1140     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
1141     cout << "\t\t(unless --units-meters specified" << endl;
1142     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
1143          << endl;
1144     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
1145     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
1146     cout << "\t--uBody=feet per second:  velocity along the body X axis"
1147          << endl;
1148     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
1149          << endl;
1150     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
1151          << endl;
1152     cout << "\t\t(unless --units-meters specified" << endl;
1153     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1154     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1155     cout << endl;
1156
1157     cout << "Rendering Options:" << endl;
1158     cout << "\t--fog-disable:  disable fog/haze" << endl;
1159     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
1160     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
1161     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
1162     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
1163     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1164     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1165          << endl;
1166     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1167     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1168     cout << "\t--shading-flat:  enable flat shading" << endl;
1169     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1170     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1171     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1172     cout << "\t--disable-textures:  disable textures" << endl;
1173     cout << "\t--enable-textures:  enable textures" << endl;
1174     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1175     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1176     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1177          << endl;
1178     cout << "\t--view-offset=xxx:  set the default forward view direction"
1179          << endl;
1180     cout << "\t\tas an offset from straight ahead.  Allowable values are"
1181          << endl;
1182     cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1183     cout << endl;
1184
1185     cout << "Scenery Options:" << endl;
1186     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1187     cout << endl;
1188
1189     cout << "Hud Options:" << endl;
1190     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1191     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1192     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1193     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1194          << endl;
1195     cout << endl;
1196         
1197     cout << "Time Options:" << endl;
1198     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1199     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1200          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1201     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1202          << "\t\tFlightGear time" << endl;   
1203     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1204          << "\t\tdate/time. Uses your system time " << endl;
1205     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1206          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1207     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1208          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1209 #ifdef FG_NETWORK_OLK
1210     cout << endl;
1211
1212     cout << "Network Options:" << endl;
1213     cout << "\t--enable-network-olk:  enable Multipilot mode" << endl;
1214     cout << "\t--disable-network-olk:  disable Multipilot mode (default)" << endl;
1215     cout << "\t--net-hud:  Hud displays network info" << endl;
1216     cout << "\t--net-id=name:  specify your own callsign" << endl;
1217 #endif
1218
1219     cout << endl;
1220     cout << "Route/Way Point Options:" << endl;
1221     cout << "\t--wp=ID[@alt]:  specify a waypoint for the GC autopilot" << endl;
1222     cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1223          << endl;
1224     cout << "\t\tinstances of --wp=" << endl;
1225 }
1226
1227
1228 // Destructor
1229 FGOptions::~FGOptions( void ) {
1230 }