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