Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Planet Class Reference

#include <planet.h>

Collaboration diagram for Planet:

Collaboration graph
[legend]

Public Member Functions

 Planet (StarSystem *&aSs, const string &aPlanetName, const int aPLanetType, const int aPlanetSize, const int aPlanetNo)
virtual ~Planet (void)
const int GetPlanetSize (void) const
const bool DrawPlanet (XRect *plRect)
const int GetType (void) const
const double GetSurfaceGravity (void) const
const double GetTotalHumidity (void) const
const double GetTotalSurfaceTemperature (void) const
const double GetTotalPressure (void) const
const double GetSoil (void) const
const double GetSunFactor (void) const
const double GetOre (void) const
const double GetEnergy (void) const
const double GetFauna (void) const
const double GetFlora (void) const
const double GetWater (void) const
const double GetLithium (void) const
const double GetDeuterium (void) const
const bool ClickedOn (const XPoint *p)
 returns true if we have clicked on the sun of the satrsystem object

void Colonize (const icstring &aSpecies, const bool aHomeWorld=false)
const bool IsColonized (void) const
const bool IsCompatible (SpeciesInfo *aPi)
const bool IsHomeWorldOf (const icstring &species)
const bool IsPlanetName (const char *aName) const

Data Fields

const int planetType
const int planetSize
const string planetName
const int planetNo

Static Public Attributes

vector< Planet * > allPlanets

Protected Member Functions

const bool Save (ofstream *of)
void Setup (void)

Protected Attributes

int ore
int energy
int soil
int fauna
int flora
int lithium
int deuterium
StarSystem *& ss
Colonycolony
double humidity
double surfaceTemperature
double gravity
double atmPressure
double sunEnergy
double water
double humidityTerraformedDelta
double surfaceTemperatureTerraformedDelta
double pressureTerraformedDelta

Private Attributes

int id
XRect area

Friends

class Colony
class StarSystem
class Galaxy

Constructor & Destructor Documentation

Planet::Planet StarSystem *&  aSs,
const string &  aPlanetName,
const int  aPLanetType,
const int  aPlanetSize,
const int  aPlanetNo
 

Definition at line 7 of file planet.cpp.

References allPlanets, and Setup().

00008 : ss( aSs ) , planetName( aPlanetName ) , planetType( aPLanetType ) , planetSize( aPlanetSize )
00009 , planetNo( aPlanetNo )
00010 , ore( 0 ) , energy( 0 ) , soil( 0 ) , fauna( 0 ) , flora( 0 ) , lithium( 0 ) , deuterium( 0 )
00011 , humidity( 0 ) , surfaceTemperature( 0 ) , gravity( 0 ) , atmPressure( 0 ) , sunEnergy( 0 )
00012 , humidityTerraformedDelta( 0 ) , surfaceTemperatureTerraformedDelta( 0 ) , pressureTerraformedDelta( 0 )
00013 , colony( 0 )
00014 {
00015         Setup();
00016         allPlanets.push_back( this );
00017 }

Planet::~Planet void   )  [virtual]
 

Definition at line 19 of file planet.cpp.

00020 {
00021 }


Member Function Documentation

const bool Planet::ClickedOn const XPoint *  p  ) 
 

returns true if we have clicked on the sun of the satrsystem object

Definition at line 98 of file planet.cpp.

References area.

Referenced by StarSystemObject::evMouseLClick(), and PlanetInfoDlg::evMouseLClick().

00099 {
00100         if( area.HitTest( *p ) == XRect::RELPOS_INSIDE )
00101                 return true;
00102         return false;
00103 }

void Planet::Colonize const icstring aSpecies,
const bool  aHomeWorld = false
 

Definition at line 105 of file planet.cpp.

References Colony, and colony.

Referenced by Parameters::CreateGalaxy().

00106 {
00107         colony = new Colony( aSpecies , *this , aHomeWorld );
00108         colony->SetGDI( GetGDI() );
00109 }

