OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameSaveSavegame Class Reference

#include <C4GameSave.h>

Inheritance diagram for C4GameSaveSavegame:
[legend]
Collaboration diagram for C4GameSaveSavegame:
[legend]

Public Member Functions

 C4GameSaveSavegame ()
 
bool Save (const char *szFilename)
 
bool Save (C4Group &hToGroup, bool fKeepGroup)
 
bool SaveDesc (C4Group &hToGroup)
 
bool Close ()
 
C4GroupGetGroup ()
 

Protected Types

enum  SyncState { SyncNONE = 0, SyncScenario = 1, SyncSavegame = 2, SyncSynchronized = 3 }
 

Protected Member Functions

bool GetSaveOrigin () override
 
bool GetSaveUserPlayerFiles () override
 
void AdjustCore (C4Scenario &rC4S) override
 
bool WriteDesc (StdStrBuf &sBuf) override
 
bool SaveComponents () override
 
bool OnSaving () override
 
virtual bool GetSaveRuntimeData ()
 
virtual bool GetKeepTitle ()
 
virtual bool GetSaveDesc ()
 
virtual bool GetCopyScenario ()
 
virtual const char * GetSortOrder ()
 
virtual bool GetCreateSmallFile ()
 
virtual bool GetForceExactLandscape ()
 
virtual bool GetClearOrigin ()
 
virtual bool GetSaveUserPlayers ()
 
virtual bool GetSaveScriptPlayers ()
 
virtual bool GetSaveScriptPlayerFiles ()
 
bool IsExact ()
 
bool IsSynced ()
 
void WriteDescLineFeed (StdStrBuf &sBuf)
 
void WriteDescDate (StdStrBuf &sBuf, bool fRecord=false)
 
void WriteDescGameTime (StdStrBuf &sBuf)
 
void WriteDescDefinitions (StdStrBuf &sBuf)
 
void WriteDescNetworkClients (StdStrBuf &sBuf)
 
void WriteDescPlayers (StdStrBuf &sBuf, bool fByTeam, int32_t idTeam)
 
void WriteDescPlayers (StdStrBuf &sBuf)
 
void WriteDescLeague (StdStrBuf &sBuf, bool fLeague, const char *strLeagueName)
 
void WriteDescEngine (StdStrBuf &sBuf)
 

Protected Attributes

C4GrouppSaveGroup
 
bool fOwnGroup
 
bool fInitial
 
enum C4GameSave::SyncState Sync
 

Detailed Description

Definition at line 128 of file C4GameSave.h.

Member Enumeration Documentation

enum C4GameSave::SyncState
protectedinherited
Enumerator
SyncNONE 
SyncScenario 
SyncSavegame 
SyncSynchronized 

Definition at line 48 of file C4GameSave.h.

49  {
50  SyncNONE = 0,
51  SyncScenario = 1, // save (eventually static) landscape and objects only to play as a separate scenario later
52  SyncSavegame = 2, // save all runtime data, so the scenario can be continued at a future date
53  SyncSynchronized = 3 // save exact runtime data to be network- or replay-save
54  } Sync; // sync is set by ctor
enum C4GameSave::SyncState Sync

Constructor & Destructor Documentation

C4GameSaveSavegame::C4GameSaveSavegame ( )
inline

Definition at line 131 of file C4GameSave.h.

131 : C4GameSave(false, SyncSavegame) {}
C4GameSave(bool fAInitial, SyncState ASync)
Definition: C4GameSave.h:82

Member Function Documentation

void C4GameSaveSavegame::AdjustCore ( C4Scenario rC4S)
overrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 486 of file C4GameSave.cpp.

References StdStrBuf::getData(), GetFilenameOnly(), C4Group::GetFullName(), GetTrailingNumber(), C4Scenario::Head, C4SHead::Icon, Inside(), and C4GameSave::pSaveGroup.

