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

#include <C4ObjectInfo.h>

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

Public Member Functions

 C4ObjectInfo ()
 
 ~C4ObjectInfo ()
 
void Default ()
 
void Clear ()
 
void Evaluate ()
 
void Retire ()
 
void Recruit ()
 
void SetBirthday ()
 
bool Save (C4Group &hGroup, bool fStoreTiny, C4DefList *pDefs)
 
bool Load (C4Group &hGroup)
 
bool Load (C4Group &hMother, const char *szEntryname)
 
bool Save (C4Group &hGroup, class C4DefList *pDefs)
 
void Default (C4ID n_id=C4ID::None, class C4DefList *pDefs=nullptr, const char *cpNames=nullptr)
 
void Promote (int32_t iRank, C4RankSystem &rRanks, bool fForceRankName)
 
bool GetNextRankInfo (C4RankSystem &rDefaultRanks, int32_t *piNextRankExp, StdStrBuf *psNextRankName)
 
void CompileFunc (StdCompiler *pComp)
 

Public Attributes

bool WasInAction
 
bool InAction
 
int32_t InActionTime
 
bool HasDied
 
int32_t ControlCount
 
class C4DefpDef
 
char Filename [_MAX_PATH+1]
 
C4ObjectInfoNext
 
C4ID id
 
char Name [C4MaxName+1]
 
int32_t Participation
 
int32_t Rank
 
StdStrBuf sRankName
 
StdStrBuf sNextRankName
 
int32_t NextRankExp
 
int32_t Experience
 
int32_t Rounds
 
int32_t DeathCount
 
char TypeName [C4MaxName+1+1]
 
int32_t Birthday
 
int32_t TotalPlayingTime
 
int32_t Age
 
char DeathMessage [C4MaxDeathMsg+1]
 
C4ValueMapData ExtraData
 

Protected Member Functions

bool Compile (const char *szSource)
 
bool Decompile (char **ppOutput, size_t *ipSize)
 
void UpdateCustomRanks (C4DefList *pDefs)
 

Detailed Description

Definition at line 28 of file C4ObjectInfo.h.

Constructor & Destructor Documentation

C4ObjectInfo::C4ObjectInfo ( )

Definition at line 37 of file C4ObjectInfo.cpp.

References Default().

38 {
39  Default();
40 }

Here is the call graph for this function:

C4ObjectInfo::~C4ObjectInfo ( )

Definition at line 42 of file C4ObjectInfo.cpp.

References Clear().

43 {
44  Clear();
45 }

Here is the call graph for this function:

Member Function Documentation

void C4ObjectInfo::Clear ( )

Definition at line 170 of file C4ObjectInfo.cpp.

References pDef.

Referenced by ~C4ObjectInfo().

171 {
172  pDef=nullptr;
173 }
class C4Def * pDef
Definition: C4ObjectInfo.h:39

Here is the caller graph for this function:

bool C4ObjectInfoCore::Compile ( const char *  szSource)
protectedinherited

Definition at line 336 of file C4InfoCore.cpp.

References C4ObjectInfoCore::DeathMessage, and mkNamingAdapt().

Referenced by C4ObjectInfoCore::Load().

337 {
338  bool ret = CompileFromBuf_LogWarn<StdCompilerINIRead>(
339  mkNamingAdapt(*this, "ObjectInfo"),
340  StdStrBuf(szSource),
341  "ObjectInfo");
342  // DeathMessages are not allowed to stay forever
343  if ('@' == DeathMessage[0]) DeathMessage[0] = ' ';
344  return ret;
345 }
char DeathMessage[C4MaxDeathMsg+1]
Definition: C4InfoCore.h:48
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfoCore::CompileFunc ( StdCompiler pComp)
inherited

Definition at line 309 of file C4InfoCore.cpp.

References C4ObjectInfoCore::Age, C4ObjectInfoCore::Birthday, C4ObjectInfoCore::DeathCount, C4ObjectInfoCore::DeathMessage, C4ValueMapData::Denumerate(), C4ValueNumbers::Denumerate(), C4ObjectInfoCore::Experience, C4ObjectInfoCore::ExtraData, StdCompiler::isDeserializer(), mkNamingAdapt(), mkParAdapt(), C4ObjectInfoCore::Name, C4ObjectInfoCore::NextRankExp, C4ID::None, C4ObjectInfoCore::Participation, C4ObjectInfoCore::Rank, C4ObjectInfoCore::Rounds, C4ObjectInfoCore::sNextRankName, C4ObjectInfoCore::sRankName, toC4CStr, C4ObjectInfoCore::TotalPlayingTime, C4ObjectInfoCore::TypeName, and StdCompiler::Value().

310 {
311  C4ValueNumbers numbers;
312  pComp->Value(mkNamingAdapt(id, "id", C4ID::None));
313  pComp->Value(mkNamingAdapt(toC4CStr(Name), "Name", "Clonk"));
314  pComp->Value(mkNamingAdapt(toC4CStr(DeathMessage), "DeathMessage", ""));
315  pComp->Value(mkNamingAdapt(Rank, "Rank", 0));
316  pComp->Value(mkNamingAdapt(sRankName, "RankName", "Clonk"));
317  pComp->Value(mkNamingAdapt(sNextRankName, "NextRankName", ""));
318  pComp->Value(mkNamingAdapt(toC4CStr(TypeName), "TypeName", "Clonk"));
319  pComp->Value(mkNamingAdapt(Participation, "Participation", 1));
320  pComp->Value(mkNamingAdapt(Experience, "Experience", 0));
321  pComp->Value(mkNamingAdapt(NextRankExp, "NextRankExp", 0));
322  pComp->Value(mkNamingAdapt(Rounds, "Rounds", 0));
323  pComp->Value(mkNamingAdapt(DeathCount, "DeathCount", 0));
324  pComp->Value(mkNamingAdapt(Birthday, "Birthday", 0));
325  pComp->Value(mkNamingAdapt(TotalPlayingTime, "TotalPlayingTime", 0));
326  pComp->Value(mkNamingAdapt(Age, "Age", 0));
327  pComp->Value(mkNamingAdapt(mkParAdapt(ExtraData, &numbers), "ExtraData", C4ValueMapData()));
328  pComp->Value(mkNamingAdapt(numbers, "ExtraDataValues"));
329  if (pComp->isDeserializer())
330  {
331  numbers.Denumerate();
332  ExtraData.Denumerate(&numbers);
333  }
334 }
void Denumerate()
Definition: C4Value.cpp:281
int32_t Rounds
Definition: C4InfoCore.h:43
void Denumerate(C4ValueNumbers *)
Definition: C4ValueMap.cpp:254
StdStrBuf sRankName
Definition: C4InfoCore.h:40
char DeathMessage[C4MaxDeathMsg+1]
Definition: C4InfoCore.h:48
#define toC4CStr(szString)
Definition: StdAdaptors.h:24
int32_t Participation
Definition: C4InfoCore.h:38
int32_t TotalPlayingTime
Definition: C4InfoCore.h:46
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
int32_t NextRankExp
Definition: C4InfoCore.h:42
static const C4ID None
Definition: C4Id.h:39
C4ValueMapData ExtraData
Definition: C4InfoCore.h:49
int32_t Birthday
Definition: C4InfoCore.h:46
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
void Value(const T &rStruct)
Definition: StdCompiler.h:161
StdStrBuf sNextRankName
Definition: C4InfoCore.h:41
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
int32_t Experience
Definition: C4InfoCore.h:43
int32_t DeathCount
Definition: C4InfoCore.h:44
char TypeName[C4MaxName+1+1]
Definition: C4InfoCore.h:45

Here is the call graph for this function:

bool C4ObjectInfoCore::Decompile ( char **  ppOutput,
size_t *  ipSize 
)
protectedinherited

Definition at line 347 of file C4InfoCore.cpp.

References StdStrBuf::getSize(), StdStrBuf::GrabPointer(), and mkNamingAdapt().

Referenced by C4ObjectInfoCore::Save().

348 {
349  StdStrBuf Buf;
350  if (!DecompileToBuf_Log<StdCompilerINIWrite>(
351  mkNamingAdapt(*this, "ObjectInfo"),
352  &Buf,
353  "ObjectInfo"))
354  {
355  if (ppOutput) *ppOutput = nullptr;
356  if (ipSize) *ipSize = 0;
357  return false;
358  }
359  if (ppOutput) *ppOutput = Buf.GrabPointer();
360  if (ipSize) *ipSize = Buf.getSize();
361  return true;
362 }
char * GrabPointer()
Definition: StdBuf.h:459
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
size_t getSize() const
Definition: StdBuf.h:444

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Default ( )

Definition at line 47 of file C4ObjectInfo.cpp.

References ControlCount, Filename, HasDied, InAction, InActionTime, Next, pDef, and WasInAction.

Referenced by C4ObjectInfo().

48 {
49  WasInAction=false;
50  InAction=false;
51  InActionTime=0;
52  HasDied=false;
53  ControlCount=0;
54  Filename[0]=0;
55  Next=nullptr;
56  pDef = nullptr;
57 }
int32_t ControlCount
Definition: C4ObjectInfo.h:38
char Filename[_MAX_PATH+1]
Definition: C4ObjectInfo.h:40
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
class C4Def * pDef
Definition: C4ObjectInfo.h:39
bool WasInAction
Definition: C4ObjectInfo.h:34
int32_t InActionTime
Definition: C4ObjectInfo.h:36

Here is the caller graph for this function:

void C4ObjectInfoCore::Default ( C4ID  n_id = C4ID::None,
class C4DefList pDefs = nullptr,
const char *  cpNames = nullptr 
)
inherited

Definition at line 181 of file C4InfoCore.cpp.

References C4ObjectInfoCore::Age, C4ObjectInfoCore::Birthday, C4MaxName, StdStrBuf::Clear(), StdStrBuf::Copy(), C4ObjectInfoCore::DeathCount, C4ObjectInfoCore::DeathMessage, C4ObjectInfoCore::Experience, C4ObjectInfoCore::ExtraData, C4PropListStatic::GetName(), C4DefList::ID2Def(), C4ObjectInfoCore::Name, C4ObjectInfoCore::NextRankExp, C4ObjectInfoCore::Participation, Random(), C4ObjectInfoCore::Rank, C4ValueMapData::Reset(), C4ObjectInfoCore::Rounds, SCharCount(), SClearFrontBack(), SCopy(), SCopySegment(), C4ObjectInfoCore::sNextRankName, C4ObjectInfoCore::sRankName, SReplaceChar(), C4ObjectInfoCore::TotalPlayingTime, C4ObjectInfoCore::TypeName, and C4ObjectInfoCore::UpdateCustomRanks().

Referenced by C4ObjectInfoCore::C4ObjectInfoCore().

184 {
185 
186  // Def
187  C4Def *pDef=nullptr;
188  if (pDefs) pDef = pDefs->ID2Def(n_id);
189 
190  // Defaults
191  id=n_id;
192  Participation=1;
193  Rank=0;
194  Experience=0;
195  Rounds=0;
196  DeathCount=0;
197  Birthday=0;
199  SCopy("Clonk",Name,C4MaxName);
200  SCopy("Clonk",TypeName,C4MaxName);
201  sRankName.Copy("Clonk");
203  NextRankExp=0;
204  DeathMessage[0]='\0';
205  Age=0;
206  ExtraData.Reset();
207 
208  // Type
209  if (pDef) SCopy(pDef->GetName(),TypeName,C4MaxName);
210 
211  // Name
212  if (cpNames)
213  {
214  SCopySegment(cpNames,Random(SCharCount(0x0A,cpNames)),Name,0x0A,C4MaxName+1);
216  SReplaceChar(Name,0x0D,0x00);
217  if (!Name[0]) SCopy("Clonk",Name,C4MaxName);
218  }
219 
220  if (pDefs) UpdateCustomRanks(pDefs);
221 }
int32_t Rounds
Definition: C4InfoCore.h:43
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
uint32_t Random()
Definition: C4Random.cpp:43
void Clear()
Definition: StdBuf.h:466
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:273
StdStrBuf sRankName
Definition: C4InfoCore.h:40
char DeathMessage[C4MaxDeathMsg+1]
Definition: C4InfoCore.h:48
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:320
int32_t Participation
Definition: C4InfoCore.h:38
const char * GetName() const override
Definition: C4PropList.cpp:267
int32_t TotalPlayingTime
Definition: C4InfoCore.h:46
int32_t NextRankExp
Definition: C4InfoCore.h:42
C4ValueMapData ExtraData
Definition: C4InfoCore.h:49
Definition: C4Def.h:98
int32_t Birthday
Definition: C4InfoCore.h:46
const unsigned int C4MaxName
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
void UpdateCustomRanks(C4DefList *pDefs)
Definition: C4InfoCore.cpp:231
StdStrBuf sNextRankName
Definition: C4InfoCore.h:41
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:455
int32_t Experience
Definition: C4InfoCore.h:43
int32_t DeathCount
Definition: C4InfoCore.h:44
void Copy()
Definition: StdBuf.h:467
char TypeName[C4MaxName+1+1]
Definition: C4InfoCore.h:45
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:348

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Evaluate ( )

Definition at line 164 of file C4ObjectInfo.cpp.

References Retire(), C4ObjectInfoCore::Rounds, and WasInAction.

Referenced by C4ObjectInfoList::Evaluate().

165 {
166  Retire();
167  if (WasInAction) Rounds++;
168 }
int32_t Rounds
Definition: C4InfoCore.h:43
bool WasInAction
Definition: C4ObjectInfo.h:34

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectInfoCore::GetNextRankInfo ( C4RankSystem rDefaultRanks,
int32_t *  piNextRankExp,
StdStrBuf psNextRankName 
)
inherited

Definition at line 262 of file C4InfoCore.cpp.

References StdStrBuf::Copy(), C4RankSystem::EXP_NoPromotion, C4RankSystem::Experience(), C4RankSystem::GetRankName(), C4ObjectInfoCore::NextRankExp, C4ObjectInfoCore::Rank, and C4ObjectInfoCore::sNextRankName.

263 {
264  int32_t iNextRankExp;
265  // custom rank assigned?
266  if (NextRankExp)
267  {
268  iNextRankExp = NextRankExp;
269  if (psNextRankName) psNextRankName->Copy(sNextRankName);
270  }
271  else
272  {
273  // no custom rank: Get from default set
274  StdStrBuf sRank(rDefaultRanks.GetRankName(Rank+1, false));
275  if (sRank)
276  {
277  iNextRankExp = rDefaultRanks.Experience(Rank+1);
278  if (psNextRankName) psNextRankName->Copy(sRank);
279  }
280  else
281  // no more promotion
282  iNextRankExp = C4RankSystem::EXP_NoPromotion;
283  }
284  // return result
285  if (piNextRankExp) *piNextRankExp = iNextRankExp;
286  // return value is whether additional promotion is possible
287  return iNextRankExp != C4RankSystem::EXP_NoPromotion;
288 }
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int32_t NextRankExp
Definition: C4InfoCore.h:42
StdStrBuf sNextRankName
Definition: C4InfoCore.h:41
void Copy()
Definition: StdBuf.h:467
int Experience(int iRank)

Here is the call graph for this function:

bool C4ObjectInfo::Load ( C4Group hGroup)

Definition at line 81 of file C4ObjectInfo.cpp.

References _MAX_FNAME, Filename, GetFilename(), C4Group::GetName(), C4ObjectInfoCore::Load(), and SCopy().

Referenced by C4ObjectInfoList::Load(), and Load().

82 {
83  // Store group file name
85  // Load core
86  if (!C4ObjectInfoCore::Load(hGroup)) return false;
87  return true;
88 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
char Filename[_MAX_PATH+1]
Definition: C4ObjectInfo.h:40
const char * GetName() const
Definition: C4Group.cpp:1845
#define _MAX_FNAME
bool Load(C4Group &hGroup)
Definition: C4InfoCore.cpp:290

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectInfo::Load ( C4Group hMother,
const char *  szEntryname 
)

Definition at line 59 of file C4ObjectInfo.cpp.

References C4Id2Def(), C4Group::Close(), GetExtension(), Load(), C4Group::OpenAsChild(), pDef, and SEqualNoCase().

60 {
61 
62  // New version
63  if (SEqualNoCase(GetExtension(szEntryname),"oci"))
64  {
65  C4Group hChild;
66  if (hChild.OpenAsChild(&hMother,szEntryname))
67  {
68  if (!C4ObjectInfo::Load(hChild))
69  { hChild.Close(); return false; }
70  // resolve definition, if possible
71  // only works in game, but is not needed in frontend or startup editing anyway
72  pDef = C4Id2Def(id);
73  hChild.Close();
74  return true;
75  }
76  }
77 
78  return false;
79 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
bool Close()
Definition: C4Group.cpp:755
class C4Def * pDef
Definition: C4ObjectInfo.h:39
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
bool Load(C4Group &hGroup)
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585

Here is the call graph for this function:

void C4ObjectInfoCore::Promote ( int32_t  iRank,
C4RankSystem rRanks,
bool  fForceRankName 
)
inherited

Definition at line 223 of file C4InfoCore.cpp.

References StdStrBuf::Copy(), C4RankSystem::GetRankName(), C4ObjectInfoCore::Rank, and C4ObjectInfoCore::sRankName.

Referenced by C4Object::Promote().

224 {
225  Rank=iRank;
226  // copy new rank name if defined only, or forced to use highest defined rank for too high info ranks
227  StdStrBuf sNewRank(rRanks.GetRankName(Rank,fForceRankName));
228  if (sNewRank) sRankName.Copy(sNewRank);
229 }
StdStrBuf sRankName
Definition: C4InfoCore.h:40
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Recruit ( )

Definition at line 175 of file C4ObjectInfo.cpp.

References StdStrBuf::Copy(), Definitions, Game, C4RankSystem::GetRankName(), C4DefList::ID2Def(), InAction, InActionTime, pDef, C4Def::pRankNames, C4ObjectInfoCore::Rank, C4ObjectInfoCore::sRankName, C4Game::Time, and WasInAction.

Referenced by C4ObjectInfoList::GetIdle(), and C4Object::GrabInfo().

176 {
177  // already recruited?
178  if (InAction) return;
179  WasInAction=true;
180  InAction=true;
182  // rank name overload by def?
184  if (pDef) if (pDef->pRankNames)
185  {
186  StdStrBuf sRank(pDef->pRankNames->GetRankName(Rank, true));
187  if (sRank) sRankName.Copy(sRank);
188  }
189 }
C4Def * ID2Def(C4ID id)
C4Game Game
Definition: C4Globals.cpp:52
StdStrBuf sRankName
Definition: C4InfoCore.h:40
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int32_t Time
Definition: C4Game.h:131
Definition: C4Def.h:98
class C4Def * pDef
Definition: C4ObjectInfo.h:39
bool WasInAction
Definition: C4ObjectInfo.h:34
C4DefList Definitions
Definition: C4Globals.cpp:49
C4RankSystem * pRankNames
Definition: C4Def.h:188
void Copy()
Definition: StdBuf.h:467
int32_t InActionTime
Definition: C4ObjectInfo.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Retire ( )

Definition at line 191 of file C4ObjectInfo.cpp.

References Game, InAction, InActionTime, C4Game::Time, and C4ObjectInfoCore::TotalPlayingTime.

Referenced by C4Object::AssignDeath(), C4Object::AssignRemoval(), Evaluate(), C4Object::GrabInfo(), and C4Player::SetObjectCrewStatus().

192 {
193  // not recruited?
194  if (!InAction) return;
195  // retire
196  InAction=false;
198 }
C4Game Game
Definition: C4Globals.cpp:52
int32_t TotalPlayingTime
Definition: C4InfoCore.h:46
int32_t Time
Definition: C4Game.h:131
int32_t InActionTime
Definition: C4ObjectInfo.h:36

Here is the caller graph for this function:

bool C4ObjectInfo::Save ( C4Group hGroup,
bool  fStoreTiny,
C4DefList pDefs 
)

Definition at line 90 of file C4ObjectInfo.cpp.

References _MAX_PATH, C4CFN_ClonkRank, C4Group::Close(), C4Group::Delete(), C4RankSystem::DrawRankSymbol(), EnforceExtension(), Filename, C4Group::FindEntry(), StdStrBuf::getData(), C4FacetSurface::GetFace(), C4Group::GetFullName(), GetTrailingNumber(), C4DefList::ID2Def(), Inside(), C4Def::iNumRankSymbols, LogF(), MakeFilenameFromTitle(), C4ObjectInfoCore::Name, C4Group::OpenAsChild(), pDef, C4Def::pRankSymbols, C4ObjectInfoCore::Rank, RemoveExtension(), C4Group::Rename(), SAppend(), C4ObjectInfoCore::Save(), C4Surface::SavePNG(), SCopy(), SEqualNoCase(), and SLen().

Referenced by C4ObjectInfoList::Save().

91 {
92  // Set group file name; rename if necessary
93  char szTempGroup[_MAX_PATH+1];
94  SCopy(Name, szTempGroup, _MAX_PATH);
95  MakeFilenameFromTitle(szTempGroup);
96  SAppend(".oci",szTempGroup, _MAX_PATH);
97  if (!SEqualNoCase(Filename, szTempGroup))
98  {
99  if (!Filename[0])
100  {
101  // first time creation of file - make sure it's not a duplicate
102  SCopy(szTempGroup, Filename, _MAX_PATH);
103  while (hGroup.FindEntry(Filename))
104  {
105  // if a crew info of that name exists already, rename!
107  int32_t iFinNum = GetTrailingNumber(Filename), iLen = SLen(Filename);
108  while (iLen && Inside(Filename[iLen-1], '0', '9')) --iLen;
109  if (iLen>_MAX_PATH-22) { LogF("Error generating unique filename for %s(%s): Path overflow", Name, hGroup.GetFullName().getData()); break; }
110  snprintf(Filename+iLen, 22, "%d", iFinNum+1);
111  EnforceExtension(Filename, "oci");
112  }
113  }
114  else
115  {
116  // Crew was renamed; file rename necessary, if the name is not blocked by another crew info
117  if (!hGroup.FindEntry(szTempGroup))
118  {
119  if (hGroup.Rename(Filename, szTempGroup))
120  SCopy(szTempGroup, Filename, _MAX_PATH);
121  else
122  {
123  // could not rename. Not fatal; just use old file
124  LogF("Error adjusting crew info for %s into %s: Rename error from %s to %s!", Name, hGroup.GetFullName().getData(), Filename, szTempGroup);
125  }
126  }
127  }
128  }
129  // Open group
130  C4Group hTemp;
131  if (!hTemp.OpenAsChild(&hGroup, Filename, false, true))
132  return false;
133  // custom rank image present?
134  if (pDefs && !fStoreTiny)
135  {
136  C4Def *pDef = pDefs->ID2Def(id);
137  if (pDef)
138  {
139  if (pDef->pRankSymbols)
140  {
141  C4FacetSurface fctRankSymbol;
142  if (C4RankSystem::DrawRankSymbol(&fctRankSymbol, Rank, pDef->pRankSymbols, pDef->iNumRankSymbols, true))
143  {
144  fctRankSymbol.GetFace().SavePNG(hTemp, C4CFN_ClonkRank);
145  }
146  }
147  else
148  {
149  // definition does not have custom rank symbols: Remove any rank image from Clonk
150  hTemp.Delete(C4CFN_ClonkRank);
151  }
152  }
153  }
154 
155  // Save info to temp group
156  if (!C4ObjectInfoCore::Save(hTemp, pDefs))
157  { hTemp.Close(); return false; }
158  // Close temp group
159  hTemp.Close();
160  // Success
161  return true;
162 }
const char * getData() const
Definition: StdBuf.h:442
C4Def * ID2Def(C4ID id)
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
int32_t iNumRankSymbols
Definition: C4Def.h:190
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
#define C4CFN_ClonkRank
Definition: C4Components.h:121
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
bool Save(C4Group &hGroup, class C4DefList *pDefs)
Definition: C4InfoCore.cpp:297
bool SavePNG(C4Group &hGroup, const char *szFilename, bool fSaveAlpha=true, bool fSaveOverlayOnly=false)
char Filename[_MAX_PATH+1]
Definition: C4ObjectInfo.h:40
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
bool Rename(const char *szFile, const char *szNewName)
Definition: C4Group.cpp:1424
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:74
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:402
int GetTrailingNumber(const char *strString)
Definition: StdFile.cpp:87
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
static bool DrawRankSymbol(C4FacetSurface *fctSymbol, int32_t iRank, C4Facet *pfctRankSymbols, int32_t iRankSymbolCount, bool fOwnSurface, int32_t iXOff=0, C4Facet *cgoDrawDirect=nullptr)
Definition: C4Def.h:98
bool Close()
Definition: C4Group.cpp:755
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
class C4Def * pDef
Definition: C4ObjectInfo.h:39
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:306
C4FacetSurface * pRankSymbols
Definition: C4Def.h:189
void EnforceExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:289
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
C4Surface & GetFace()
Definition: C4FacetEx.h:52
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectInfoCore::Save ( C4Group hGroup,
class C4DefList pDefs 
)
inherited

Definition at line 297 of file C4InfoCore.cpp.

References C4Group::Add(), C4CFN_ObjectInfoCore, C4ObjectInfoCore::Decompile(), and C4ObjectInfoCore::UpdateCustomRanks().

Referenced by Save().

298 {
299  // rank overload by def: Update any NextRank-stuff
300  if (pDefs) UpdateCustomRanks(pDefs);
301  char *Buffer; size_t BufferSize;
302  if (!Decompile(&Buffer,&BufferSize))
303  return false;
304  if (!hGroup.Add(C4CFN_ObjectInfoCore,Buffer,BufferSize,false,true) )
305  { delete [] Buffer; return false; }
306  return true;
307 }
bool Decompile(char **ppOutput, size_t *ipSize)
Definition: C4InfoCore.cpp:347
void UpdateCustomRanks(C4DefList *pDefs)
Definition: C4InfoCore.cpp:231
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
#define C4CFN_ObjectInfoCore
Definition: C4Components.h:47

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::SetBirthday ( )

Definition at line 200 of file C4ObjectInfo.cpp.

References C4ObjectInfoCore::Birthday.

201 {
202  Birthday=time(nullptr);
203 }
int32_t Birthday
Definition: C4InfoCore.h:46
void C4ObjectInfoCore::UpdateCustomRanks ( C4DefList pDefs)
protectedinherited

Definition at line 231 of file C4InfoCore.cpp.

References StdStrBuf::Clear(), StdStrBuf::Copy(), C4RankSystem::EXP_NoPromotion, C4RankSystem::Experience(), C4RankSystem::GetRankName(), C4DefList::ID2Def(), C4ObjectInfoCore::NextRankExp, C4Def::pRankNames, C4ObjectInfoCore::Rank, C4ObjectInfoCore::sNextRankName, and C4ObjectInfoCore::sRankName.

Referenced by C4ObjectInfoCore::Default(), and C4ObjectInfoCore::Save().

232 {
233  assert(pDefs);
234  C4Def *pDef = pDefs->ID2Def(id);
235  if (!pDef) return;
236  if (pDef->pRankNames)
237  {
238  StdStrBuf sRank(pDef->pRankNames->GetRankName(Rank,false));
239  if (sRank) sRankName.Copy(sRank);
240  // next rank data
241  StdStrBuf sNextRank(pDef->pRankNames->GetRankName(Rank+1,false));
242  if (sNextRank)
243  {
244  sNextRankName.Copy(sNextRank);
246  }
247  else
248  {
249  // no more promotion possible by custom rank system
252  }
253  }
254  else
255  {
256  // definition does not have custom rank names
258  NextRankExp = 0;
259  }
260 }
C4Def * ID2Def(C4ID id)
void Clear()
Definition: StdBuf.h:466
StdStrBuf sRankName
Definition: C4InfoCore.h:40
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int32_t NextRankExp
Definition: C4InfoCore.h:42
Definition: C4Def.h:98
StdStrBuf sNextRankName
Definition: C4InfoCore.h:41
C4RankSystem * pRankNames
Definition: C4Def.h:188
void Copy()
Definition: StdBuf.h:467
int Experience(int iRank)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int32_t C4ObjectInfoCore::Age
inherited
int32_t C4ObjectInfoCore::Birthday
inherited
int32_t C4ObjectInfo::ControlCount

Definition at line 38 of file C4ObjectInfo.h.

Referenced by C4Player::CountControl(), Default(), and C4Command::Finish().

int32_t C4ObjectInfoCore::DeathCount
inherited
char C4ObjectInfoCore::DeathMessage[C4MaxDeathMsg+1]
inherited
int32_t C4ObjectInfoCore::Experience
inherited
C4ValueMapData C4ObjectInfoCore::ExtraData
inherited

Definition at line 49 of file C4InfoCore.h.

Referenced by C4ObjectInfoCore::CompileFunc(), and C4ObjectInfoCore::Default().

char C4ObjectInfo::Filename[_MAX_PATH+1]

Definition at line 40 of file C4ObjectInfo.h.

Referenced by Default(), Load(), and Save().

bool C4ObjectInfo::HasDied

Definition at line 37 of file C4ObjectInfo.h.

Referenced by C4Object::AssignDeath(), Default(), and C4ObjectInfoList::GetIdle().

bool C4ObjectInfo::InAction

Definition at line 35 of file C4ObjectInfo.h.

Referenced by Default(), C4ObjectInfoList::GetIdle(), Recruit(), and Retire().

int32_t C4ObjectInfo::InActionTime

Definition at line 36 of file C4ObjectInfo.h.

Referenced by Default(), C4Object::ExecLife(), Recruit(), and Retire().

int32_t C4ObjectInfoCore::NextRankExp
inherited
int32_t C4ObjectInfoCore::Participation
inherited
class C4Def* C4ObjectInfo::pDef

Definition at line 39 of file C4ObjectInfo.h.

Referenced by Clear(), Default(), Load(), Recruit(), and Save().

int32_t C4ObjectInfoCore::Rounds
inherited

Definition at line 43 of file C4InfoCore.h.

Referenced by C4ObjectInfoCore::CompileFunc(), C4ObjectInfoCore::Default(), and Evaluate().

int32_t C4ObjectInfoCore::TotalPlayingTime
inherited
char C4ObjectInfoCore::TypeName[C4MaxName+1+1]
inherited

Definition at line 45 of file C4InfoCore.h.

Referenced by C4ObjectInfoCore::CompileFunc(), and C4ObjectInfoCore::Default().

bool C4ObjectInfo::WasInAction

Definition at line 34 of file C4ObjectInfo.h.

Referenced by Default(), Evaluate(), and Recruit().


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