const bool Planet::DrawPlanet XRect *  plRect  ) 
 

Definition at line 58 of file planet.cpp.

References area, colony, GetPlanetSize(), GetType(), id, IsColonized(), Parameters::species, and Colony::species.

Referenced by StarSystem::DrawStarSystem().

00059 {
00060         XRect   ara = *plRect;
00061         if( GetType() != -1 && GetPlanetSize() != 7 )
00062         {
00063                 SDL_Surface     *sfc = Graf::Img( id );
00064                 const int       size = (int)(sfc->h * (GetPlanetSize() / 6.0));
00065                 XRect   src( sfc->h * GetType() , 0 , sfc->h , sfc->h );
00066 
00067                 XRect   r( 0 , 0 , size , size );
00068                 
00069                 ara.w = r.w + 20;
00070                 ara.x = plRect->Right() - ara.w;
00071 
00072                 XPoint  c = ara.Center();
00073                 r.x = c.x - r.w / 2;
00074                 r.y = c.y - r.h / 2;
00075                 Graf::SDL_StretchBlt( sfc , &src , GetGDI() , &r , true );
00076                 area = r;
00077 
00078                 if( IsColonized() )
00079                 {
00080                         XPoint  sz = GetTextSize( colony->species.c_str() );
00081                         
00082                         XRect   rct( r.Center().x - sz.x / 2, r.y - GetFontSize() * 4 , sz.x , GetFontSize() * 2 );
00083                         TextOutStr( rct , colony->species.c_str() , Parameters::species[colony->species]->color );
00084                 }
00085         }
00086         else
00087         {
00088                 XRect   r( 0 , 0 , -1 , -1 );
00089                 Graf::Img( id , &r );
00090                 ara.x = ara.Right() - r.h;
00091                 ara.w = r.h;
00092         }
00093         plRect->w -= ara.Width();
00094         
00095         return true;
00096 }

const double Planet::GetDeuterium void   )  const [inline]
 

Definition at line 70 of file planet.h.

References deuterium, and GetWater().

Referenced by PlanetInfoDlg::SetupInfo().

00070 {       return deuterium + deuterium * GetWater() / 100.0;      }

const double Planet::GetEnergy void   )  const [inline]
 

Definition at line 65 of file planet.h.

References energy.

Referenced by PlanetInfoDlg::SetupInfo().

00065 {       return energy;  }

const double Planet::GetFauna void   )  const [inline]
 

Definition at line 66 of file planet.h.

References fauna, and GetFlora().

Referenced by PlanetInfoDlg::SetupInfo().

00066 {       return fauna * GetFlora() / 100.0;      }

const double Planet::GetFlora void   )  const [inline]
 

Definition at line 67 of file planet.h.

References flora, GetSoil(), and GetWater().

Referenced by GetFauna(), and PlanetInfoDlg::SetupInfo().

00067 {       return flora * (GetWater() + GetSoil()) / 200.0;        }

const double Planet::GetLithium void   )  const [inline]
 

Definition at line 69 of file planet.h.

References GetOre(), and lithium.

Referenced by PlanetInfoDlg::SetupInfo().

00069 {       return lithium + lithium * GetOre() / 100.0;    }

const double Planet::GetOre void   )  const [inline]
 

Definition at line 64 of file planet.h.

References ore.

Referenced by GetLithium(), and PlanetInfoDlg::SetupInfo().

00064 {       return ore;     }

const int Planet::GetPlanetSize void   )  const [inline]
 

Definition at line 53 of file planet.h.

References planetSize.

Referenced by DrawPlanet().

00053 {       return 1 + planetSize;  }

const double Planet::GetSoil void   )  const [inline]
 

Definition at line 62 of file planet.h.

References GetSunFactor(), GetTotalHumidity(), and soil.

Referenced by GetFlora(), and PlanetInfoDlg::SetupInfo().

00062 {       return soil + soil * (GetTotalHumidity() + (1 - GetSunFactor())) / 200.0;       }

