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

starsystem.cpp

Go to the documentation of this file.
00001 #include "../borqueror.h"
00002 
00003 const icstring  stn[] = { "Red" , "Orange" , "Yellow" , "Green" , "white" , "blue" , "Dwarf"    };
00005 
00006 StarSystem::StarSystem( const string &aStarName , const string &aStarNameDescr , const string &aSsName , const int aStarType , const int aStarSize )
00007 : starName( aStarName) , starNameDescr( aStarNameDescr ) , ssName( aSsName ) 
00008 , starType( aStarType ) , starSize( aStarSize ) , sId( -1 ) , general( "@GenStars" )
00009 {
00010         Setup();
00011 }
00012 
00013 StarSystem::~StarSystem( void )
00014 {
00015         for( vector<Planet *>::iterator it = begin() ; it != end() ; ++it )
00016                 delete (*it);
00017         clear();
00018 }
00019 
00020 const string StarSystem::GetPlanetName( const int pl )
00021 {
00022         string ans = ssName.substr( 0 , 3 );
00023 
00024         const char      *romans[] = { "" , "I" , "II" , "III" , "IV" , "V" , "VI" , "VII" , "VIII" , "IX"       };
00025         ans += romans[pl];
00026         ans += ssName.substr( 4 );
00027 
00028         return ans;
00029 }
00030 
00031 void StarSystem::Setup( void )
00032 {
00033         const string    str = ssName.substr( 0 , 2 );
00034 
00035         if( (sId = Graf::HasImage( str )) == -1 )
00036         {
00037                 const int id = Graf::LoadImg( "Stars" , "Stars" , "@Images" );
00038 
00039                 SDL_Surface     *sfc = Graf::Img( id );
00040                 int     size = (int)(sfc->h * (GetStarSize() / 6.0));
00041 
00042                 SDL_Surface     *tmp = Graf::NewSurface( size , size  );
00043                 XRect   src( sfc->h * starType , 0 , sfc->h , sfc->h );
00044                 Graf::SDL_StretchBlt( sfc , &src , tmp );
00045                 Graf::AddImage( tmp , str );
00046         
00047                 sId = Graf::HasImage( str );
00048         }
00049         ssDst = XRect( 0 , 0  , 0 , 0 );
00050 }
00051 
00052 const bool StarSystem::DrawInGalaxy( SDL_Surface *target )
00053 {
00054         SDL_Surface     *sfc = Graf::Img( sId );
00055         dst = XRect( x - sfc->w / 2 , y - sfc->h / 2 , sfc->w , sfc->h );
00056         SDL_BlitSurface( sfc , 0 , target , &dst );
00057 
00058         return true;
00059 }
00060 
00061 const bool StarSystem::DrawInfluenceZones( SDL_Surface *target )
00062 {
00063         //      Must mark the star with the species'color...
00064         //      temporarily mark one star with one species... we will allow mix of colonies later on...
00065         vector<Planet *>::iterator pos = find_if( begin() , end() , mem_fun( &Planet::IsColonized ) );
00066         if( pos != end() )
00067         {
00068                 const icstring sp = (*pos)->colony->species;
00069                 unsigned int    cnt0 = Parameters::species.size();
00070                 unsigned int    cnt1 = Parameters::allSpecies.size();
00071                 map<icstring , SpeciesInfo*>::iterator pos2 = Parameters::species.find( sp );
00072                 assert( pos2 != Parameters::species.end() );
00073                 RGBColor        speciesColor = pos2->second->color;
00074                 XPoint  p( x - (int)Parameters::ratio / 2 , y - (int)Parameters::ratio / 2 );
00075                 for( int i = 0 ; i < Parameters::ratio ; i++ )
00076                         for( int j = 0 ; j < Parameters::ratio ; j++ )
00077                                 if( (i + j) % 4 == 0 )
00078                                         DrawPoint( target , p + XPoint( i , j ) , speciesColor );
00079                 return DrawInGalaxy( target );
00080         }
00081         return false;
00082 }
00083 
00084 void StarSystem::DrawStarSystem( SDL_Surface *target , XRect &in , const int aSunIds )
00085 {
00086         XRect   r( 0 , 0 , -1 , -1 );
00087         SDL_Surface     *suns = Graf::Img( aSunIds , &r );
00088 
00089         XRect   src( r.h * GetStarType() , 0 , r.h , r.h );
00090         XRect   maxDst( in.Right() - in.h , in.y , in.h , in.h );
00091         int size = (int)(in.h * (GetStarSize() / 6.0));
00092         XPoint  c = maxDst.Center();
00093         ssDst = XRect( c.x - size / 2 , c.y - size / 2 , size , size );
00094 
00095         Graf::SDL_StretchBlt( suns , &src , target , &ssDst );
00096                 
00097         XRect   plRect( in.x , in.y , ssDst.x , in.h );
00098         for_each( begin() , end() , bind2nd( mem_fun( &Planet::DrawPlanet ) , &plRect ) ); 
00099 }
00100 
00101 const bool StarSystem::InVicinity( const XPoint *p )
00102 {
00103         return dst.HitTest( *p ) == XRect::RELPOS_INSIDE;
00104 }
00105 
00106 const bool StarSystem::ClickedOn( const XPoint *p )
00107 {
00108         if( ssDst.HitTest( *p ) == XRect::RELPOS_INSIDE )
00109                 return true;
00110         return false;
00111 }
00112 
00113 string StarSystem::GetStarInfo( void )
00114 {
00115         string  ans = 
00116                    "Borg Denomination: ";
00117         ans += ssName + "\n";
00118         ans += "Star Name  : ";
00119         ans += starName;
00120         if( !starNameDescr.empty() )
00121         {
00122                 ans += " (";
00123                 ans += starNameDescr + ")";
00124         }
00125         ans += "\n";
00126         int     thisId =  GetStarType() << 8 | GetStarSize() - 1;
00127         vector<StarInfo *>::iterator pos = find_if( Parameters::starInfo.begin() , Parameters::starInfo.end() , bind2nd( mem_fun( &StarInfo::IsId ) , &thisId ) );
00128 
00129         if( pos != Parameters::starInfo.end() )
00130         {
00131                 ans += "Class: ";
00132                 ans += (*pos)->classInf;
00133                 ans += "\n";
00134                 ans += "Temperature: ";
00135                 ans += (*pos)->temInf;
00136         }
00137         return ans;
00138 
00139 }
00140 
00141 const bool StarSystem::Save( ofstream *of )
00142 {
00143         *of << "(\"" << starName << "\" \"" << starNameDescr << "\" " << x << " " << y << " " << GetStarType() << " " << starSize << " " << size() << endl;
00144         for_each( begin() , end() , bind2nd( mem_fun( &Planet::Save ) , of ) );
00145         *of << ")~" << endl;
00146         
00147         return true;
00148 }

Generated on Fri Dec 5 04:06:00 2003 for Borqueror by doxygen 1.3.3