1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
34 09/03/99 JSB Changed Rocket thrust equation to correct -= Thrust instead of
35 += Thrust (thanks to Tony Peden)
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_ENGINE;
58 extern short debug_lvl;
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 FGEngine::FGEngine(FGFDMExec* exec) {
67 State = FDMExec->GetState();
68 Atmosphere = FDMExec->GetAtmosphere();
69 FCS = FDMExec->GetFCS();
70 Propulsion = FDMExec->GetPropulsion();
71 Aircraft = FDMExec->GetAircraft();
72 Translation = FDMExec->GetTranslation();
73 Rotation = FDMExec->GetRotation();
74 Position = FDMExec->GetPosition();
75 Auxiliary = FDMExec->GetAuxiliary();
76 Output = FDMExec->GetOutput();
78 Thrust = PctPower = 0.0;
79 Starved = Flameout = false;
82 if (debug_lvl & 2) cout << "Instantiated: FGEngine" << endl;
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 if (debug_lvl & 2) cout << "Destroyed: FGEngine" << endl;
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 // This base class function should be called from within the
95 // derived class' Calculate() function before any other calculations are done.
96 // This base class method removes fuel from the fuel tanks as appropriate,
97 // and sets the starved flag if necessary.
99 void FGEngine::ConsumeFuel(void) {
100 float Fshortage, Oshortage;
103 if (TrimMode) return;
105 Fshortage = Oshortage = 0.0;
106 for (unsigned int i=0; i<SourceTanks.size(); i++) {
107 Tank = Propulsion->GetTank(i);
108 if (Tank->GetType() == FGTank::ttFUEL) {
109 Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());
111 Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());
115 if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;
116 else Starved = false;
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 float FGEngine::CalcFuelNeed(void) {
122 FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 float FGEngine::CalcOxidizerNeed(void) {
129 OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 void FGEngine::SetPlacement(float x, float y, float z, float pitch, float yaw) {
143 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 void FGEngine::AddFeedTank(int tkID)
147 SourceTanks.push_back(tkID);
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 void FGEngine::Debug(void)
154 //TODO: Add your source code here