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

#include <C4ObjectInfoList.h>

Collaboration diagram for C4ObjectInfoList:
[legend]

Public Member Functions

 C4ObjectInfoList ()
 
 ~C4ObjectInfoList ()
 
void Default ()
 
void Clear ()
 
void Evaluate ()
 
void DetachFromObjects ()
 
int32_t Load (C4Group &hGroup)
 
bool Add (C4ObjectInfo *pInfo)
 
bool Save (C4Group &hGroup, bool fSavegame, bool fStoreTiny, C4DefList *pDefs)
 
C4ObjectInfoNew (C4ID n_id, C4DefList *pDefs)
 
C4ObjectInfoGetIdle (C4ID c_id, C4DefList &rDefs)
 
C4ObjectInfoGetIdle (const char *szByName)
 
C4ObjectInfoGetFirst ()
 
bool IsElement (C4ObjectInfo *pInfo)
 
void Strip (C4DefList &rDefs)
 
void MakeValidName (char *sName)
 
bool NameExists (const char *szName)
 

Public Attributes

int32_t iNumCreated
 

Protected Member Functions

C4ObjectInfoGetLast ()
 
C4ObjectInfoGetPrevious (C4ObjectInfo *pInfo)
 

Protected Attributes

C4ObjectInfoFirst
 

Detailed Description

Definition at line 25 of file C4ObjectInfoList.h.

Constructor & Destructor Documentation

C4ObjectInfoList::C4ObjectInfoList ( )

Definition at line 32 of file C4ObjectInfoList.cpp.

References Default().

33 {
34  Default();
35 }

Here is the call graph for this function:

C4ObjectInfoList::~C4ObjectInfoList ( )

Definition at line 37 of file C4ObjectInfoList.cpp.

References Clear().

38 {
39  Clear();
40 }

Here is the call graph for this function:

Member Function Documentation

bool C4ObjectInfoList::Add ( C4ObjectInfo pInfo)

Definition at line 86 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Load(), and New().

