1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
5 Date started: 01/21/99
\r
6 Called by: FGAircraft
\r
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
\r
10 This program is free software; you can redistribute it and/or modify it under
\r
11 the terms of the GNU General Public License as published by the Free Software
\r
12 Foundation; either version 2 of the License, or (at your option) any later
\r
15 This program is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
20 You should have received a copy of the GNU General Public License along with
\r
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
\r
22 Place - Suite 330, Boston, MA 02111-1307, USA.
\r
24 Further information about the GNU General Public License can also be found on
\r
25 the world wide web at http://www.gnu.org.
\r
27 FUNCTIONAL DESCRIPTION
\r
28 --------------------------------------------------------------------------------
\r
32 --------------------------------------------------------------------------------
\r
33 01/21/99 JSB Created
\r
34 09/03/99 JSB Changed Rocket thrust equation to correct -= Thrust instead of
\r
35 += Thrust (thanks to Tony Peden)
\r
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
42 # include <simgear/compiler.h>
\r
43 # ifdef SG_HAVE_STD_INCLUDES
\r
46 # include <fstream.h>
\r
49 # if defined(sgi) && !defined(__GNUC__)
\r
50 # include <fstream.h>
\r
56 #include "FGEngine.h"
\r
59 static const char *IdSrc = "$Id$";
\r
60 static const char *IdHdr = ID_ENGINE;
\r
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
63 CLASS IMPLEMENTATION
\r
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
67 FGEngine::FGEngine(FGFDMExec* exec) {
\r
69 State = FDMExec->GetState();
\r
70 Atmosphere = FDMExec->GetAtmosphere();
\r
71 FCS = FDMExec->GetFCS();
\r
72 Propulsion = FDMExec->GetPropulsion();
\r
73 Aircraft = FDMExec->GetAircraft();
\r
74 Translation = FDMExec->GetTranslation();
\r
75 Rotation = FDMExec->GetRotation();
\r
76 Position = FDMExec->GetPosition();
\r
77 Auxiliary = FDMExec->GetAuxiliary();
\r
78 Output = FDMExec->GetOutput();
\r
80 Mixture = 1.0; // FIXME: get actual value
\r
82 Thrust = PctPower = 0.0;
\r
83 Starved = Flameout = false;
\r
85 Cranking = Starter = false;
\r
87 if (debug_lvl & 2) cout << "Instantiated: FGEngine" << endl;
\r
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
93 FGEngine::~FGEngine()
\r
95 if (debug_lvl & 2) cout << "Destroyed: FGEngine" << endl;
\r
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
99 // This base class function should be called from within the
\r
100 // derived class' Calculate() function before any other calculations are done.
\r
101 // This base class method removes fuel from the fuel tanks as appropriate,
\r
102 // and sets the starved flag if necessary.
\r
104 void FGEngine::ConsumeFuel(void) {
\r
105 float Fshortage, Oshortage;
\r
108 if (TrimMode) return;
\r
110 Fshortage = Oshortage = 0.0;
\r
111 for (unsigned int i=0; i<SourceTanks.size(); i++) {
\r
112 Tank = Propulsion->GetTank(i);
\r
113 if (Tank->GetType() == FGTank::ttFUEL) {
\r
114 Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());
\r
116 Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());
\r
120 if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;
\r
121 else Starved = false;
\r
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
126 float FGEngine::CalcFuelNeed(void) {
\r
127 FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
\r
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
133 float FGEngine::CalcOxidizerNeed(void) {
\r
134 OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
\r
135 return OxidizerNeed;
\r
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
140 void FGEngine::SetPlacement(float x, float y, float z, float pitch, float yaw) {
\r
144 EnginePitch = pitch;
\r
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
150 void FGEngine::AddFeedTank(int tkID)
\r
152 SourceTanks.push_back(tkID);
\r
155 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
157 void FGEngine::Debug(void)
\r
159 //TODO: Add your source code here
\r