]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
42817c8531fbe61748f7c8060d253e0bb764572a
[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
194     // HUD options
195     units(FG_UNITS_FEET),
196     tris_or_culled(0),
197         
198     // Time options
199     time_offset(0),
200
201     network_olk(false)
202 {
203     // set initial values/defaults
204     time_offset_type = FG_TIME_SYS_OFFSET;
205     char* envp = ::getenv( "FG_ROOT" );
206
207     if ( envp != NULL ) {
208         // fg_root could be anywhere, so default to environmental
209         // variable $FG_ROOT if it is set.
210         fg_root = envp;
211     } else {
212         // Otherwise, default to a random compiled-in location if
213         // $FG_ROOT is not set.  This can still be overridden from the
214         // command line or a config file.
215
216 #if defined( WIN32 )
217         fg_root = "\\FlightGear";
218 #elif defined( macintosh )
219         fg_root = "";
220 #else
221         fg_root = PKGLIBDIR;
222 #endif
223     }
224
225     // set a possibly independent location for scenery data
226     envp = ::getenv( "FG_SCENERY" );
227
228     if ( envp != NULL ) {
229         // fg_root could be anywhere, so default to environmental
230         // variable $FG_ROOT if it is set.
231         fg_scenery = envp;
232     } else {
233         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
234         fg_scenery = "";
235     }
236
237     airport_id = "KPAO";        // default airport id
238     net_id = "Johnney";         // default pilot's name
239
240     // initialize port config string list
241     channel_options_list.clear();
242 }
243
244 void 
245 FGOptions::toggle_panel() {
246     
247     bool freeze = globals->get_freeze();
248
249     if( !freeze )
250         globals->set_freeze(true);
251     
252     if( panel_status ) {
253         panel_status = false;
254         if ( current_panel != NULL )
255           current_panel->setVisibility(false);
256     } else {
257         panel_status = true;
258         if ( current_panel != NULL )
259           current_panel->setVisibility(true);
260     }
261
262     fgReshape( xsize, ysize);
263
264     if( !freeze )
265         globals->set_freeze( false );
266 }
267
268 double
269 FGOptions::parse_time(const string& time_in) {
270     char *time_str, num[256];
271     double hours, minutes, seconds;
272     double result = 0.0;
273     int sign = 1;
274     int i;
275
276     time_str = (char *)time_in.c_str();
277
278     // printf("parse_time(): %s\n", time_str);
279
280     // check for sign
281     if ( strlen(time_str) ) {
282         if ( time_str[0] == '+' ) {
283             sign = 1;
284             time_str++;
285         } else if ( time_str[0] == '-' ) {
286             sign = -1;
287             time_str++;
288         }
289     }
290     // printf("sign = %d\n", sign);
291
292     // get hours
293     if ( strlen(time_str) ) {
294         i = 0;
295         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
296             num[i] = time_str[0];
297             time_str++;
298             i++;
299         }
300         if ( time_str[0] == ':' ) {
301             time_str++;
302         }
303         num[i] = '\0';
304         hours = atof(num);
305         // printf("hours = %.2lf\n", hours);
306
307         result += hours;
308     }
309
310     // get minutes
311     if ( strlen(time_str) ) {
312         i = 0;
313         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
314             num[i] = time_str[0];
315             time_str++;
316             i++;
317         }
318         if ( time_str[0] == ':' ) {
319             time_str++;
320         }
321         num[i] = '\0';
322         minutes = atof(num);
323         // printf("minutes = %.2lf\n", minutes);
324
325         result += minutes / 60.0;
326     }
327
328     // get seconds
329     if ( strlen(time_str) ) {
330         i = 0;
331         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
332             num[i] = time_str[0];
333             time_str++;
334             i++;
335         }
336         num[i] = '\0';
337         seconds = atof(num);
338         // printf("seconds = %.2lf\n", seconds);
339
340         result += seconds / 3600.0;
341     }
342
343     return(sign * result);
344 }
345
346
347 long int FGOptions::parse_date( const string& date)
348 {
349     struct tm gmt;
350     char * date_str, num[256];
351     int i;
352     // initialize to zero
353     gmt.tm_sec = 0;
354     gmt.tm_min = 0;
355     gmt.tm_hour = 0;
356     gmt.tm_mday = 0;
357     gmt.tm_mon = 0;
358     gmt.tm_year = 0;
359     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
360     date_str = (char *)date.c_str();
361     // get year
362     if ( strlen(date_str) ) {
363         i = 0;
364         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
365             num[i] = date_str[0];
366             date_str++;
367             i++;
368         }
369         if ( date_str[0] == ':' ) {
370             date_str++;
371         }
372         num[i] = '\0';
373         gmt.tm_year = atoi(num) - 1900;
374     }
375     // get month
376     if ( strlen(date_str) ) {
377         i = 0;
378         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
379             num[i] = date_str[0];
380             date_str++;
381             i++;
382         }
383         if ( date_str[0] == ':' ) {
384             date_str++;
385         }
386         num[i] = '\0';
387         gmt.tm_mon = atoi(num) -1;
388     }
389     // get day
390     if ( strlen(date_str) ) {
391         i = 0;
392         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
393             num[i] = date_str[0];
394             date_str++;
395             i++;
396         }
397         if ( date_str[0] == ':' ) {
398             date_str++;
399         }
400         num[i] = '\0';
401         gmt.tm_mday = atoi(num);
402     }
403     // get hour
404     if ( strlen(date_str) ) {
405         i = 0;
406         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
407             num[i] = date_str[0];
408             date_str++;
409             i++;
410         }
411         if ( date_str[0] == ':' ) {
412             date_str++;
413         }
414         num[i] = '\0';
415         gmt.tm_hour = atoi(num);
416     }
417     // get minute
418     if ( strlen(date_str) ) {
419         i = 0;
420         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
421             num[i] = date_str[0];
422             date_str++;
423             i++;
424         }
425         if ( date_str[0] == ':' ) {
426             date_str++;
427         }
428         num[i] = '\0';
429         gmt.tm_min = atoi(num);
430     }
431     // get second
432     if ( strlen(date_str) ) {
433         i = 0;
434         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
435             num[i] = date_str[0];
436             date_str++;
437             i++;
438         }
439         if ( date_str[0] == ':' ) {
440             date_str++;
441         }
442         num[i] = '\0';
443         gmt.tm_sec = atoi(num);
444     }
445     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
446                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
447     //printf ("Date is %s\n", ctime(&theTime));
448     //printf ("in seconds that is %d\n", theTime);
449     //exit(1);
450     return (theTime);
451 }
452
453
454 // parse degree in the form of [+/-]hhh:mm:ss
455 void FGOptions::parse_control( const string& mode ) {
456     if ( mode == "joystick" ) {
457         control_mode = FG_JOYSTICK;
458     } else if ( mode == "mouse" ) {
459         control_mode = FG_MOUSE;
460     } else {
461         control_mode = FG_KEYBOARD;
462     }
463 }
464
465
466 /// parse degree in the form of [+/-]hhh:mm:ss
467 double
468 FGOptions::parse_degree( const string& degree_str) {
469     double result = parse_time( degree_str );
470
471     // printf("Degree = %.4f\n", result);
472
473     return(result);
474 }
475
476
477 // parse time offset command line option
478 int
479 FGOptions::parse_time_offset( const string& time_str) {
480     int result;
481
482     // printf("time offset = %s\n", time_str);
483
484 #ifdef HAVE_RINT
485     result = (int)rint(parse_time(time_str) * 3600.0);
486 #else
487     result = (int)(parse_time(time_str) * 3600.0);
488 #endif
489
490     // printf("parse_time_offset(): %d\n", result);
491
492     return( result );
493 }
494
495
496 // Parse --fdm=abcdefg type option 
497 int
498 FGOptions::parse_fdm( const string& fm ) {
499     // cout << "fdm = " << fm << endl;
500
501     if ( fm == "ada" ) {
502         return FGInterface::FG_ADA;
503     } else if ( fm == "balloon" ) {
504         return FGInterface::FG_BALLOONSIM;
505     } else if ( fm == "external" ) {
506         return FGInterface::FG_EXTERNAL;
507     } else if ( fm == "jsb" ) {
508         return FGInterface::FG_JSBSIM;
509     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
510         return FGInterface::FG_LARCSIM;
511     } else if ( fm == "magic" ) {
512         return FGInterface::FG_MAGICCARPET;
513     } else {
514         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
515         exit(-1);
516     }
517
518     // we'll never get here, but it makes the compiler happy.
519     return -1;
520 }
521
522
523 // Parse --fov=x.xx type option 
524 double
525 FGOptions::parse_fov( const string& arg ) {
526     double fov = atof(arg);
527
528     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
529     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
530
531     globals->get_current_view()->set_fov( fov );
532
533     // printf("parse_fov(): result = %.4f\n", fov);
534
535     return fov;
536 }
537
538
539 // Parse I/O channel option
540 //
541 // Format is "--protocol=medium,direction,hz,medium_options,..."
542 //
543 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
544 //   medium = { serial, socket, file, etc. }
545 //   direction = { in, out, bi }
546 //   hz = number of times to process channel per second (floating
547 //        point values are ok.
548 //
549 // Serial example "--nmea=serial,dir,hz,device,baud" where
550 // 
551 //  device = OS device name of serial line to be open()'ed
552 //  baud = {300, 1200, 2400, ..., 230400}
553 //
554 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
555 // 
556 //  machine = machine name or ip address if client (leave empty if server)
557 //  port = port, leave empty to let system choose
558 //  style = tcp or udp
559 //
560 // File example "--garmin=file,dir,hz,filename" where
561 // 
562 //  filename = file system file name
563
564 bool 
565 FGOptions::parse_channel( const string& type, const string& channel_str ) {
566     // cout << "Channel string = " << channel_str << endl;
567
568     channel_options_list.push_back( type + "," + channel_str );
569
570     return true;
571 }
572
573
574 // Parse --wp=ID[,alt]
575 bool FGOptions::parse_wp( const string& arg ) {
576     string id, alt_str;
577     double alt = 0.0;
578
579     int pos = arg.find( "@" );
580     if ( pos != string::npos ) {
581         id = arg.substr( 0, pos );
582         alt_str = arg.substr( pos + 1 );
583         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
584         alt = atof( alt_str.c_str() );
585         if ( units == FG_UNITS_FEET ) {
586             alt *= FEET_TO_METER;
587         }
588     } else {
589         id = arg;
590     }
591
592     FGAirport a;
593     if ( fgFindAirportID( id, &a ) ) {
594         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
595         globals->get_route()->add_waypoint( wp );
596
597         return true;
598     } else {
599         return false;
600     }
601 }
602
603
604 // Parse --flight-plan=[file]
605 bool FGOptions::parse_flightplan(const string& arg)
606 {
607     fg_gzifstream infile(arg.c_str());
608     if (!infile) {
609         return false;
610     }
611     while ( true ) {
612         string line;
613 #ifdef GETLINE_NEEDS_TERMINATOR
614         getline( infile, line, '\n' );
615 #elif defined( macintosh )
616         getline( infile, line, '\r' );
617 #else
618         getline( infile, line );
619 #endif
620         if ( infile.eof() ) {
621             break;
622         }
623         parse_wp(line);
624     }
625
626     return true;
627 }
628
629
630 // Parse a single option
631 int FGOptions::parse_option( const string& arg ) {
632     // General Options
633     if ( (arg == "--help") || (arg == "-h") ) {
634         // help/usage request
635         return(FG_OPTIONS_HELP);
636     } else if ( arg == "--disable-game-mode") {
637         game_mode = false;
638     } else if ( arg == "--enable-game-mode" ) {
639         game_mode = true;
640     } else if ( arg == "--disable-splash-screen" ) {
641         splash_screen = false;
642     } else if ( arg == "--enable-splash-screen" ) {
643         splash_screen = true;
644     } else if ( arg == "--disable-intro-music" ) {
645         intro_music = false;
646     } else if ( arg == "--enable-intro-music" ) {
647         intro_music = true;
648     } else if ( arg == "--disable-mouse-pointer" ) {
649         mouse_pointer = 1;
650     } else if ( arg == "--enable-mouse-pointer" ) {
651         mouse_pointer = 2;
652     } else if ( arg == "--disable-freeze" ) {
653         globals->set_freeze( false );
654     } else if ( arg == "--enable-freeze" ) {
655         globals->set_freeze( true );
656     } else if ( arg == "--disable-anti-alias-hud" ) {
657         anti_alias_hud = false; 
658     } else if ( arg == "--enable-anti-alias-hud" ) {
659         anti_alias_hud = true;  
660     } else if ( arg.find( "--control=") != string::npos ) {
661         parse_control( arg.substr(10) );
662     } else if ( arg == "--disable-auto-coordination" ) {
663         auto_coordination = FG_AUTO_COORD_DISABLED;     
664     } else if ( arg == "--enable-auto-coordination" ) {
665         auto_coordination = FG_AUTO_COORD_ENABLED;      
666     } else if ( arg == "--disable-hud" ) {
667         hud_status = false;     
668         current_properties.setBoolValue("/sim/hud/visibility", false);
669     } else if ( arg == "--enable-hud" ) {
670         hud_status = true;      
671         current_properties.setBoolValue("/sim/hud/visibility", true);
672     } else if ( arg == "--disable-panel" ) {
673         panel_status = false;
674         current_properties.setBoolValue("/sim/panel/visibility", false);
675         if ( current_panel != NULL )
676           current_panel->setVisibility(false);
677     } else if ( arg == "--enable-panel" ) {
678         panel_status = true;
679         current_properties.setBoolValue("/sim/panel/visibility", true);
680         if ( current_panel != NULL )
681             current_panel->setVisibility(true);
682     } else if ( arg == "--disable-sound" ) {
683         sound = false;
684     } else if ( arg == "--enable-sound" ) {
685         sound = true;
686     } else if ( arg.find( "--airport-id=") != string::npos ) {
687         airport_id = arg.substr( 13 );
688         current_properties.setStringValue("/position/airport-id", airport_id);
689     } else if ( arg.find( "--lon=" ) != string::npos ) {
690         lon = parse_degree( arg.substr(6) );
691         airport_id = "";
692         current_properties.setDoubleValue("/position/longitude", lon);
693         current_properties.setStringValue("/position/airport-id", airport_id);
694     } else if ( arg.find( "--lat=" ) != string::npos ) {
695         lat = parse_degree( arg.substr(6) );
696         airport_id = "";
697         current_properties.setDoubleValue("/position/latitude", lat);
698         current_properties.setStringValue("/position/airport-id", airport_id);
699     } else if ( arg.find( "--altitude=" ) != string::npos ) {
700         if ( units == FG_UNITS_FEET ) {
701             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
702         } else {
703             altitude = atof( arg.substr(11) );
704         }
705         current_properties.setDoubleValue("/position/altitude", altitude);
706     } else if ( arg.find( "--uBody=" ) != string::npos ) {
707         speedset = FG_VTUVW;
708         if ( units == FG_UNITS_FEET ) {
709             uBody = atof( arg.substr(8) );
710         } else {
711             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
712         }
713         //current_properties.setDoubleValue("/velocities/speed-north", uBody);
714     } else if ( arg.find( "--vBody=" ) != string::npos ) {
715         speedset = FG_VTUVW;
716         if ( units == FG_UNITS_FEET ) {
717             vBody = atof( arg.substr(8) );
718         } else {
719             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
720         }
721         //current_properties.setDoubleValue("/velocities/speed-east", vBody);
722     } else if ( arg.find( "--wBody=" ) != string::npos ) {
723         speedset = FG_VTUVW;
724         if ( units == FG_UNITS_FEET ) {
725             wBody = atof( arg.substr(8) );
726         } else {
727             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
728         }
729     } else if ( arg.find( "--vNorth=" ) != string::npos ) {
730         speedset = FG_VTNED;
731         if ( units == FG_UNITS_FEET ) {
732             vNorth = atof( arg.substr(9) );
733         } else {
734             vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
735         }
736         current_properties.setDoubleValue("/velocities/speed-north", vNorth);
737     } else if ( arg.find( "--vEast=" ) != string::npos ) {
738         speedset = FG_VTNED;
739         if ( units == FG_UNITS_FEET ) {
740             vEast = atof( arg.substr(8) );
741         } else {
742             vEast = atof( arg.substr(8) ) * FEET_TO_METER;
743         }
744         current_properties.setDoubleValue("/velocities/speed-east", vEast);
745     } else if ( arg.find( "--vDown=" ) != string::npos ) {
746         speedset = FG_VTNED;
747         if ( units == FG_UNITS_FEET ) {
748             vDown = atof( arg.substr(8) );
749         } else {
750             vDown = atof( arg.substr(8) ) * FEET_TO_METER;
751         }
752         current_properties.setDoubleValue("/velocities/speed-down", vDown);
753     } else if ( arg.find( "--vc=" ) != string::npos) {
754         speedset = FG_VC;
755         vkcas=atof( arg.substr(5) );
756         cout << "Got vc: " << vkcas << endl;
757     } else if ( arg.find( "--mach=" ) != string::npos) {
758         speedset = FG_MACH;
759         mach=atof( arg.substr(7) );
760     } else if ( arg.find( "--heading=" ) != string::npos ) {
761         heading = atof( arg.substr(10) );
762         current_properties.setDoubleValue("/orientation/heading", heading);
763     } else if ( arg.find( "--roll=" ) != string::npos ) {
764         roll = atof( arg.substr(7) );
765         current_properties.setDoubleValue("/orientation/roll", roll);
766     } else if ( arg.find( "--pitch=" ) != string::npos ) {
767         pitch = atof( arg.substr(8) );
768         current_properties.setDoubleValue("/orientation/pitch", pitch);
769     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
770         fg_root = arg.substr( 10 );
771     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
772         fg_scenery = arg.substr( 13 );
773     } else if ( arg.find( "--fdm=" ) != string::npos ) {
774         flight_model = parse_fdm( arg.substr(6) );
775         current_properties.setIntValue("/sim/flight-model", flight_model);
776     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
777         set_trim_mode(1);
778     } else {
779         set_trim_mode(0);
780     }        
781     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
782         aircraft = arg.substr(11);
783         current_properties.setStringValue("/sim/aircraft", aircraft);
784     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
785         aircraft_dir =  arg.substr(15); //  (UIUC)
786     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
787         model_hz = atoi( arg.substr(11) );
788     } else if ( arg.find( "--speed=" ) != string::npos ) {
789         speed_up = atoi( arg.substr(8) );
790     } else if ( arg.find( "--notrim") != string::npos) {
791         trim=-1;
792     } else if ( arg == "--fog-disable" ) {
793         fog = FG_FOG_DISABLED;  
794     } else if ( arg == "--fog-fastest" ) {
795         fog = FG_FOG_FASTEST;   
796     } else if ( arg == "--fog-nicest" ) {
797         fog = FG_FOG_NICEST;    
798     } else if ( arg == "--disable-clouds" ) {
799         clouds = false; 
800     } else if ( arg == "--enable-clouds" ) {
801         clouds = true;  
802     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
803         if ( units == FG_UNITS_FEET ) {
804             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
805         } else {
806             clouds_asl = atof( arg.substr(13) );
807         }
808     } else if ( arg.find( "--fov=" ) != string::npos ) {
809         parse_fov( arg.substr(6) );
810     } else if ( arg == "--disable-fullscreen" ) {
811         fullscreen = false;     
812     } else if ( arg== "--enable-fullscreen") {
813         fullscreen = true;      
814     } else if ( arg == "--shading-flat") {
815         shading = 0;    
816     } else if ( arg == "--shading-smooth") {
817         shading = 1;    
818     } else if ( arg == "--disable-skyblend") {
819         skyblend = false;       
820     } else if ( arg== "--enable-skyblend" ) {
821         skyblend = true;        
822     } else if ( arg == "--disable-textures" ) {
823         textures = false;       
824     } else if ( arg == "--enable-textures" ) {
825         textures = true;
826     } else if ( arg == "--disable-wireframe" ) {
827         wireframe = false;      
828     } else if ( arg == "--enable-wireframe" ) {
829         wireframe = true;
830     } else if ( arg.find( "--geometry=" ) != string::npos ) {
831         bool geometry_ok = true;
832         string geometry = arg.substr( 11 );
833         string::size_type i = geometry.find('x');
834
835         if (i != string::npos) {
836             xsize = atoi(geometry.substr(0, i));
837             ysize = atoi(geometry.substr(i+1));
838             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
839         } else {
840             geometry_ok = false;
841         }
842
843         if ( xsize <= 0 || ysize <= 0 ) {
844             xsize = 640;
845             ysize = 480;
846             geometry_ok = false;
847         }
848
849         if ( !geometry_ok ) {
850             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
851             FG_LOG( FG_GENERAL, FG_ALERT,
852                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
853         }
854     } else if ( arg.find( "--bpp=" ) != string::npos ) {
855         string bits_per_pix = arg.substr( 6 );
856         if ( bits_per_pix == "16" ) {
857             bpp = 16;
858         } else if ( bits_per_pix == "24" ) {
859             bpp = 24;
860         } else if ( bits_per_pix == "32" ) {
861             bpp = 32;
862         }
863     } else if ( arg == "--units-feet" ) {
864         units = FG_UNITS_FEET;  
865     } else if ( arg == "--units-meters" ) {
866         units = FG_UNITS_METERS;        
867     } else if ( arg.find( "--time-offset" ) != string::npos ) {
868         time_offset = parse_time_offset( (arg.substr(14)) );
869         //time_offset_type = FG_TIME_SYS_OFFSET;
870     } else if ( arg.find( "--time-match-real") != string::npos ) {
871       //time_offset = parse_time_offset(arg.substr(18));
872         time_offset_type = FG_TIME_SYS_OFFSET;
873     } else if ( arg.find( "--time-match-local") != string::npos ) {
874       //time_offset = parse_time_offset(arg.substr(18));
875         time_offset_type = FG_TIME_LAT_OFFSET;
876     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
877         time_offset = parse_date( (arg.substr(17)) );
878         time_offset_type = FG_TIME_SYS_ABSOLUTE;
879     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
880         time_offset = parse_date( (arg.substr(17)) );
881         time_offset_type = FG_TIME_LAT_ABSOLUTE;
882     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
883         time_offset = parse_date( (arg.substr(17)) );
884         time_offset_type = FG_TIME_GMT_ABSOLUTE;
885
886     } else if ( arg == "--hud-tris" ) {
887         tris_or_culled = 0;     
888     } else if ( arg == "--hud-culled" ) {
889         tris_or_culled = 1;
890     } else if ( arg.find( "--native=" ) != string::npos ) {
891         parse_channel( "native", arg.substr(9) );
892     } else if ( arg.find( "--garmin=" ) != string::npos ) {
893         parse_channel( "garmin", arg.substr(9) );
894     } else if ( arg.find( "--nmea=" ) != string::npos ) {
895         parse_channel( "nmea", arg.substr(7) );
896     } else if ( arg.find( "--props=" ) != string::npos ) {
897         parse_channel( "props", arg.substr(8) );
898     } else if ( arg.find( "--pve=" ) != string::npos ) {
899         parse_channel( "pve", arg.substr(6) );
900     } else if ( arg.find( "--ray=" ) != string::npos ) {
901         parse_channel( "ray", arg.substr(6) );
902     } else if ( arg.find( "--rul=" ) != string::npos ) {
903         parse_channel( "rul", arg.substr(6) );
904     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
905         parse_channel( "joyclient", arg.substr(12) );
906 #ifdef FG_NETWORK_OLK
907     } else if ( arg == "--disable-network-olk" ) {
908         network_olk = false;    
909     } else if ( arg== "--enable-network-olk") {
910         network_olk = true;     
911     } else if ( arg == "--net-hud" ) {
912         net_hud_display = 1;    
913     } else if ( arg.find( "--net-id=") != string::npos ) {
914         net_id = arg.substr( 9 );
915 #endif
916     } else if ( arg.find( "--prop:" ) == 0 ) {
917         string assign = arg.substr(7);
918         int pos = assign.find('=');
919         if (pos == arg.npos || pos == 0) {
920             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
921             return FG_OPTIONS_ERROR;
922         }
923         string name = assign.substr(0, pos);
924         string value = assign.substr(pos + 1);
925         current_properties.setStringValue(name.c_str(), value);
926         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
927                << name << " to \"" << value << '"');
928     // $$$ begin - added VS Renganathan, 14 Oct 2K
929     // for multi-window outside window imagery
930     } else if ( arg.find( "--view-offset=" ) != string::npos ) {
931         string woffset = arg.substr( 14 );
932         if ( woffset == "LEFT" ) {
933                default_view_offset = M_PI * 0.25;
934         } else if ( woffset == "RIGHT" ) {
935             default_view_offset = M_PI * 1.75;
936         } else if ( woffset == "CENTER" ) {
937             default_view_offset = 0.00;
938         } else {
939             default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
940         }
941         FGViewerRPH *pilot_view =
942             (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
943         pilot_view->set_view_offset( default_view_offset );
944         pilot_view->set_goal_view_offset( default_view_offset );
945     // $$$ end - added VS Renganathan, 14 Oct 2K
946     } else if ( arg.find( "--wp=" ) != string::npos ) {
947         parse_wp( arg.substr( 5 ) );
948     } else if ( arg.find( "--flight-plan=") != string::npos) {
949         parse_flightplan ( arg.substr (14) );
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     cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1226 }
1227
1228
1229 // Destructor
1230 FGOptions::~FGOptions( void ) {
1231 }