#include STL_STRING
+#include <plib/ul.h>
+
+#include <simgear/math/sg_random.h>
#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/route/route.hxx>
{
FG_OPTIONS_OK = 0,
FG_OPTIONS_HELP = 1,
- FG_OPTIONS_ERROR = 2
+ FG_OPTIONS_ERROR = 2,
+ FG_OPTIONS_VERBOSE_HELP = 3,
+ FG_OPTIONS_SHOW_AIRCRAFT = 4
};
static double
parse_wind (const string &wind, double * min_hdg, double * max_hdg,
double * speed, double * gust)
{
- unsigned int pos = wind.find('@');
+ string::size_type pos = wind.find('@');
if (pos == string::npos)
return false;
string dir = wind.substr(0, pos);
}
+static void
+setup_wind (double min_hdg, double max_hdg, double speed, double gust)
+{
+ fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
+ fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
+ fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
+ fgSetDouble("/environment/wind-speed-kt", speed);
+ fgSetDouble("/environment/params/base-wind-speed-kt", speed);
+ fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
+
+ SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
+ speed << " knots" << endl);
+
+#ifdef FG_WEATHERCM
+ // convert to fps
+ speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
+ while (min_hdg > 360)
+ min_hdg -= 360;
+ while (min_hdg <= 0)
+ min_hdg += 360;
+ min_hdg *= SGD_DEGREES_TO_RADIANS;
+ fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
+ fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
+#endif // FG_WEATHERCM
+}
+
+
// Parse --wp=ID[@alt]
static bool
parse_wp( const string& arg ) {
string id, alt_str;
double alt = 0.0;
- unsigned int pos = arg.find( "@" );
+ string::size_type pos = arg.find( "@" );
if ( pos != string::npos ) {
id = arg.substr( 0, pos );
alt_str = arg.substr( pos + 1 );
if ( (arg == "--help") || (arg == "-h") ) {
// help/usage request
return(FG_OPTIONS_HELP);
+ } else if ( (arg == "--verbose") || (arg == "-v") ) {
+ // verbose help/usage request
+ return(FG_OPTIONS_VERBOSE_HELP);
} else if ( arg == "--disable-game-mode") {
fgSetBool("/sim/startup/game-mode", false);
} else if ( arg == "--enable-game-mode" ) {
fgSetString("/sim/startup/mouse-pointer", "disabled");
} else if ( arg == "--enable-mouse-pointer" ) {
fgSetString("/sim/startup/mouse-pointer", "enabled");
+ } else if ( arg == "--disable-random-objects" ) {
+ fgSetBool("/sim/rendering/random-objects", false);
+ } else if ( arg == "--enable-random-objects" ) {
+ fgSetBool("/sim/rendering/random-objects", true);
} else if ( arg == "--disable-freeze" ) {
fgSetBool("/sim/freeze/master", false);
} else if ( arg == "--enable-freeze" ) {
fgSetString("/sim/aero", arg.substr(7).c_str());
} else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
+ } else if ( arg.find( "--show-aircraft") == 0) {
+ return(FG_OPTIONS_SHOW_AIRCRAFT);
} else if ( arg.find( "--model-hz=" ) == 0 ) {
fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
} else if ( arg.find( "--speed=" ) == 0 ) {
fgSetBool("/environment/clouds/status", false);
} else if ( arg == "--enable-clouds" ) {
fgSetBool("/environment/clouds/status", true);
+ } else if ( arg == "--disable-clouds3d" ) {
+ fgSetBool("/sim/rendering/clouds3d", false);
+ } else if ( arg == "--enable-clouds3d" ) {
+ fgSetBool("/sim/rendering/clouds3d", true);
} else if ( arg.find( "--fov=" ) == 0 ) {
parse_fov( arg.substr(6) );
} else if ( arg == "--disable-fullscreen" ) {
#endif
} else if ( arg.find( "--prop:" ) == 0 ) {
string assign = arg.substr(7);
- unsigned int pos = assign.find('=');
+ string::size_type pos = assign.find('=');
if ( pos == arg.npos || pos == 0 ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
return FG_OPTIONS_ERROR;
} else if ( arg.find( "--visibility-miles=" ) == 0 ) {
double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
fgSetDouble("/environment/visibility-m", visibility);
+ } else if ( arg.find( "--random-wind" ) == 0 ) {
+ double min_hdg = sg_random() * 360.0;
+ double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
+ double speed = 40 - sqrt(sg_random() * 1600.0);
+ double gust = speed + (10 - sqrt(sg_random() * 100));
+ setup_wind(min_hdg, max_hdg, speed, gust);
} else if ( arg.find( "--wind=" ) == 0 ) {
double min_hdg, max_hdg, speed, gust;
if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
return FG_OPTIONS_ERROR;
}
- fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
- fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
- fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
- fgSetDouble("/environment/wind-speed-kt", speed);
- fgSetDouble("/environment/params/base-wind-speed-kt", speed);
- fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
-
- string val = arg.substr(7);
- unsigned int pos = val.find('@');
- if ( pos == string::npos ) {
- SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
- return FG_OPTIONS_ERROR;
- }
- SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
- speed << " knots" << endl);
-
-#ifdef FG_WEATHERCM
- // convert to fps
- speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
- while (min_hdg > 360)
- min_hdg -= 360;
- while (min_hdg <= 0)
- min_hdg += 360;
- min_hdg *= SGD_DEGREES_TO_RADIANS;
- fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
- fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
-#endif // FG_WEATHERCM
-
+ setup_wind(min_hdg, max_hdg, speed, gust);
} else if ( arg.find( "--wp=" ) == 0 ) {
parse_wp( arg.substr( 5 ) );
} else if ( arg.find( "--flight-plan=") == 0) {
fgParseArgs (int argc, char **argv)
{
bool in_options = true;
+ bool verbose = false;
+ bool help = false;
SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
in_options = false;
} else {
int result = parse_option(arg);
- if ( (result == FG_OPTIONS_HELP) ||
- (result == FG_OPTIONS_ERROR) ) {
- fgUsage();
- exit(-1);
- }
+ if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
+ help = true;
+
+ else if (result == FG_OPTIONS_VERBOSE_HELP)
+ verbose = true;
+
+ else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
+ fgShowAircraft();
+ exit(0);
+ }
}
} else {
in_options = false;
}
}
+ if (help) {
+ fgUsage(verbose);
+ exit(0);
+ }
+
SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
}
}
if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Config file parse error: " << path << " '"
- << line << "'" );
+ cout << endl << "Config file parse error: " << path << " '"
+ << line << "'" << endl;
fgUsage();
exit(-1);
}
// Print usage message
void
-fgUsage ()
+fgUsage (bool verbose)
{
SGPropertyNode options_root;
SGPath opath( globals->get_fg_root() );
} catch (const sg_exception &ex) {
cout << "Unable to read the help file." << endl;
cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
- cout << "and the location of the base directory is specified bij setting $FG_ROOT or" << endl;
+ cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
cout << "by adding --fg-root=path as a program argument." << endl;
exit(-1);
vector<SGPropertyNode_ptr>section = options->getChildren("section");
for (unsigned int j = 0; j < section.size(); j++) {
-
- SGPropertyNode *name = section[j]->getNode("name");
- if (name) {
- cout << endl << name->getStringValue() << ":" << endl;
- }
+ string msg = "";
vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
for (unsigned int k = 0; k < option.size(); k++) {
SGPropertyNode *short_name = option[k]->getNode("short");
SGPropertyNode *key = option[k]->getNode("key");
SGPropertyNode *arg = option[k]->getNode("arg");
+ bool brief = option[k]->getNode("brief");
- if (name) {
+ if ((brief || verbose) && name) {
string tmp = name->getStringValue();
if (key){
} else {
snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
}
- string msg = cstr;
+ msg += cstr;
SGPropertyNode *desc = option[k]->getNode("description");
if (desc) {
msg += desc->getStringValue();
desc->getStringValue());
msg += cstr;
}
+ msg += '\n';
}
- cout << msg << endl;
}
}
+
+ SGPropertyNode *name = section[j]->getNode("name");
+ if (!msg.empty() && name) {
+ cout << endl << name->getStringValue() << ":" << endl;
+ cout << msg;
+ msg.erase();
+ }
}
+
+ if ( !verbose ) {
+ cout << endl;
+ cout << "For a complete list of options use --help --verbose" << endl;
+ }
+}
+
+// Show available aircraft types
+void fgShowAircraft(void) {
+ SGPath path( globals->get_fg_root() );
+ path.append("Aircraft");
+
+ ulDirEnt* dire;
+ ulDir *dirp;
+
+ dirp = ulOpenDir(path.c_str());
+ if (dirp == NULL) {
+ cout << "Unable to open aircraft directory." << endl;
+ exit(-1);
+ }
+
+ cout << "Available aircraft:" << endl;
+ while ((dire = ulReadDir(dirp)) != NULL) {
+ char *ptr;
+
+ if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
+ SGPath afile = path;
+ afile.append(dire->d_name);
+
+ *ptr = '\0';
+
+ SGPropertyNode root;
+ try {
+ readProperties(afile.str(), &root);
+ } catch (...) {
+ continue;
+ }
+
+ SGPropertyNode *desc, *node = root.getNode("sim");
+ if (node)
+ desc = node->getNode("description");
+
+ char cstr[96];
+ if (strlen(dire->d_name) <= 27)
+ snprintf(cstr, 96, " %-27s %s", dire->d_name,
+ (desc) ? desc->getStringValue() : "" );
+
+ else
+ snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
+ (desc) ? desc->getStringValue() : "" );
+
+ cout << cstr << endl;
+ }
+ }
+
+ ulCloseDir(dirp);
}