487 {
488  // Determine save game index from trailing number in group file name
489  int iSaveGameIndex = GetTrailingNumber(GetFilenameOnly(pSaveGroup->GetFullName().getData()));
490  // Looks like a decent index: set numbered icon
491  if (Inside(iSaveGameIndex, 1, 10))
492  rC4S.Head.Icon = 2 + (iSaveGameIndex - 1);
493  // Else: set normal script icon
494  else
495  rC4S.Head.Icon = 29;
496 }
const char * getData() const
Definition: StdBuf.h:442
int32_t Icon
Definition: C4Scenario.h:68
C4Group * pSaveGroup
Definition: C4GameSave.h:38
const char * GetFilenameOnly(const char *strFilename)
Definition: StdFile.cpp:60
int GetTrailingNumber(const char *strString)
Definition: StdFile.cpp:87
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
C4SHead Head
Definition: C4Scenario.h:230
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

Here is the call graph for this function:

bool C4GameSave::Close ( )
inherited

Definition at line 447 of file C4GameSave.cpp.

References C4Group::Close(), C4GameSave::fOwnGroup, C4GameSave::GetSortOrder(), C4GameSave::pSaveGroup, and C4Group::Sort().

Referenced by C4Network2::CreateDynamic(), C4GameSave::Save(), C4Record::Start(), C4Record::StartStreaming(), and C4GameSave::~C4GameSave().

448 {
449  bool fSuccess = true;
450  // any group open?
451  if (pSaveGroup)
452  {
453  // sort group
454  const char *szSortOrder = GetSortOrder();
455  if (szSortOrder) pSaveGroup->Sort(szSortOrder);
456  // close if owned group
457  if (fOwnGroup)
458  {
459  fSuccess = !!pSaveGroup->Close();
460  delete pSaveGroup;
461  fOwnGroup = false;
462  }
463  pSaveGroup = nullptr;
464  }
465  return fSuccess;
466 }
bool fOwnGroup
Definition: C4GameSave.h:39
C4Group * pSaveGroup
Definition: C4GameSave.h:38
virtual const char * GetSortOrder()
Definition: C4GameSave.h:61
bool Close()
Definition: C4Group.cpp:755
bool Sort(const char *szSortList)
Definition: C4Group.cpp:1963

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4GameSave::GetClearOrigin ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveScenario.

Definition at line 65 of file C4GameSave.h.

References C4GameSave::GetSaveOrigin().

65 { return !GetSaveOrigin(); } // return whether C4S.Head.Origin shall be cleared if it's set
virtual bool GetSaveOrigin()
Definition: C4GameSave.h:64

Here is the call graph for this function:

virtual bool C4GameSave::GetCopyScenario ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveNetwork, and C4GameSaveRecord.

Definition at line 60 of file C4GameSave.h.

60 { return true; } // return whether the savegame depends on the game scenario file
virtual bool C4GameSave::GetCreateSmallFile ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveNetwork, and C4GameSaveRecord.

Definition at line 62 of file C4GameSave.h.

62 { return false; } // return whether file size should be minimized
virtual bool C4GameSave::GetForceExactLandscape ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveScenario.

Definition at line 63 of file C4GameSave.h.

References C4GameSave::GetSaveRuntimeData(), and C4GameSave::IsExact().

Referenced by C4GameSaveScenario::GetForceExactLandscape().

63 { return GetSaveRuntimeData() && IsExact(); } // whether exact landscape shall be saved
bool IsExact()
Definition: C4GameSave.h:78
virtual bool GetSaveRuntimeData()
Definition: C4GameSave.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

C4Group* C4GameSave::GetGroup ( )
inlineinherited

Definition at line 109 of file C4GameSave.h.

References C4GameSave::pSaveGroup.

109 { return pSaveGroup; } // get scenario saving group; only open between calls to Save() and Close()
C4Group * pSaveGroup
Definition: C4GameSave.h:38
virtual bool C4GameSave::GetKeepTitle ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveNetwork.

Definition at line 58 of file C4GameSave.h.

References C4GameSave::IsExact().

Referenced by C4GameSave::Save().

58 { return !IsExact(); } // whether original, localized title with image and icon shall be deleted
bool IsExact()
Definition: C4GameSave.h:78

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4GameSave::GetSaveDesc ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveNetwork, C4GameSaveRecord, and C4GameSaveScenario.

Definition at line 59 of file C4GameSave.h.

Referenced by C4GameSave::Save().

59 { return true; } // should WriteDescData be executed in Save()-call?

Here is the caller graph for this function:

bool C4GameSaveSavegame::GetSaveOrigin ( )
inlineoverrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 135 of file C4GameSave.h.

135 { return true; } // origin must be saved in savegames
virtual bool C4GameSave::GetSaveRuntimeData ( )
inlineprotectedvirtualinherited

Definition at line 57 of file C4GameSave.h.

References C4GameSave::fInitial.

Referenced by C4GameSave::GetForceExactLandscape(), and C4GameSave::Save().

57 { return !fInitial; } // save exact landscape, players, etc.
bool fInitial
Definition: C4GameSave.h:45

Here is the caller graph for this function:

virtual bool C4GameSave::GetSaveScriptPlayerFiles ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveScenario.

Definition at line 69 of file C4GameSave.h.

References C4GameSave::IsExact().

69 { return IsExact(); } // return whether .ocp files of joined script players shall be put into the scenario
bool IsExact()
Definition: C4GameSave.h:78

Here is the call graph for this function:

virtual bool C4GameSave::GetSaveScriptPlayers ( )
inlineprotectedvirtualinherited

Reimplemented in C4GameSaveScenario.

Definition at line 67 of file C4GameSave.h.

References C4GameSave::IsExact().

67 { return IsExact(); } // return whether joined script players shall be saved into SavePlayerInfos
bool IsExact()
Definition: C4GameSave.h:78

Here is the call graph for this function:

bool C4GameSaveSavegame::GetSaveUserPlayerFiles ( )
inlineoverrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 136 of file C4GameSave.h.

136 { return false; } // user player files are not needed in savegames, because they will be replaced by player files of resuming playerss
virtual bool C4GameSave::GetSaveUserPlayers ( )
inlineprotectedvirtualinherited

Definition at line 66 of file C4GameSave.h.

References C4GameSave::IsExact().

66 { return IsExact(); } // return whether joined user players shall be saved into SavePlayerInfos
bool IsExact()
Definition: C4GameSave.h:78

Here is the call graph for this function:

virtual const char* C4GameSave::GetSortOrder ( )
inlineprotectedvirtualinherited

Definition at line 61 of file C4GameSave.h.

References C4FLS_Scenario.

Referenced by C4GameSave::Close().

61 { return C4FLS_Scenario; } // return nullptr to prevent sorting
#define C4FLS_Scenario
Definition: C4Components.h:188

Here is the caller graph for this function:

bool C4GameSave::IsExact ( )
inlineprotectedinherited

Definition at line 78 of file C4GameSave.h.

References C4GameSave::Sync, and C4GameSave::SyncSavegame.

Referenced by C4GameSave::GetForceExactLandscape(), C4GameSave::GetKeepTitle(), C4GameSave::GetSaveScriptPlayerFiles(), C4GameSave::GetSaveScriptPlayers(), C4GameSave::GetSaveUserPlayerFiles(), and C4GameSave::GetSaveUserPlayers().

78 { return Sync>=SyncSavegame; } // exact save (players, always exact landscape, etc.)
enum C4GameSave::SyncState Sync

Here is the caller graph for this function:

bool C4GameSave::IsSynced ( )
inlineprotectedinherited

Definition at line 79 of file C4GameSave.h.

References C4GameSave::Sync, and C4GameSave::SyncSynchronized.

79 { return Sync>=SyncSynchronized; } // synchronized
enum C4GameSave::SyncState Sync
bool C4GameSaveSavegame::OnSaving ( )
overrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 471 of file C4GameSave.cpp.

