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

StarSystem Class Reference

#include <starsystem.h>


Public Member Functions

 StarSystem (const string &aStarName, const string &aStarNameDescr, const string &aSsName, const int aStarType, const int aStarSize)
 ~StarSystem (void)
const int GetImageId (void) const
const bool DrawInGalaxy (SDL_Surface *target)
const bool DrawInfluenceZones (SDL_Surface *target)
void DrawStarSystem (SDL_Surface *target, XRect &in, const int aSunIds)
const bool InVicinity (const XPoint *p)
const bool ClickedOn (const XPoint *p)
 returns true if we have clicked on the sun of the satrsystem object

const string GetPlanetName (const int pl)
const int GetStarType (void) const
const int GetStarSize (void) const
string GetStarInfo (void)
const bool Save (ofstream *of)

Data Fields

const int starType
const int starSize
const string ssName
const string starName
const string starNameDescr

Protected Member Functions

void Setup (void)

Private Attributes

int sId
XRect dst
XRect ssDst
Rsrc general


Constructor & Destructor Documentation

StarSystem::StarSystem const string &  aStarName,
const string &  aStarNameDescr,
const string &  aSsName,
const int  aStarType,
const int  aStarSize
 

Definition at line 6 of file starsystem.cpp.

References Setup().

00007 : starName( aStarName) , starNameDescr( aStarNameDescr ) , ssName( aSsName ) 
00008 , starType( aStarType ) , starSize( aStarSize ) , sId( -1 ) , general( "@GenStars" )
00009 {
00010         Setup();
00011 }

StarSystem::~StarSystem void   ) 
 

Definition at line 13 of file starsystem.cpp.

00014 {
00015         for( vector<Planet *>::iterator it = begin() ; it != end() ; ++it )
00016                 delete (*it);
00017         clear();
00018 }


Member Function Documentation

const bool StarSystem::ClickedOn const XPoint *  p  ) 
 

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

Definition at line 106 of file starsystem.cpp.

References ssDst.

Referenced by StarSystemObject::evMouseLClick().

00107 {
00108         if( ssDst.HitTest( *p ) == XRect::RELPOS_INSIDE )
00109                 return true;
00110         return false;
00111 }

const bool StarSystem::DrawInfluenceZones SDL_Surface *  target  ) 
 

Definition at line 61 of file starsystem.cpp.

References Parameters::allSpecies, DrawInGalaxy(), icstring, Planet::IsColonized(), Parameters::ratio, and Parameters::species.

Referenced by GalaxyScreen::ResetGalaxyDisplay().

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 }

const bool StarSystem::DrawInGalaxy SDL_Surface *  target  ) 
 

Definition at line 52 of file starsystem.cpp.

References dst, and sId.

Referenced by DrawInfluenceZones(), and GalaxyScreen::ResetGalaxyDisplay().

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 }

void StarSystem::DrawStarSystem SDL_Surface *  target,
XRect &  in,
const int  aSunIds
 

Definition at line 84 of file starsystem.cpp.

References Planet::DrawPlanet(), GetStarSize(), GetStarType(), and ssDst.

Referenced by StarSystemObject::Draw().

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 }

const int StarSystem::GetImageId void   )  const [inline]
 

Definition at line 41 of file starsystem.h.

References sId.

00041 {       return sId;     }

const string StarSystem::GetPlanetName const int  pl  ) 
 

Definition at line 20 of file starsystem.cpp.

References ssName.

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 }

string StarSystem::GetStarInfo void   ) 
 

Definition at line 113 of file starsystem.cpp.

References GetStarSize(), GetStarType(), StarInfo::IsId(), ssName, Parameters::starInfo, starName, and starNameDescr.

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 }

const int StarSystem::GetStarSize void   )  const [inline]
 

Definition at line 53 of file starsystem.h.

References starSize.

Referenced by DrawStarSystem(), GetStarInfo(), Setup(), Planet::Setup(), and StarInfoDlg::SetupWindow().

00053 {       return starSize + 1;    }

const int StarSystem::GetStarType void   )  const [inline]
 

Definition at line 52 of file starsystem.h.

References starType.

Referenced by DrawStarSystem(), GetStarInfo(), Save(), Planet::Setup(), and StarInfoDlg::SetupWindow().

00052 {       return starType;        }

const bool StarSystem::InVicinity const XPoint *  p  ) 
 

Definition at line 101 of file starsystem.cpp.

References dst.

Referenced by GalaxyScreen::evMouseLClick(), GalaxyScreen::evMouseMove(), and GalaxyScreen::ShowTip().

00102 {
00103         return dst.HitTest( *p ) == XRect::RELPOS_INSIDE;
00104 }

const bool StarSystem::Save ofstream *  of  ) 
 

Definition at line 141 of file starsystem.cpp.

References GetStarType(), Planet::Save(), starName, starNameDescr, and starSize.

Referenced by Galaxy::Run().

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 }

void StarSystem::Setup void   )  [protected]
 

Definition at line 31 of file starsystem.cpp.

References GetStarSize(), sId, ssDst, ssName, and starType.

Referenced by StarSystem().

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 }


Field Documentation

XRect StarSystem::dst [private]
 

Definition at line 25 of file starsystem.h.

Referenced by DrawInGalaxy(), and InVicinity().

Rsrc StarSystem::general [private]
 

Definition at line 27 of file starsystem.h.

int StarSystem::sId [private]
 

Definition at line 23 of file starsystem.h.

Referenced by DrawInGalaxy(), GetImageId(), and Setup().

XRect StarSystem::ssDst [private]
 

Definition at line 25 of file starsystem.h.

Referenced by ClickedOn(), DrawStarSystem(), and Setup().

const string StarSystem::ssName
 

Definition at line 33 of file starsystem.h.

Referenced by GetPlanetName(), GetStarInfo(), Setup(), and StarInfoDlg::SetupWindow().

const string StarSystem::starName
 

Definition at line 33 of file starsystem.h.

Referenced by GetStarInfo(), Save(), and StarInfoDlg::SetupWindow().

const string StarSystem::starNameDescr
 

Definition at line 33 of file starsystem.h.

Referenced by GetStarInfo(), Save(), and StarInfoDlg::SetupWindow().

const int StarSystem::starSize
 

Definition at line 32 of file starsystem.h.

Referenced by GetStarSize(), and Save().

const int StarSystem::starType
 

Definition at line 31 of file starsystem.h.

Referenced by GetStarType(), and Setup().


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