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