OpenClonk
C4IDList Class Reference

#include <C4IDList.h>

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

Public Member Functions

 C4IDList ()
 
 C4IDList (const C4IDList &rCopy)
 
C4IDListoperator= (const C4IDList &rCopy)
 
 ~C4IDList ()
 
bool operator== (const C4IDList &rhs) const
 
void Default ()
 
void Clear ()
 
bool IsClear () const
 
C4ID GetID (size_t index, int32_t *ipCount=nullptr) const
 
int32_t GetCount (size_t index) const
 
bool SetCount (size_t index, int32_t iCount)
 
int32_t GetIDCount (C4ID c_id, int32_t iZeroDefVal=0) const
 
bool SetIDCount (C4ID c_id, int32_t iCount, bool fAddNewID=false)
 
bool IncreaseIDCount (C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false)
 
bool DecreaseIDCount (C4ID c_id, bool fRemoveEmptyID=true)
 
int32_t GetNumberOfIDs () const
 
int32_t GetIndex (C4ID c_id) const
 
C4ID GetID (C4DefList &rDefs, int32_t dwCategory, int32_t index, int32_t *ipCount=nullptr) const
 
int32_t GetCount (C4DefList &rDefs, int32_t dwCategory, int32_t index) const
 
bool SetCount (C4DefList &rDefs, int32_t dwCategory, int32_t index, int32_t iCount)
 
int32_t GetNumberOfIDs (C4DefList &rDefs, int32_t dwCategory) const
 
bool Add (C4IDList &rList)
 
bool ConsolidateValids (C4DefList &rDefs, int32_t dwCategory=0)
 
bool DeleteItem (size_t iIndex)
 
void Draw (C4Facet &cgo, int32_t iSelection, C4DefList &rDefs, DWORD dwCategory, bool fCounts=true, int32_t iAlign=0) const
 
void CompileFunc (StdCompiler *pComp, bool fValues=true)
 

Protected Attributes

size_t Count
 
C4ID id [C4IDListChunkSize]
 
C4IDListChunkpNext
 

Detailed Description

Definition at line 46 of file C4IDList.h.

Constructor & Destructor Documentation

◆ C4IDList() [1/2]

C4IDList::C4IDList ( )

Definition at line 61 of file stub-handle.cpp.

61 {}

◆ C4IDList() [2/2]

C4IDList::C4IDList ( const C4IDList rCopy)

Definition at line 60 of file C4IDList.cpp.

60  : C4IDListChunk()
61 {
62  Default();
63  *this = rCopy;
64 }
void Default()
Definition: stub-handle.cpp:63

References Default().

Here is the call graph for this function:

◆ ~C4IDList()

C4IDList::~C4IDList ( )

Definition at line 62 of file stub-handle.cpp.

62 {}

Member Function Documentation

◆ Add()

bool C4IDList::Add ( C4IDList rList)

Definition at line 422 of file C4IDList.cpp.

423 {
424  C4IDListChunk *pQueryChunk = &rList;
425  size_t cnt = rList.Count;
426  size_t cntl = 0;
427  while (cnt--)
428  {
429  IncreaseIDCount(pQueryChunk->id[cntl], true, pQueryChunk->Count[cntl]);
430  if (++cntl == C4IDListChunkSize)
431  {
432  pQueryChunk = pQueryChunk->pNext;
433  cntl = 0;
434  }
435  }
436  return true;
437 }
const size_t C4IDListChunkSize
Definition: C4IDList.h:28
C4IDListChunk * pNext
Definition: C4IDList.h:36
int32_t Count[C4IDListChunkSize]
Definition: C4IDList.h:34
C4ID id[C4IDListChunkSize]
Definition: C4IDList.h:33
bool IncreaseIDCount(C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false)
Definition: C4IDList.cpp:258
size_t Count
Definition: C4IDList.h:55

References C4IDListChunkSize, C4IDListChunk::Count, Count, C4IDListChunk::id, IncreaseIDCount(), and C4IDListChunk::pNext.

