OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 (char **ppOutput, size_t *ipSize)
 
void UpdateCustomRanks (C4DefList *pDefs)
 

Detailed Description

Definition at line 31 of file C4InfoCore.h.

Constructor & Destructor Documentation

C4ObjectInfoCore::C4ObjectInfoCore ( )

Definition at line 176 of file C4InfoCore.cpp.

References Default().

177 {
178  Default();
179 }
void Default(C4ID n_id=C4ID::None, class C4DefList *pDefs=nullptr, const char *cpNames=nullptr)
Definition: C4InfoCore.cpp:181

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 336 of file C4InfoCore.cpp.

References DeathMessage, and mkNamingAdapt().

Referenced by 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)

Definition at line 309 of file C4InfoCore.cpp.

References Age, Birthday, DeathCount, DeathMessage, C4ValueMapData::Denumerate(), C4ValueNumbers::Denumerate(), Experience, ExtraData, StdCompiler::isDeserializer(), mkNamingAdapt(), mkParAdapt(), Name, NextRankExp, C4ID::None, Participation, Rank, Rounds, sNextRankName, sRankName, toC4CStr, TotalPlayingTime, 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 
)
protected

Definition at line 347 of file C4InfoCore.cpp.

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

Referenced by 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 C4ObjectInfoCore::Default ( C4ID  n_id = C4ID::None,
class C4DefList pDefs = nullptr,
const char *  cpNames = nullptr 
)

Definition at line 181 of file C4InfoCore.cpp.

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

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:

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

Definition at line 262 of file C4InfoCore.cpp.

References StdStrBuf::Copy(), C4RankSystem::EXP_NoPromotion, C4RankSystem::Experience(), C4RankSystem::GetRankName(), NextRankExp, Rank, and 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 C4ObjectInfoCore::Load ( C4Group hGroup)

Definition at line 290 of file C4InfoCore.cpp.

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

Referenced by C4ObjectInfo::Load().

291 {
292  StdStrBuf Source;
293  return hGroup.LoadEntryString(C4CFN_ObjectInfoCore, &Source) &&
294  Compile(Source.getData());
295 }
const char * getData() const
Definition: StdBuf.h:442
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
bool Compile(const char *szSource)
Definition: C4InfoCore.cpp:336
#define C4CFN_ObjectInfoCore
Definition: C4Components.h:47

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 223 of file C4InfoCore.cpp.

References StdStrBuf::Copy(), C4RankSystem::GetRankName(), Rank, and 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:

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

Definition at line 297 of file C4InfoCore.cpp.

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

Referenced by C4ObjectInfo::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 C4ObjectInfoCore::UpdateCustomRanks ( C4DefList pDefs)
protected

Definition at line 231 of file C4InfoCore.cpp.

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

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

Definition at line 47 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Birthday
int32_t C4ObjectInfoCore::DeathCount

Definition at line 44 of file C4InfoCore.h.

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

char C4ObjectInfoCore::DeathMessage[C4MaxDeathMsg+1]

Definition at line 48 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Experience
C4ValueMapData C4ObjectInfoCore::ExtraData

Definition at line 49 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().

int32_t C4ObjectInfoCore::NextRankExp

Definition at line 42 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Participation

Definition at line 38 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Rounds

Definition at line 43 of file C4InfoCore.h.

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

StdStrBuf C4ObjectInfoCore::sNextRankName

Definition at line 41 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::TotalPlayingTime

Definition at line 46 of file C4InfoCore.h.

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

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: