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

playgame.cpp

Go to the documentation of this file.
00001 #include "../borqueror.h"
00002 
00003 PlayGame::PlayGame( void )
00004 {
00005         MessageServer::Instance().RegisterMessageClient( this , Message::USER );
00006 }
00007 
00008 PlayGame::~PlayGame( void )
00009 {
00010 }
00011 
00012 const bool PlayGame::evMessage( const UserMessage &msg )
00013 {
00014         char    temp[10];
00015 
00016         if( msg.SubMessage() == SAVE_SPECIES )
00017         {
00018                 Save( Cfg::GetCfg().GetCfgString( "SavedGames" , itoa( (int)msg.Data() , temp , 10 ) ) + ".spc" );
00019                 return true;
00020         }
00021         else if( msg.SubMessage() == LOAD_SPECIES )
00022         {
00023                 Load( Cfg::GetCfg().GetCfgString( "SavedGames" , itoa( (int)msg.Data() , temp , 10 ) ) + ".spc" );
00024                 return true;
00025         }
00026 
00027         return false;
00028 }
00029 
00030 void PlayGame::Load( string filename )
00031 {
00032         Colony::ResetAllColonies();
00033         Parameters::species.clear();
00034         ifstream        inf( filename.c_str() , ios::in );
00035         
00036         if( inf.good() && !inf.fail() )
00037         {
00038                 char    buffer[4096];
00039                 inf.getline( buffer , sizeof( buffer ) , '~' );
00040 
00041                 while( !inf.eof() )
00042                 {
00043                         icstring        ics = buffer;
00044                         ics = Rsrc::GetList( ics );
00045                         icstring        species = Rsrc::GetId( ics );
00046                         ics = Rsrc::GetList( ics );
00047                         const string ssName = Rsrc::GetStr( ics );
00048                         const bool hw = Rsrc::GetInt( ics ) != 0;
00049                         vector<Planet *>::iterator pos = find_if( Planet::allPlanets.begin() , Planet::allPlanets.end() , bind2nd( mem_fun( &Planet::IsPlanetName ) , ssName.c_str() ) );
00050                         if( pos != Planet::allPlanets.end() )           
00051                                 (*pos)->Colonize( species , hw );
00052 
00053                         vector<SpeciesInfo *>::iterator pos2 = find_if( Parameters::allSpecies.begin() , Parameters::allSpecies.end() , bind2nd( mem_fun( &SpeciesInfo::IsSpecies ) , species.c_str() ) );
00054                         if( pos2 != Parameters::allSpecies.end() )
00055                         {
00056                                 (*pos2)->humidity = (int)(*pos)->GetTotalHumidity();
00057                                 (*pos2)->atmPressure = (int)(*pos)->GetTotalPressure();
00058                                 (*pos2)->surfaceTemperature = (int)(*pos)->GetTotalSurfaceTemperature();
00059                                 Parameters::species.insert( make_pair( (*pos2)->name , (*pos2) ) );
00060                         }
00061                         inf.getline( buffer , sizeof( buffer ) , '~' );
00062                 }
00063         }
00064 }
00065 
00066 void PlayGame::Save( string filename )
00067 {
00068         ofstream        of( filename.c_str() , ios::out );
00069 
00070         for( map<icstring,SpeciesInfo *>::iterator sp = Parameters::species.begin() ; sp != Parameters::species.end() ; ++sp )
00071         {
00072                 of << "(" << sp->first.c_str() << " ";
00073                 
00074                 for( multimap<icstring,Colony *>::iterator it = Colony::colonies.lower_bound( sp->first ) ; it != Colony::colonies.upper_bound( sp->first ) ; ++it )
00075                         it->second->Save( of );
00076 
00077                 of << ")~" << endl;
00078         }
00079 }
00080 

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