References C4Control::Add(), CID_Synchronize, Game, C4Game::Input, C4Network2::isEnabled(), C4Game::IsRunning, Network, Players, and C4PlayerList::SynchronizeLocalFiles().

472 {
473  if (!Game.IsRunning) return true;
474  // synchronization to sync player files on all clients
475  // this resets playing times and stores them in the players?
476  // but doing so would be too late when the queue is executed!
477  // TODO: remove it? (-> PeterW ;))
478  if (::Network.isEnabled())
480  else
482  // OK; save now
483  return true;
484 }
bool IsRunning
Definition: C4Game.h:139
bool SynchronizeLocalFiles()
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Network2 Network
Definition: C4Globals.cpp:53
C4PlayerList Players
bool isEnabled() const
Definition: C4Network2.h:203
C4Control & Input
Definition: C4Game.h:82

Here is the call graph for this function:

bool C4GameSave::Save ( const char *  szFilename)
inherited

Definition at line 398 of file C4GameSave.cpp.

References C4GameSave::Close(), LoadResStr(), and LogF().

Referenced by C4Network2::CreateDynamic(), C4Game::QuickSave(), C4Console::SaveGame(), and C4Console::SaveScenario().

399 {
400  // close any previous
401  Close();
402  // create group
403  C4Group *pLSaveGroup = new C4Group();
404  if (!SaveCreateGroup(szFilename, *pLSaveGroup))
405  {
406  LogF(LoadResStr("IDS_ERR_SAVE_TARGETGRP"), szFilename ? szFilename : "nullptr!");
407  delete pLSaveGroup;
408  return false;
409  }
410  // save to it
411  return Save(*pLSaveGroup, true);
412 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Close()
Definition: C4GameSave.cpp:447
bool Save(const char *szFilename)
Definition: C4GameSave.cpp:398
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameSave::Save ( C4Group hToGroup,
bool  fKeepGroup 
)
inherited

Definition at line 414 of file C4GameSave.cpp.

References C4CFN_Info, C4CFN_PlayerFiles, C4CFN_ScenarioDesc, C4CFN_ScenarioIcon, C4CFN_ScenarioTitle, C4CFN_Titles, C4GameSave::Close(), C4Group::Delete(), FormatString(), C4GameSave::fOwnGroup, C4GameSave::GetKeepTitle(), C4GameSave::GetSaveDesc(), C4GameSave::GetSaveRuntimeData(), LoadResStr(), Log(), C4GameSave::OnSaving(), C4GameSave::pSaveGroup, C4GameSave::SaveComponents(), and C4GameSave::SaveDesc().

415 {
416  // close any previous
417  Close();
418  // set group
419  pSaveGroup = &hToGroup; fOwnGroup = fKeepGroup;
420  // PreSave-actions (virtual call)
421  if (!OnSaving()) return false;
422  // always save core
423  if (!SaveCore()) { Log(LoadResStr("IDS_ERR_SAVE_CORE")); return false; }
424  // cleanup group
426  // remove: Title text, image and icon if specified
427  if (!GetKeepTitle())
428  {
434  }
435  // save additional runtime data
436  if (GetSaveRuntimeData()) if (!SaveRuntimeData()) return false;
437  // Desc
438  if (GetSaveDesc())
439  if (!SaveDesc(*pSaveGroup))
440  Log(LoadResStr("IDS_ERR_SAVE_DESC")); /* nofail */
441  // save specialized components (virtual call)
442  if (!SaveComponents()) return false;
443  // done, success
444  return true;
445 }
bool fOwnGroup
Definition: C4GameSave.h:39
C4Group * pSaveGroup
Definition: C4GameSave.h:38
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
#define C4CFN_Titles
Definition: C4Components.h:146
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
#define C4CFN_PlayerFiles
Definition: C4Components.h:167
#define C4CFN_Info
Definition: C4Components.h:70
bool SaveDesc(C4Group &hToGroup)
Definition: C4GameSave.cpp:235
bool Close()
Definition: C4GameSave.cpp:447
virtual bool GetSaveDesc()
Definition: C4GameSave.h:59
virtual bool GetKeepTitle()
Definition: C4GameSave.h:58
virtual bool GetSaveRuntimeData()
Definition: C4GameSave.h:57
virtual bool SaveComponents()
Definition: C4GameSave.h:74
#define C4CFN_ScenarioDesc
Definition: C4Components.h:88
virtual bool OnSaving()
Definition: C4GameSave.h:75
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
#define C4CFN_ScenarioIcon
Definition: C4Components.h:85
#define C4CFN_ScenarioTitle
Definition: C4Components.h:84
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

bool C4GameSaveSavegame::SaveComponents ( )
overrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 498 of file C4GameSave.cpp.

References Game, LoadResStr(), Log(), C4GameSave::pSaveGroup, and C4Game::SaveGameTitle().

499 {
500  // special for savegames: save a screenshot
501  if (!Game.SaveGameTitle((*pSaveGroup)))
502  Log(LoadResStr("IDS_ERR_SAVE_GAMETITLE")); /* nofail */
503  // done, success
504  return true;
505 }
C4Game Game
Definition: C4Globals.cpp:52
C4Group * pSaveGroup
Definition: C4GameSave.h:38
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool SaveGameTitle(C4Group &hGroup)
Definition: C4Game.cpp:1829
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

bool C4GameSave::SaveDesc ( C4Group hToGroup)
inherited

Definition at line 235 of file C4GameSave.cpp.

References C4Group::Add(), StdStrBuf::Append(), C4CFN_ScenarioDesc, Config, StdStrBuf::Format(), Game, C4Config::General, StdStrBuf::getData(), C4ConfigGeneral::Language, LineFeed, C4Game::ScenarioTitle, SCopyUntil(), and C4GameSave::WriteDesc().

Referenced by C4GameSave::Save(), and C4Record::Stop().

236 {
237  // Unfortunately, there's no way to prealloc the buffer in an appropriate size
238  StdStrBuf sBuffer;
239 
240  // Scenario title
241  sBuffer.Append(Game.ScenarioTitle.getData());
242  sBuffer.Append(LineFeed LineFeed);
243 
244  // OK; each specializations has its own desc format
245  WriteDesc(sBuffer);
246 
247  // Generate Filename
248  StdStrBuf sFilename; char szLang[3];
249  SCopyUntil(Config.General.Language, szLang, ',', 2);
250  sFilename.Format(C4CFN_ScenarioDesc,szLang);
251 
252  // Save to file
253  return !!hToGroup.Add(sFilename.getData(),sBuffer,false,true);
254 }
const char * getData() const
Definition: StdBuf.h:442
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
C4ConfigGeneral General
Definition: C4Config.h:251
StdCopyStrBuf ScenarioTitle
Definition: C4Game.h:103
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
char Language[CFG_MaxString+1]
Definition: C4Config.h:36
#define LineFeed
Definition: Standard.h:147
#define C4CFN_ScenarioDesc
Definition: C4Components.h:88
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
virtual bool WriteDesc(StdStrBuf &sBuf)
Definition: C4GameSave.h:73
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:146

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameSaveSavegame::WriteDesc ( StdStrBuf sBuf)
overrideprotectedvirtual

Reimplemented from C4GameSave.

Definition at line 507 of file C4GameSave.cpp.

References C4Network2::isEnabled(), Network, C4GameSave::WriteDescDate(), C4GameSave::WriteDescDefinitions(), C4GameSave::WriteDescGameTime(), C4GameSave::WriteDescNetworkClients(), and C4GameSave::WriteDescPlayers().

508 {
509  // compose savegame desc
510  WriteDescDate(sBuf);
511  WriteDescGameTime(sBuf);
512  WriteDescDefinitions(sBuf);
514  WriteDescPlayers(sBuf);
515  // done, success
516  return true;
517 }
void WriteDescNetworkClients(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:328
void WriteDescGameTime(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:277
C4Network2 Network
Definition: C4Globals.cpp:53
void WriteDescDate(StdStrBuf &sBuf, bool fRecord=false)
Definition: C4GameSave.cpp:262
void WriteDescDefinitions(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:304
bool isEnabled() const
Definition: C4Network2.h:203
void WriteDescPlayers(StdStrBuf &sBuf, bool fByTeam, int32_t idTeam)
Definition: C4GameSave.cpp:339

Here is the call graph for this function:

void C4GameSave::WriteDescDate ( StdStrBuf sBuf,
bool  fRecord = false 
)
protectedinherited

Definition at line 262 of file C4GameSave.cpp.

References StdStrBuf::AppendFormat(), C4Network2::isEnabled(), LoadResStr(), Network, and C4GameSave::WriteDescLineFeed().

Referenced by WriteDesc(), and C4GameSaveRecord::WriteDesc().

263 {
264  // write local time/date
265  time_t tTime; time(&tTime);
266  struct tm *pLocalTime;
267  pLocalTime=localtime(&tTime);
268  sBuf.AppendFormat(LoadResStr(fRecord ? "IDS_DESC_DATEREC" : (::Network.isEnabled() ? "IDS_DESC_DATENET" : "IDS_DESC_DATE")),
269  pLocalTime->tm_mday,
270  pLocalTime->tm_mon+1,
271  pLocalTime->tm_year+1900,
272  pLocalTime->tm_hour,
273  pLocalTime->tm_min);
274  WriteDescLineFeed(sBuf);
275 }
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
C4Network2 Network
Definition: C4Globals.cpp:53
bool isEnabled() const
Definition: C4Network2.h:203

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescDefinitions ( StdStrBuf sBuf)
protectedinherited

Definition at line 304 of file C4GameSave.cpp.

References _MAX_PATH, StdStrBuf::Append(), C4Config::AtRelativePath(), Config, StdStrBuf::Copy(), C4Game::DefinitionFilenames, Game, LoadResStr(), SGetModule(), and C4GameSave::WriteDescLineFeed().

Referenced by WriteDesc(), and C4GameSaveRecord::WriteDesc().

305 {
306  // Definition specs
307  if (Game.DefinitionFilenames[0])
308  {
309  char szDef[_MAX_PATH+1];
310  // Desc
311  sBuf.Append(LoadResStr("IDS_DESC_DEFSPECS"));
312  // Get definition modules
313  for (int cnt=0; SGetModule(Game.DefinitionFilenames,cnt,szDef); cnt++)
314  {
315  // Get exe relative path
316  StdStrBuf sDefFilename;
317  sDefFilename.Copy(Config.AtRelativePath(szDef));
318  // Append comma
319  if (cnt>0) sBuf.Append(", ");
320  // Apend to desc
321  sBuf.Append(sDefFilename);
322  }
323  // End of line
324  WriteDescLineFeed(sBuf);
325  }
326 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:511
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
#define _MAX_PATH
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
char DefinitionFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:105
const char * AtRelativePath(const char *szFilename)
Definition: C4Config.cpp:656
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescEngine ( StdStrBuf sBuf)
protectedinherited

Definition at line 288 of file C4GameSave.cpp.

References StdStrBuf::AppendFormat(), LoadResStr(), sprintf, and C4GameSave::WriteDescLineFeed().

Referenced by C4GameSaveRecord::WriteDesc().

289 {
290  char ver[32]; sprintf(ver, "%d.%d", (int)C4XVER1, (int)C4XVER2);
291  sBuf.AppendFormat(LoadResStr("IDS_DESC_VERSION"), ver);
292  WriteDescLineFeed(sBuf);
293 }
#define sprintf
Definition: Standard.h:164
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescGameTime ( StdStrBuf sBuf)
protectedinherited

Definition at line 277 of file C4GameSave.cpp.

References StdStrBuf::AppendFormat(), Game, LoadResStr(), C4Game::Time, and C4GameSave::WriteDescLineFeed().

Referenced by WriteDesc(), and C4GameSaveRecord::WriteDesc().

278 {
279  // Write game duration
280  if (Game.Time)
281  {
282  sBuf.AppendFormat(LoadResStr("IDS_DESC_DURATION"),
283  Game.Time/3600,(Game.Time%3600)/60,Game.Time%60);
284  WriteDescLineFeed(sBuf);
285  }
286 }
C4Game Game
Definition: C4Globals.cpp:52
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
int32_t Time
Definition: C4Game.h:131

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescLeague ( StdStrBuf sBuf,
bool  fLeague,
const char *  strLeagueName 
)
protectedinherited

Definition at line 295 of file C4GameSave.cpp.

References StdStrBuf::AppendFormat(), LoadResStr(), and C4GameSave::WriteDescLineFeed().

Referenced by C4GameSaveRecord::WriteDesc().

296 {
297  if (fLeague)
298  {
299  sBuf.AppendFormat(LoadResStr("IDS_PRC_LEAGUE"), strLeagueName);
300  WriteDescLineFeed(sBuf);
301  }
302 }
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescLineFeed ( StdStrBuf sBuf)
protectedinherited

Definition at line 256 of file C4GameSave.cpp.

References StdStrBuf::Append(), and LineFeed.

Referenced by C4GameSave::WriteDescDate(), C4GameSave::WriteDescDefinitions(), C4GameSave::WriteDescEngine(), C4GameSave::WriteDescGameTime(), C4GameSave::WriteDescLeague(), C4GameSave::WriteDescNetworkClients(), and C4GameSave::WriteDescPlayers().

257 {
258  // paragraph end + cosmetics
259  sBuf.Append(LineFeed LineFeed);
260 }
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
#define LineFeed
Definition: Standard.h:147

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescNetworkClients ( StdStrBuf sBuf)
protectedinherited

Definition at line 328 of file C4GameSave.cpp.

References StdStrBuf::Append(), C4Network2::Clients, C4Network2ClientList::GetNextClient(), LoadResStr(), Network, and C4GameSave::WriteDescLineFeed().

Referenced by WriteDesc(), and C4GameSaveRecord::WriteDesc().

329 {
330  // Desc
331  sBuf.Append(LoadResStr("IDS_DESC_CLIENTS"));
332  // Client names
333  for (C4Network2Client *pClient=::Network.Clients.GetNextClient(nullptr); pClient; pClient=::Network.Clients.GetNextClient(pClient))
334  { sBuf.Append(", "); sBuf.Append(pClient->getName()); }
335  // End of line
336  WriteDescLineFeed(sBuf);
337 }
C4Network2Client * GetNextClient(C4Network2Client *pClient)
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Network2 Network
Definition: C4Globals.cpp:53
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
C4Network2ClientList Clients
Definition: C4Network2.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescPlayers ( StdStrBuf sBuf,
bool  fByTeam,
int32_t  idTeam 
)
protectedinherited

Definition at line 339 of file C4GameSave.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendFormat(), Game, C4Team::GetName(), C4PlayerInfo::GetName(), C4PlayerInfoList::GetPlayerInfoByIndex(), C4PlayerInfo::GetTeam(), C4TeamList::GetTeamByID(), C4PlayerInfo::HasJoined(), C4PlayerInfo::IsInvisible(), C4PlayerInfo::IsRemoved(), C4Game::PlayerInfos, C4Game::Teams, and C4GameSave::WriteDescLineFeed().

Referenced by WriteDesc(), C4GameSaveRecord::WriteDesc(), and C4GameSave::WriteDescPlayers().

340 {
341  // write out all players; only if they match the given team if specified
342  C4PlayerInfo *pPlr; bool fAnyPlrWritten = false;
343  for (int i = 0; (pPlr = Game.PlayerInfos.GetPlayerInfoByIndex(i)); i++)
344  if (pPlr->HasJoined() && !pPlr->IsRemoved() && !pPlr->IsInvisible())
345  {
346  if (fByTeam)
347  {
348  if (idTeam)
349  {
350  // match team
351  if (pPlr->GetTeam() != idTeam) continue;
352  }
353  else
354  {
355  // must be in no known team
356  if (Game.Teams.GetTeamByID(pPlr->GetTeam())) continue;
357  }
358  }
359  if (fAnyPlrWritten)
360  sBuf.Append(", ");
361  else if (fByTeam && idTeam)
362  {
363  C4Team *pTeam = Game.Teams.GetTeamByID(idTeam);
364  if (pTeam) sBuf.AppendFormat("%s: ", pTeam->GetName());
365  }
366  sBuf.Append(pPlr->GetName());
367  fAnyPlrWritten = true;
368  }
369  if (fAnyPlrWritten) WriteDescLineFeed(sBuf);
370 }
const char * GetName() const
Definition: C4PlayerInfo.h:157
C4Game Game
Definition: C4Globals.cpp:52
Definition: C4Teams.h:30
C4PlayerInfo * GetPlayerInfoByIndex(int32_t index) const
bool IsInvisible() const
Definition: C4PlayerInfo.h:175
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
C4TeamList & Teams
Definition: C4Game.h:70
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
int32_t GetTeam() const
Definition: C4PlayerInfo.h:195
bool IsRemoved() const
Definition: C4PlayerInfo.h:164
const char * GetName() const
Definition: C4Teams.h:65
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool HasJoined() const
Definition: C4PlayerInfo.h:165

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameSave::WriteDescPlayers ( StdStrBuf sBuf)
protectedinherited

Definition at line 372 of file C4GameSave.cpp.

References StdStrBuf::Append(), Game, C4Team::GetID(), C4PlayerInfoList::GetPlayerCount(), C4TeamList::GetTeamByIndex(), C4TeamList::IsAutoGenerateTeams(), C4TeamList::IsMultiTeams(), LoadResStr(), C4Game::PlayerInfos, C4Game::Teams, C4GameSave::WriteDescLineFeed(), and C4GameSave::WriteDescPlayers().

373 {
374  // New style using Game.PlayerInfos
376  {
377  sBuf.Append(LoadResStr("IDS_DESC_PLRS"));
379  {
380  // Teams defined: Print players sorted by teams
381  WriteDescLineFeed(sBuf);
382  C4Team *pTeam; int32_t i=0;
383  while ((pTeam = Game.Teams.GetTeamByIndex(i++)))
384  {
385  WriteDescPlayers(sBuf, true, pTeam->GetID());
386  }
387  // Finally, print out players outside known teams (those can only be achieved by script using SetPlayerTeam)
388  WriteDescPlayers(sBuf, true, 0);
389  }
390  else
391  {
392  // No teams defined: Print all players that have ever joined
393  WriteDescPlayers(sBuf, false, 0);
394  }
395  }
396 }
int32_t GetID() const
Definition: C4Teams.h:66
int32_t GetPlayerCount() const
C4Game Game
Definition: C4Globals.cpp:52
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
bool IsMultiTeams() const
Definition: C4Teams.h:162
void WriteDescLineFeed(StdStrBuf &sBuf)
Definition: C4GameSave.cpp:256
C4TeamList & Teams
Definition: C4Game.h:70
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
void WriteDescPlayers(StdStrBuf &sBuf, bool fByTeam, int32_t idTeam)
Definition: C4GameSave.cpp:339

Here is the call graph for this function:

Member Data Documentation

bool C4GameSave::fInitial
protectedinherited
bool C4GameSave::fOwnGroup
protectedinherited

Definition at line 39 of file C4GameSave.h.

Referenced by C4GameSave::Close(), and C4GameSave::Save().

C4Group* C4GameSave::pSaveGroup
protectedinherited
enum C4GameSave::SyncState C4GameSave::Sync
protectedinherited

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