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 40 of file C4ObjectInfo.cpp.

References Default().

41 {
42  Default();
43 }

Here is the call graph for this function:

C4ObjectInfo::~C4ObjectInfo ( )

Definition at line 45 of file C4ObjectInfo.cpp.

References Clear().

46 {
47  Clear();
48 }

Here is the call graph for this function:

Member Function Documentation

void C4ObjectInfo::Clear ( )

Definition at line 173 of file C4ObjectInfo.cpp.

References pDef.

Referenced by ~C4ObjectInfo().

174 {
175  pDef=nullptr;
176 }
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 339 of file C4InfoCore.cpp.

References C4ObjectInfoCore::DeathMessage, and mkNamingAdapt().

Referenced by C4ObjectInfoCore::Load().

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

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 312 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().

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

Here is the call graph for this function:

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

Definition at line 350 of file C4InfoCore.cpp.

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

Referenced by C4ObjectInfoCore::Save().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Default ( )

Definition at line 50 of file C4ObjectInfo.cpp.

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

Referenced by C4ObjectInfo().

51 {
52  WasInAction=false;
53  InAction=false;
54  InActionTime=0;
55  HasDied=false;
56  ControlCount=0;
57  Filename[0]=0;
58  Next=nullptr;
59  pDef = nullptr;
60 }
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 184 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().

187 {
188 
189  // Def
190  C4Def *pDef=nullptr;
191  if (pDefs) pDef = pDefs->ID2Def(n_id);
192 
193  // Defaults
194  id=n_id;
195  Participation=1;
196  Rank=0;
197  Experience=0;
198  Rounds=0;
199  DeathCount=0;
200  Birthday=0;
202  SCopy("Clonk",Name,C4MaxName);
203  SCopy("Clonk",TypeName,C4MaxName);
204  sRankName.Copy("Clonk");
206  NextRankExp=0;
207  DeathMessage[0]='\0';
208  Age=0;
209  ExtraData.Reset();
210 
211  // Type
212  if (pDef) SCopy(pDef->GetName(),TypeName,C4MaxName);
213 
214  // Name
215  if (cpNames)
216  {
217  SCopySegment(cpNames,Random(SCharCount(0x0A,cpNames)),Name,0x0A,C4MaxName+1);
219  SReplaceChar(Name,0x0D,0x00);
220  if (!Name[0]) SCopy("Clonk",Name,C4MaxName);
221  }
222 
223  if (pDefs) UpdateCustomRanks(pDefs);
224 }
int32_t Rounds
Definition: C4InfoCore.h:44
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
virtual const char * GetName() const
Definition: C4PropList.cpp:267
uint32_t Random()
Definition: C4Random.cpp:43
void Clear()
Definition: StdBuf.h:474
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:250
StdStrBuf sRankName
Definition: C4InfoCore.h:41
char DeathMessage[C4MaxDeathMsg+1]
Definition: C4InfoCore.h:49
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:297
int32_t Participation
Definition: C4InfoCore.h:39
int32_t TotalPlayingTime
Definition: C4InfoCore.h:47
int32_t NextRankExp
Definition: C4InfoCore.h:43
C4ValueMapData ExtraData
Definition: C4InfoCore.h:50
Definition: C4Def.h:100
int32_t Birthday
Definition: C4InfoCore.h:47
const unsigned int C4MaxName
char Name[C4MaxName+1]
Definition: C4InfoCore.h:38
void UpdateCustomRanks(C4DefList *pDefs)
Definition: C4InfoCore.cpp:234
StdStrBuf sNextRankName
Definition: C4InfoCore.h:42
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:432
int32_t Experience
Definition: C4InfoCore.h:44
int32_t DeathCount
Definition: C4InfoCore.h:45
void Copy()
Definition: StdBuf.h:475
char TypeName[C4MaxName+1+1]
Definition: C4InfoCore.h:46
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:325

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Evaluate ( )

Definition at line 167 of file C4ObjectInfo.cpp.

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

Referenced by C4ObjectInfoList::Evaluate().

168 {
169  Retire();
170  if (WasInAction) Rounds++;
171 }
int32_t Rounds
Definition: C4InfoCore.h:44
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 265 of file C4InfoCore.cpp.

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

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

Here is the call graph for this function:

bool C4ObjectInfo::Load ( C4Group hGroup)

Definition at line 84 of file C4ObjectInfo.cpp.

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

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

85 {
86  // Store group file name
88  // Load core
89  if (!C4ObjectInfoCore::Load(hGroup)) return false;
90  return true;
91 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
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:293

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 62 of file C4ObjectInfo.cpp.

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

63 {
64 
65  // New version
66  if (SEqualNoCase(GetExtension(szEntryname),"oci"))
67  {
68  C4Group hChild;
69  if (hChild.OpenAsChild(&hMother,szEntryname))
70  {
71  if (!C4ObjectInfo::Load(hChild))
72  { hChild.Close(); return false; }
73  // resolve definition, if possible
74  // only works in game, but is not needed in frontend or startup editing anyway
75  pDef = C4Id2Def(id);
76  hChild.Close();
77  return true;
78  }
79  }
80 
81  return false;
82 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
bool Close()
Definition: C4Group.cpp:755
class C4Def * pDef
Definition: C4ObjectInfo.h:39
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:80
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 226 of file C4InfoCore.cpp.

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

Referenced by C4Object::Promote().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfo::Recruit ( )

Definition at line 178 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().

179 {
180  // already recruited?
181  if (InAction) return;
182  WasInAction=true;
183  InAction=true;
185  // rank name overload by def?
187  if (pDef) if (pDef->pRankNames)
188  {
189  StdStrBuf sRank(pDef->pRankNames->GetRankName(Rank, true));
190  if (sRank) sRankName.Copy(sRank);
191  }
192 }
C4Def * ID2Def(C4ID id)
C4Game Game
Definition: C4Globals.cpp:52
StdStrBuf sRankName
Definition: C4InfoCore.h:41
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int32_t Time
Definition: C4Game.h:133
Definition: C4Def.h:100
class C4Def * pDef
Definition: C4ObjectInfo.h:39
bool WasInAction
Definition: C4ObjectInfo.h:34
C4DefList Definitions
Definition: C4Globals.cpp:49
C4RankSystem * pRankNames
Definition: C4Def.h:191
void Copy()
Definition: StdBuf.h:475
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 194 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().

195 {
196  // not recruited?
197  if (!InAction) return;
198  // retire
199  InAction=false;
201 }
C4Game Game
Definition: C4Globals.cpp:52
int32_t TotalPlayingTime
Definition: C4InfoCore.h:47
int32_t Time
Definition: C4Game.h:133
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 93 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().

94 {
95  // Set group file name; rename if necessary
96  char szTempGroup[_MAX_PATH+1];
97  SCopy(Name, szTempGroup, _MAX_PATH);
98  MakeFilenameFromTitle(szTempGroup);
99  SAppend(".oci",szTempGroup, _MAX_PATH);
100  if (!SEqualNoCase(Filename, szTempGroup))
101  {
102  if (!Filename[0])
103  {
104  // first time creation of file - make sure it's not a duplicate
105  SCopy(szTempGroup, Filename, _MAX_PATH);
106  while (hGroup.FindEntry(Filename))
107  {
108  // if a crew info of that name exists already, rename!
110  int32_t iFinNum = GetTrailingNumber(Filename), iLen = SLen(Filename);
111  while (iLen && Inside(Filename[iLen-1], '0', '9')) --iLen;
112  if (iLen>_MAX_PATH-22) { LogF("Error generating unique filename for %s(%s): Path overflow", Name, hGroup.GetFullName().getData()); break; }
113  snprintf(Filename+iLen, 22, "%d", iFinNum+1);
114  EnforceExtension(Filename, "oci");
115  }
116  }
117  else
118  {
119  // Crew was renamed; file rename necessary, if the name is not blocked by another crew info
120  if (!hGroup.FindEntry(szTempGroup))
121  {
122  if (hGroup.Rename(Filename, szTempGroup))
123  SCopy(szTempGroup, Filename, _MAX_PATH);
124  else
125  {
126  // could not rename. Not fatal; just use old file
127  LogF("Error adjusting crew info for %s into %s: Rename error from %s to %s!", Name, hGroup.GetFullName().getData(), Filename, szTempGroup);
128  }
129  }
130  }
131  }
132  // Open group
133  C4Group hTemp;
134  if (!hTemp.OpenAsChild(&hGroup, Filename, false, true))
135  return false;
136  // custom rank image present?
137  if (pDefs && !fStoreTiny)
138  {
139  C4Def *pDef = pDefs->ID2Def(id);
140  if (pDef)
141  {
142  if (pDef->pRankSymbols)
143  {
144  C4FacetSurface fctRankSymbol;
145  if (C4RankSystem::DrawRankSymbol(&fctRankSymbol, Rank, pDef->pRankSymbols, pDef->iNumRankSymbols, true))
146  {
147  fctRankSymbol.GetFace().SavePNG(hTemp, C4CFN_ClonkRank);
148  }
149  }
150  else
151  {
152  // definition does not have custom rank symbols: Remove any rank image from Clonk
153  hTemp.Delete(C4CFN_ClonkRank);
154  }
155  }
156  }
157 
158  // Save info to temp group
159  if (!C4ObjectInfoCore::Save(hTemp, pDefs))
160  { hTemp.Close(); return false; }
161  // Close temp group
162  hTemp.Close();
163  // Success
164  return true;
165 }
const char * getData() const
Definition: StdBuf.h:450
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:193
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
#define C4CFN_ClonkRank
Definition: C4Components.h:121
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:234
bool Save(C4Group &hGroup, class C4DefList *pDefs)
Definition: C4InfoCore.cpp:300
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:184
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:78
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:412
int GetTrailingNumber(const char *strString)
Definition: StdFile.cpp:97
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:100
bool Close()
Definition: C4Group.cpp:755
char Name[C4MaxName+1]
Definition: C4InfoCore.h:38
class C4Def * pDef
Definition: C4ObjectInfo.h:39
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
C4FacetSurface * pRankSymbols
Definition: C4Def.h:192
void EnforceExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:299
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:45
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 300 of file C4InfoCore.cpp.

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

Referenced by Save().

301 {
302  // rank overload by def: Update any NextRank-stuff
303  if (pDefs) UpdateCustomRanks(pDefs);
304  char *Buffer; size_t BufferSize;
305  if (!Decompile(&Buffer,&BufferSize))
306  return false;
307  if (!hGroup.Add(C4CFN_ObjectInfoCore,Buffer,BufferSize,false,true) )
308  { delete [] Buffer; return false; }
309  return true;
310 }
bool Decompile(char **ppOutput, size_t *ipSize)
Definition: C4InfoCore.cpp:350
void UpdateCustomRanks(C4DefList *pDefs)
Definition: C4InfoCore.cpp:234
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 203 of file C4ObjectInfo.cpp.

References C4ObjectInfoCore::Birthday.

204 {
205  Birthday=time(nullptr);
206 }
int32_t Birthday
Definition: C4InfoCore.h:47
void C4ObjectInfoCore::UpdateCustomRanks ( C4DefList pDefs)
protectedinherited

Definition at line 234 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().

235 {
236  assert(pDefs);
237  C4Def *pDef = pDefs->ID2Def(id);
238  if (!pDef) return;
239  if (pDef->pRankNames)
240  {
241  StdStrBuf sRank(pDef->pRankNames->GetRankName(Rank,false));
242  if (sRank) sRankName.Copy(sRank);
243  // next rank data
244  StdStrBuf sNextRank(pDef->pRankNames->GetRankName(Rank+1,false));
245  if (sNextRank)
246  {
247  sNextRankName.Copy(sNextRank);
249  }
250  else
251  {
252  // no more promotion possible by custom rank system
255  }
256  }
257  else
258  {
259  // definition does not have custom rank names
261  NextRankExp = 0;
262  }
263 }
C4Def * ID2Def(C4ID id)
void Clear()
Definition: StdBuf.h:474
StdStrBuf sRankName
Definition: C4InfoCore.h:41
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int32_t NextRankExp
Definition: C4InfoCore.h:43
Definition: C4Def.h:100
StdStrBuf sNextRankName
Definition: C4InfoCore.h:42
C4RankSystem * pRankNames
Definition: C4Def.h:191
void Copy()
Definition: StdBuf.h:475
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 50 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 44 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 46 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: