diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 562c0ec68..1b37fa256 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -224,6 +224,15 @@ void FGRouteMgr::init() { void FGRouteMgr::postinit() { + SGPath path(_pathNode->getStringValue()); + if (path.exists()) { + SG_LOG(SG_AUTOPILOT, SG_INFO, "loading flight-plan from:" << path.str()); + loadRoute(); + } + +// this code only matters for the --wp option now - perhaps the option +// should be deprecated in favour of an explicit flight-plan file? +// then the global initial waypoint list could die. string_list *waypoints = globals->get_initial_waypoints(); if (waypoints) { string_list::iterator it; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index d61ffcf02..df50b344c 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -555,54 +555,6 @@ add_channel( const string& type, const string& channel_str ) { return true; } - -// The parse wp and parse flight-plan options don't work anymore, because -// the route manager and the airport subsystems have not yet been initialized -// at this stage. - -// Parse --wp=ID[@alt] -static void -parse_wp( const string& arg ) { - string_list *waypoints = globals->get_initial_waypoints(); - if (!waypoints) { - waypoints = new string_list; - globals->set_initial_waypoints(waypoints); - } - waypoints->push_back(arg); -} - - -// Parse --flight-plan=[file] -static bool -parse_flightplan(const string& arg) -{ - string_list *waypoints = globals->get_initial_waypoints(); - if (!waypoints) { - waypoints = new string_list; - globals->set_initial_waypoints(waypoints); - } - - sg_gzifstream in(arg.c_str()); - if ( !in.is_open() ) - return false; - - while ( true ) { - string line; - getline( in, line, '\n' ); - - // catch extraneous (DOS) line ending character - if ( line[line.length() - 1] < 32 ) - line = line.substr( 0, line.length()-1 ); - - if ( in.eof() ) - break; - - waypoints->push_back(line); - } - return true; -} - - static int fgOptLanguage( const char *arg ) { @@ -1067,14 +1019,12 @@ fgOptCeiling( const char *arg ) static int fgOptWp( const char *arg ) { - parse_wp( arg ); - return FG_OPTIONS_OK; -} - -static int -fgOptFlightPlan( const char *arg ) -{ - parse_flightplan ( arg ); + string_list *waypoints = globals->get_initial_waypoints(); + if (!waypoints) { + waypoints = new string_list; + globals->set_initial_waypoints(waypoints); + } + waypoints->push_back(arg); return FG_OPTIONS_OK; } @@ -1496,7 +1446,7 @@ struct OptionDesc { {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence }, {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling }, {"wp", true, OPTION_FUNC, "", false, "", fgOptWp }, - {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan }, + {"flight-plan", true, OPTION_STRING, "/autopilot/route-manager/file-path", false, "", NULL }, {"config", true, OPTION_FUNC, "", false, "", fgOptConfig }, {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 }, {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },