OpenClonk
C4FindObjectOr Class Reference

#include <C4FindObject.h>

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

Public Member Functions

 C4FindObjectOr (int32_t iCnt, C4FindObject **ppConds)
 
 ~C4FindObjectOr () override
 
int32_t Count (const C4ObjectList &Objs)
 
int32_t Count (const C4ObjectList &Objs, const C4LSectors &Sct)
 
C4ObjectFind (const C4ObjectList &Objs)
 
C4ObjectFind (const C4ObjectList &Objs, const C4LSectors &Sct)
 
C4ValueArrayFindMany (const C4ObjectList &Objs)
 
C4ValueArrayFindMany (const C4ObjectList &Objs, const C4LSectors &Sct)
 
void SetSort (C4SortObject *pToSort)
 

Static Public Member Functions

static C4FindObjectCreateByValue (const C4Value &Data, C4SortObject **ppSortObj=nullptr, const C4Object *context=nullptr, bool *has_layer_check=nullptr)
 

Protected Member Functions

bool Check (C4Object *pObj) override
 
C4RectGetBounds () override
 
bool UseShapes () override
 
bool IsEnsured () override
 
bool IsImpossible () override
 

Detailed Description

Definition at line 146 of file C4FindObject.h.

Constructor & Destructor Documentation

◆ C4FindObjectOr()

C4FindObjectOr::C4FindObjectOr ( int32_t  iCnt,
C4FindObject **  ppConds 
)

Definition at line 583 of file C4FindObject.cpp.

References C4Rect::Add(), C4FindObject::GetBounds(), IsImpossible(), C4FindObject::UseShapes(), and UseShapes().

584  : iCnt(inCnt), ppConds(ppConds), fHasBounds(false)
585 {
586  // Filter impossible entries
587  int32_t i;
588  for (i = 0; i < iCnt; )
589  if (ppConds[i]->IsImpossible())
590  {
591  delete ppConds[i];
592  iCnt--;
593  for (int32_t j = i; j < iCnt; j++)
594  ppConds[j] = ppConds[j + 1];
595  }
596  else
597  i++;
598  // Sum up all child bounds
599  for (i = 0; i < iCnt; i++)
600  {
601  C4Rect *pChildBounds = ppConds[i]->GetBounds();
602  if (!pChildBounds) { fHasBounds = false; break; }
603  // With objects that have a position outside their shape, mixing
604  // shape bounds with rect bounds results in no bounds
605  if (fHasBounds && fUseShapes != ppConds[i]->UseShapes())
606  { fHasBounds = false; break; }
607  if (fHasBounds)
608  Bounds.Add(*pChildBounds);
609  else
610  {
611  fUseShapes = ppConds[i]->UseShapes();
612  Bounds = *pChildBounds;
613  fHasBounds = true;
614  }
615  }
616 }
virtual bool UseShapes()
Definition: C4FindObject.h:96
Definition: C4Rect.h:27
virtual C4Rect * GetBounds()
Definition: C4FindObject.h:95
void Add(const C4Rect &r2)
Definition: C4Rect.cpp:144
bool UseShapes() override
Definition: C4FindObject.h:158
bool IsImpossible() override
Definition: C4FindObject.h:160
Here is the call graph for this function:

◆ ~C4FindObjectOr()

C4FindObjectOr::~C4FindObjectOr ( )
override

Definition at line 618 of file C4FindObject.cpp.

619 {
620  for (int32_t i = 0; i < iCnt; i++)
621  delete ppConds[i];
622  delete [] ppConds;
623 }

Member Function Documentation

◆ Check()

bool C4FindObjectOr::Check ( C4Object pObj)
overrideprotectedvirtual

Implements C4FindObject.

Definition at line 625 of file C4FindObject.cpp.

626 {
627  for (int32_t i = 0; i < iCnt; i++)
628  if (ppConds[i]->Check(pObj))
629  return true;
630  return false;
631 }
bool Check(C4Object *pObj) override

◆ Count() [1/2]

int32_t C4FindObject::Count ( const C4ObjectList Objs)
inherited

Definition at line 260 of file C4FindObject.cpp.

References C4FindObject::Check(), C4FindObject::IsEnsured(), C4FindObject::IsImpossible(), and C4ObjectList::ObjectCount().

Referenced by C4FindObject::Count().

261 {
262  // Trivial cases
263  if (IsImpossible())
264  return 0;
265  if (IsEnsured())
266  return Objs.ObjectCount();
267  // Count
268  int32_t iCount = 0;
269  for (C4Object *obj : Objs)
270  if (obj->Status && Check(obj))
271  iCount++;
272  return iCount;
273 }
virtual bool IsEnsured()
Definition: C4FindObject.h:98
int ObjectCount(C4ID id=C4ID::None) const
virtual bool IsImpossible()
Definition: C4FindObject.h:97
virtual bool Check(C4Object *pObj)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Count() [2/2]

int32_t C4FindObject::Count ( const C4ObjectList Objs,
const C4LSectors Sct 
)
inherited

Definition at line 327 of file C4FindObject.cpp.

References C4FindObject::Check(), C4FindObject::Count(), C4LArea::FirstObjects(), C4LArea::FirstObjectShapes(), C4FindObject::GetBounds(), C4GameObjects::GetNextMarker(), C4FindObject::IsEnsured(), C4FindObject::IsImpossible(), C4LArea::Next(), C4LArea::NextObjects(), C4LArea::NextObjectShapes(), C4ObjectList::ObjectCount(), Objects, C4LSector::ObjectShapes, C4GameObjects::Sectors, and C4FindObject::UseShapes().

328 {
329  // Trivial cases
330  if (IsImpossible())
331  return 0;
332  if (IsEnsured())
333  return Objs.ObjectCount();
334  // Check bounds
335  C4Rect *pBounds = GetBounds();
336  if (!pBounds)
337  return Count(Objs);
338  else if (UseShapes())
339  {
340  // Get area
341  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
342  C4ObjectList *pLst = Area.FirstObjectShapes(&pSct);
343  // Check if a single-sector check is enough
344  if (!Area.Next(pSct))
345  return Count(pSct->ObjectShapes);
346  // Create marker, count over all areas
347  uint32_t iMarker = ::Objects.GetNextMarker();
348  int32_t iCount = 0;
349  for (; pLst; pLst=Area.NextObjectShapes(pLst, &pSct))
350  for (C4Object *obj : Objs)
351  if (obj->Status)
352  if (obj->Marker != iMarker)
353  {
354  obj->Marker = iMarker;
355  if (Check(obj))
356  iCount++;
357  }
358  return iCount;
359  }
360  else
361  {
362  // Count objects per area
363  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
364  int32_t iCount = 0;
365  for (C4ObjectList *pLst=Area.FirstObjects(&pSct); pLst; pLst=Area.NextObjects(pLst, &pSct))
366  iCount += Count(*pLst);
367  return iCount;
368  }
369 }
virtual bool UseShapes()
Definition: C4FindObject.h:96
virtual bool IsEnsured()
Definition: C4FindObject.h:98
Definition: C4Rect.h:27
virtual C4Rect * GetBounds()
Definition: C4FindObject.h:95
int ObjectCount(C4ID id=C4ID::None) const
uint32_t GetNextMarker()
virtual bool IsImpossible()
Definition: C4FindObject.h:97
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
int32_t Count(const C4ObjectList &Objs)
C4LSectors Sectors
Definition: C4GameObjects.h:42
virtual bool Check(C4Object *pObj)=0
C4GameObjects Objects
Definition: C4Globals.cpp:48
Here is the call graph for this function:

◆ CreateByValue()

C4FindObject * C4FindObject::CreateByValue ( const C4Value Data,
C4SortObject **  ppSortObj = nullptr,
const C4Object context = nullptr,
bool *  has_layer_check = nullptr 
)
staticinherited

Definition at line 33 of file C4FindObject.cpp.

References C4FindObject::C4FindObjectAnd, C4FindObject::C4FindObjectNot, C4FindObject::C4FindObjectOr, C4FO_Action, C4FO_ActionTarget, C4FO_And, C4FO_AnyContainer, C4FO_AnyLayer, C4FO_AtPoint, C4FO_AtRect, C4FO_Category, C4FO_Cone, C4FO_Container, C4FO_Controller, C4FO_Distance, C4FO_Exclude, C4FO_Func, C4FO_ID, C4FO_InArray, C4FO_InRect, C4FO_Layer, C4FO_Not, C4FO_OCF, C4FO_OnLine, C4FO_Or, C4FO_Owner, C4FO_Procedure, C4FO_Property, C4SO_First, C4SO_Last, Clamp(), C4SortObject::CreateByValue(), C4Value::getArray(), C4String::GetCStr(), C4ValueArray::GetSize(), C4Object::GetX(), C4Object::GetY(), iSize, and C4FindObjectFunc::SetPar().

Referenced by C4SortObject::CompareCache(), C4SortObject::CreateByValue(), and CreateCriterionsFromPars().

34 {
35  // Must be an array
36  C4ValueArray *pArray = C4Value(DataVal).getArray();
37  if (!pArray) return nullptr;
38 
39  const C4ValueArray &Data = *pArray;
40  int32_t iType = Data[0].getInt();
41  if (Inside<int32_t>(iType, C4SO_First, C4SO_Last))
42  {
43  // this is not a FindObject but a sort condition!
44  // sort condition not desired here?
45  if (!ppSortObj) return nullptr;
46  // otherwise, create it!
47  *ppSortObj = C4SortObject::CreateByValue(iType, Data, context);
48  // done
49  return nullptr;
50  }
51 
52  switch (iType)
53  {
54  case C4FO_Not:
55  {
56  // Create child condition
57  C4FindObject *pCond = C4FindObject::CreateByValue(Data[1], nullptr, context, has_layer_check);
58  if (!pCond) return nullptr;
59  // wrap
60  return new C4FindObjectNot(pCond);
61  }
62 
63  case C4FO_And: case C4FO_Or:
64  {
65  // Trivial case (one condition)
66  if (Data.GetSize() == 2)
67  return C4FindObject::CreateByValue(Data[1], nullptr, context, has_layer_check);
68  // Create all childs
69  int32_t i;
70  C4FindObject **ppConds = new C4FindObject *[Data.GetSize() - 1];
71  for (i = 0; i < Data.GetSize() - 1; i++)
72  ppConds[i] = C4FindObject::CreateByValue(Data[i + 1], nullptr, context, has_layer_check);
73  // Count real entries, move them to start of list
74  int32_t iSize = 0;
75  for (i = 0; i < Data.GetSize() - 1; i++)
76  if (ppConds[i])
77  if (iSize++ != i)
78  ppConds[iSize-1] = ppConds[i];
79  // Create
80  if (iType == C4FO_And)
81  return new C4FindObjectAnd(iSize, ppConds);
82  else
83  return new C4FindObjectOr(iSize, ppConds);
84  }
85 
86  case C4FO_Exclude:
87  {
88  C4Object *obj = Data[1].getObj();
89  if (!obj) return nullptr;
90 
91  return new C4FindObjectExclude(obj);
92  }
93 
94  case C4FO_ID:
95  return new C4FindObjectDef(Data[1].getPropList());
96 
97 
98  // #973: For all criteria using coordinates: If FindObject et al. are called in object context, offset by object center
99  case C4FO_InRect:
100  {
101  int32_t x = Data[1].getInt();
102  int32_t y = Data[2].getInt();
103  int32_t w = Data[3].getInt();
104  int32_t h = Data[4].getInt();
105  if (context)
106  {
107  x += context->GetX();
108  y += context->GetY();
109  }
110  return new C4FindObjectInRect(C4Rect(x, y, w, h));
111  }
112 
113  case C4FO_AtPoint:
114  {
115  int32_t x = Data[1].getInt();
116  int32_t y = Data[2].getInt();
117  if (context)
118  {
119  x += context->GetX();
120  y += context->GetY();
121  }
122  return new C4FindObjectAtPoint(x, y);
123  }
124 
125  case C4FO_AtRect:
126  {
127  int32_t x = Data[1].getInt();
128  int32_t y = Data[2].getInt();
129  int32_t w = Data[3].getInt();
130  int32_t h = Data[4].getInt();
131  if (context)
132  {
133  x += context->GetX();
134  y += context->GetY();
135  }
136  return new C4FindObjectAtRect(x, y, w, h);
137  }
138 
139  case C4FO_OnLine:
140  {
141  int32_t x1 = Data[1].getInt();
142  int32_t y1 = Data[2].getInt();
143  int32_t x2 = Data[3].getInt();
144  int32_t y2 = Data[4].getInt();
145  if (context)
146  {
147  x1 += context->GetX();
148  x2 += context->GetX();
149  y1 += context->GetY();
150  y2 += context->GetY();
151  }
152  return new C4FindObjectOnLine(x1, y1, x2, y2);
153  }
154 
155  case C4FO_Distance:
156  {
157  int32_t x = Data[1].getInt();
158  int32_t y = Data[2].getInt();
159  if (context)
160  {
161  x += context->GetX();
162  y += context->GetY();
163  }
164  return new C4FindObjectDistance(x, y, Data[3].getInt());
165  }
166 
167  case C4FO_Cone:
168  {
169  int32_t x = Data[1].getInt();
170  int32_t y = Data[2].getInt();
171  if (context)
172  {
173  x += context->GetX();
174  y += context->GetY();
175  }
176  return new C4FindObjectCone(x, y, Data[3].getInt(), Data[4].getInt(), Data[5].getInt(), Data[6].getInt());
177  }
178 
179  case C4FO_OCF:
180  return new C4FindObjectOCF(Data[1].getInt());
181 
182  case C4FO_Category:
183  return new C4FindObjectCategory(Data[1].getInt());
184 
185  case C4FO_Action:
186  {
187  C4String *pStr = Data[1].getStr();
188  if (!pStr) return nullptr;
189  // Don't copy, it should be safe
190  return new C4FindObjectAction(pStr->GetCStr());
191  }
192 
193  case C4FO_Func:
194  {
195  // Get function name
196  C4String *pStr = Data[1].getStr();
197  if (!pStr) return nullptr;
198  // Construct
199  C4FindObjectFunc *pFO = new C4FindObjectFunc(pStr);
200  // Add parameters
201  for (int i = 2; i < Data.GetSize(); i++)
202  pFO->SetPar(i - 2, Data[i]);
203  // Done
204  return pFO;
205  }
206 
207  case C4FO_ActionTarget:
208  {
209  int index = 0;
210  if (Data.GetSize() >= 3)
211  index = Clamp(Data[2].getInt(), 0, 1);
212  return new C4FindObjectActionTarget(Data[1].getObj(), index);
213  }
214 
215  case C4FO_Procedure:
216  return new C4FindObjectProcedure(Data[1].getStr());
217 
218  case C4FO_Container:
219  return new C4FindObjectContainer(Data[1].getObj());
220 
221  case C4FO_AnyContainer:
222  return new C4FindObjectAnyContainer();
223 
224  case C4FO_Owner:
225  return new C4FindObjectOwner(Data[1].getInt());
226 
227  case C4FO_Controller:
228  return new C4FindObjectController(Data[1].getInt());
229 
230  case C4FO_Layer:
231  // explicit layer check given. do not add implicit layer check
232  if (has_layer_check) *has_layer_check = true;
233  return new C4FindObjectLayer(Data[1].getObj());
234 
235  case C4FO_InArray:
236  return new C4FindObjectInArray(Data[1].getArray());
237 
238  case C4FO_Property:
239  {
240  // Get property name
241  C4String *pStr = Data[1].getStr();
242  if (!pStr) return nullptr;
243  // Construct
244  C4FindObjectProperty *pFO = Data.GetSize() >= 3
245  ? new C4FindObjectProperty(pStr, Data[2])
246  : new C4FindObjectProperty(pStr);
247  // Done
248  return pFO;
249  }
250 
251  case C4FO_AnyLayer:
252  // do not add implicit layer check
253  if (has_layer_check) *has_layer_check = true;
254  return nullptr;
255 
256  }
257  return nullptr;
258 }
friend class C4FindObjectNot
Definition: C4FindObject.h:71
static C4FindObject * CreateByValue(const C4Value &Data, C4SortObject **ppSortObj=nullptr, const C4Object *context=nullptr, bool *has_layer_check=nullptr)
int32_t GetX() const
Definition: C4Object.h:287
C4ValueArray * getArray() const
Definition: C4Value.h:118
Definition: C4Rect.h:27
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
friend class C4FindObjectAnd
Definition: C4FindObject.h:72
const char * GetCStr() const
Definition: C4StringTable.h:49
int32_t GetSize() const
Definition: C4ValueArray.h:36
int32_t GetY() const
Definition: C4Object.h:288
void SetPar(int i, const C4Value &val)
friend class C4FindObjectOr
Definition: C4FindObject.h:73
static C4SortObject * CreateByValue(const C4Value &Data, const C4Object *context=nullptr)
int iSize
Definition: TstC4NetIO.cpp:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Find() [1/2]

C4Object * C4FindObject::Find ( const C4ObjectList Objs)
inherited

Definition at line 275 of file C4FindObject.cpp.

References C4FindObject::Check(), C4SortObject::Compare(), and C4FindObject::IsImpossible().

Referenced by C4FindObject::Find().

276 {
277  // Trivial case
278  if (IsImpossible())
279  return nullptr;
280  // Search
281  // Double-check object status, as object might be deleted after Check()!
282  C4Object *pBestResult = nullptr;
283  for (C4Object *obj : Objs)
284  if (obj->Status)
285  if (Check(obj))
286  if (obj->Status)
287  {
288  // no sorting: Use first object found
289  if (!pSort) return obj;
290  // Sorting: Check if found object is better
291  if (!pBestResult || pSort->Compare(obj, pBestResult) > 0)
292  if (obj->Status)
293  pBestResult = obj;
294  }
295  return pBestResult;
296 }
virtual int32_t Compare(C4Object *pObj1, C4Object *pObj2)=0
virtual bool IsImpossible()
Definition: C4FindObject.h:97
virtual bool Check(C4Object *pObj)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Find() [2/2]

C4Object * C4FindObject::Find ( const C4ObjectList Objs,
const C4LSectors Sct 
)
inherited

Definition at line 371 of file C4FindObject.cpp.

References C4SortObject::Compare(), C4FindObject::Find(), C4LArea::FirstObjects(), C4LArea::FirstObjectShapes(), C4FindObject::GetBounds(), C4FindObject::IsImpossible(), C4LArea::NextObjects(), C4LArea::NextObjectShapes(), Objects, C4GameObjects::Sectors, C4PropList::Status, and C4FindObject::UseShapes().

372 {
373  // Trivial case
374  if (IsImpossible())
375  return nullptr;
376  C4Object *pBestResult = nullptr;
377  // Check bounds
378  C4Rect *pBounds = GetBounds();
379  if (!pBounds)
380  return Find(Objs);
381  // Traverse areas, return first matching object w/o sort or best with sort
382  else if (UseShapes())
383  {
384  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
385  C4Object *pObj;
386  for (C4ObjectList *pLst=Area.FirstObjectShapes(&pSct); pLst; pLst=Area.NextObjectShapes(pLst, &pSct))
387  if ((pObj = Find(*pLst)))
388  {
389  if (!pSort)
390  return pObj;
391  else if (!pBestResult || pSort->Compare(pObj, pBestResult) > 0)
392  if (pObj->Status)
393  pBestResult = pObj;
394  }
395  }
396  else
397  {
398  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
399  C4Object *pObj;
400  for (C4ObjectList *pLst=Area.FirstObjects(&pSct); pLst; pLst=Area.NextObjects(pLst, &pSct))
401  {
402  if ((pObj = Find(*pLst)))
403  {
404  if (!pSort)
405  return pObj;
406  else if (!pBestResult || pSort->Compare(pObj, pBestResult) > 0)
407  if (pObj->Status)
408  pBestResult = pObj;
409  }
410  }
411  }
412  return pBestResult;
413 }
virtual bool UseShapes()
Definition: C4FindObject.h:96
Definition: C4Rect.h:27
virtual C4Rect * GetBounds()
Definition: C4FindObject.h:95
virtual int32_t Compare(C4Object *pObj1, C4Object *pObj2)=0
virtual bool IsImpossible()
Definition: C4FindObject.h:97
int32_t Status
Definition: C4PropList.h:168
C4LSectors Sectors
Definition: C4GameObjects.h:42
C4Object * Find(const C4ObjectList &Objs)
C4GameObjects Objects
Definition: C4Globals.cpp:48
Here is the call graph for this function:

◆ FindMany() [1/2]

C4ValueArray * C4FindObject::FindMany ( const C4ObjectList Objs)
inherited

Definition at line 299 of file C4FindObject.cpp.

References C4VObj(), C4FindObject::Check(), C4ValueArray::GetSize(), C4FindObject::IsImpossible(), iSize, C4ValueArray::SetSize(), and C4SortObject::SortObjects().

Referenced by C4EditCursor::DoContextMenu(), C4FindObject::FindMany(), and C4Landscape::P::PrepareFreeShape().

300 {
301  // Trivial case
302  if (IsImpossible())
303  return new C4ValueArray();
304  // Set up array
305  C4ValueArray *pArray = new C4ValueArray(32);
306  int32_t iSize = 0;
307  // Search
308  for (C4Object *obj : Objs)
309  if (obj->Status)
310  if (Check(obj))
311  {
312  // Grow the array, if neccessary
313  if (iSize >= pArray->GetSize())
314  pArray->SetSize(iSize * 2);
315  // Add object
316  (*pArray)[iSize++] = C4VObj(obj);
317  }
318  // Shrink array
319  pArray->SetSize(iSize);
320  // Recheck object status (may shrink array again)
321  CheckObjectStatus(pArray);
322  // Apply sorting
323  if (pSort) pSort->SortObjects(pArray);
324  return pArray;
325 }
void SortObjects(C4ValueArray *pArray)
C4Value C4VObj(C4Object *pObj)
Definition: C4Value.cpp:88
void SetSize(int32_t inSize)
virtual bool IsImpossible()
Definition: C4FindObject.h:97
int32_t GetSize() const
Definition: C4ValueArray.h:36
virtual bool Check(C4Object *pObj)=0
int iSize
Definition: TstC4NetIO.cpp:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindMany() [2/2]

C4ValueArray * C4FindObject::FindMany ( const C4ObjectList Objs,
const C4LSectors Sct 
)
inherited

Definition at line 416 of file C4FindObject.cpp.

References C4VObj(), C4FindObject::Check(), C4FindObject::FindMany(), C4LArea::FirstObjects(), C4LArea::FirstObjectShapes(), C4FindObject::GetBounds(), C4ValueArray::GetItem(), C4GameObjects::GetNextMarker(), C4Value::getObj(), C4ValueArray::GetSize(), C4FindObject::IsImpossible(), iSize, C4LArea::Next(), C4LArea::NextObjects(), C4LArea::NextObjectShapes(), Objects, C4LSector::ObjectShapes, C4GameObjects::Sectors, C4ValueArray::SetSize(), C4SortObject::SortObjects(), C4PropList::Status, and C4FindObject::UseShapes().

417 {
418  // Trivial case
419  if (IsImpossible())
420  return new C4ValueArray();
421  C4Rect *pBounds = GetBounds();
422  if (!pBounds)
423  return FindMany(Objs);
424  // Prepare for array that may be generated
425  C4ValueArray *pArray; int32_t iSize;
426  // Check shape lists?
427  if (UseShapes())
428  {
429  // Get area
430  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
431  C4ObjectList *pLst = Area.FirstObjectShapes(&pSct);
432  // Check if a single-sector check is enough
433  if (!Area.Next(pSct))
434  return FindMany(pSct->ObjectShapes);
435  // Set up array
436  pArray = new C4ValueArray(32); iSize = 0;
437  // Create marker, search all areas
438  uint32_t iMarker = ::Objects.GetNextMarker();
439  for (; pLst; pLst=Area.NextObjectShapes(pLst, &pSct))
440  for (C4Object *obj : *pLst)
441  if (obj->Status)
442  if (obj->Marker != iMarker)
443  {
444  obj->Marker = iMarker;
445  if (Check(obj))
446  {
447  // Grow the array, if neccessary
448  if (iSize >= pArray->GetSize())
449  pArray->SetSize(iSize * 2);
450  // Add object
451  (*pArray)[iSize++] = C4VObj(obj);
452  }
453  }
454  }
455  else
456  {
457  // Set up array
458  pArray = new C4ValueArray(32); iSize = 0;
459  // Search
460  C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct;
461  for (C4ObjectList *pLst=Area.FirstObjects(&pSct); pLst; pLst=Area.NextObjects(pLst, &pSct))
462  for (C4Object *obj : *pLst)
463  if (obj->Status)
464  if (Check(obj))
465  {
466  // Grow the array, if neccessary
467  if (iSize >= pArray->GetSize())
468  pArray->SetSize(iSize * 2);
469  // Add object
470  (*pArray)[iSize++] = C4VObj(obj);
471  }
472  }
473  // Shrink array
474  pArray->SetSize(iSize);
475  // Recheck object status (may shrink array again)
476  CheckObjectStatus(pArray);
477  // Apply sorting
478  if (pSort) pSort->SortObjects(pArray);
479  return pArray;
480 }
virtual bool UseShapes()
Definition: C4FindObject.h:96
void SortObjects(C4ValueArray *pArray)
Definition: C4Rect.h:27
virtual C4Rect * GetBounds()
Definition: C4FindObject.h:95
C4Value C4VObj(C4Object *pObj)
Definition: C4Value.cpp:88
C4ValueArray * FindMany(const C4ObjectList &Objs)
uint32_t GetNextMarker()
void SetSize(int32_t inSize)
virtual bool IsImpossible()
Definition: C4FindObject.h:97
int32_t GetSize() const
Definition: C4ValueArray.h:36
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSectors Sectors
Definition: C4GameObjects.h:42
virtual bool Check(C4Object *pObj)=0
C4GameObjects Objects
Definition: C4Globals.cpp:48
int iSize
Definition: TstC4NetIO.cpp:32
Here is the call graph for this function:

◆ GetBounds()

C4Rect* C4FindObjectOr::GetBounds ( )
inlineoverrideprotectedvirtual

Reimplemented from C4FindObject.

Definition at line 157 of file C4FindObject.h.

157 { return fHasBounds ? &Bounds : nullptr; }

◆ IsEnsured()

bool C4FindObjectOr::IsEnsured ( )
overrideprotectedvirtual

Reimplemented from C4FindObject.

Definition at line 633 of file C4FindObject.cpp.

634 {
635  for (int32_t i = 0; i < iCnt; i++)
636  if (ppConds[i]->IsEnsured())
637  return true;
638  return false;
639 }
bool IsEnsured() override

◆ IsImpossible()

bool C4FindObjectOr::IsImpossible ( )
inlineoverrideprotectedvirtual

Reimplemented from C4FindObject.

Definition at line 160 of file C4FindObject.h.

References iCnt.

Referenced by C4FindObjectOr().

160 { return !iCnt; }
Here is the caller graph for this function:

◆ SetSort()

void C4FindObject::SetSort ( C4SortObject pToSort)
inherited

Definition at line 499 of file C4FindObject.cpp.

Referenced by CreateCriterionsFromPars().

500 {
501  delete pSort;
502  pSort = pToSort;
503 }
Here is the caller graph for this function:

◆ UseShapes()

bool C4FindObjectOr::UseShapes ( )
inlineoverrideprotectedvirtual

Reimplemented from C4FindObject.

Definition at line 158 of file C4FindObject.h.

References C4FindObject::IsEnsured().

Referenced by C4FindObjectOr().

158 { return fUseShapes; }
Here is the call graph for this function:
Here is the caller graph for this function:

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