src/vamos/body/Fuel_Tank.cc

Go to the documentation of this file.
00001 //  Fuel_Tank.cc - a particle that holds fuel for the engine.
00002 //
00003 //  Copyright (C) 2002 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #include <vamos/body/Fuel_Tank.h>
00022 
00023 //** Constructor
00024 Vamos_Body::Fuel_Tank::
00025 Fuel_Tank (const Vamos_Geometry::Three_Vector& position,
00026                    double capacity,
00027                    double volume,
00028                    double density)
00029   // The mass of the Particle is initially set to 0.0.  The real mas will be
00030   // calculated by the call to update_mass () in the constructor body.
00031   : Particle (0.0, position),
00032         m_capacity (capacity),
00033         m_volume (volume),
00034         m_density (density)
00035 {
00036   update_mass ();
00037 }
00038 
00039 // Put fuel in the tank.  With the default VOLUME of -1.0, the tank is
00040 // filled to capacity.  With any other negative VOLUME, or zero, the
00041 // tank is emptied, i.e. the volume is set to zero.
00042 void Vamos_Body::Fuel_Tank::
00043 fill (double volume)
00044 {
00045   if (volume == -1.0)
00046         {
00047           m_volume = m_capacity;
00048         }
00049   else
00050         {
00051           m_volume = volume;
00052         }
00053 
00054   update_mass ();
00055 }
00056 
00057 // Return the volume of fuel remaining.
00058 double Vamos_Body::Fuel_Tank::
00059 consume (double amount)
00060 {
00061   m_volume -= amount;
00062   if (m_volume < 0.0)
00063         {
00064           m_volume = 0.0;
00065         }
00066 
00067   update_mass ();
00068   return m_volume;
00069 }

Generated on Thu Oct 19 04:05:55 2006 by  doxygen 1.4.6