Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SaveGame Class Reference

#include <savegame.h>

Public Member Functions

 ~SaveGame ()
 
void ReloadPickledData ()
 
const std::string & GetCallsign () const
 
void SetCallsign (const std::string &cs)
 
std::vector< float > & getMissionData (const std::string &magic_number)
 
const std::vector< float > & readMissionData (const std::string &magic_number) const
 
unsigned int getMissionDataLength (const std::string &magic_number) const
 
std::vector< std::string > & getMissionStringData (const std::string &magic_number)
 
const std::vector< std::string > & readMissionStringData (const std::string &magic_number) const
 
unsigned int getMissionStringDataLength (const std::string &magic_number) const
 
 SaveGame (const std::string &pilotname)
 
void PurgeZeroStarships ()
 
float GetSavedCredits ()
 
void SetSavedCredits (float)
 
void SetPlayerLocation (const QVector &playerloc)
 
QVector GetPlayerLocation ()
 
void SetStarSystem (std::string sys)
 
std::string GetStarSystem ()
 
std::string GetOldStarSystem ()
 
std::string GetPlayerFaction ()
 
void SetPlayerFaction (std::string faction)
 
std::string WriteSavedUnit (SavedUnits *su)
 
std::string WriteSaveGame (const char *systemname, const class QVector &Pos, float credits, std::vector< std::string >unitname, int player_num, std::string fact="", bool write=true)
 
std::string WritePlayerData (const QVector &FP, std::vector< std::string >unitname, const char *systemname, float credits, std::string fact="")
 
std::string WriteDynamicUniverse ()
 
void ReadSavedPackets (char *&buf, bool commitfaction, bool skip_news=false, bool select_data=false, const std::set< std::string > &select_data_filter=std::set< std::string >())
 
void AddUnitToSave (const char *unitname, int type, const char *faction, long address)
 cast address to long (for 64 bits compatibility) More...
 
void RemoveUnitFromSave (long address)
 
void SetOutputFileName (const std::string &filename)
 
void ParseSaveGame (const std::string &filename, std::string &ForceStarSystem, const std::string &originalstarsystem, QVector &pos, bool &shouldupdatedfighter0pos, float &credits, std::vector< std::string > &originalunit, int player_num, const std::string &savestr=std::string(), bool read=true, bool commitFaction=true, bool quick_read=false, bool skip_news=false, bool select_data=false, const std::set< std::string > &select_data_filter=std::set< std::string >())
 
void LoadSavedMissions ()
 

Detailed Description

Definition at line 28 of file savegame.h.

Constructor & Destructor Documentation

SaveGame::~SaveGame ( )

Definition at line 182 of file savegame.cpp.

183 {
184  delete missionstringdata;
185  delete missiondata;
186 }
SaveGame::SaveGame ( const std::string &  pilotname)

Definition at line 173 of file savegame.cpp.

174 {
175  callsign = pilot;
176  ForceStarSystem = string( "" );
177  PlayerLocation.Set( FLT_MAX, FLT_MAX, FLT_MAX );
178  missionstringdata = new MissionStringDat;
179  missiondata = new MissionFloatDat;
180 }

Member Function Documentation

void SaveGame::AddUnitToSave ( const char *  unitname,
int  type,
const char *  faction,
long  address 
)

cast address to long (for 64 bits compatibility)

Definition at line 374 of file savegame.cpp.

References vs_options::Drone.

Referenced by Enhancement::reactToCollision().

375 {
376  if ( game_options.Drone.compare( filename ) )
377  RemoveUnitFromSave( address );
378 }
const std::string& SaveGame::GetCallsign ( ) const
inline

Definition at line 53 of file savegame.h.

Referenced by ZoneInfo::display(), ZoneMgr::displayNPCs(), CockpitKeys::TextMessageCallback(), and Cockpit::Update().

54  {
55  return callsign;
56  }
std::vector< float > & SaveGame::getMissionData ( const std::string &  magic_number)
unsigned int SaveGame::getMissionDataLength ( const std::string &  magic_number) const

Get mission data length (read-only)

Definition at line 392 of file savegame.cpp.

Referenced by getSaveDataLength(), and saveStringList().

393 {
394  MissionFloatDat::MFD::const_iterator it = missiondata->m.find( magic_number );
395  return ( it == missiondata->m.end() ) ? 0 : it->second.size();
396 }
std::vector< string > & SaveGame::getMissionStringData ( const std::string &  magic_number)
unsigned int SaveGame::getMissionStringDataLength ( const std::string &  magic_number) const

Get mission string data length (read-only)

Definition at line 410 of file savegame.cpp.

Referenced by getSaveStringLength(), and fg_util::PurgeZeroShips().

411 {
412  MissionStringDat::MSD::const_iterator it = missionstringdata->m.find( magic_number );
413  return ( it == missionstringdata->m.end() ) ? 0 : it->second.size();
414 }
string SaveGame::GetOldStarSystem ( )

Definition at line 198 of file savegame.cpp.

199 {
200  return ForceStarSystem;
201 }
std::string SaveGame::GetPlayerFaction ( )
inline

Definition at line 90 of file savegame.h.

Referenced by createObjects(), and NetClient::Respawn().

91  {
92  return playerfaction;
93  }
QVector SaveGame::GetPlayerLocation ( )

Definition at line 214 of file savegame.cpp.

Referenced by Cockpit::Update().

215 {
216  return PlayerLocation;
217 }
float SaveGame::GetSavedCredits ( )

Definition at line 856 of file savegame.cpp.

References savedcredits.

Referenced by Cockpit::Update().

857 {
858  return savedcredits;
859 }
string SaveGame::GetStarSystem ( )

Definition at line 193 of file savegame.cpp.

Referenced by Cockpit::Update().

194 {
195  return ForceStarSystem;
196 }
void SaveGame::LoadSavedMissions ( )

Definition at line 692 of file savegame.cpp.

References _Universe, active_missions, Universe::CurrentCockpit(), Mission::getNthPlayerMission(), LoadMission(), and UniverseUtil::terminateMission().

Referenced by bootstrap_main_loop(), buyShip(), and Cockpit::Update().

693 {
694  unsigned int i;
695  vector< string >scripts = getMissionStringData( "active_scripts" );
696  vector< string >missions = getMissionStringData( "active_missions" );
697  PyRun_SimpleString(
698  "import VS\nVS.loading_active_missions=True\nprint \"Loading active missions \"+str(VS.loading_active_missions)\n" );
699  //kill any leftovers so they don't get loaded twice.
701  for (i = active_missions.size()-1; i > 0; --i) //don't terminate zeroth mission
702  if (active_missions[i]->player_num == _Universe->CurrentCockpit()
703  && active_missions[i] != ignoreMission)
705  for (i = 0; i < scripts.size() && i < missions.size(); ++i) {
706  try {
707  if ( !missions[i].empty() ) //Built-in/networking missions
708  LoadMission( missions[i].c_str(), scripts[i], false );
709  }
710  catch (...) {
711  if ( PyErr_Occurred() ) {
712  PyErr_Print();
713  PyErr_Clear();
714  fflush( stderr );
715  fflush( stdout );
716  } else {throw; }}
717  }
718  PyRun_SimpleString( "import VS\nVS.loading_active_missions=False\n" );
719  getMissionStringData( "active_scripts" ) = scripts;
720  getMissionStringData( "active_missions" ) = missions;
721 }
void SaveGame::ParseSaveGame ( const std::string &  filename,
std::string &  ForceStarSystem,
const std::string &  originalstarsystem,
QVector pos,
bool shouldupdatedfighter0pos,
float credits,
std::vector< std::string > &  originalunit,
int  player_num,
const std::string &  savestr = std::string(),
bool  read = true,
bool  commitFaction = true,
bool  quick_read = false,
bool  skip_news = false,
bool  select_data = false,
const std::set< std::string > &  select_data_filter = std::set< std::string > () 
)

Definition at line 874 of file savegame.cpp.

References VSFileSystem::VSFile::Close(), f, VSFileSystem::FileNotFound, GetReadPlayerSaveGame(), hopto(), j, VsnetOSS::memcpy(), VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), parsePipedString(), vs_options::quick_savegame_summaries_buffer, QVector, VSFileSystem::VSFile::ReadFull(), VSFileSystem::VSFile::ReadLine(), VSFileSystem::SaveFile, and VSFileSystem::UnknownFile.

Referenced by bootstrap_main_loop(), UniverseUtil::getSaveInfo(), NetClient::Respawn(), NetClient::startGame(), and Cockpit::Update().

