00001 #include "../borqueror.h" 00002 00003 vector<Planet *> Planet::allPlanets; 00004 00006 00007 Planet::Planet( StarSystem *&aSs , const string &aPlanetName , const int aPLanetType , const int aPlanetSize , const int aPlanetNo ) 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 } 00018 00019 Planet::~Planet( void ) 00020 { 00021 } 00022 00023 void Planet::Setup( void ) 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 } 00057 00058 const bool Planet::DrawPlanet( XRect *plRect ) 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 } 00097 00098 const bool Planet::ClickedOn( const XPoint *p ) 00099 { 00100 if( area.HitTest( *p ) == XRect::RELPOS_INSIDE ) 00101 return true; 00102 return false; 00103 } 00104 00105 void Planet::Colonize( const icstring &aSpecies , const bool aHomeWorld ) 00106 { 00107 colony = new Colony( aSpecies , *this , aHomeWorld ); 00108 colony->SetGDI( GetGDI() ); 00109 } 00110 00111 const bool Planet::IsCompatible( SpeciesInfo *aSi ) 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 } 00134 00135 const bool Planet::IsHomeWorldOf( const icstring &species ) 00136 { 00137 return IsColonized() && colony->homeWorld && colony->species == species; 00138 } 00139 00140 const bool Planet::Save( ofstream *of ) 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 }