87 {
88  if (!pInfo) return false;
89  pInfo->Next=First;
90  First=pInfo;
91  return true;
92 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the caller graph for this function:

void C4ObjectInfoList::Clear ( )

Definition at line 48 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by ~C4ObjectInfoList().

49 {
50  C4ObjectInfo *next;
51  while (First)
52  {
53  next=First->Next;
54  delete First;
55  First=next;
56  }
57 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the caller graph for this function:

void C4ObjectInfoList::Default ( )

Definition at line 42 of file C4ObjectInfoList.cpp.

References First, and iNumCreated.

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

43 {
44  First=nullptr;
45  iNumCreated=0;
46 }
C4ObjectInfo * First

Here is the caller graph for this function:

void C4ObjectInfoList::DetachFromObjects ( )

Definition at line 211 of file C4ObjectInfoList.cpp.

References C4ObjectList::ClearInfo(), First, C4ObjectInfo::Next, and Objects.

Referenced by C4PlayerList::Remove().

212 {
213  C4ObjectInfo *cinf;
214  for (cinf=First; cinf; cinf=cinf->Next)
215  ::Objects.ClearInfo(cinf);
216 }
void ClearInfo(C4ObjectInfo *pInfo)
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First
C4GameObjects Objects
Definition: C4Globals.cpp:48

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfoList::Evaluate ( )

Definition at line 171 of file C4ObjectInfoList.cpp.

References C4ObjectInfo::Evaluate(), First, and C4ObjectInfo::Next.

Referenced by C4Player::Evaluate().

172 {
173  C4ObjectInfo *cinf;
174  for (cinf=First; cinf; cinf=cinf->Next)
175  cinf->Evaluate();
176 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the call graph for this function:

Here is the caller graph for this function:

C4ObjectInfo* C4ObjectInfoList::GetFirst ( )
inline

Definition at line 45 of file C4ObjectInfoList.h.

References First.

Referenced by C4Player::LocalSync().

45 { return First; }
C4ObjectInfo * First

Here is the caller graph for this function:

C4ObjectInfo * C4ObjectInfoList::GetIdle ( C4ID  c_id,
C4DefList rDefs 
)

Definition at line 115 of file C4ObjectInfoList.cpp.

References C4ObjectInfoCore::Experience, First, C4ObjectInfo::HasDied, C4ObjectInfoCore::id, C4DefList::ID2Def(), C4ObjectInfo::InAction, C4Def::NativeCrew, C4ObjectInfo::Next, C4ObjectInfoCore::Participation, and C4ObjectInfo::Recruit().

Referenced by C4Player::MakeCrewMember(), and C4Player::PlaceReadyCrew().

116 {
117  C4Def *pDef;
118  C4ObjectInfo *pInfo;
119  C4ObjectInfo *pHiExp=nullptr;
120 
121  // Search list
122  for (pInfo=First; pInfo; pInfo=pInfo->Next)
123  // Valid only
124  if ((pDef = rDefs.ID2Def(pInfo->id)))
125  // Use standard crew or matching id
126  if ( (!c_id && !pDef->NativeCrew) || (pInfo->id==c_id) )
127  // Participating and not in action
128  if (pInfo->Participation && !pInfo->InAction && !pInfo->HasDied)
129  // Highest experience
130  if (!pHiExp || (pInfo->Experience>pHiExp->Experience))
131  // Set this
132  pHiExp=pInfo;
133 
134  // Found
135  if (pHiExp)
136  {
137  pHiExp->Recruit();
138  return pHiExp;
139  }
140 
141  return nullptr;
142 }
C4Def * ID2Def(C4ID id)
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
int32_t NativeCrew
Definition: C4Def.h:115
int32_t Participation
Definition: C4InfoCore.h:39
Definition: C4Def.h:100
C4ObjectInfo * First
int32_t Experience
Definition: C4InfoCore.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

C4ObjectInfo * C4ObjectInfoList::GetIdle ( const char *  szByName)

Definition at line 197 of file C4ObjectInfoList.cpp.

References First, C4ObjectInfo::HasDied, C4ObjectInfo::InAction, C4ObjectInfoCore::Name, C4ObjectInfo::Next, C4ObjectInfoCore::Participation, C4ObjectInfo::Recruit(), and SEqualNoCase().

198 {
199  C4ObjectInfo *pInfo;
200  // Find matching name, participating, alive and not in action
201  for (pInfo=First; pInfo; pInfo=pInfo->Next)
202  if (SEqualNoCase(pInfo->Name,szByName))
203  if (pInfo->Participation && !pInfo->InAction && !pInfo->HasDied)
204  {
205  pInfo->Recruit();
206  return pInfo;
207  }
208  return nullptr;
209 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
int32_t Participation
Definition: C4InfoCore.h:39
char Name[C4MaxName+1]
Definition: C4InfoCore.h:38
C4ObjectInfo * First

Here is the call graph for this function:

C4ObjectInfo * C4ObjectInfoList::GetLast ( )
protected

Definition at line 218 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Save().

219 {
220  C4ObjectInfo *cInfo = First;
221  while (cInfo && cInfo->Next) cInfo=cInfo->Next;
222  return cInfo;
223 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the caller graph for this function:

C4ObjectInfo * C4ObjectInfoList::GetPrevious ( C4ObjectInfo pInfo)
protected

Definition at line 225 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Save().

226 {
227  for (C4ObjectInfo *cInfo = First; cInfo; cInfo=cInfo->Next)
228  if (cInfo->Next == pInfo)
229  return cInfo;
230  return nullptr;
231 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the caller graph for this function:

bool C4ObjectInfoList::IsElement ( C4ObjectInfo pInfo)

Definition at line 233 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by C4Player::SetObjectCrewStatus().

234 {
235  for (C4ObjectInfo *cInfo = First; cInfo; cInfo=cInfo->Next)
236  if (cInfo == pInfo) return true;
237  return false;
238 }
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the caller graph for this function:

int32_t C4ObjectInfoList::Load ( C4Group hGroup)

Definition at line 59 of file C4ObjectInfoList.cpp.

References Add(), C4CFN_ObjectInfoFiles, C4Group::FindNextEntry(), C4ObjectInfo::Load(), C4Group::OpenAsChild(), and C4Group::ResetSearch().

Referenced by C4Player::Load(), and C4Player::Strip().

60 {
61  C4ObjectInfo *ninf;
62  int32_t infn=0;
63  char entryname[256+1];
64 
65  // Search all oci files
66  hGroup.ResetSearch();
67  while (hGroup.FindNextEntry(C4CFN_ObjectInfoFiles,entryname))
68  if ((ninf=new C4ObjectInfo))
69  {
70  if (ninf->Load(hGroup,entryname)) { Add(ninf); infn++; }
71  else delete ninf;
72  }
73 
74  // Search subfolders
75  hGroup.ResetSearch();
76  while (hGroup.FindNextEntry("*", entryname))
77  {
78  C4Group ItemGroup;
79  if (ItemGroup.OpenAsChild(&hGroup, entryname))
80  Load(ItemGroup);
81  }
82 
83  return infn;
84 }
int32_t Load(C4Group &hGroup)
#define C4CFN_ObjectInfoFiles
Definition: C4Components.h:169
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
bool Add(C4ObjectInfo *pInfo)
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:

Here is the caller graph for this function:

void C4ObjectInfoList::MakeValidName ( char *  sName)

Definition at line 94 of file C4ObjectInfoList.cpp.

References _MAX_PATH, C4MaxName, NameExists(), SCopy(), SLen(), and sprintf.

Referenced by New().

95 {
96  char tstr[_MAX_PATH];
97  int32_t iname;
98  size_t namelen = SLen(sName);
99  for (iname=2; NameExists(sName); iname++)
100  {
101  sprintf(tstr," %d",iname);
102  SCopy(tstr, sName + std::min(namelen, C4MaxName - SLen(tstr)));
103  }
104 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
#define sprintf
Definition: Standard.h:171
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:78
const unsigned int C4MaxName
bool NameExists(const char *szName)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectInfoList::NameExists ( const char *  szName)

Definition at line 106 of file C4ObjectInfoList.cpp.

References First, C4ObjectInfoCore::Name, C4ObjectInfo::Next, and SEqualNoCase().

Referenced by MakeValidName().

107 {
108  C4ObjectInfo *cinf;
109  for (cinf=First; cinf; cinf=cinf->Next)
110  if (SEqualNoCase(szName,cinf->Name))
111  return true;
112  return false;
113 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
char Name[C4MaxName+1]
Definition: C4InfoCore.h:38
C4ObjectInfo * First

Here is the call graph for this function:

Here is the caller graph for this function:

C4ObjectInfo * C4ObjectInfoList::New ( C4ID  n_id,
C4DefList pDefs 
)

Definition at line 144 of file C4ObjectInfoList.cpp.

References Add(), C4ObjectInfoCore::Birthday, C4ID::Clonk, Game, C4ComponentHost::GetData(), C4DefList::ID2Def(), iNumCreated, MakeValidName(), C4ObjectInfoCore::Name, C4Game::Names, C4ID::None, and C4Def::pClonkNames.

Referenced by C4Player::MakeCrewMember(), and C4Player::PlaceReadyCrew().

145 {
146  C4ObjectInfo *pInfo;
147  // Create new info object
148  if (!(pInfo = new C4ObjectInfo)) return nullptr;
149  // Default type clonk if none specified
150  if (n_id == C4ID::None) n_id = C4ID::Clonk;
151  // Check type valid and def available
152  C4Def *pDef = nullptr;
153  if (pDefs)
154  if (!(pDef = pDefs->ID2Def(n_id)))
155  { delete pInfo; return nullptr; }
156  // Set name source
157  const char *cpNames = Game.Names.GetData();
158  if (pDef->pClonkNames) cpNames = pDef->pClonkNames->GetData();
159  // Default by type
160  ((C4ObjectInfoCore*)pInfo)->Default(n_id, pDefs, cpNames);
161  // Set birthday
162  pInfo->Birthday=time(nullptr);
163  // Make valid names
164  MakeValidName(pInfo->Name);
165  // Add
166  Add(pInfo);
167  ++iNumCreated;
168  return pInfo;
169 }
C4Def * ID2Def(C4ID id)
C4Game Game
Definition: C4Globals.cpp:52
const char * GetData() const
void MakeValidName(char *sName)
C4ComponentHost * pClonkNames
Definition: C4Def.h:188
C4ComponentHost Names
Definition: C4Game.h:80
static const C4ID None
Definition: C4Id.h:42
Definition: C4Def.h:100
int32_t Birthday
Definition: C4InfoCore.h:47
char Name[C4MaxName+1]
Definition: C4InfoCore.h:38
static const C4ID Clonk
Definition: C4Id.h:45
bool Add(C4ObjectInfo *pInfo)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectInfoList::Save ( C4Group hGroup,
bool  fSavegame,
bool  fStoreTiny,
C4DefList pDefs 
)

Definition at line 178 of file C4ObjectInfoList.cpp.

References C4Id2Def(), GetLast(), GetPrevious(), C4ObjectInfoCore::id, C4ObjectInfo::Save(), and C4Def::TemporaryCrew.

Referenced by C4Player::Save(), and C4Player::Strip().

179 {
180  // Save in opposite order (for identical crew order on load)
181  C4ObjectInfo *pInfo;
182  for (pInfo = GetLast(); pInfo; pInfo = GetPrevious(pInfo))
183  {
184  // don't safe TemporaryCrew in regular player files
185  if (!fSavegame)
186  {
187  C4Def *pDef=C4Id2Def(pInfo->id);
188  if (pDef) if (pDef->TemporaryCrew) continue;
189  }
190  // save
191  if (!pInfo->Save(hGroup, fStoreTiny, pDefs))
192  return false;
193  }
194  return true;
195 }
Definition: C4Def.h:100
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:80
C4ObjectInfo * GetLast()
int32_t TemporaryCrew
Definition: C4Def.h:143
C4ObjectInfo * GetPrevious(C4ObjectInfo *pInfo)
bool Save(C4Group &hGroup, bool fStoreTiny, C4DefList *pDefs)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectInfoList::Strip ( C4DefList rDefs)

Definition at line 240 of file C4ObjectInfoList.cpp.

References First, C4ObjectInfoCore::id, C4DefList::ID2Def(), and C4ObjectInfo::Next.

Referenced by C4Player::Save(), and C4Player::Strip().

241 {
242  C4ObjectInfo *pInfo, *pPrev;
243  // Search list
244  for (pInfo=First, pPrev=nullptr; pInfo; )
245  {
246  // Invalid?
247  if (!rDefs.ID2Def(pInfo->id))
248  {
249  C4ObjectInfo *pDelete = pInfo;
250  if (pPrev) pPrev->Next = pInfo->Next; else First = pInfo->Next;
251  pInfo = pInfo->Next;
252  delete pDelete;
253  }
254  else
255  {
256  pPrev = pInfo;
257  pInfo = pInfo->Next;
258  }
259  }
260 }
C4Def * ID2Def(C4ID id)
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
C4ObjectInfo * First

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4ObjectInfo* C4ObjectInfoList::First
protected
int32_t C4ObjectInfoList::iNumCreated

Definition at line 33 of file C4ObjectInfoList.h.

Referenced by C4Player::CompileFunc(), Default(), and New().


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