]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Attached is a reasonably large patch to add a proper ATC
[flightgear.git] / src / Main / fg_init.cxx
index 09748891a72dd5197967bf8f9868458eec474056..d3012aadda4e0dc0c60ec12c03fd9639438b2775 100644 (file)
@@ -70,6 +70,8 @@
 #include <Airports/runways.hxx>
 #include <Airports/simple.hxx>
 #include <ATC/ATCdisplay.hxx>
+#include <ATC/ATCmgr.hxx>
+#include <ATC/atislist.hxx>
 #include <Autopilot/auto_gui.hxx>
 #include <Autopilot/newauto.hxx>
 #include <Cockpit/cockpit.hxx>
@@ -79,7 +81,7 @@
 #include <FDM/ADA.hxx>
 #include <FDM/Balloon.h>
 #include <FDM/External.hxx>
-#include <FDM/JSBSim.hxx>
+#include <FDM/JSBSim/JSBSim.hxx>
 #include <FDM/LaRCsim.hxx>
 #include <FDM/MagicCarpet.hxx>
 #include <FDM/NullFDM.hxx>
 #include <Time/moonpos.hxx>
 #include <Time/tmp.hxx>
 
-#ifndef FG_OLD_WEATHER
+#ifndef FG_NEW_ENVIRONMENT
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #else
-#  include <Weather/weather.hxx>
+#  include <Environment/environment_mgr.hxx>
 #endif
 
 #include "fg_init.hxx"
@@ -467,6 +469,33 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
     return true;
 }
 
+void fgSetPosFromGlideSlope(void) {
+    double gs = fgGetDouble("/velocities/glideslope");
+    double od = fgGetDouble("/sim/startup/offset-distance");
+    double alt = fgGetDouble("/position/altitude-ft");
+    
+    //if glideslope and offset-distance are set and altitude is
+    //not, calculate the initial altitude
+    if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
+       od *= SG_NM_TO_METER * SG_METER_TO_FEET;
+       alt = fabs(od*tan(gs));
+       fgSetDouble("/position/altitude-ft",alt);
+       fgSetBool("/sim/startup/onground", false);
+       SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt  << " ft");
+    } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
+       od  = alt/tan(gs);
+       od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
+       fgSetDouble("/sim/startup/offset-distance",od);
+       SG_LOG(SG_GENERAL,SG_INFO, "Calculated offset distance as: " 
+                                      << od  << " nm");
+    } else if( fabs(gs) > 0.01 ) {
+       SG_LOG(SG_GENERAL,SG_ALERT, "Glideslope given but not altitude" 
+                                 << " or offset-distance.  Resetting"
+                                 << " glideslope to zero" );
+        fgSetDouble("/velocities/glideslope",0);                                 
+    }                             
+                                     
+}                      
 
 // General house keeping initializations
 bool fgInitGeneral( void ) {
@@ -764,7 +793,7 @@ bool fgInitSubsystems( void ) {
     ////////////////////////////////////////////////////////////////////
 
     // Initialize the weather modeling subsystem
-#ifndef FG_OLD_WEATHER
+#ifndef FG_NEW_ENVIRONMENT
     // Initialize the WeatherDatabase
     SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
     sgVec3 position;
@@ -805,7 +834,8 @@ bool fgInitSubsystems( void ) {
     global_events.Register( "weather update", fgUpdateWeatherDatabase,
                             fgEVENT::FG_EVENT_READY, 30000);
 #else
-    current_weather.Init();
+    globals->get_environment_mgr()->init();
+    globals->get_environment_mgr()->bind();
 #endif
 
     ////////////////////////////////////////////////////////////////////
@@ -838,7 +868,6 @@ bool fgInitSubsystems( void ) {
     // Initialize ATC list management and query systems
     ////////////////////////////////////////////////////////////////////
 
-    //DCL
     SG_LOG(SG_GENERAL, SG_INFO, "  ATIS");
     current_atislist = new FGATISList;
     SGPath p_atis( globals->get_fg_root() );
@@ -849,10 +878,17 @@ bool fgInitSubsystems( void ) {
     // Initialise ATC display system
     ////////////////////////////////////////////////////////////////////
 
-    //DCL
     SG_LOG(SG_GENERAL, SG_INFO, "  ATC Display");
-    current_atcdisplay = new FGATCDisplay;
-    current_atcdisplay->init();   
+    globals->set_ATC_display(new FGATCDisplay);
+    globals->get_ATC_display()->init(); 
+
+    ////////////////////////////////////////////////////////////////////
+    // Initialise the ATC Manager 
+    ////////////////////////////////////////////////////////////////////
+
+    SG_LOG(SG_GENERAL, SG_INFO, "  ATC Manager");
+    globals->set_ATC_mgr(new FGATCMgr);
+    globals->get_ATC_mgr()->init();     
 
     ////////////////////////////////////////////////////////////////////
     // Initialize the built-in commands.
@@ -1017,6 +1053,10 @@ void fgReInitSubsystems( void )
 #endif
 
     fgInitFDM();
+    
+    // allocates structures so must happen before any of the flight
+    // model or control parameters are set
+    fgAircraftInit();   // In the future this might not be the case.
 
     fgInitView();