]> git.mxchange.org Git - flightgear.git/blob - JSBsim/FGTank.cpp
New changes to address various feedback from initial release.
[flightgear.git] / JSBsim / FGTank.cpp
1 /*******************************************************************************
2
3  Module:       FGTank.cpp
4  Author:       Jon Berndt
5  Date started: 01/21/99
6  Called by:    FGAircraft
7
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 See header file.
30
31 HISTORY
32 --------------------------------------------------------------------------------
33 01/21/99   JSB   Created
34
35 ********************************************************************************
36 INCLUDES
37 *******************************************************************************/
38
39 #include "FGTank.h"
40 #include <fstream.h>
41 #include <string.h>
42
43 /*******************************************************************************
44 ************************************ CODE **************************************
45 *******************************************************************************/
46
47
48 FGTank::FGTank(ifstream& acfile)
49 {
50   char type[20];
51
52   acfile >> type;                              // Type = 0: rocket, 1: piston
53   if (strstr(type,"FUEL")) Type = 0;
54   else if (strstr(type,"OXIDIZER")) Type = 1;
55   else Type = -1;
56   acfile >> X;                                 // inches
57   acfile >> Y;                                 // "
58   acfile >> Z;                                 // "
59   acfile >> Radius;                            // "
60   acfile >> Capacity;                          // pounds (amount it can hold)
61   acfile >> Contents;                          // pounds  (amount it is holding)
62   Selected = true;
63   PctFull = 100.0*Contents/Capacity;           // percent full; 0 to 100.0
64 }
65
66
67 FGTank::~FGTank(void)
68 {
69 }
70
71
72 float FGTank::Reduce(float used)
73 {
74   float shortage;
75
76   if (used < Contents) {
77     Contents -= used;
78     PctFull = 100.0*Contents/Capacity;
79     return Contents;
80   } else {
81     shortage = Contents - used;
82     Contents = 0.0;
83     PctFull = 0.0;
84     Selected = false;
85     return shortage;
86   }
87 }
88