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 30 of file C4ObjectInfoList.cpp.

References Default().

31 {
32  Default();
33 }

Here is the call graph for this function:

C4ObjectInfoList::~C4ObjectInfoList ( )

Definition at line 35 of file C4ObjectInfoList.cpp.

References Clear().

36 {
37  Clear();
38 }

Here is the call graph for this function:

Member Function Documentation

bool C4ObjectInfoList::Add ( C4ObjectInfo pInfo)

Definition at line 84 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Load(), and New().

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

Here is the caller graph for this function:

void C4ObjectInfoList::Clear ( )

Definition at line 46 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by ~C4ObjectInfoList().

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

Here is the caller graph for this function:

void C4ObjectInfoList::Default ( )

Definition at line 40 of file C4ObjectInfoList.cpp.

References First, and iNumCreated.

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

41 {
42  First=nullptr;
43  iNumCreated=0;
44 }
C4ObjectInfo * First

Here is the caller graph for this function:

void C4ObjectInfoList::DetachFromObjects ( )

Definition at line 209 of file C4ObjectInfoList.cpp.

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

Referenced by C4PlayerList::Remove().

210 {
211  C4ObjectInfo *cinf;
212  for (cinf=First; cinf; cinf=cinf->Next)
213  ::Objects.ClearInfo(cinf);
214 }
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 169 of file C4ObjectInfoList.cpp.

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

Referenced by C4Player::Evaluate().

170 {
171  C4ObjectInfo *cinf;
172  for (cinf=First; cinf; cinf=cinf->Next)
173  cinf->Evaluate();
174 }
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 113 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().

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

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 195 of file C4ObjectInfoList.cpp.

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

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

Here is the call graph for this function:

C4ObjectInfo * C4ObjectInfoList::GetLast ( )
protected

Definition at line 216 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Save().

217 {
218  C4ObjectInfo *cInfo = First;
219  while (cInfo && cInfo->Next) cInfo=cInfo->Next;
220  return cInfo;
221 }
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 223 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by Save().

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

Here is the caller graph for this function:

bool C4ObjectInfoList::IsElement ( C4ObjectInfo pInfo)

Definition at line 231 of file C4ObjectInfoList.cpp.

References First, and C4ObjectInfo::Next.

Referenced by C4Player::SetObjectCrewStatus().

232 {
233  for (C4ObjectInfo *cInfo = First; cInfo; cInfo=cInfo->Next)
234  if (cInfo == pInfo) return true;
235  return false;
236 }
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 57 of file C4ObjectInfoList.cpp.

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

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

58 {
59  C4ObjectInfo *ninf;
60  int32_t infn=0;
61  char entryname[256+1];
62 
63  // Search all oci files
64  hGroup.ResetSearch();
65  while (hGroup.FindNextEntry(C4CFN_ObjectInfoFiles,entryname))
66  if ((ninf=new C4ObjectInfo))
67  {
68  if (ninf->Load(hGroup,entryname)) { Add(ninf); infn++; }
69  else delete ninf;
70  }
71 
72  // Search subfolders
73  hGroup.ResetSearch();
74  while (hGroup.FindNextEntry("*", entryname))
75  {
76  C4Group ItemGroup;
77  if (ItemGroup.OpenAsChild(&hGroup, entryname))
78  Load(ItemGroup);
79  }
80 
81  return infn;
82 }
int32_t Load(C4Group &hGroup)
#define C4CFN_ObjectInfoFiles
Definition: C4Components.h:170
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 92 of file C4ObjectInfoList.cpp.

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

Referenced by New().

93 {
94  char tstr[_MAX_PATH];
95  int32_t iname;
96  size_t namelen = SLen(sName);
97  for (iname=2; NameExists(sName); iname++)
98  {
99  sprintf(tstr," %d",iname);
100  SCopy(tstr, sName + std::min(namelen, C4MaxName - SLen(tstr)));
101  }
102 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
#define sprintf
Definition: Standard.h:164
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:74
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 104 of file C4ObjectInfoList.cpp.

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

Referenced by MakeValidName().

105 {
106  C4ObjectInfo *cinf;
107  for (cinf=First; cinf; cinf=cinf->Next)
108  if (SEqualNoCase(szName,cinf->Name))
109  return true;
110  return false;
111 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
C4ObjectInfo * Next
Definition: C4ObjectInfo.h:41
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
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 142 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().

143 {
144  C4ObjectInfo *pInfo;
145  // Create new info object
146  if (!(pInfo = new C4ObjectInfo)) return nullptr;
147  // Default type clonk if none specified
148  if (n_id == C4ID::None) n_id = C4ID::Clonk;
149  // Check type valid and def available
150  C4Def *pDef = nullptr;
151  if (pDefs)
152  if (!(pDef = pDefs->ID2Def(n_id)))
153  { delete pInfo; return nullptr; }
154  // Set name source
155  const char *cpNames = Game.Names.GetData();
156  if (pDef->pClonkNames) cpNames = pDef->pClonkNames->GetData();
157  // Default by type
158  ((C4ObjectInfoCore*)pInfo)->Default(n_id, pDefs, cpNames);
159  // Set birthday
160  pInfo->Birthday=time(nullptr);
161  // Make valid names
162  MakeValidName(pInfo->Name);
163  // Add
164  Add(pInfo);
165  ++iNumCreated;
166  return pInfo;
167 }
C4Def * ID2Def(C4ID id)
C4Game Game
Definition: C4Globals.cpp:52
const char * GetData() const
void MakeValidName(char *sName)
C4ComponentHost * pClonkNames
Definition: C4Def.h:185
C4ComponentHost Names
Definition: C4Game.h:78
static const C4ID None
Definition: C4Id.h:39
Definition: C4Def.h:98
int32_t Birthday
Definition: C4InfoCore.h:46
char Name[C4MaxName+1]
Definition: C4InfoCore.h:37
static const C4ID Clonk
Definition: C4Id.h:42
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 176 of file C4ObjectInfoList.cpp.

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

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

177 {
178  // Save in opposite order (for identical crew order on load)
179  C4ObjectInfo *pInfo;
180  for (pInfo = GetLast(); pInfo; pInfo = GetPrevious(pInfo))
181  {
182  // don't safe TemporaryCrew in regular player files
183  if (!fSavegame)
184  {
185  C4Def *pDef=C4Id2Def(pInfo->id);
186  if (pDef) if (pDef->TemporaryCrew) continue;
187  }
188  // save
189  if (!pInfo->Save(hGroup, fStoreTiny, pDefs))
190  return false;
191  }
192  return true;
193 }
Definition: C4Def.h:98
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
C4ObjectInfo * GetLast()
int32_t TemporaryCrew
Definition: C4Def.h:140
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 238 of file C4ObjectInfoList.cpp.

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

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

239 {
240  C4ObjectInfo *pInfo, *pPrev;
241  // Search list
242  for (pInfo=First, pPrev=nullptr; pInfo; )
243  {
244  // Invalid?
245  if (!rDefs.ID2Def(pInfo->id))
246  {
247  C4ObjectInfo *pDelete = pInfo;
248  if (pPrev) pPrev->Next = pInfo->Next; else First = pInfo->Next;
249  pInfo = pInfo->Next;
250  delete pDelete;
251  }
252  else
253  {
254  pPrev = pInfo;
255  pInfo = pInfo->Next;
256  }
257  }
258 }
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: