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