889 {
890  const string &str = save_contents; //alias
891  string filename;
892  //Now leave filename empty, use the default name regardless...
893  shouldupdatepos = !(PlayerLocation.i == FLT_MAX || PlayerLocation.j == FLT_MAX || PlayerLocation.k == FLT_MAX);
894  //WE WILL ALWAYS SAVE THE CURRENT SAVEGAME IN THE MISSION SAVENAME (IT WILL BE COPIED TO THE SPECIFIED SAVENAME)
895  SetOutputFileName( filename );
896  VSFile f;
897  VSError err = FileNotFound;
898  if (read) {
899  //TRY TO GET THE SPECIFIED SAVENAME TO LOAD
900  string plsave = GetReadPlayerSaveGame( player_num );
901  if ( plsave.length() ) {
902  err = f.OpenReadOnly( plsave, SaveFile );
903  if (err > Ok) //failed in SaveFile
904  //Try as an UnknownFile to get a datadir saved game, like New_Game.
905  err = f.OpenReadOnly( plsave, UnknownFile );
906  } else if (filename.length() > 0) {
907  //IF NONE SIMPLY LOAD THE MISSION DEFAULT ONE
908  err = f.OpenReadOnly( filename, SaveFile );
909  }
910  }
911  if (err <= Ok) {
912  if (quick_read) {
913  char *buf = (char*) malloc( game_options.quick_savegame_summaries_buffer+1 );
916  savestring = buf;
917  free( buf );
918  } else {
919  savestring = f.ReadFull();
920  }
921  }
922  if ( err <= Ok || (!read && str != "") ) {
923  if (!read)
924  savestring = str;
925  if (savestring.length() > 0) {
926  char *buf = new char[savestring.length()+1];
927  buf[savestring.length()] = '\0';
928  memcpy( buf, savestring.c_str(), savestring.length() );
929  int headlen = hopto( buf, '\n', '\n', 0 );
930  char *deletebuf = buf;
931  char *tmp2 = (char*) malloc( headlen+2 );
932  char *freetmp2 = tmp2;
933  char *factionname = (char*) malloc( headlen+2 );
934  if ( headlen > 0 && (buf[headlen-1] == '\n' || buf[headlen-1] == ' ' || buf[headlen-1] == '\r') )
935  buf[headlen-1] = '\0';
936  factionname[headlen+1] = '\0';
937  QVector tmppos;
938  int res = sscanf( buf, "%s %lf %lf %lf %s", tmp2, &tmppos.i, &tmppos.j, &tmppos.k, factionname );
939  if (res == 4 || res == 5) {
940  //Extract credits & starship
941  for (int j = 0; '\0' != tmp2[j]; j++)
942  if (tmp2[j] == '^') {
943  sscanf( tmp2+j+1, "%f", &credits );
944  tmp2[j] = '\0';
945  for (int k = j+1; tmp2[k] != '\0'; k++)
946  if (tmp2[k] == '^') {
947  tmp2[k] = '\0';
948  savedstarship.clear();
949  savedstarship = parsePipedString( tmp2+k+1 );
950  break;
951  }
952  break;
953  }
954  //In networking save we include the faction at the end of the first line
955  if (res == 5) {
956  playerfaction = string( factionname );
957  cout<<"Found faction in save file : "<<playerfaction<<endl;
958  } else {
959  //If no faction -> default to privateer
960  playerfaction = string( "privateer" );
961  cout<<"Faction not found assigning default one: privateer"<<endl;
962  }
963  free( factionname );
964  if (ForceStarSystem.length() == 0)
965  ForceStarSystem = string( tmp2 );
966  if (PlayerLocation.i == FLT_MAX || PlayerLocation.j == FLT_MAX || PlayerLocation.k == FLT_MAX) {
967  shouldupdatepos = true;
968  PlayerLocation = tmppos; //LaunchUnitNear(tmppos);
969  }
970  buf += headlen;
971  ReadSavedPackets( buf, commitfaction, skip_news, select_data, select_data_filter );
972  }
973  free( freetmp2 );
974  freetmp2 = NULL;
975  tmp2 = NULL;
976  delete[] deletebuf;
977  }
978  if (read)
979  f.Close();
980  }
981  if (PlayerLocation.i == FLT_MAX || PlayerLocation.j == FLT_MAX || PlayerLocation.k == FLT_MAX) {
982  shouldupdatepos = false;
983  PlayerLocation = PP;
984  } else {
985  PP = PlayerLocation;
986  shouldupdatepos = true;
987  }
988  if (ForceStarSystem.length() == 0) {
989  ForceStarSystem = FSS;
990  originalsystem = FSS;
991  } else {
992  originalsystem = ForceStarSystem;
993  FSS = ForceStarSystem;
994  }
995  SetSavedCredits( credits );
996 }
void SaveGame::PurgeZeroStarships ( )