Here is the call graph for this function:

◆ Clear()

void C4IDList::Clear ( )

Definition at line 64 of file stub-handle.cpp.

64 {}

Referenced by C4GameParameters::Clear(), C4RoundResults::Clear(), C4SGame::Default(), C4SAnimals::Default(), C4SEnvironment::Default(), C4Def::DefaultDefCore(), and C4RoundResults::EvaluateGoals().

Here is the caller graph for this function:

◆ CompileFunc()

void C4IDList::CompileFunc ( StdCompiler pComp,
bool  fValues = true 
)

Definition at line 69 of file stub-handle.cpp.

69 {}

◆ ConsolidateValids()

bool C4IDList::ConsolidateValids ( C4DefList rDefs,
int32_t  dwCategory = 0 
)

Definition at line 439 of file C4IDList.cpp.

440 {
441  bool fIDsRemoved = false;
442  C4IDListChunk *pQueryChunk = this;
443  size_t cnt = Count;
444  size_t cntl = 0;
445  C4Def* pDef;
446  while (cnt--)
447  {
448  // ID does not resolve to a valid def or category is specified and def does not match category
449  if (!(pDef = rDefs.ID2Def(pQueryChunk->id[cntl])) || (dwCategory && !(pDef->Category & dwCategory)))
450  {
451  // Delete it
452  DeleteItem(Count - cnt - 1);
453  // Handle this list index again!
454  --cntl;
455  // Something was done
456  fIDsRemoved = true;
457  }
458  if (++cntl == C4IDListChunkSize)
459  {
460  pQueryChunk = pQueryChunk->pNext;
461  cntl = 0;
462  }
463  }
464  return fIDsRemoved;
465 }
Definition: C4Def.h:99
int32_t Category
Definition: C4Def.h:117
C4Def * ID2Def(C4ID id)
bool DeleteItem(size_t iIndex)
Definition: C4IDList.cpp:498

References C4IDListChunkSize, C4Def::Category, Count, DeleteItem(), C4IDListChunk::id, C4DefList::ID2Def(), and C4IDListChunk::pNext.

Referenced by C4Player::ScenarioInit().

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

◆ DecreaseIDCount()

bool C4IDList::DecreaseIDCount ( C4ID  c_id,
bool  fRemoveEmptyID = true 
)
inline

Definition at line 69 of file C4IDList.h.

70  { return IncreaseIDCount(c_id, false, -1, fRemoveEmptyID); }

References IncreaseIDCount().

Here is the call graph for this function:

◆ Default()

void C4IDList::Default ( )

Definition at line 63 of file stub-handle.cpp.

63 {}

Referenced by C4IDList(), C4SDefinitions::Default(), C4SRealism::Default(), C4SPlrStart::Default(), C4SLandscape::Default(), and C4Player::DefaultRuntimeData().

Here is the caller graph for this function:

◆ DeleteItem()

bool C4IDList::DeleteItem ( size_t  iIndex)

Definition at line 498 of file C4IDList.cpp.

499 {
500  // Invalid index
501  if (!Inside<size_t>(iIndex + 1, 1u, Count))
502  {
503  return false;
504  }
505  // Get chunk to delete of
506  size_t index = iIndex;
507  C4IDListChunk *pQueryChunk = this;
508  while (index >= C4IDListChunkSize)
509  {
510  pQueryChunk = pQueryChunk->pNext;
511  index -= C4IDListChunkSize;
512  }
513  // Shift down all entries behind
514  size_t cnt = --Count - iIndex;
515  size_t cntl = index;
516  size_t cntl2 = cntl;
517  C4IDListChunk *pNextChunk = pQueryChunk;
518  while (cnt--)
519  {
520  // Check for list overlap
521  if (++cntl2 == C4IDListChunkSize)
522  {
523  pNextChunk = pQueryChunk->pNext;
524  cntl2 = 0;
525  }
526  // Move down
527  pQueryChunk->id[cntl] = pNextChunk->id[cntl2];
528  pQueryChunk->Count[cntl] = pNextChunk->Count[cntl2];
529  // Next item
530  pQueryChunk = pNextChunk;
531  cntl = cntl2;
532  }
533  // Done
534  return true;
535 }

References C4IDListChunkSize, C4IDListChunk::Count, Count, C4IDListChunk::id, and C4IDListChunk::pNext.

Referenced by ConsolidateValids(), IncreaseIDCount(), and C4Player::SetKnowledge().

Here is the caller graph for this function:

◆ Draw()

void C4IDList::Draw ( C4Facet cgo,
int32_t  iSelection,
C4DefList rDefs,
DWORD  dwCategory,
bool  fCounts = true,
int32_t  iAlign = 0 
) const

Definition at line 467 of file C4IDList.cpp.

470 {
471 
472  int32_t sections = cgo.GetSectionCount();
473  int32_t idnum = GetNumberOfIDs(rDefs,dwCategory);
474  int32_t firstid = Clamp<int32_t>(iSelection - sections / 2, 0, std::max<int32_t>(idnum - sections, 0));
475  int32_t idcount;
476  C4ID c_id;
477  C4Facet cgo2;
478  char buf[10];
479  for (int32_t cnt = 0; (cnt<sections) && (c_id = GetID(rDefs, dwCategory, firstid + cnt, &idcount)); cnt++)
480  {
481  cgo2 = cgo.TruncateSection(iAlign);
482  rDefs.Draw(c_id, cgo2, (firstid + cnt == iSelection), 0);
483  sprintf(buf, "%dx", idcount);
484  if (fCounts)
485  {
487  }
488  }
489 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4GraphicsResource GraphicsResource
const int ARight
Definition: C4Surface.h:41
#define sprintf
Definition: Standard.h:162
void Draw(C4ID id, C4Facet &cgo, bool fSelected, int32_t iColor)
Definition: C4DefList.cpp:407
@ DEFAULT_MESSAGE_COLOR
Definition: C4Draw.h:167
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:561
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
int32_t GetSectionCount()
Definition: C4Facet.cpp:46
C4Facet TruncateSection(int32_t iAlign=C4FCT_Left)
Definition: C4Facet.cpp:250
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
Definition: C4Id.h:26
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:103
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:231
int GetLineHeight() const
Definition: C4FontLoader.h:125

References ARight, C4Draw::DEFAULT_MESSAGE_COLOR, C4DefList::Draw(), C4GraphicsResource::FontRegular, GetID(), CStdFont::GetLineHeight(), GetNumberOfIDs(), C4Facet::GetSectionCount(), GraphicsResource, C4Facet::Hgt, pDraw, sprintf, C4Facet::Surface, C4Draw::TextOut(), C4Facet::TruncateSection(), C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Here is the call graph for this function:

◆ GetCount() [1/2]

int32_t C4IDList::GetCount ( C4DefList rDefs,
int32_t  dwCategory,
int32_t  index 
) const

Definition at line 346 of file C4IDList.cpp.

347 {
348  int32_t cindex = -1;
349  C4Def *cDef;
350  const C4IDListChunk *pQueryChunk = this;
351  size_t cnt = Count;
352  size_t cntl = 0;
353  while (cnt--)
354  {
355  if ((dwCategory == C4D_All) || ( (cDef = rDefs.ID2Def(pQueryChunk->id[cntl])) && (cDef->Category & dwCategory) ) )
356  {
357  cindex++;
358  if (cindex == index)
359  {
360  return pQueryChunk->Count[cntl];
361  }
362  }
363  if (++cntl == C4IDListChunkSize)
364  {
365  pQueryChunk = pQueryChunk->pNext;
366  cntl = 0;
367  }
368  }
369  return 0;
370 }
const int32_t C4D_All
Definition: C4Def.h:39

References C4D_All, C4IDListChunkSize, C4Def::Category, C4IDListChunk::Count, Count, C4IDListChunk::id, C4DefList::ID2Def(), and C4IDListChunk::pNext.

Here is the call graph for this function:

◆ GetCount() [2/2]

int32_t C4IDList::GetCount ( size_t  index) const

Definition at line 125 of file C4IDList.cpp.

126 {
127  // Outside list?
128  if (!Inside<size_t>(index + 1, 1u, Count))
129  {
130  return 0;
131  }
132  // Get chunk to query
133  const C4IDListChunk *pQueryChunk = this;
134  while (index >= C4IDListChunkSize)
135  {
136  pQueryChunk = pQueryChunk->pNext;
137  index -= C4IDListChunkSize;
138  }
139  // Query it
140  return pQueryChunk->Count[index];
141 }

References C4IDListChunkSize, C4IDListChunk::Count, Count, and C4IDListChunk::pNext.

Referenced by C4Object::CreateContentsByList(), C4Player::ExecBaseProduction(), C4Player::PlaceReadyBase(), C4Player::PlaceReadyMaterial(), and C4Player::PlaceReadyVehic().

Here is the caller graph for this function:

◆ GetID() [1/2]

C4ID C4IDList::GetID ( C4DefList rDefs,
int32_t  dwCategory,
int32_t  index,
int32_t *  ipCount = nullptr 
) const

Definition at line 311 of file C4IDList.cpp.

312 {
313  int32_t cindex = -1;
314  C4Def *cDef;
315  if (ipCount)
316  {
317  *ipCount = 0;
318  }
319  // Find id
320  const C4IDListChunk *pQueryChunk = this;
321  size_t cnt = Count;
322  size_t cntl = 0;
323  while (cnt--)
324  {
325  if ((dwCategory == C4D_All) || ( (cDef = rDefs.ID2Def(pQueryChunk->id[cntl])) && (cDef->Category & dwCategory) ) )
326  {
327  cindex++;
328  if (cindex==index)
329  {
330  if (ipCount)
331  {
332  *ipCount = pQueryChunk->Count[cntl];
333  }
334  return pQueryChunk->id[cntl];
335  }
336  }
337  if (++cntl == C4IDListChunkSize)
338  {
339  pQueryChunk = pQueryChunk->pNext;
340  cntl = 0;
341  }
342  }
343  return C4ID::None;
344 }
static const C4ID None
Definition: C4Id.h:39

References C4D_All, C4IDListChunkSize, C4Def::Category, C4IDListChunk::Count, Count, C4IDListChunk::id, C4DefList::ID2Def(), C4ID::None, and C4IDListChunk::pNext.

Here is the call graph for this function:

◆ GetID() [2/2]

C4ID C4IDList::GetID ( size_t  index,
int32_t *  ipCount = nullptr 
) const

Definition at line 103 of file C4IDList.cpp.

104 {
105  // Outside list?
106  if (!Inside<size_t>(index + 1, 1u, Count))
107  {
108  return C4ID::None;
109  }
110  // Get chunk to query
111  const C4IDListChunk *pQueryChunk = this;
112  while (index >= C4IDListChunkSize)
113  {
114  pQueryChunk = pQueryChunk->pNext;
115  index -= C4IDListChunkSize;
116  }
117  // Query it
118  if (ipCount)
119  {
120  *ipCount = pQueryChunk->Count[index];
121  }
122  return pQueryChunk->id[index];
123 }

References C4IDListChunkSize, C4IDListChunk::Count, Count, C4IDListChunk::id, C4ID::None, and C4IDListChunk::pNext.

Referenced by C4MainMenu::ActivateGoals(), C4DefList::CheckRequireDef(), C4Object::CreateContentsByList(), Draw(), C4Player::ExecBaseProduction(), C4GameParameters::GetGameGoalString(), C4Game::InitAnimals(), C4Game::InitEnvironment(), C4Game::InitGoals(), C4Game::InitRules(), C4Game::InitValueOverloads(), ListExpandValids(), C4Player::PlaceReadyBase(), C4Player::PlaceReadyCrew(), C4Player::PlaceReadyMaterial(), C4Player::PlaceReadyVehic(), and C4GoalDisplay::SetGoals().

Here is the caller graph for this function:

◆ GetIDCount()

int32_t C4IDList::GetIDCount ( C4ID  c_id,
int32_t  iZeroDefVal = 0 
) const

Definition at line 67 of file stub-handle.cpp.

67 { return 0; }

Referenced by C4MainMenu::ActivateGoals(), C4Player::ExecBaseProduction(), C4Game::InitValueOverloads(), and C4GoalDisplay::SetGoals().

Here is the caller graph for this function:

◆ GetIndex()

int32_t C4IDList::GetIndex ( C4ID  c_id) const

Definition at line 236 of file C4IDList.cpp.

237 {
238  // Find id in list
239  const C4IDListChunk *pQueryChunk = this;
240  size_t cnt = Count;
241  size_t cntl = 0;
242  while (cnt--)
243  {
244  if (pQueryChunk->id[cntl] == c_id)
245  {
246  return Count-cnt-1;
247  }
248  if (++cntl == C4IDListChunkSize)
249  {
250  pQueryChunk = pQueryChunk->pNext;
251  cntl = 0;
252  }
253  }
254  // Not found
255  return -1;
256 }

References C4IDListChunkSize, Count, C4IDListChunk::id, and C4IDListChunk::pNext.

Referenced by C4Player::SetKnowledge().

Here is the caller graph for this function:

◆ GetNumberOfIDs() [1/2]

int32_t C4IDList::GetNumberOfIDs ( ) const

Definition at line 231 of file C4IDList.cpp.

232 {
233  return Count;
234 }

References Count.

Referenced by C4MainMenu::ActivateGoals(), C4GameOverDlg::C4GameOverDlg(), C4DefList::CheckRequireDef(), Draw(), C4GameParameters::GetGameGoalString(), and C4GoalDisplay::SetGoals().

Here is the caller graph for this function:

◆ GetNumberOfIDs() [2/2]

int32_t C4IDList::GetNumberOfIDs ( C4DefList rDefs,
int32_t  dwCategory 
) const

Definition at line 399 of file C4IDList.cpp.

400 {
401  int32_t idnum = 0;
402  C4Def *cDef;
403  const C4IDListChunk *pQueryChunk = this;
404  size_t cnt = Count;
405  size_t cntl = 0;
406  while (cnt--)
407  {
408  if ((dwCategory == C4D_All) || ( (cDef = rDefs.ID2Def(pQueryChunk->id[cntl])) && (cDef->Category & dwCategory) ) )
409  {
410  idnum++;
411  }
412  if (++cntl == C4IDListChunkSize)
413  {
414  pQueryChunk = pQueryChunk->pNext;
415  cntl = 0;
416  }
417  }
418  return idnum;
419 }

References C4D_All, C4IDListChunkSize, C4Def::Category, Count, C4IDListChunk::id, C4DefList::ID2Def(), and C4IDListChunk::pNext.

Here is the call graph for this function:

◆ IncreaseIDCount()

bool C4IDList::IncreaseIDCount ( C4ID  c_id,
bool  fAddNewID = true,
int32_t  IncreaseBy = 1,
bool  fRemoveEmpty = false 
)

Definition at line 258 of file C4IDList.cpp.

259 {
260  // Find id in list
261  C4IDListChunk *pQueryChunk = this;
262  size_t cnt = Count;
263  size_t cntl = 0;
264  while (cnt--)
265  {
266  if (pQueryChunk->id[cntl] == c_id)
267  {
268  // Increase count
269  pQueryChunk->Count[cntl] += IncreaseBy;
270  // Check count
271  if (fRemoveEmpty && !pQueryChunk->Count[cntl])
272  {
273  DeleteItem(Count - cnt - 1);
274  }
275  // Success
276  return true;
277  }
278  if (++cntl == C4IDListChunkSize)
279  {
280  pQueryChunk = pQueryChunk->pNext;
281  cntl = 0;
282  }
283  }
284  // Add desired?
285  if (!fAddNewID)
286  {
287  return true;
288  }
289  // Add it
290  // If end was reached, add new chunk
291  if (!pQueryChunk)
292  {
293  C4IDListChunk *pLast = this;
294  while (pLast->pNext)
295  {
296  pLast = pLast->pNext;
297  }
298  pQueryChunk = new C4IDListChunk();
299  pLast->pNext = pQueryChunk;
300  }
301  // Set id
302  pQueryChunk->id[cntl] = c_id;
303  pQueryChunk->Count[cntl] = IncreaseBy;
304  ++Count;
305  // Success
306  return true;
307 }

References C4IDListChunk::C4IDListChunk(), C4IDListChunkSize, C4IDListChunk::Count, Count, DeleteItem(), C4IDListChunk::id, and C4IDListChunk::pNext.

Referenced by Add(), DecreaseIDCount(), and C4Player::ExecBaseProduction().

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

◆ IsClear()

bool C4IDList::IsClear ( ) const

Definition at line 98 of file C4IDList.cpp.

99 {
100  return !Count;
101 }

References Count.

◆ operator=()

C4IDList & C4IDList::operator= ( const C4IDList rCopy)

Definition at line 65 of file stub-handle.cpp.

65 { return *this; }

◆ operator==()

bool C4IDList::operator== ( const C4IDList rhs) const

Definition at line 66 of file stub-handle.cpp.

66 { return false; }

◆ SetCount() [1/2]

bool C4IDList::SetCount ( C4DefList rDefs,
int32_t  dwCategory,
int32_t  index,
int32_t  iCount 
)

Definition at line 372 of file C4IDList.cpp.

373 {
374  int32_t cindex = -1;
375  C4Def *cDef;
376  C4IDListChunk *pQueryChunk = this;
377  size_t cnt = Count;
378  size_t cntl = 0;
379  while (cnt--)
380  {
381  if ((dwCategory == C4D_All) || ( (cDef = rDefs.ID2Def(pQueryChunk->id[cntl])) && (cDef->Category & dwCategory) ) )
382  {
383  cindex++;
384  if (cindex == index)
385  {
386  pQueryChunk->Count[cntl] = iCount;
387  return true;
388  }
389  }
390  if (++cntl == C4IDListChunkSize)
391  {
392  pQueryChunk = pQueryChunk->pNext;
393  cntl = 0;
394  }
395  }
396  return false;
397 }

References C4D_All, C4IDListChunkSize, C4Def::Category, C4IDListChunk::Count, Count, C4IDListChunk::id, C4DefList::ID2Def(), and C4IDListChunk::pNext.

Here is the call graph for this function:

◆ SetCount() [2/2]

bool C4IDList::SetCount ( size_t  index,
int32_t  iCount 
)

Definition at line 143 of file C4IDList.cpp.

144 {
145  // Outside list?
146  if (!Inside<size_t>(index + 1, 1u, Count))
147  {
148  return false;
149  }
150  // Get chunk to set in
151  C4IDListChunk *pQueryChunk = this;
152  while (index >= C4IDListChunkSize)
153  {
154  pQueryChunk = pQueryChunk->pNext;
155  index -= C4IDListChunkSize;
156  }
157  // Set it
158  pQueryChunk->Count[index] = iCount;
159  // Success
160  return true;
161 }

References C4IDListChunkSize, C4IDListChunk::Count, Count, and C4IDListChunk::pNext.

◆ SetIDCount()

bool C4IDList::SetIDCount ( C4ID  c_id,
int32_t  iCount,
bool  fAddNewID = false 
)

Definition at line 68 of file stub-handle.cpp.

68 { return false; }

Referenced by C4SPlrStart::CompileFunc(), C4RoundResults::EvaluateGoals(), and C4Player::SetKnowledge().

Here is the caller graph for this function:

Member Data Documentation

◆ Count

size_t C4IDList::Count
protected

◆ id

C4ID C4IDListChunk::id[C4IDListChunkSize]
inherited

◆ pNext

C4IDListChunk* C4IDListChunk::pNext
inherited

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