Hello, I have made a little patch for a requested feature.
Makes it possible to start at a parking location defined in the
AI/Airports/*/parking.xml files, using the parkpos command line
option.
Note that the name to pass is the concatenation of the "name" and
"number" fields in the xml.

This can be extended by
- adding an option to list the available positions
- allowing startup at a randomly picked location
- marking position as used/free when appropriate
- adding parking position information to airportinfo nasal function

-- 
Csaba/Jester
Index: src/Main/fg_init.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Main/fg_init.cxx,v
retrieving revision 1.195
diff -u -r1.195 fg_init.cxx
--- src/Main/fg_init.cxx        15 Feb 2008 17:54:23 -0000      1.195
+++ src/Main/fg_init.cxx        26 Feb 2008 16:23:50 -0000
@@ -824,6 +824,59 @@
     return true;
 }
 
+// Set current_options lon/lat given an airport id and parkig position name
+static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& 
parkpos ) {
+    if ( id.empty() )
+        return false;
+
+    // can't see an easy way around this const_cast at the moment
+    FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
+    if (!apt) {
+        SG_LOG( SG_GENERAL, SG_ALERT,
+                "Failed to find airport " << id );
+        return false;
+    }
+    FGAirportDynamics* dcs = apt->getDynamics();
+    if (!dcs) {
+        SG_LOG( SG_GENERAL, SG_ALERT,
+                "Failed to find parking position " << parkpos <<
+                " at airport " << id );
+        return false;
+    }
+    
+    int park_index = dcs->getNrOfParkings() - 1;
+    while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) 
park_index--;
+    if (park_index < 0) {
+        SG_LOG( SG_GENERAL, SG_ALERT,
+                "Failed to find parking position " << parkpos <<
+                " at airport " << id );
+        return false;
+    }
+    FGParking* parking = dcs->getParking(park_index);
+    
+    double lat = parking->getLatitude();
+    double lon = parking->getLongitude();
+    double hdg = parking->getHeading();
+    
+    // presets
+    fgSetDouble("/sim/presets/longitude-deg",  lon );
+    fgSetDouble("/sim/presets/latitude-deg",  lat );
+    fgSetDouble("/sim/presets/heading-deg", hdg );
+    
+    // other code depends on the actual values being set ...
+    fgSetDouble("/position/longitude-deg",  lon );
+    fgSetDouble("/position/latitude-deg",  lat );
+    fgSetDouble("/orientation/heading-deg", hdg );
+    
+    SG_LOG( SG_GENERAL, SG_INFO,
+    "Position for " << id << " is ("
+    << lon << ", "
+    << lat << ") new heading is "
+    << hdg );
+    
+    return true;
+}
+
 
 // Set current_options lon/lat given an airport id and runway number
 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, 
bool rwy_req ) {
@@ -1221,6 +1274,15 @@
     if (hdg > 9990.0)
         hdg = 
fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
 
+    if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
+        // An airport + parking position is requested
+        if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
+            // set tower position
+            fgSetString("/sim/tower/airport-id",  apt.c_str());
+            set_pos = true;
+        }
+    }
+
     if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
         // An airport + runway is requested
         if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to