OpenClonk
C4ObjectInfoCore Class Reference

#include <C4InfoCore.h>

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

Public Member Functions

 C4ObjectInfoCore ()
 
bool Save (C4Group &hGroup, class C4DefList *pDefs)
 
bool Load (C4Group &hGroup)
 
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

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 (StdStrBuf &Buf)
 
void UpdateCustomRanks (C4DefList *pDefs)
 

Detailed Description

Definition at line 31 of file C4InfoCore.h.

Constructor & Destructor Documentation

◆ C4ObjectInfoCore()

C4ObjectInfoCore::C4ObjectInfoCore ( )

Definition at line 196 of file C4InfoCore.cpp.

197 {
198  Default();
199 }
void Default(C4ID n_id=C4ID::None, class C4DefList *pDefs=nullptr, const char *cpNames=nullptr)
Definition: C4InfoCore.cpp:201

References Default().

Here is the call graph for this function:

Member Function Documentation

◆ Compile()

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

Definition at line 389 of file C4InfoCore.cpp.

390 {
391  bool ret = CompileFromBuf_LogWarn<StdCompilerINIRead>(
392  mkNamingAdapt(*this, "ObjectInfo"),
393  StdStrBuf(szSource),
394  "ObjectInfo");
395  // DeathMessages are not allowed to stay forever
396  if ('@' == DeathMessage[0])
397  {
398  DeathMessage[0] = ' ';
399  }
400  return ret;
401 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
char DeathMessage[C4MaxDeathMsg+1]
Definition: C4InfoCore.h:48

References DeathMessage, and mkNamingAdapt().

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4ObjectInfoCore::CompileFunc ( StdCompiler pComp)

Definition at line 362 of file C4InfoCore.cpp.

363 {
364  C4ValueNumbers numbers;
365  pComp->Value(mkNamingAdapt(id, "id", C4ID::None));
366  pComp->Value(mkNamingAdapt(toC4CStr(Name), "Name", "Clonk"));
367  pComp->Value(mkNamingAdapt(toC4CStr(DeathMessage), "DeathMessage", ""));
368  pComp->Value(mkNamingAdapt(Rank, "Rank", 0));
369  pComp->Value(mkNamingAdapt(sRankName, "RankName", "Clonk"));
370  pComp->Value(mkNamingAdapt(sNextRankName, "NextRankName", ""));
371  pComp->Value(mkNamingAdapt(toC4CStr(TypeName), "TypeName", "Clonk"));
372  pComp->Value(mkNamingAdapt(Participation, "Participation", 1));
373  pComp->Value(mkNamingAdapt(Experience, "Experience", 0));
374  pComp->Value(mkNamingAdapt(NextRankExp, "NextRankExp", 0));
375  pComp->Value(mkNamingAdapt(Rounds, "Rounds", 0));
376  pComp->Value(mkNamingAdapt(DeathCount, "DeathCount", 0));
377  pComp->Value(mkNamingAdapt(Birthday, "Birthday", 0));
378  pComp->Value(mkNamingAdapt(TotalPlayingTime, "TotalPlayingTime", 0));
379  pComp->Value(mkNamingAdapt(Age, "Age", 0));
380  pComp->Value(mkNamingAdapt(mkParAdapt(ExtraData, &numbers), "ExtraData", C4ValueMapData()));
381  pComp->Value(mkNamingAdapt(numbers, "ExtraDataValues"));
382  if (pComp->isDeserializer())
383  {
384  numbers.Denumerate();
385  ExtraData.Denumerate(&numbers);
386  }
387 }
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
#define toC4CStr(szString)
Definition: StdAdaptors.h:24
static const C4ID None
Definition: C4Id.h:39
int32_t DeathCount
Definition: C4InfoCore.h:44
int32_t TotalPlayingTime
Definition: C4InfoCore.h:46
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
int32_t NextRankExp
Definition: C4InfoCore.h:42
int32_t Birthday
Definition: C4InfoCore.h:46
StdStrBuf sNextRankName
Definition: C4InfoCore.h:41
int32_t Participation
Definition: C4InfoCore.h:38
int32_t Rounds
Definition: C4InfoCore.h:43
char TypeName[C4MaxName+1+1]
Definition: C4InfoCore.h:45
StdStrBuf sRankName
Definition: C4InfoCore.h:40
int32_t Experience
Definition: C4InfoCore.h:43
C4ValueMapData ExtraData
Definition: C4InfoCore.h:49
void Denumerate(C4ValueNumbers *)
Definition: C4ValueMap.cpp:254
void Denumerate()
Definition: C4Value.cpp:281
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

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

Here is the call graph for this function:

◆ Decompile()

bool C4ObjectInfoCore::Decompile ( StdStrBuf Buf)
protected

Definition at line 403 of file C4InfoCore.cpp.

404 {
405  if (!DecompileToBuf_Log<StdCompilerINIWrite>(
406  mkNamingAdapt(*this, "ObjectInfo"),
407  &Buf,
408  "ObjectInfo"))
409  {
410  return false;
411  }
412  return true;
413 }

References mkNamingAdapt().

Referenced by Save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Default()

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

Definition at line 201 of file C4InfoCore.cpp.

202 {
203  // Def
204  C4Def *pDef = nullptr;
205  if (pDefs)
206  {
207  pDef = pDefs->ID2Def(n_id);
208  }
209 
210  // Defaults
211  id = n_id;
212  Participation = 1;
213  Rank = 0;
214  Experience = 0;
215  Rounds = 0;
216  DeathCount = 0;
217  Birthday = 0;
218  TotalPlayingTime = 0;
219  SCopy("Clonk", Name, C4MaxName);
220  SCopy("Clonk", TypeName, C4MaxName);
221  sRankName.Copy("Clonk");
223  NextRankExp = 0;
224  DeathMessage[0] = '\0';
225  Age = 0;
226  ExtraData.Reset();
227 
228  // Type
229  if (pDef)
230  {
231  SCopy(pDef->GetName(), TypeName, C4MaxName);
232  }
233 
234  // Name
235  if (cpNames)
236  {
237  SCopySegment(cpNames, Random(SCharCount(0x0A, cpNames)), Name, 0x0A, C4MaxName + 1);
239  SReplaceChar(Name, 0x0D, 0x00);
240  if (!Name[0])
241  {
242  SCopy("Clonk", Name, C4MaxName);
243  }
244  }
245 
246  if (pDefs)
247  {
248  UpdateCustomRanks(pDefs);
249  }
250 }
const unsigned int C4MaxName
uint32_t Random()
Definition: C4Random.cpp:43
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:326
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:354
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:279
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:461
Definition: C4Def.h:99
void UpdateCustomRanks(C4DefList *pDefs)
Definition: C4InfoCore.cpp:263
const char * GetName() const override
Definition: C4PropList.cpp:243
void Copy()
Definition: StdBuf.h:467
void Clear()
Definition: StdBuf.h:466

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

Referenced by C4ObjectInfoCore().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNextRankInfo()

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

Definition at line 297 of file C4InfoCore.cpp.

298 {
299  int32_t iNextRankExp;
300  // Custom rank assigned?
301  if (NextRankExp)
302  {
303  iNextRankExp = NextRankExp;
304  if (psNextRankName)
305  {
306  psNextRankName->Copy(sNextRankName);
307  }
308  }
309  else
310  {
311  // No custom rank: Get from default set
312  StdStrBuf sRank(rDefaultRanks.GetRankName(Rank + 1, false));
313  if (sRank)
314  {
315  iNextRankExp = rDefaultRanks.Experience(Rank + 1);
316  if (psNextRankName)
317  {
318  psNextRankName->Copy(sRank);
319  }
320  }
321  else
322  {
323  // No more promotion
324  iNextRankExp = C4RankSystem::EXP_NoPromotion;
325  }
326  }
327  // Return result
328  if (piNextRankExp)
329  {
330  *piNextRankExp = iNextRankExp;
331  }
332  // Return value is whether additional promotion is possible
333  return iNextRankExp != C4RankSystem::EXP_NoPromotion;
334 }
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int Experience(int iRank)

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

Here is the call graph for this function:

◆ Load()

bool C4ObjectInfoCore::Load ( C4Group hGroup)

Definition at line 336 of file C4InfoCore.cpp.

337 {
338  StdStrBuf Source;
339  return hGroup.LoadEntryString(C4CFN_ObjectInfoCore, &Source) &&
340  Compile(Source.getData());
341 }
#define C4CFN_ObjectInfoCore
Definition: C4Components.h:47
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430
bool Compile(const char *szSource)
Definition: C4InfoCore.cpp:389
const char * getData() const
Definition: StdBuf.h:442

References C4CFN_ObjectInfoCore, Compile(), StdStrBuf::getData(), and C4Group::LoadEntryString().

Referenced by C4ObjectInfo::Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Promote()

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

Definition at line 252 of file C4InfoCore.cpp.

253 {
254  Rank = iRank;
255  // Copy new rank name if defined only, or forced to use highest defined rank for too high info ranks
256  StdStrBuf sNewRank(rRanks.GetRankName(Rank, fForceRankName));
257  if (sNewRank)
258  {
259  sRankName.Copy(sNewRank);
260  }
261 }

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

Referenced by C4Object::Promote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Save()

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

Definition at line 343 of file C4InfoCore.cpp.

344 {
345  // Rank overload by def: Update any NextRank-stuff
346  if (pDefs)
347  {
348  UpdateCustomRanks(pDefs);
349  }
350  StdStrBuf Buffer;
351  if (!Decompile(Buffer))
352  {
353  return false;
354  }
355  if (!hGroup.Add(C4CFN_ObjectInfoCore, Buffer, false, true))
356  {
357  return false;
358  }
359  return true;
360 }
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621
bool Decompile(StdStrBuf &Buf)
Definition: C4InfoCore.cpp:403

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

Referenced by C4ObjectInfo::Save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCustomRanks()

void C4ObjectInfoCore::UpdateCustomRanks ( C4DefList pDefs)
protected

Definition at line 263 of file C4InfoCore.cpp.

264 {
265  assert(pDefs);
266  C4Def *pDef = pDefs->ID2Def(id);
267  if (!pDef) return;
268  if (pDef->pRankNames)
269  {
270  StdStrBuf sRank(pDef->pRankNames->GetRankName(Rank, false));
271  if (sRank)
272  {
273  sRankName.Copy(sRank);
274  }
275  // Next rank data
276  StdStrBuf sNextRank(pDef->pRankNames->GetRankName(Rank + 1, false));
277  if (sNextRank)
278  {
279  sNextRankName.Copy(sNextRank);
280  NextRankExp = pDef->pRankNames->Experience(Rank + 1);
281  }
282  else
283  {
284  // No more promotion possible by custom rank system
287  }
288  }
289  else
290  {
291  // Definition does not have custom rank names
293  NextRankExp = 0;
294  }
295 }
C4RankSystem * pRankNames
Definition: C4Def.h:188
C4Def * ID2Def(C4ID id)

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

Referenced by Default(), and Save().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Age

int32_t C4ObjectInfoCore::Age

Definition at line 47 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4Object::ExecLife().

◆ Birthday

int32_t C4ObjectInfoCore::Birthday

◆ DeathCount

int32_t C4ObjectInfoCore::DeathCount

Definition at line 44 of file C4InfoCore.h.

Referenced by C4Object::AssignDeath(), CompileFunc(), and Default().

◆ DeathMessage

char C4ObjectInfoCore::DeathMessage[C4MaxDeathMsg+1]

Definition at line 48 of file C4InfoCore.h.

Referenced by Compile(), CompileFunc(), and Default().

◆ Experience

int32_t C4ObjectInfoCore::Experience

◆ ExtraData

C4ValueMapData C4ObjectInfoCore::ExtraData

Definition at line 49 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().

◆ id

◆ Name

◆ NextRankExp

int32_t C4ObjectInfoCore::NextRankExp

Definition at line 42 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), GetNextRankInfo(), and UpdateCustomRanks().

◆ Participation

int32_t C4ObjectInfoCore::Participation

Definition at line 38 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4ObjectInfoList::GetIdle().

◆ Rank

◆ Rounds

int32_t C4ObjectInfoCore::Rounds

Definition at line 43 of file C4InfoCore.h.

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

◆ sNextRankName

StdStrBuf C4ObjectInfoCore::sNextRankName

Definition at line 41 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), GetNextRankInfo(), and UpdateCustomRanks().

◆ sRankName

◆ TotalPlayingTime

int32_t C4ObjectInfoCore::TotalPlayingTime

Definition at line 46 of file C4InfoCore.h.

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

◆ TypeName

char C4ObjectInfoCore::TypeName[C4MaxName+1+1]

Definition at line 45 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().


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