Definition at line 581 of file savegame.cpp.

References fg_util::CheckFG(), and fg_util::IsFGKey().

582 {
583  for (MissionStringDat::MSD::iterator i = missionstringdata->m.begin(), ie = missionstringdata->m.end(); i != ie; ++i)
584  if ( fg_util::IsFGKey( i->first ) )
585  if ( fg_util::CheckFG( i->second ) )
586  {
587  //printf( "correcting flightgroup %s to have right landed ships\n", i->first.c_str() );
588  }
589 }
const std::vector< float > & SaveGame::readMissionData ( const std::string &  magic_number) const

Get read-only access to mission data - note: returns empty stub if key isn't found

Definition at line 385 of file savegame.cpp.

Referenced by loadStringList().

386 {
387  static const std::vector< float > empty;
388  MissionFloatDat::MFD::const_iterator it = missiondata->m.find( magic_number );
389  return ( it == missiondata->m.end() ) ? empty : it->second;
390 }
const std::vector< string > & SaveGame::readMissionStringData ( const std::string &  magic_number) const

Get read-only access to mission string data - note: returns empty stub if key isn't found

Definition at line 398 of file savegame.cpp.

Referenced by getStringList(), and loadStringList().

399 {
400  static const std::vector< string > empty;
401  MissionStringDat::MSD::const_iterator it = missionstringdata->m.find( magic_number );
402  return ( it == missionstringdata->m.end() ) ? empty : it->second;
403 }
void SaveGame::ReadSavedPackets ( char *&  buf,
bool  commitfaction,
bool  skip_news = false,
bool  select_data = false,
const std::set< std::string > &  select_data_filter = std::set< std::string > () 
)

Definition at line 651 of file savegame.cpp.

References a, AnyStringScanInString(), hopto(), FactionUtil::LoadSerializedFaction(), SERVER, and UnpickleAllMissions().

656 {
657  int a = 0;
658  char unitname[1024];
659  char factname[1024];
660  while ( 3 == sscanf( buf, "%d %s %s", &a, unitname, factname ) ) {
661  //Put i to point after what we parsed (on the 3rd space read)
662  while ( (*buf) && isspace( *buf ) )
663  ++buf;
664  buf += hopto( buf, ' ', '\n', 0 );
665  buf += hopto( buf, ' ', '\n', 0 );
666  buf += hopto( buf, ' ', '\n', 0 );
667  if ( a == 0 && 0 == strcmp( unitname, "factions" ) && 0 == strcmp( factname, "begin" ) ) {
668  if (commitfactions) FactionUtil::LoadSerializedFaction( buf );
669  break; //GOT TO BE THE LAST>... cus it's stupid :-) and mac requires the factions to be loaded AFTER this function call
670  } else if ( a == 0 && 0 == strcmp( unitname, "mission" ) && 0 == strcmp( factname, "data" ) ) {
671  ReadMissionData( buf, select_data, select_data_filter );
672  } else if ( a == 0 && 0 == strcmp( unitname, "missionstring" ) && 0 == strcmp( factname, "data" ) ) {
673  ReadMissionStringData( buf, select_data, select_data_filter );
674  } else if ( a == 0 && 0 == strcmp( unitname, "python" ) && 0 == strcmp( factname, "data" ) ) {
675  last_written_pickled_data = last_pickled_data = UnpickleAllMissions( buf );
676  } else if ( a == 0 && 0 == strcmp( unitname, "news" ) && 0 == strcmp( factname, "data" ) ) {
677  if (commitfactions) ReadNewsData( buf, skip_news );
678  } else if ( a == 0 && 0 == strcmp( unitname, "stardate" ) && 0 == strcmp( factname, "data" ) ) {
679  //On server side we expect the latest saved stardate in dynaverse.dat too
680  if (commitfactions && !SERVER /*server never wants to take "orders" from shapeshifters...*/)
681  ReadStardate( buf );
682  else
683  AnyStringScanInString( buf );
684  } else {
685  char output[31] = {0};
686  strncpy( output, buf, 30 );
687  printf( "buf unrecognized %s...\n", output );
688  }
689  }
690 }
void SaveGame::ReloadPickledData ( )

Definition at line 101 of file load_mission.cpp.

References _Universe, active_missions, i, Universe::numPlayers(), PickledDataSansMissionName(), ReadIntSpace(), and UnpickleMission().

Referenced by Cockpit::Update().

102 {
103  std::string lpd = last_pickled_data;
104  if (_Universe->numPlayers() == 1) {
105  if ( !lpd.empty() ) {
106  unsigned int nummis = ReadIntSpace( lpd );
107  for (unsigned int i = 0; i < nummis; i++) {
108  int len = ReadIntSpace( lpd );
109  std::string pickled = lpd.substr( 0, len );
110  lpd = lpd.substr( len, lpd.length()-len );
111  if ( i < active_missions.size() )
112  active_missions[i]->UnPickle( PickledDataSansMissionName( pickled ) );
113  else
114  UnpickleMission( lpd );
115  }
116  }
117  }
118 }
void SaveGame::RemoveUnitFromSave ( long  address)

Definition at line 219 of file savegame.cpp.

220 {
221 }
void SaveGame::SetCallsign ( const std::string &  cs)
inline

Definition at line 57 of file savegame.h.

Referenced by Cockpit::recreate().

58  {
59  callsign = cs;
60  }
void SaveGame::SetOutputFileName ( const std::string &  filename)

Definition at line 866 of file savegame.cpp.

Referenced by bootstrap_main_loop().

867 {
868  if ( !filename.empty() )
869  outputsavegame = string( "Autosave-" )+filename;
870  else
871  outputsavegame = string( "Autosave" ); //empty name?
872 }
void SaveGame::SetPlayerFaction ( std::string  faction)
inline

Definition at line 94 of file savegame.h.

References StarSystemGent::faction.

95  {
96  playerfaction = faction;
97  }
void SaveGame::SetPlayerLocation ( const QVector playerloc)

Definition at line 203 of file savegame.cpp.

References FINITE, v, and VSFileSystem::vs_fprintf().

Referenced by bootstrap_main_loop(), createObjects(), Cockpit::Update(), and WriteSaveGame().

204 {
205  if ( ( FINITE( v.i ) && FINITE( v.j ) && FINITE( v.k ) ) ) {
206  PlayerLocation = v;
207  } else {
208  VSFileSystem::vs_fprintf( stderr, "NaN ERROR saving unit\n" );
209  assert( FINITE( v.i ) && FINITE( v.j ) && FINITE( v.k ) );
210  PlayerLocation.Set( 1, 1, 1 );
211  }
212 }
void SaveGame::SetSavedCredits ( float  c)

Definition at line 861 of file savegame.cpp.

References c, and savedcredits.

Referenced by WriteSaveGame().

862 {
863  savedcredits = c;
864 }
void SaveGame::SetStarSystem ( std::string  sys)

Definition at line 188 of file savegame.cpp.

Referenced by bootstrap_main_loop(), UniverseUtil::getSaveInfo(), NetClient::Respawn(), NetClient::startGame(), Cockpit::Update(), and WriteSaveGame().

189 {
190  ForceStarSystem = sys;
191 }
string SaveGame::WriteDynamicUniverse ( )

Definition at line 770 of file savegame.cpp.

References _Universe, AnyStringWriteString(), Universe::current_stardate, StarDate::GetFullTrekDate(), MAXBUFFER, PickleAllMissions(), FactionUtil::SerializeFaction(), SERVER, STATIC_VARS_DESTROYED, and tmprealloc().

771 {
772  string dyn_univ( "" );
773  int MB = MAXBUFFER;
774  char *tmp = (char*) malloc( MB );
775  memset( tmp, 0, MB );
776  //Write mission data
777  //we save the stardate
778  if (SERVER) {
779  cerr<<"SAVING STARDATE - SERVER="<<SERVER<<endl;
780  }
782  dyn_univ += "\n0 stardate data " + stardate;
783 
784  memset( tmp, 0, MB );
785  sprintf( tmp, "\n%d %s %s", 0, "mission", "data " );
786  dyn_univ += string( tmp );
787  dyn_univ += WriteMissionData();
788  memset( tmp, 0, MB );
789  sprintf( tmp, "\n%d %s %s", 0, "missionstring", "data " );
790  dyn_univ += string( tmp );
791  vector< char >missionstringdata1;
792  WriteMissionStringData( missionstringdata1 );
793  dyn_univ += string( &missionstringdata1[0], missionstringdata1.size() );
795  last_written_pickled_data = PickleAllMissions();
796  tmp = tmprealloc( tmp, MB, last_written_pickled_data.length()+256 /*4 floats*/ );
797  sprintf( tmp, "\n%d %s %s %s ", 0, "python", "data", last_written_pickled_data.c_str() );
798  dyn_univ += string( tmp );
799 
800  //Write news data
801  memset( tmp, 0, MB );
802  sprintf( tmp, "\n%d %s %s", 0, "news", "data " );
803  dyn_univ += string( tmp );
804  dyn_univ += WriteNewsData();
805  //Write faction relationships
806  memset( tmp, 0, MB );
807  sprintf( tmp, "\n%d %s %s", 0, "factions", "begin " );
808  dyn_univ += string( tmp );
809  dyn_univ += FactionUtil::SerializeFaction();
810 
811  free( tmp );
812  tmp = NULL;
813 
814  return dyn_univ;
815 }
string SaveGame::WritePlayerData ( const QVector FP,
std::vector< std::string >  unitname,
const char *  systemname,
float  credits,
std::string  fact = "" 
)

