]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Airplane.cpp
YASim now supports the new fuel.nas fuel management system. It
[flightgear.git] / src / FDM / YASim / Airplane.cpp
index bb95ae9bada26178b5d591789988e679551cec43..166a861b54b1b352792da5b002dcfb2ef86d14f2 100644 (file)
@@ -66,6 +66,8 @@ Airplane::~Airplane()
        delete (Surface*)_surfs.get(i);    
     for(i=0; i<_contacts.size(); i++)
         delete[] (float*)_contacts.get(i);
+    for(i=0; i<_solveWeights.size(); i++)
+        delete[] (SolveWeight*)_solveWeights.get(i);
 }
 
 void Airplane::iterate(float dt)
@@ -76,32 +78,9 @@ void Airplane::iterate(float dt)
     _model.iterate();
 }
 
-void Airplane::consumeFuel(float dt)
+void Airplane::calcFuelWeights()
 {
-    // This is a really simple implementation that assumes all engines
-    // draw equally from all tanks in proportion to the amount of fuel
-    // stored there.  Needs to be fixed, but that has to wait for a
-    // decision as to what the property interface will look like.
-    int i, outOfFuel = 0;
-    float fuelFlow = 0, totalFuel = 0.00001; // <-- overflow protection
-    for(i=0; i<_thrusters.size(); i++)
-        fuelFlow += ((ThrustRec*)_thrusters.get(i))->thruster->getFuelFlow();
-    for(i=0; i<_tanks.size(); i++)
-        totalFuel += ((Tank*)_tanks.get(i))->fill;
-    for(i=0; i<_tanks.size(); i++) {
-        Tank* t = (Tank*)_tanks.get(i);
-        t->fill -= dt * fuelFlow * (t->fill/totalFuel);
-        if(t->fill <= 0) {
-            t->fill = 0;
-            outOfFuel = 1;
-        }
-    }
-    if(outOfFuel)
-        for(int i=0; i<_thrusters.size(); i++)
-            ((ThrustRec*)_thrusters.get(i))->thruster->setFuelState(false);
-
-    // Set the tank masses on the RigidBody
-    for(i=0; i<_tanks.size(); i++) {
+    for(int i=0; i<_tanks.size(); i++) {
         Tank* t = (Tank*)_tanks.get(i);
         _model.getBody()->setMass(t->handle, t->fill);
     }
@@ -212,6 +191,15 @@ void Airplane::addCruiseControl(int control, float val)
     _cruiseControls.add(c);
 }
 
+void Airplane::addSolutionWeight(bool approach, int idx, float wgt)
+{
+    SolveWeight* w = new SolveWeight();
+    w->approach = approach;
+    w->idx = idx;
+    w->wgt = wgt;
+    _solveWeights.add(w);
+}
+
 int Airplane::numTanks()
 {
     return _tanks.size();
@@ -222,6 +210,11 @@ float Airplane::getFuel(int tank)
     return ((Tank*)_tanks.get(tank))->fill;
 }
 
+float Airplane::setFuel(int tank, float fuel)
+{
+    ((Tank*)_tanks.get(tank))->fill = fuel;
+}
+
 float Airplane::getFuelDensity(int tank)
 {
     return ((Tank*)_tanks.get(tank))->density;
@@ -755,6 +748,18 @@ void Airplane::stabilizeThrust()
        _model.getThruster(i)->stabilize();
 }
 
+void Airplane::setupWeights(bool isApproach)
+{
+    int i;
+    for(i=0; i<_weights.size(); i++)
+        setWeight(i, 0);
+    for(i=0; i<_solveWeights.size(); i++) {
+        SolveWeight* w = (SolveWeight*)_solveWeights.get(i);
+        if(w->approach == isApproach)
+            setWeight(w->idx, w->wgt);
+    }
+}
+
 void Airplane::runCruise()
 {
     setupState(_cruiseAoA, _cruiseSpeed, &_cruiseState);
@@ -777,6 +782,7 @@ void Airplane::runCruise()
     Math::vmul33(_cruiseState.orient, wind, wind);
  
     setFuelFraction(_cruiseFuel);
+    setupWeights(false);
    
     // Set up the thruster parameters and iterate until the thrust
     // stabilizes.
@@ -818,9 +824,10 @@ void Airplane::runApproach()
     Math::mul3(-1, _approachState.v, wind);
     Math::vmul33(_approachState.orient, wind, wind);
     
-    // Approach is by convention at 20% tank capacity
     setFuelFraction(_approachFuel);
 
+    setupWeights(true);
+
     // Run the thrusters until they get to a stable setting.  FIXME:
     // this is lots of wasted work.
     for(i=0; i<_thrusters.size(); i++) {