const double Planet::GetSunFactor void   )  const [inline]
 

Definition at line 63 of file planet.h.

References sunEnergy.

Referenced by GetSoil(), and PlanetInfoDlg::SetupInfo().

00063 {       return sunEnergy;       }       //       - sunEnergy * GetTotalHumidity() / 100.0;      }

const double Planet::GetSurfaceGravity void   )  const [inline]
 

Definition at line 58 of file planet.h.

References gravity.

Referenced by PlanetInfoDlg::SetupInfo().

00058 {       return gravity; }

const double Planet::GetTotalHumidity void   )  const [inline]
 

Definition at line 59 of file planet.h.

References humidity, and humidityTerraformedDelta.

Referenced by Parameters::CreateGalaxy(), GetSoil(), GetWater(), IsCompatible(), and PlanetInfoDlg::SetupInfo().

00059 {       return humidity + humidityTerraformedDelta;     }

const double Planet::GetTotalPressure void   )  const [inline]
 

Definition at line 61 of file planet.h.

References atmPressure, and pressureTerraformedDelta.

Referenced by Parameters::CreateGalaxy(), GetWater(), IsCompatible(), and PlanetInfoDlg::SetupInfo().

const double Planet::GetTotalSurfaceTemperature void   )  const [inline]
 

Definition at line 60 of file planet.h.

References surfaceTemperature, and surfaceTemperatureTerraformedDelta.

Referenced by Parameters::CreateGalaxy(), IsCompatible(), and PlanetInfoDlg::SetupInfo().

const int Planet::GetType void   )  const [inline]
 

Definition at line 57 of file planet.h.

References planetType.

Referenced by DrawPlanet(), and Setup().

00057 {       return planetType;      }

const double Planet::GetWater void   )  const [inline]
 

Definition at line 68 of file planet.h.

References GetTotalHumidity(), GetTotalPressure(), and water.

Referenced by GetDeuterium(), GetFlora(), and PlanetInfoDlg::SetupInfo().

00068 {       return water * GetTotalPressure() / 100.0 + GetTotalHumidity() / 10.0;  }

const bool Planet::IsColonized void   )  const [inline]
 

Definition at line 76 of file planet.h.

References colony.

Referenced by StarSystem::DrawInfluenceZones(), DrawPlanet(), IsCompatible(), and IsHomeWorldOf().

00076 {       return colony != 0;     }

const bool Planet::IsCompatible SpeciesInfo aPi  ) 
 

Definition at line 111 of file planet.cpp.

References SpeciesInfo::atmPressure, GetTotalHumidity(), GetTotalPressure(), GetTotalSurfaceTemperature(), SpeciesInfo::humidity, SpeciesInfo::hwPlanet, IsColonized(), SpeciesInfo::residue, and SpeciesInfo::surfaceTemperature.

Referenced by Parameters::CreateGalaxy().

00112 {
00113         if( !IsColonized() )
00114         {
00115                 double residue = fabs( aSi->surfaceTemperature - GetTotalSurfaceTemperature() );
00116                 if( residue < 5.0 )
00117                 {
00118                         residue += fabs( aSi->atmPressure - GetTotalPressure() );
00119                         residue += fabs( aSi->humidity - GetTotalHumidity() );
00120                         residue /= 3.0;
00121 
00122                         if( aSi->residue > residue )
00123                         {
00124                                 aSi->residue = residue;
00125                                 aSi->hwPlanet = this;
00126                         }
00127 
00128                 }
00129                 if( residue < 0.01 )
00130                         return true;
00131         }
00132         return false;
00133 }

const bool Planet::IsHomeWorldOf const icstring species  ) 
 

Definition at line 135 of file planet.cpp.

References colony, Colony::homeWorld, IsColonized(), and Colony::species.

00136 {
00137         return IsColonized() && colony->homeWorld && colony->species == species;
00138 }

const bool Planet::IsPlanetName const char *  aName  )  const [inline]
 

Definition at line 82 of file planet.h.

References planetName.

Referenced by PlayGame::Load().

00082 {       return planetName == aName;     }

const bool Planet::Save ofstream *  of  )  [protected]
 

Definition at line 140 of file planet.cpp.

References atmPressure, deuterium, energy, fauna, flora, gravity, humidity, humidityTerraformedDelta, lithium, ore, planetNo, planetSize, planetType, pressureTerraformedDelta, soil, sunEnergy, surfaceTemperature, surfaceTemperatureTerraformedDelta, and water.

Referenced by StarSystem::Save().

00141 {
00142         *of << "\t(" << planetNo << " " 
00143                 << planetSize << " " << planetType << " " 
00144                 << ore << " " << energy << " " << soil << " " << fauna << " " << flora << " " << lithium << " " << deuterium << " "
00145                 << std::fixed << std::setprecision( 2 ) << humidity << " " << surfaceTemperature << " " << gravity << " " << atmPressure << " " << sunEnergy << " " << water <<" "
00146                 << humidityTerraformedDelta << " " << surfaceTemperatureTerraformedDelta << " " << pressureTerraformedDelta
00147                 << ")" << endl;
00148 
00149         return true;
00150 }

void Planet::Setup void   )  [protected]
 

Definition at line 23 of file planet.cpp.

References PlanetInfo::atmPressure, atmPressure, Parameters::compensator, PlanetInfo::delta, PlanetInfo::deuterium, deuterium, PlanetInfo::energy, energy, PlanetInfo::fauna, fauna, PlanetInfo::flora, flora, PlanetInfo::GetAbsValueOf(), StarSystem::GetStarSize(), StarSystem::GetStarType(), GetType(), PlanetInfo::GetValueOf(), gravity, PlanetInfo::humidity, humidity, id, PlanetInfo::lithium, lithium, ProbaHolder::Next(), PlanetInfo::ore, ore, planetNo, planetSize, planetType, Parameters::plIndice, PlanetInfo::soil, soil, ss, sunEnergy, PlanetInfo::surfaceTemperature, surfaceTemperature, PlanetInfo::water, and water.

Referenced by Planet().

00024 {
00025         SetGDI( View::GetMainFrame()->GetGDI() );
00026 
00027         id = Graf::LoadImg( "Planets" , "Planets" , "@Images" );
00028 
00029         if( GetType() > -1 )
00030         {
00031                 map<int,PlanetInfo *>::iterator it = Parameters::plIndice.find( planetType );
00032                 PlanetInfo      *pi = 0;
00033                 if( it != Parameters::plIndice.end() )
00034                         pi = it->second;
00035 
00036                 gravity = max( 0.0 , 9.81 * Parameters::compensator["Size"][planetSize] + (1.0 - pi->delta->Next( 2 )) );
00037                 soil = (int)pi->GetAbsValueOf( pi->soil );
00038                 ore = (int)pi->GetAbsValueOf( pi->ore );
00039                 energy = (int)pi->GetAbsValueOf( pi->energy );
00040                 sunEnergy = 1 * Parameters::compensator["Temperature"][planetNo]
00041                                           * Parameters::compensator["SunType"][ss->GetStarType()]
00042                                           * Parameters::compensator["SunSize"][ss->GetStarSize()];
00043 
00044                 surfaceTemperature = pi->GetValueOf( pi->surfaceTemperature ) * sunEnergy;
00045                 atmPressure = pi->GetAbsValueOf( pi->atmPressure ) * Parameters::compensator["Size"][planetSize];
00046                 water = pi->GetAbsValueOf( pi->water ) * (gravity / 10);
00047                 humidity = pi->GetAbsValueOf( pi->humidity ) * (atmPressure / 100.0) * sunEnergy * (gravity / 10);
00048                 humidity = max( 0.0 , min( 99.9 , humidity ) );
00049 
00050                 flora = (int)pi->GetAbsValueOf( pi->flora );
00051                 fauna = (int)pi->GetAbsValueOf( pi->fauna );
00052                 lithium = (int)pi->GetAbsValueOf( pi->lithium );
00053                 deuterium = (int)pi->GetAbsValueOf( pi->deuterium );
00054 
00055         }
00056 }


Friends And Related Function Documentation

friend class Colony [friend]
 

Definition at line 27 of file planet.h.

Referenced by Colonize().

friend class Galaxy [friend]
 

Definition at line 29 of file planet.h.

friend class StarSystem [friend]
 

Definition at line 28 of file planet.h.


Field Documentation

vector< Planet * > Planet::allPlanets [static]
 

Definition at line 3 of file planet.cpp.

Referenced by Parameters::CreateGalaxy(), PlayGame::Load(), Planet(), and Galaxy::Reset().

XRect Planet::area [private]
 

Definition at line 23 of file planet.h.

Referenced by ClickedOn(), and DrawPlanet().

double Planet::atmPressure [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetTotalPressure(), Galaxy::Load(), Save(), and Setup().

Colony* Planet::colony [protected]
 

Definition at line 35 of file planet.h.

Referenced by Colonize(), DrawPlanet(), IsColonized(), and IsHomeWorldOf().

int Planet::deuterium [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetDeuterium(), Galaxy::Load(), Save(), and Setup().

int Planet::energy [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetEnergy(), Galaxy::Load(), Save(), and Setup().

int Planet::fauna [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetFauna(), Galaxy::Load(), Save(), and Setup().

int Planet::flora [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetFlora(), Galaxy::Load(), Save(), and Setup().

double Planet::gravity [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetSurfaceGravity(), Galaxy::Load(), Save(), and Setup().

double Planet::humidity [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetTotalHumidity(), Galaxy::Load(), Save(), and Setup().

double Planet::humidityTerraformedDelta [protected]
 

Definition at line 38 of file planet.h.

Referenced by GetTotalHumidity(), Galaxy::Load(), and Save().

int Planet::id [private]
 

Definition at line 21 of file planet.h.

Referenced by DrawPlanet(), and Setup().

int Planet::lithium [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetLithium(), Galaxy::Load(), Save(), and Setup().

int Planet::ore [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetOre(), Galaxy::Load(), Save(), and Setup().

const string Planet::planetName
 

Definition at line 44 of file planet.h.

Referenced by IsPlanetName(), Colony::Save(), and PlanetInfoDlg::SetupInfo().

const int Planet::planetNo
 

Definition at line 45 of file planet.h.

Referenced by Save(), and Setup().

const int Planet::planetSize
 

Definition at line 43 of file planet.h.

Referenced by GetPlanetSize(), Save(), and Setup().

const int Planet::planetType
 

Definition at line 42 of file planet.h.

Referenced by GetType(), Save(), Setup(), and PlanetInfoDlg::SetupInfo().

double Planet::pressureTerraformedDelta [protected]
 

Definition at line 38 of file planet.h.

Referenced by GetTotalPressure(), Galaxy::Load(), and Save().

int Planet::soil [protected]
 

Definition at line 31 of file planet.h.

Referenced by GetSoil(), Galaxy::Load(), Save(), and Setup().

StarSystem*& Planet::ss [protected]
 

Definition at line 33 of file planet.h.

Referenced by Setup().

double Planet::sunEnergy [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetSunFactor(), Galaxy::Load(), Save(), and Setup().

double Planet::surfaceTemperature [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetTotalSurfaceTemperature(), Galaxy::Load(), Save(), and Setup().

double Planet::surfaceTemperatureTerraformedDelta [protected]
 

Definition at line 38 of file planet.h.

Referenced by GetTotalSurfaceTemperature(), Galaxy::Load(), and Save().

double Planet::water [protected]
 

Definition at line 37 of file planet.h.

Referenced by GetWater(), Galaxy::Load(), Save(), and Setup().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:30 2003 for Borqueror by doxygen 1.3.3