Definition at line 740 of file savegame.cpp.

References createPipedString(), MAXBUFFER, QVector, and tmprealloc().

745 {
746  string playerdata( "" );
747  int MB = MAXBUFFER;
748  char *tmp = (char*) malloc( MB );
749  memset( tmp, 0, MB );
750 
751  QVector FighterPos = PlayerLocation-FP;
752  FighterPos = FP;
753  string pipedunitname = createPipedString( unitname );
754  tmp = tmprealloc( tmp, MB, pipedunitname.length()+strlen( systemname )+256 /*4 floats*/ );
755  //If we specify no faction, it won't be saved in there
756  if (fact != "")
757  sprintf( tmp, "%s^%f^%s %f %f %f %s", systemname, credits,
758  pipedunitname.c_str(), FighterPos.i, FighterPos.j, FighterPos.k, fact.c_str() );
759  else
760  sprintf( tmp, "%s^%f^%s %f %f %f", systemname, credits, pipedunitname.c_str(), FighterPos.i, FighterPos.j, FighterPos.k );
761  playerdata = string( tmp );
762  this->playerfaction = fact;
763  SetSavedCredits( credits );
764  free( tmp );
765  tmp = NULL;
766 
767  return playerdata;
768 }
string SaveGame::WriteSavedUnit ( SavedUnits su)

Definition at line 723 of file savegame.cpp.

References SavedUnits::faction, SavedUnits::filename, XMLSupport::tostring(), and SavedUnits::type.

724 {
725  return string( "\n" )+XMLSupport::tostring( su->type )+string( " " )+su->filename+" "+su->faction;
726 }
string SaveGame::WriteSaveGame ( const char *  systemname,
const class QVector Pos,
float  credits,
std::vector< std::string >  unitname,
int  player_num,
std::string  fact = "",
bool  write = true 
)

Definition at line 819 of file savegame.cpp.

References VSFileSystem::VSFile::Close(), f, GetWritePlayerSaveGame(), VSFileSystem::Ok, VSFileSystem::VSFile::OpenCreateWrite(), VSFileSystem::SaveFile, SaveFileCopy(), and VSFileSystem::VSFile::Write().

Referenced by SaveNetUtil::GetSaveStrings(), GameUniverse::WriteSaveGame(), and WriteSaveGame().

826 {
827  savestring = string( "" );
828  printf( "Writing Save Game %s", outputsavegame.c_str() );
829  savestring += WritePlayerData( FP, unitname, systemname, credits, fact );
830  savestring += WriteDynamicUniverse();
831  if (outputsavegame.length() != 0) {
832  if (write) {
833  VSFile f;
834  VSError err = f.OpenCreateWrite( outputsavegame, SaveFile );
835  if (err <= Ok) {
836  //check
837  //WRITE THE SAVEGAME TO THE MISSION SAVENAME
838  f.Write( savestring.c_str(), savestring.length() );
839  f.Close();
840  if (player_num != -1) {
841  //AND THEN COPY IT TO THE SPECIFIED SAVENAME (from save.4.x.txt)
842  last_pickled_data = last_written_pickled_data;
843  string sg = GetWritePlayerSaveGame( player_num );
844  SaveFileCopy( outputsavegame.c_str(), sg.c_str() );
845  }
846  } else {
847  //error occured while opening file
848  cerr<<"occured while opening file: "<<outputsavegame<<endl;
849  }
850  }
851  }
852  return savestring;
853 }

The documentation for this class was generated from the following files: