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 32 of file C4InfoCore.h.

Constructor & Destructor Documentation

C4ObjectInfoCore::C4ObjectInfoCore ( )

Definition at line 179 of file C4InfoCore.cpp.

References Default().

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

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 339 of file C4InfoCore.cpp.

References DeathMessage, and mkNamingAdapt().

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

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

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 
)
protected

Definition at line 350 of file C4InfoCore.cpp.

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

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

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

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:

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

Definition at line 265 of file C4InfoCore.cpp.

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

Definition at line 293 of file C4InfoCore.cpp.

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

Referenced by C4ObjectInfo::Load().

294 {
295  StdStrBuf Source;
296  return hGroup.LoadEntryString(C4CFN_ObjectInfoCore, &Source) &&
297  Compile(Source.getData());
298 }
const char * getData() const
Definition: StdBuf.h:450
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
bool Compile(const char *szSource)
Definition: C4InfoCore.cpp:339
#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 226 of file C4InfoCore.cpp.

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

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

Definition at line 300 of file C4InfoCore.cpp.

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

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

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

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

Definition at line 48 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Birthday
int32_t C4ObjectInfoCore::DeathCount

Definition at line 45 of file C4InfoCore.h.

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

char C4ObjectInfoCore::DeathMessage[C4MaxDeathMsg+1]

Definition at line 49 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Experience
C4ValueMapData C4ObjectInfoCore::ExtraData

Definition at line 50 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().

int32_t C4ObjectInfoCore::NextRankExp

Definition at line 43 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Participation

Definition at line 39 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::Rounds

Definition at line 44 of file C4InfoCore.h.

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

StdStrBuf C4ObjectInfoCore::sNextRankName

Definition at line 42 of file C4InfoCore.h.

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

int32_t C4ObjectInfoCore::TotalPlayingTime

Definition at line 47 of file C4InfoCore.h.

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

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

Definition at line 46 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().


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