-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module: FGTank.cpp
Author: Jon Berndt
--------------------------------------------------------------------------------
01/21/99 JSB Created
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
#include "FGTank.h"
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+static const char *IdSrc = "$Id$";
+static const char *IdHdr = ID_TANK;
+extern short debug_lvl;
-FGTank::FGTank(FGConfigFile* AC_cfg)
-{
- string type;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- *AC_cfg >> type; // Type = 0: fuel, 1: oxidizer
+using std::cerr;
+using std::endl;
+using std::cout;
- if (type == "FUEL") Type = ttFUEL;
+FGTank::FGTank(FGConfigFile* AC_cfg)
+{
+ string type = AC_cfg->GetValue("TYPE");
+ string token;
+
+ if (type == "FUEL") Type = ttFUEL;
else if (type == "OXIDIZER") Type = ttOXIDIZER;
- else Type = ttUNKNOWN;
- *AC_cfg >> X; // inches
- *AC_cfg >> Y; // "
- *AC_cfg >> Z; // "
- *AC_cfg >> Radius; // "
- *AC_cfg >> Capacity; // pounds (amount it can hold)
- *AC_cfg >> Contents; // pounds (amount it is holding)
+ else Type = ttUNKNOWN;
+
+ AC_cfg->GetNextConfigLine();
+ while ((token = AC_cfg->GetValue()) != "/AC_TANK") {
+ if (token == "XLOC") *AC_cfg >> X;
+ else if (token == "YLOC") *AC_cfg >> Y;
+ else if (token == "ZLOC") *AC_cfg >> Z;
+ else if (token == "RADIUS") *AC_cfg >> Radius;
+ else if (token == "CAPACITY") *AC_cfg >> Capacity;
+ else if (token == "CONTENTS") *AC_cfg >> Contents;
+ else cerr << "Unknown identifier: " << token << " in tank definition." << endl;
+ }
+
Selected = true;
- PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0
+
+ if (Capacity != 0) {
+ PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0
+ } else {
+ Contents = 0;
+ PctFull = 0;
+ }
+
+ if (debug_lvl > 0) {
+ cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
+ cout << " currently at " << PctFull << "% of maximum capacity" << endl;
+ cout << " Tank location (X, Y, Z): " << X << ", " << Y << ", " << Z << endl;
+ cout << " Effective radius: " << Radius << " inches" << endl;
+ }
+
+ if (debug_lvl & 2) cout << "Instantiated: FGTank" << endl;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGTank::~FGTank(void)
+FGTank::~FGTank()
{
+ if (debug_lvl & 2) cout << "Destroyed: FGTank" << endl;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
float FGTank::Reduce(float used)
{
if (used < Contents) {
Contents -= used;
PctFull = 100.0*Contents/Capacity;
- return Contents;
+ return 0.0;
} else {
shortage = Contents - used;
Contents = 0.0;
}
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGTank::Debug(void)
+{
+ //TODO: Add your source code here
+}
+