OpenClonk
C4GameObjects Class Reference

#include <C4GameObjects.h>

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

Public Types

enum  SortType { stNone = 0 , stMain , stContents , stReverse }
 
typedef int SortProc(C4Object *, C4Object *)
 

Public Member Functions

 C4GameObjects ()
 
 ~C4GameObjects () override
 
void Default () override
 
void Init (int32_t width, int32_t height)
 
void Clear (bool fClearInactive)
 
void Clear () override
 
bool Add (C4Object *game_object)
 
bool Remove (C4Object *game_object) override
 
void CrossCheck ()
 
void Synchronize ()
 
void UpdateSolidMasks ()
 
C4ObjectObjectPointer (int32_t object_number)
 
C4ObjectSafeObjectPointer (int32_t object_number)
 
int PostLoad (bool keep_inactive_objects, C4ValueNumbers *)
 
void Denumerate (C4ValueNumbers *)
 
void UpdateScriptPointers ()
 
C4Value GRBroadcast (const char *function_name, C4AulParSet *parameters, bool pass_error, bool reject_test)
 
void UpdatePos (C4Object *game_object)
 
void UpdatePosResort (C4Object *game_object)
 
void FixObjectOrder ()
 
void ResortUnsorted ()
 
void DeleteObjects (bool delete_inactive_objects)
 
bool ValidateOwners () override
 
bool AssignInfo () override
 
void AssignLightRange ()
 
void SyncClearance ()
 
void ResetAudibility ()
 
void OnSynchronized ()
 
void SetOCF ()
 
uint32_t GetNextMarker ()
 
virtual bool Add (C4Object *new_obj, SortType sort_type, C4ObjectList *sorted_list=nullptr)
 
iterator begin () const
 
const iterator end () const
 
const ReverseView reverse () const
 
void Sort ()
 
void Copy (const C4ObjectList &list)
 
void DrawIfCategory (C4TargetFacet &cgo, int player, uint32_t dwCategory, bool invert)
 
void Draw (C4TargetFacet &cgo, int player, int MinPlane, int MaxPlane)
 
void DrawSelectMark (C4TargetFacet &cgo) const
 
void CloseMenus ()
 
void UpdateGraphics (bool graphics_changed)
 
void UpdateFaces (bool update_shape)
 
void ClearInfo (C4ObjectInfo *info)
 
virtual bool Add (C4Object *new_obj, SortType sort_type, C4ObjectList *sorted_list=nullptr)
 
bool AddSortCustom (C4Object *new_obj, SortProc &pSortProc)
 
StdStrBuf GetNameList (C4DefList &defs) const
 
bool IsClear () const
 
bool DenumeratePointers ()
 
bool Write (char *szTarget)
 
void CompileFunc (StdCompiler *pComp, C4ValueNumbers *=nullptr)
 
void CompileFunc (StdCompiler *pComp, bool skip_player_objects, C4ValueNumbers *)
 
bool IsContained (const C4Object *obj) const
 
int ClearPointers (C4Object *obj)
 
int ObjectCount (C4ID id=C4ID::None) const
 
int MassCount ()
 
int ListIDCount (int32_t dwCategory) const
 
C4ObjectGetObject (int index=0) const
 
C4ObjectGetFirstObject () const
 
C4ObjectGetLastObject () const
 
C4ObjectFind (C4Def *def, int owner=ANY_OWNER, DWORD dwOCF=OCF_All)
 
C4ObjectFindOther (C4ID id, int owner=ANY_OWNER)
 
const C4ObjectLinkGetLink (const C4Object *obj) const
 
C4ObjectLinkGetLink (const C4Object *obj)
 
C4ID GetListID (int32_t dwCategory, int index) const
 
bool ShiftContents (C4Object *new_first)
 
void DeleteObjects ()
 
bool CheckSort (C4ObjectList *list)
 
void CheckCategorySort ()
 

Public Attributes

C4LSectors Sectors
 
C4ObjectList InactiveObjects
 
C4ObjectList ForeObjects
 
C4ObjectLinkFirst
 
C4ObjectLinkLast
 
int Mass
 
std::list< int32_t > * pEnumerated
 

Protected Member Functions

void InsertLinkBefore (C4ObjectLink *link, C4ObjectLink *before_link) override
 
void InsertLink (C4ObjectLink *link, C4ObjectLink *after_link) override
 
void RemoveLink (C4ObjectLink *link) override
 
iteratorAddIter (iterator *iter) const
 
void RemoveIter (iterator *iter) const
 

Protected Attributes

iteratorFirstIter {nullptr}
 

Detailed Description

Definition at line 26 of file C4GameObjects.h.

Member Typedef Documentation

◆ SortProc

typedef int C4ObjectList::SortProc(C4Object *, C4Object *)
inherited

Definition at line 118 of file C4ObjectList.h.

Member Enumeration Documentation

◆ SortType

enum C4ObjectList::SortType
inherited
Enumerator
stNone 
stMain 
stContents 
stReverse 

Definition at line 55 of file C4ObjectList.h.

Constructor & Destructor Documentation

◆ C4GameObjects()

C4GameObjects::C4GameObjects ( )

Definition at line 32 of file C4GameObjects.cpp.

33 {
34  Default();
35 }
void Default() override

References Default().

Here is the call graph for this function:

◆ ~C4GameObjects()

C4GameObjects::~C4GameObjects ( )
override

Definition at line 37 of file C4GameObjects.cpp.

38 {
39  Sectors.Clear();
40 }
C4LSectors Sectors
Definition: C4GameObjects.h:42
void Clear()
Definition: C4Sector.cpp:74

References C4LSectors::Clear(), and Sectors.

Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/3]

bool C4GameObjects::Add ( C4Object game_object)

Definition at line 55 of file C4GameObjects.cpp.

56 {
57  // Add inactive objects to the inactive list only
58  if (object->Status == C4OS_INACTIVE)
59  {
61  }
62  // If this is a foreground object, add it to the list
63  if (object->Category & C4D_Foreground)
64  {
66  }
67  // Manipulate main list
69  return false;
70  // Add to sectors
71  Sectors.Add(object, this);
72  return true;
73 }
const int32_t C4D_Foreground
Definition: C4Def.h:53
#define C4OS_INACTIVE
Definition: C4Object.h:36
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:91
virtual bool Add(C4Object *new_obj, SortType sort_type, C4ObjectList *sorted_list=nullptr)

References C4ObjectList::Add(), C4LSectors::Add(), C4D_Foreground, C4OS_INACTIVE, C4Object::Category, ForeObjects, InactiveObjects, Sectors, C4PropList::Status, and C4ObjectList::stMain.

Referenced by C4Object::AssignRemoval(), C4Game::NewObject(), and C4Object::StatusActivate().

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

◆ Add() [2/3]

bool C4ObjectList::Add

Definition at line 120 of file C4ObjectList.cpp.

165 {
166  if (!new_obj || !new_obj->Def || !new_obj->Status)
167  {
168  return false;
169  }
170 
171 #ifdef _DEBUG
172  if (sort_type == stMain)
173  {
175  if (sorted_list)
176  {
177  assert(CheckSort(sorted_list));
178  }
179  }
180 #endif
181 
182  // Debug: don't do double links
183  assert(!GetLink(new_obj));
184 
185  // No self-sort
186  assert(sorted_list != this);
187 
188  // Allocate new link
189  C4ObjectLink *new_link = new C4ObjectLink;
190  if (!new_link)
191  {
192  return false;
193  }
194  // Set link
195  new_link->Obj = new_obj;
196 
197  // Search insert position (default: end of list)
198  C4ObjectLink *current = nullptr;
199  C4ObjectLink *previous = Last;
200 
201  // Should sort?
202  if (sort_type == stReverse)
203  {
204  // Reverse sort: Add to beginning of list
205  current = First;
206  previous = nullptr;
207  }
208  else if (sort_type)
209  {
210  // Sort override? Leave default as is.
211  bool is_sorted = !(new_obj->Unsorted);
212  if (is_sorted)
213  {
214  // Sort by master list?
215  if (sorted_list)
216  {
217  previous = nullptr;
218  current = First;
219  while (current && (!current->Obj->Status || current->Obj->Unsorted))
220  {
221  current = current->Next;
222  }
223 
224 #ifndef _DEBUG
225  if (current)
226 #endif
227  {
228  C4ObjectLink* link2;
229  for (link2 = sorted_list->First; link2; link2 = link2->Next)
230  {
231  if (link2->Obj->Status && !link2->Obj->Unsorted)
232  {
233  if (link2->Obj == new_obj)
234  {
235  assert(!current || current->Obj != new_obj);
236  break;
237  }
238 
239  if (current && link2->Obj == current->Obj)
240  {
241  previous = current;
242  current = current->Next;
243  while (current && (!current->Obj->Status || current->Obj->Unsorted))
244  {
245  current = current->Next;
246  }
247 
248 #ifndef _DEBUG
249  if (!current)
250  {
251  break;
252  }
253 #endif
254  }
255  }
256  }
257 
258  assert(link2 != nullptr);
259  }
260  }
261  else
262  {
263  // No master list: Find successor by matching Plane / id
264  // Sort by matching Plane/id is necessary for inventory shifting.
265  // It is not done for static back to allow multiobject outside structure.
266  // Unsorted objects are ignored in comparison.
267  if (!(new_obj->Category & C4D_StaticBack))
268  {
269  for (previous = nullptr, current = First; current; current = current->Next)
270  {
271  if (current->Obj->Status && !current->Obj->Unsorted)
272  {
273  if ((current->Obj->GetPlane() == new_obj->GetPlane())
274  && (current->Obj->id == new_obj->id))
275  {
276  break;
277  }
278  previous = current;
279  }
280  }
281  }
282 
283  // Find successor by relative category
284  if (!current)
285  {
286  for (previous = nullptr, current = First; current; current = current->Next)
287  {
288  if (current->Obj->Status && !current->Obj->Unsorted)
289  {
290  if (current->Obj->GetPlane() <= new_obj->GetPlane())
291  {
292  break;
293  }
294  previous = current;
295  }
296  }
297  }
298  }
299 
300  current = previous ? previous->Next : First;
301  }
302  }
303 
304  assert(!previous || previous->Next == current);
305  assert(!current || current->Prev == previous);
306 
307  // Insert new link after predecessor
308  InsertLink(new_link, previous);
309 
310 #ifdef _DEBUG
311  // Debug: Check sort
312  if (sort_type == stMain)
313  {
315  if (sorted_list)
316  {
317  assert(CheckSort(sorted_list));
318  }
319  }
320 #endif
321 
322  // Add mass
323  Mass += new_obj->Mass;
324 
325  return true;
326 }
const int32_t C4D_StaticBack
Definition: C4Def.h:40
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Object * Obj
Definition: C4ObjectList.h:28
void InsertLink(C4ObjectLink *link, C4ObjectLink *after_link) override
C4ID id
Definition: C4Object.h:106
bool Unsorted
Definition: C4Object.h:127
int32_t GetPlane() const
Definition: C4Object.h:179
C4ObjectLink * First
Definition: C4ObjectList.h:51
const C4ObjectLink * GetLink(const C4Object *obj) const
C4ObjectLink * Last
Definition: C4ObjectList.h:51
void CheckCategorySort()
bool CheckSort(C4ObjectList *list)
int32_t Status
Definition: C4PropList.h:173

References C4ID::None, and TempListID.

Referenced by ResortUnsorted().

Here is the caller graph for this function:

◆ Add() [3/3]

bool C4ObjectList::Add ( C4Object new_obj,
SortType  sort_type,
C4ObjectList sorted_list = nullptr 
)
virtualinherited

Definition at line 164 of file C4ObjectList.cpp.

165 {
166  if (!new_obj || !new_obj->Def || !new_obj->Status)
167  {
168  return false;
169  }
170 
171 #ifdef _DEBUG
172  if (sort_type == stMain)
173  {
175  if (sorted_list)
176  {
177  assert(CheckSort(sorted_list));
178  }
179  }
180 #endif
181 
182  // Debug: don't do double links
183  assert(!GetLink(new_obj));
184 
185  // No self-sort
186  assert(sorted_list != this);
187 
188  // Allocate new link
189  C4ObjectLink *new_link = new C4ObjectLink;
190  if (!new_link)
191  {
192  return false;
193  }
194  // Set link
195  new_link->Obj = new_obj;
196 
197  // Search insert position (default: end of list)
198  C4ObjectLink *current = nullptr;
199  C4ObjectLink *previous = Last;
200 
201  // Should sort?
202  if (sort_type == stReverse)
203  {
204  // Reverse sort: Add to beginning of list
205  current = First;
206  previous = nullptr;
207  }
208  else if (sort_type)
209  {
210  // Sort override? Leave default as is.
211  bool is_sorted = !(new_obj->Unsorted);
212  if (is_sorted)
213  {
214  // Sort by master list?
215  if (sorted_list)
216  {
217  previous = nullptr;
218  current = First;
219  while (current && (!current->Obj->Status || current->Obj->Unsorted))
220  {
221  current = current->Next;
222  }
223 
224 #ifndef _DEBUG
225  if (current)
226 #endif
227  {
228  C4ObjectLink* link2;
229  for (link2 = sorted_list->First; link2; link2 = link2->Next)
230  {
231  if (link2->Obj->Status && !link2->Obj->Unsorted)
232  {
233  if (link2->Obj == new_obj)
234  {
235  assert(!current || current->Obj != new_obj);
236  break;
237  }
238 
239  if (current && link2->Obj == current->Obj)
240  {
241  previous = current;
242  current = current->Next;
243  while (current && (!current->Obj->Status || current->Obj->Unsorted))
244  {
245  current = current->Next;
246  }
247 
248 #ifndef _DEBUG
249  if (!current)
250  {
251  break;
252  }
253 #endif
254  }
255  }
256  }
257 
258  assert(link2 != nullptr);
259  }
260  }
261  else
262  {
263  // No master list: Find successor by matching Plane / id
264  // Sort by matching Plane/id is necessary for inventory shifting.
265  // It is not done for static back to allow multiobject outside structure.
266  // Unsorted objects are ignored in comparison.
267  if (!(new_obj->Category & C4D_StaticBack))
268  {
269  for (previous = nullptr, current = First; current; current = current->Next)
270  {
271  if (current->Obj->Status && !current->Obj->Unsorted)
272  {
273  if ((current->Obj->GetPlane() == new_obj->GetPlane())
274  && (current->Obj->id == new_obj->id))
275  {
276  break;
277  }
278  previous = current;
279  }
280  }
281  }
282 
283  // Find successor by relative category
284  if (!current)
285  {
286  for (previous = nullptr, current = First; current; current = current->Next)
287  {
288  if (current->Obj->Status && !current->Obj->Unsorted)
289  {
290  if (current->Obj->GetPlane() <= new_obj->GetPlane())
291  {
292  break;
293  }
294  previous = current;
295  }
296  }
297  }
298  }
299 
300  current = previous ? previous->Next : First;
301  }
302  }
303 
304  assert(!previous || previous->Next == current);
305  assert(!current || current->Prev == previous);
306 
307  // Insert new link after predecessor
308  InsertLink(new_link, previous);
309 
310 #ifdef _DEBUG
311  // Debug: Check sort
312  if (sort_type == stMain)
313  {
315  if (sorted_list)
316  {
317  assert(CheckSort(sorted_list));
318  }
319  }
320 #endif
321 
322  // Add mass
323  Mass += new_obj->Mass;
324 
325  return true;
326 }
int32_t Category
Definition: C4Object.h:111
int32_t Mass
Definition: C4Object.h:113
C4Def * Def
Definition: C4Object.h:141
virtual void InsertLink(C4ObjectLink *link, C4ObjectLink *after_link)

References C4D_StaticBack, C4Object::Category, C4ObjectList::CheckCategorySort(), C4ObjectList::CheckSort(), C4Object::Def, C4ObjectList::First, C4ObjectList::GetLink(), C4Object::GetPlane(), C4Object::id, C4ObjectList::InsertLink(), C4ObjectList::Last, C4Object::Mass, C4ObjectList::Mass, C4ObjectLink::Next, C4ObjectLink::Obj, C4ObjectLink::Prev, C4PropList::Status, C4ObjectList::stMain, C4ObjectList::stReverse, and C4Object::Unsorted.

Referenced by Add(), C4LSectors::Add(), C4ObjectList::CompileFunc(), C4ObjectList::Copy(), C4ObjectList::DenumeratePointers(), C4Object::Enter(), C4Player::MakeCrewMember(), C4Player::PlaceReadyCrew(), PostLoad(), C4Object::StatusDeactivate(), C4LSectors::Update(), and C4MouseControl::UpdateSingleSelection().

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

◆ AddIter()

C4ObjectList::iterator * C4ObjectList::AddIter ( iterator iter) const
protectedinherited

Definition at line 1238 of file C4ObjectList.cpp.

1239 {
1240  iterator * r = FirstIter;
1241  FirstIter = iter;
1242  return r;
1243 }
friend class iterator
Definition: C4ObjectList.h:169
iterator * FirstIter
Definition: C4ObjectList.h:165

References C4ObjectList::FirstIter.

Referenced by C4ObjectList::iterator::iterator().

Here is the caller graph for this function:

◆ AddSortCustom()

bool C4ObjectList::AddSortCustom ( C4Object new_obj,
SortProc pSortProc 
)
inherited

◆ AssignInfo()

bool C4GameObjects::AssignInfo ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 563 of file C4GameObjects.cpp.

564 {
565  // Assign in sublists
566  // Note: Both functions need to be called,
567  // before the evaluation. Do not call foo() && bar()
568  // because then only foo() will be evaluated.
569  bool object_list_assigned = C4ObjectList::AssignInfo();
570  bool inactive_objects_assigned = InactiveObjects.AssignInfo();
571  return object_list_assigned && inactive_objects_assigned;
572 }
virtual bool AssignInfo()

References C4ObjectList::AssignInfo(), and InactiveObjects.

Referenced by C4Game::InitGameFinal().

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

◆ AssignLightRange()

void C4GameObjects::AssignLightRange ( )

Definition at line 574 of file C4GameObjects.cpp.

575 {
576  for (C4Object *object : reverse())
577  {
578  if (object->Status)
579  {
580  object->AssignLightRange();
581  }
582  }
583 }
const ReverseView reverse() const
Definition: C4ObjectList.h:104

References C4ObjectList::reverse().

Referenced by C4Game::InitGameFinal().

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

◆ begin()

C4ObjectList::iterator C4ObjectList::begin ( ) const
inherited

Definition at line 1230 of file C4ObjectList.cpp.

1231 {
1232  return iterator(*this, First, false);
1233 }

References C4ObjectList::First, and C4ObjectList::iterator.

Referenced by PostLoad(), and C4Object::ShiftContents().

Here is the caller graph for this function:

◆ CheckCategorySort()

void C4ObjectList::CheckCategorySort ( )
inherited

Definition at line 1126 of file C4ObjectList.cpp.

1127 {
1128  // debug: Check whether object list is sorted correctly
1129  C4ObjectLink *link;
1130  C4ObjectLink *previous = nullptr;
1131  for (link = First; link; link = link->Next)
1132  {
1133  if (!link->Obj->Unsorted && link->Obj->Status)
1134  {
1135  if (previous)
1136  {
1137  assert(previous->Obj->GetPlane() >= link->Obj->GetPlane());
1138  }
1139  previous = link;
1140  }
1141  }
1142 }

References C4ObjectList::First, C4Object::GetPlane(), C4ObjectLink::Next, C4ObjectLink::Obj, C4PropList::Status, and C4Object::Unsorted.

Referenced by C4ObjectList::Add().

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

◆ CheckSort()

bool C4ObjectList::CheckSort ( C4ObjectList list)
inherited

Definition at line 1091 of file C4ObjectList.cpp.

1092 {
1093  C4ObjectLink *link = First;
1094  C4ObjectLink *compare_link = list->First;
1095  while (link && (!link->Obj->Status || link->Obj->Unsorted))
1096  {
1097  link = link->Next;
1098  }
1099 
1100  while (link)
1101  {
1102  if (!compare_link)
1103  {
1104  Log("CheckSort failure");
1105  C4ValueNumbers numbers;
1106  LogSilent(DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(C4ObjectListDumpHelper(this, &numbers), "SectorList")).getData());
1107  LogSilent(DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(C4ObjectListDumpHelper(list, &numbers), "MainList")).getData());
1108  return false;
1109  }
1110  else
1111  {
1112  if (link->Obj == compare_link->Obj)
1113  {
1114  link = link->Next;
1115  while (link && (!link->Obj->Status || link->Obj->Unsorted))
1116  {
1117  link = link->Next;
1118  }
1119  }
1120  compare_link = compare_link->Next;
1121  }
1122 }
1123  return true;
1124 }
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:126
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92

References C4ObjectList::First, Log(), LogSilent(), mkNamingAdapt(), C4ObjectLink::Next, C4ObjectLink::Obj, C4PropList::Status, and C4Object::Unsorted.

Referenced by C4ObjectList::Add(), and C4LSectors::CheckSort().

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

◆ Clear() [1/2]

void C4GameObjects::Clear ( )
inlineoverridevirtual

Reimplemented from C4ObjectList.

Definition at line 36 of file C4GameObjects.h.

36 { Clear(false); }
void Clear() override
Definition: C4GameObjects.h:36

References Clear().

Referenced by Clear().

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

◆ Clear() [2/2]

void C4GameObjects::Clear ( bool  fClearInactive)

Definition at line 263 of file C4GameObjects.cpp.

264 {
265  DeleteObjects(clear_inactive_objects);
266  if (clear_inactive_objects)
267  {
269  }
270  LastUsedMarker = 0;
271 }
virtual void Clear()
void DeleteObjects()

References C4ObjectList::Clear(), C4ObjectList::DeleteObjects(), and InactiveObjects.

Referenced by C4Game::CompileRuntimeData().

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

◆ ClearInfo()

void C4ObjectList::ClearInfo ( C4ObjectInfo info)
inherited

Definition at line 748 of file C4ObjectList.cpp.

749 {
750  C4ObjectLink *link;
751  for (link = First; link; link = link->Next)
752  {
753  if (link->Obj->Status)
754  {
755  link->Obj->ClearInfo(pInfo);
756  }
757  }
758 }
void ClearInfo(C4ObjectInfo *pInfo)
Definition: C4Object.cpp:1075

References C4Object::ClearInfo(), C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, and C4PropList::Status.

Referenced by C4ObjectInfoList::DetachFromObjects().

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

◆ ClearPointers()

int C4ObjectList::ClearPointers ( C4Object obj)
inherited

Definition at line 481 of file C4ObjectList.cpp.

482 {
483  int removed_amount = 0;
484  // Clear all primary list pointers
485  while (Remove(obj))
486  {
487  removed_amount++;
488  }
489  // Clear all sub pointers
490  C4Object *current_obj;
491  C4ObjectLink *link;
492  for (link = First; link && (current_obj = link->Obj); link = link->Next)
493  {
494  current_obj->ClearPointers(obj);
495  }
496  return removed_amount;
497 }
virtual bool Remove(C4Object *obj)

References C4Object::ClearPointers(), C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, and C4ObjectList::Remove().

Referenced by C4Game::ClearPointers(), and C4MouseControl::ClearPointers().

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

◆ CloseMenus()

void C4ObjectList::CloseMenus ( )
inherited

Definition at line 933 of file C4ObjectList.cpp.

934 {
935  C4Object *obj;
936  C4ObjectLink *link;
937  for (link = First; link && (obj = link->Obj); link = link->Next)
938  {
939  obj->CloseMenu(true);
940  }
941 }

References C4Object::CloseMenu(), C4ObjectList::First, C4ObjectLink::Next, and C4ObjectLink::Obj.

Here is the call graph for this function:

◆ CompileFunc() [1/2]

void C4ObjectList::CompileFunc ( StdCompiler pComp,
bool  skip_player_objects,
C4ValueNumbers numbers 
)
inherited

Definition at line 622 of file C4ObjectList.cpp.

623 {
624  // "Object" section count
625  int32_t object_count = ObjectCount();
626  pComp->Value(mkNamingCountAdapt(object_count, "Object"));
627  if (pComp->isSerializer())
628  {
629  // skipping player objects would screw object counting in non-naming compilers
630  assert(!skip_player_objects || pComp->hasNaming());
631  // Decompile all objects in reverse order
632  for (C4ObjectLink *link = Last; link; link = link->Prev)
633  {
634  if (link->Obj->Status && (!skip_player_objects || !link->Obj->IsUserPlayerObject()))
635  {
636  pComp->Value(mkNamingAdapt(mkParAdapt(*link->Obj, numbers), "Object"));
637  }
638  }
639  }
640  else
641  {
642  // FIXME: Check that no PlayerObjects are loaded when skip_player_objects is true
643  // i.e. that loading and saving was done with the same flag.
644  // Remove previous data
645  Clear();
646  // Load objects, add them to the list.
647  for (int i = 0; i < object_count; i++)
648  {
649  C4Object *obj = nullptr;
650  try
651  {
652  pComp->Value(mkNamingAdapt(mkParAdapt(mkPtrAdaptNoNull(obj), numbers), "Object"));
653  Add(obj, stReverse);
654  }
655  catch (StdCompiler::Exception *exception)
656  {
657  // Failsafe object loading: If an error occurs during object loading, just skip that object and load the next one
658  if (!exception->Pos.getLength())
659  {
660  LogF("ERROR: Object loading: %s", exception->Msg.getData());
661  }
662  else
663  {
664  LogF("ERROR: Object loading(%s): %s", exception->Pos.getData(), exception->Msg.getData());
665  }
666  delete exception;
667  }
668  }
669  }
670 }
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:638
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:1008
int ObjectCount(C4ID id=C4ID::None) const
void Value(const T &rStruct)
Definition: StdCompiler.h:161
bool isSerializer()
Definition: StdCompiler.h:54
virtual bool hasNaming()
Definition: StdCompiler.h:58
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445

References C4ObjectList::Add(), C4ObjectList::Clear(), StdStrBuf::getData(), StdStrBuf::getLength(), StdCompiler::hasNaming(), StdCompiler::isSerializer(), C4Object::IsUserPlayerObject(), C4ObjectList::Last, LogF(), mkNamingAdapt(), mkNamingCountAdapt(), mkParAdapt(), mkPtrAdaptNoNull(), StdCompiler::Exception::Msg, C4ObjectLink::Obj, C4ObjectList::ObjectCount(), StdCompiler::Exception::Pos, C4ObjectLink::Prev, C4PropList::Status, C4ObjectList::stReverse, and StdCompiler::Value().

Here is the call graph for this function:

◆ CompileFunc() [2/2]

void C4ObjectList::CompileFunc ( StdCompiler pComp,
C4ValueNumbers numbers = nullptr 
)
inherited

Definition at line 672 of file C4ObjectList.cpp.

673 {
674  // (Re)create list
675  delete pEnumerated;
676  pEnumerated = new std::list<int32_t>();
677  // Decompiling: Build list
678  if (!pComp->isDeserializer())
679  {
680  for (C4ObjectLink *link = First; link; link = link->Next)
681  {
682  if (link->Obj->Status)
683  {
684  pEnumerated->push_back(link->Obj->Number);
685  }
686  }
687  }
688  // Compile list
690  // Decompiling: Delete list
691  if (!pComp->isDeserializer())
692  {
693  delete pEnumerated;
694  pEnumerated = nullptr;
695  }
696  // Compiling: Nothing to do - list will be denumerated later
697 }
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:713
std::list< int32_t > * pEnumerated
Definition: C4ObjectList.h:53
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References C4ObjectList::First, StdCompiler::isDeserializer(), mkSTLContainerAdapt(), C4ObjectLink::Next, C4PropListNumbered::Number, C4ObjectLink::Obj, C4ObjectList::pEnumerated, StdCompiler::SEP_SEP2, C4PropList::Status, and StdCompiler::Value().

Here is the call graph for this function:

◆ Copy()

void C4ObjectList::Copy ( const C4ObjectList list)
inherited

Definition at line 943 of file C4ObjectList.cpp.

944 {
945  Clear(); Default();
946  C4ObjectLink *link;
947  for (link = list.First; link; link = link->Next)
948  {
949  Add(link->Obj, C4ObjectList::stNone);
950  }
951 }
virtual void Default()

References C4ObjectList::Add(), C4ObjectList::Clear(), C4ObjectList::Default(), C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, and C4ObjectList::stNone.

Referenced by C4ObjectList::C4ObjectList(), C4Object::GrabContents(), and PostLoad().

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

◆ CrossCheck()

void C4GameObjects::CrossCheck ( )

Definition at line 91 of file C4GameObjects.cpp.

92 {
93  // Reverse area check: Checks for all <ball> at <goal>
94  // Using a sports metaphor here, because that is easier to visualize when reading the code
95 
96  // Only those objects that have one of the required OCFs will be checked for collision/collection.
97  // This lets us filter the objects early, so that the loop does not get too large.
98  DWORD goal_required_ocf = OCF_None | OCF_Collection | OCF_Alive;
99 
100  // Only those objects that have one of the required OCFs can cause a collision/collection
101  DWORD ball_required_ocf = OCF_None | OCF_HitSpeed2;
102  // Fewer checks for collection
103  if (!::Game.iTick3)
104  {
105  ball_required_ocf |= OCF_Carryable;
106  }
107 
108  for (C4Object* goal : *this)
109  {
110  if (goal->Status && !goal->Contained && (goal->OCF & goal_required_ocf))
111  {
112  uint32_t Marker = GetNextMarker();
113  C4LSector *sector;
114  for (C4ObjectList *in_goal_area = goal->Area.FirstObjects(&sector); in_goal_area; in_goal_area = goal->Area.NextObjects(in_goal_area, &sector))
115  {
116  for (C4Object* ball : *in_goal_area)
117  {
118  if ((ball != goal) // Ball should not hit itself,
119  && ball->Status // it cannot hit if it was deleted,
120  && !ball->Contained // it cannot hit if it is contained,
121  && (ball->OCF & ball_required_ocf) // it must have either of the required OFCs,
122  && (goal->Layer == ball->Layer) // and must be in the correct layer
123  // TODO: Instead of a custom check, use C4Rect::Contains with the correct coordinates
124  && Inside<int32_t>(ball->GetX() - (goal->GetX() + goal->Shape.x), 0, goal->Shape.Wdt - 1)
125  && Inside<int32_t>(ball->GetY() - (goal->GetY() + goal->Shape.y), 0, goal->Shape.Hgt - 1))
126  {
127  // Handle cross check only once
128  if (ball->Marker == Marker)
129  {
130  continue;
131  }
132  ball->Marker = Marker;
133 
134  // Collision check
135 
136  // Note: the layer check was already done further above.
137 
138  if ((goal->OCF & OCF_Alive) // <goal> must be alive,
139  && (ball->OCF & OCF_HitSpeed2) // <ball> is fast enough (otherwise a fast <goal> will collide when passing a non-moving ball)
140  && (ball->Category & C4D_Object)) // <ball> is an object
141  {
142  C4Real relative_xdir = ball->xdir - goal->xdir;
143  C4Real relative_ydir = ball->ydir - goal->ydir;
144  C4Real hit_speed = relative_xdir * relative_xdir + relative_ydir * relative_ydir;
145  // Only hit if the relative speed is larger than HitSpeed2, and the <goal> does not prevent getting hit
146  if ((hit_speed > HitSpeed2) && !goal->Call(PSF_QueryCatchBlow, &C4AulParSet(ball)))
147  {
148  int32_t hit_energy = fixtoi(hit_speed * ball->Mass / 5);
149  // Hit energy reduced to 1/3rd, but do not drop to zero because of this division.
150  // However, if the hit energy is low because of either speed or <ball> mass, then
151  // having it stay 0 is OK.
152  if (hit_energy != 0)
153  {
154  hit_energy = std::max(hit_energy / 3, 1);
155  }
156  // Apply damage to the goal - not sure why this is divided by 5 yet again,
157  // and this time we allow it being reduced to 0...
158  int32_t damage = -hit_energy / 5;
159  goal->DoEnergy(damage, false, C4FxCall_EngObjHit, ball->Controller);
160  // Fling it around:
161  // light objects will be flung with full speed,
162  // heavier objects will be affected less
163  int min_mass = 50;
164  int goal_mass = std::max<int32_t>(goal->Mass, min_mass);
165  C4PropList* pActionDef = goal->GetAction();
166  if (!::Game.iTick3 || (pActionDef && pActionDef->GetPropertyP(P_Procedure) != DFA_FLIGHT))
167  {
168  goal->Fling(ball->xdir * min_mass / goal_mass, -Abs(ball->ydir / 2) * min_mass / goal_mass, false);
169  }
170  // Callback with the damage value
171  goal->Call(PSF_CatchBlow, &C4AulParSet(damage, ball));
172  // <goal> might have been tampered with
173  if (!goal->Status || goal->Contained || !(goal->OCF & goal_required_ocf))
174  {
175  goto check_next_goal;
176  }
177  // Skip collection check
178  continue;
179  }
180  }
181 
182  // Collection check
183 
184  // Note: the layer check was already done further above.
185  // This is confusing, because this requires
186  // the ball to be both inside the goal shape AND the goal collection area, so
187  // collection areas that go further than the goal shape are useless, as well
188  // as collection areas that are entirely outside of the goal shape.
189 
190  if ((goal->OCF & OCF_Collection) // <goal> has a collection area?
191  && (ball->OCF & OCF_Carryable) // <ball> can be collected?
192  // TODO: Instead of a custom check, use C4Rect::Contains with the correct coordinates
193  && Inside<int32_t>(ball->GetX() - (goal->GetX() + goal->Def->Collection.x), 0, goal->Def->Collection.Wdt - 1)
194  && Inside<int32_t>(ball->GetY() - (goal->GetY() + goal->Def->Collection.y), 0, goal->Def->Collection.Hgt - 1))
195  {
196  goal->Collect(ball);
197  // <goal> might have been tampered with
198  if (!goal->Status || goal->Contained || !(goal->OCF & goal_required_ocf))
199  {
200  goto check_next_goal;
201  }
202  }
203  }
204  }
205  }
206  // Goto-marker for more obvious loop-control
207  check_next_goal: ;
208  }
209  }
210 }
const uint32_t OCF_Carryable
Definition: C4Constants.h:82
const uint32_t OCF_Collection
Definition: C4Constants.h:93
const uint32_t OCF_Alive
Definition: C4Constants.h:103
const uint32_t OCF_None
Definition: C4Constants.h:77
const uint32_t OCF_HitSpeed2
Definition: C4Constants.h:91
const int32_t C4D_Object
Definition: C4Def.h:44
#define C4FxCall_EngObjHit
Definition: C4Effect.h:57
#define PSF_CatchBlow
Definition: C4GameScript.h:72
#define PSF_QueryCatchBlow
Definition: C4GameScript.h:73
C4Game Game
Definition: C4Globals.cpp:52
const C4Real HitSpeed2
Definition: C4Physics.h:29
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
@ DFA_FLIGHT
@ P_Procedure
uint32_t DWORD
T Abs(T val)
Definition: Standard.h:42
C4Rect Collection
Definition: C4Def.h:106
Definition: C4Real.h:59
int32_t iTick3
Definition: C4Game.h:130
uint32_t GetNextMarker()
C4ObjectList * NextObjects(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:303
C4ObjectList * FirstObjects(C4LSector **ppSct)
Definition: C4Sector.h:118
C4Real ydir
Definition: C4Object.h:124
C4PropList * GetAction() const
C4Real xdir
Definition: C4Object.h:124
int32_t GetX() const
Definition: C4Object.h:285
uint32_t OCF
Definition: C4Object.h:132
void Fling(C4Real txdir, C4Real tydir, bool fAddSpeed)
C4ObjectPtr Layer
Definition: C4Object.h:134
int32_t GetY() const
Definition: C4Object.h:286
bool Collect(C4Object *pObj)
C4ObjectPtr Contained
Definition: C4Object.h:142
C4LArea Area
Definition: C4Object.h:112
C4Shape Shape
Definition: C4Object.h:146
void DoEnergy(int32_t iChange, bool fExact, int32_t iCause, int32_t iCausedByPlr)
Definition: C4Object.cpp:585
C4PropertyName GetPropertyP(C4PropertyName k) const
Definition: C4PropList.cpp:824
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30

References Abs(), C4Object::Area, C4D_Object, C4FxCall_EngObjHit, C4PropList::Call(), C4Object::Collect(), C4Def::Collection, C4Object::Contained, C4Object::Def, DFA_FLIGHT, C4Object::DoEnergy(), C4LArea::FirstObjects(), fixtoi(), C4Object::Fling(), Game, C4Object::GetAction(), GetNextMarker(), C4PropList::GetPropertyP(), C4Object::GetX(), C4Object::GetY(), C4Rect::Hgt, HitSpeed2, C4Game::iTick3, C4Object::Layer, C4Object::Mass, C4LArea::NextObjects(), C4Object::OCF, OCF_Alive, OCF_Carryable, OCF_Collection, OCF_HitSpeed2, OCF_None, P_Procedure, PSF_CatchBlow, PSF_QueryCatchBlow, C4Object::Shape, C4PropList::Status, C4Rect::Wdt, C4Rect::x, C4Object::xdir, C4Rect::y, and C4Object::ydir.

Referenced by C4Game::ExecObjects().

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

◆ Default()

void C4GameObjects::Default ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 42 of file C4GameObjects.cpp.

43 {
44  Sectors.Clear();
45  LastUsedMarker = 0;
47 }

References C4LSectors::Clear(), C4ObjectList::Default(), ForeObjects, and Sectors.

Referenced by C4GameObjects(), and C4Game::Default().

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

◆ DeleteObjects() [1/2]

void C4ObjectList::DeleteObjects ( )
inherited

Definition at line 986 of file C4ObjectList.cpp.

987 {
988  // Delete links and objects
989  while (First)
990  {
991  C4Object *obj = First->Obj;
992  if (obj->Status)
993  {
994  Game.ClearPointers(obj); // Clear pointers to removed objects that weren't deleted (game end or section change)
995  }
996  obj->Status = C4OS_DELETED;
997  Remove(obj);
998  delete obj;
999  }
1000  // Reset mass
1001  Mass = 0;
1002 }
#define C4OS_DELETED
Definition: C4Object.h:34
void ClearPointers(C4Object *obj)
Definition: C4Game.cpp:1125

References C4OS_DELETED, C4Game::ClearPointers(), C4ObjectList::First, Game, C4ObjectList::Mass, C4ObjectLink::Obj, C4ObjectList::Remove(), and C4PropList::Status.

Referenced by Clear(), and DeleteObjects().

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

◆ DeleteObjects() [2/2]

void C4GameObjects::DeleteObjects ( bool  delete_inactive_objects)

Definition at line 252 of file C4GameObjects.cpp.

253 {
256  ForeObjects.Clear();
257  if (delete_inactive_objects)
258  {
260  }
261 }
void ClearObjects()
Definition: C4Sector.cpp:225

References C4ObjectList::Clear(), C4LSectors::ClearObjects(), C4ObjectList::DeleteObjects(), ForeObjects, InactiveObjects, and Sectors.

Referenced by C4Game::DeleteObjects().

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

◆ Denumerate()

void C4GameObjects::Denumerate ( C4ValueNumbers numbers)

Definition at line 399 of file C4GameObjects.cpp.

400 {
401  C4ObjectList::Denumerate(numbers);
402  InactiveObjects.Denumerate(numbers);
403 }
void Denumerate(C4ValueNumbers *)

References C4ObjectList::Denumerate(), and InactiveObjects.

Referenced by PostLoad().

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

◆ DenumeratePointers()

bool C4ObjectList::DenumeratePointers ( )
inherited

Definition at line 577 of file C4ObjectList.cpp.

578 {
579  if (!pEnumerated)
580  {
581  return false;
582  }
583  // Denumerate all object pointers
584  for (std::list<int32_t>::const_iterator pNum = pEnumerated->begin(); pNum != pEnumerated->end(); ++pNum)
585  {
586  Add(::Objects.ObjectPointer(*pNum), stNone); // Add to tail, unsorted
587  }
588  // Delete old list
589  delete pEnumerated;
590  pEnumerated = nullptr;
591  return true;
592 }
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4Object * ObjectPointer(int32_t object_number)

References C4ObjectList::Add(), ObjectPointer(), Objects, C4ObjectList::pEnumerated, and C4ObjectList::stNone.

Referenced by C4Object::Denumerate(), and C4Player::DenumeratePointers().

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

◆ Draw()

void C4ObjectList::Draw ( C4TargetFacet cgo,
int  player,
int  MinPlane,
int  MaxPlane 
)
inherited

Definition at line 499 of file C4ObjectList.cpp.

500 {
501  C4ObjectLink *link;
502  C4ObjectLink *first;
503  for (first = Last; first; first = first->Prev)
504  {
505  if (first->Obj->GetPlane() >= MinPlane)
506  {
507  break;
508  }
509  }
510  // Draw objects (base)
511  for (link = first; link; link = link->Prev)
512  {
513  if (link->Obj->GetPlane() > MaxPlane)
514  {
515  break;
516  }
517  if (link->Obj->Category & C4D_Foreground)
518  {
519  continue;
520  }
521  link->Obj->Draw(cgo, player);
522  }
523  // Draw objects (top face)
524  for (link = first; link; link = link->Prev)
525  {
526  if (link->Obj->GetPlane() > MaxPlane)
527  {
528  break;
529  }
530  if (link->Obj->Category & C4D_Foreground)
531  {
532  continue;
533  }
534  link->Obj->DrawTopFace(cgo, player);
535  }
536 }
void DrawTopFace(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
void Draw(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)

References C4D_Foreground, C4Object::Category, C4Object::Draw(), C4Object::DrawTopFace(), C4Object::GetPlane(), C4ObjectList::Last, C4ObjectLink::Obj, C4ScriptGuiWindowPropertyName::player, and C4ObjectLink::Prev.

Referenced by C4Viewport::Draw().

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

◆ DrawIfCategory()

void C4ObjectList::DrawIfCategory ( C4TargetFacet cgo,
int  player,
uint32_t  dwCategory,
bool  invert 
)
inherited

Definition at line 538 of file C4ObjectList.cpp.

539 {
540  C4ObjectLink *link;
541  // Draw objects (base)
542  for (link = Last; link; link = link->Prev)
543  {
544  if (!(link->Obj->Category & dwCategory) == invert)
545  {
546  link->Obj->Draw(cgo, player);
547  }
548  }
549  // Draw objects (top face)
550  for (link = Last; link; link = link->Prev)
551  {
552  if (!(link->Obj->Category & dwCategory) == invert)
553  {
554  link->Obj->DrawTopFace(cgo, player);
555  }
556  }
557 }

References C4Object::Category, C4Object::Draw(), C4Object::DrawTopFace(), C4ObjectList::Last, C4ObjectLink::Obj, C4ScriptGuiWindowPropertyName::player, and C4ObjectLink::Prev.

Referenced by C4Viewport::Draw().

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

◆ DrawSelectMark()

void C4ObjectList::DrawSelectMark ( C4TargetFacet cgo) const
inherited

Definition at line 924 of file C4ObjectList.cpp.

925 {
926  C4ObjectLink *link;
927  for (link = Last; link; link = link->Prev)
928  {
929  link->Obj->DrawSelectMark(cgo);
930  }
931 }
void DrawSelectMark(C4TargetFacet &cgo) const

References C4Object::DrawSelectMark(), C4ObjectList::Last, C4ObjectLink::Obj, and C4ObjectLink::Prev.

Referenced by C4MouseControl::Draw().

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

◆ end()

const C4ObjectList::iterator C4ObjectList::end ( ) const
inherited

Definition at line 1234 of file C4ObjectList.cpp.

1235 {
1236  return iterator(*this, nullptr, false);
1237 }

References C4ObjectList::iterator.

Referenced by C4ObjectListIterator::GetNext().

Here is the caller graph for this function:

◆ Find()

C4Object * C4ObjectList::Find ( C4Def def,
int  owner = ANY_OWNER,
DWORD  dwOCF = OCF_All 
)
inherited

Definition at line 383 of file C4ObjectList.cpp.

384 {
385  C4ObjectLink *link;
386  // Find link and object
387  for (link = First; link; link = link->Next)
388  {
389  if ((link->Obj->Status)
390  && (link->Obj->Def == def)
391  && ((owner == ANY_OWNER) || (link->Obj->Owner == owner))
392  && (dwOCF & link->Obj->OCF))
393  {
394  return link->Obj;
395  }
396  }
397  return nullptr;
398 }
const int ANY_OWNER
Definition: C4Constants.h:138
int32_t Owner
Definition: C4Object.h:108

References ANY_OWNER, C4Object::Def, C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, C4Object::OCF, C4Object::Owner, and C4PropList::Status.

Referenced by C4Command::Acquire(), C4ObjectMenu::DoRefillInternal(), C4RoundResults::EvaluateGoals(), C4Command::Get(), C4MainMenu::MenuCommand(), and C4Command::Put().

Here is the caller graph for this function:

◆ FindOther()

C4Object * C4ObjectList::FindOther ( C4ID  id,
int  owner = ANY_OWNER 
)
inherited

Definition at line 400 of file C4ObjectList.cpp.

401 {
402  C4ObjectLink *link;
403  // Find link and object
404  for (link = First; link; link = link->Next)
405  {
406  if ((link->Obj->Status)
407  && (link->Obj->Def->id!=id)
408  && ((owner==ANY_OWNER) || (link->Obj->Owner == owner)))
409  {
410  return link->Obj;
411  }
412  }
413  return nullptr;
414 }
C4ID id
Definition: C4Def.h:101

References ANY_OWNER, C4Object::Def, C4ObjectList::First, C4Def::id, C4ObjectLink::Next, C4ObjectLink::Obj, C4Object::Owner, and C4PropList::Status.

◆ FixObjectOrder()

void C4GameObjects::FixObjectOrder ( )

Definition at line 443 of file C4GameObjects.cpp.

444 {
445  // Fixes the object order so it matches the global object order sorting constraints
446  C4ObjectLink *pLnk0 = First;
447  C4ObjectLink *pLnkL = Last;
448  while (pLnk0 != pLnkL)
449  {
450  C4ObjectLink *pLnk1stUnsorted = nullptr;
451  C4ObjectLink *pLnkLastUnsorted = nullptr;
452  C4ObjectLink *pLnkPrev = nullptr;
453  C4ObjectLink *pLnk;
454  C4Object *pLastWarnObj = nullptr;
455  // Forward fix
456  int lastPlane = 2147483647; //INT32_MAX;
457  for (pLnk = pLnk0; pLnk != pLnkL->Next; pLnk = pLnk->Next)
458  {
459  C4Object *pObj = pLnk->Obj;
460  if (pObj->Unsorted || !pObj->Status)
461  {
462  continue;
463  }
464  int currentPlane = pObj->GetPlane();
465  // Must have nonzero Plane
466  if (!currentPlane)
467  {
468  DebugLogF("Objects.txt: Object #%d has zero Plane!", (int) pObj->Number);
469  pObj->SetPlane(lastPlane); currentPlane = lastPlane;
470  }
471  // Fix order
472  if (currentPlane > lastPlane)
473  {
474  // SORT ERROR! (note that pLnkPrev can't be 0)
475  if (pLnkPrev->Obj != pLastWarnObj)
476  {
477  DebugLogF("Objects.txt: Wrong object order of #%d-#%d! (down)", (int) pObj->Number, (int) pLnkPrev->Obj->Number);
478  pLastWarnObj = pLnkPrev->Obj;
479  }
480  pLnk->Obj = pLnkPrev->Obj;
481  pLnkPrev->Obj = pObj;
482  pLnkLastUnsorted = pLnkPrev;
483  }
484  else
485  {
486  lastPlane = currentPlane;
487  }
488  pLnkPrev = pLnk;
489  }
490  if (!pLnkLastUnsorted)
491  {
492  break; // Done
493  }
494  pLnkL = pLnkLastUnsorted;
495  // Backwards fix
496  lastPlane = -2147483647-1; //INT32_MIN;
497  for (pLnk = pLnkL; pLnk != pLnk0->Prev; pLnk = pLnk->Prev)
498  {
499  C4Object *pObj = pLnk->Obj;
500  if (pObj->Unsorted || !pObj->Status)
501  {
502  continue;
503  }
504  int currentPlane = pObj->GetPlane();
505  if (currentPlane < lastPlane)
506  {
507  // SORT ERROR! (note that pLnkPrev can't be 0)
508  if (pLnkPrev->Obj != pLastWarnObj)
509  {
510  DebugLogF("Objects.txt: Wrong object order of #%d-#%d! (up)", (int) pObj->Number, (int) pLnkPrev->Obj->Number);
511  pLastWarnObj = pLnkPrev->Obj;
512  }
513  pLnk->Obj = pLnkPrev->Obj;
514  pLnkPrev->Obj = pObj;
515  pLnk1stUnsorted = pLnkPrev;
516  }
517  else
518  {
519  lastPlane = currentPlane;
520  }
521  pLnkPrev = pLnk;
522  }
523  if (!pLnk1stUnsorted)
524  {
525  break; // Done
526  }
527  pLnk0 = pLnk1stUnsorted;
528  }
529  // Objects fixed!
530 }
bool DebugLogF(const char *strMessage ...)
Definition: C4Log.cpp:290
void SetPlane(int32_t z)
Definition: C4Object.h:178

References DebugLogF(), C4ObjectList::First, C4Object::GetPlane(), C4ObjectList::Last, C4ObjectLink::Next, C4PropListNumbered::Number, C4ObjectLink::Obj, C4ObjectLink::Prev, C4Object::SetPlane(), C4PropList::Status, and C4Object::Unsorted.

Referenced by PostLoad().

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

◆ GetFirstObject()

C4Object* C4ObjectList::GetFirstObject ( ) const
inlineinherited

Definition at line 141 of file C4ObjectList.h.

141 { return First ? First->Obj : nullptr; }

References C4ObjectList::First, and C4ObjectLink::Obj.

Referenced by C4Player::CheckElimination().

Here is the caller graph for this function:

◆ GetLastObject()

C4Object* C4ObjectList::GetLastObject ( ) const
inlineinherited

Definition at line 142 of file C4ObjectList.h.

142 { return Last ? Last->Obj : nullptr; }

References C4ObjectList::Last, and C4ObjectLink::Obj.

Referenced by C4Object::PutAwayUnusedObject().

Here is the caller graph for this function:

◆ GetLink() [1/2]

C4ObjectLink* C4ObjectList::GetLink ( const C4Object obj)
inlineinherited

Definition at line 147 of file C4ObjectList.h.

148  { return const_cast<C4ObjectLink*>(const_cast<const C4ObjectList*>(this)->GetLink(obj)); }

References C4ObjectList::GetLink().

Here is the call graph for this function:

◆ GetLink() [2/2]

const C4ObjectLink * C4ObjectList::GetLink ( const C4Object obj) const
inherited

Definition at line 435 of file C4ObjectList.cpp.

436 {
437  if (!obj)
438  {
439  return nullptr;
440  }
441  C4ObjectLink *link;
442  for (link = First; link; link = link->Next)
443  {
444  if (link->Obj == obj)
445  {
446  return link;
447  }
448  }
449  return nullptr;
450 }

References C4ObjectList::First, C4ObjectLink::Next, and C4ObjectLink::Obj.

Referenced by C4ObjectList::Add(), C4Object::AssignInfo(), C4Command::Drop(), C4ObjectList::GetLink(), C4Player::MakeCrewMember(), PostLoad(), C4Command::Put(), C4ObjectList::Remove(), C4ObjectList::ShiftContents(), and C4Command::Throw().

Here is the caller graph for this function:

◆ GetListID()

C4ID C4ObjectList::GetListID ( int32_t  dwCategory,
int  index 
) const
inherited

Definition at line 73 of file C4ObjectList.cpp.

74 {
75  C4ObjectLink *link;
76 
77  // Create a temporary list of all id's and counts
78  for (int i = 0; i < MaxTempListID; i++)
79  {
81  }
82  for (link = First; link && link->Obj; link = link->Next)
83  {
84  if (link->Obj->Status)
85  {
86  C4Def *def;
87  if ((dwCategory==C4D_All) || ( (def = C4Id2Def(link->Obj->Def->id)) && (def->Category & dwCategory) ))
88  {
89  for (int i = 0; i < MaxTempListID; i++)
90  {
91  // Already there
92  if (TempListID[i] == link->Obj->Def->id)
93  {
94  break;
95  }
96  // End of list, add id
97  if (TempListID[i] == C4ID::None)
98  {
99  TempListID[i] = link->Obj->Def->id;
100  break;
101  }
102  }
103  }
104  }
105  }
106 
107  // Returns indexed id
108  if (Inside(index, 0, MaxTempListID - 1))
109  {
110  return TempListID[index];
111  }
112 
113  return C4ID::None;
114 }
const int32_t C4D_All
Definition: C4Def.h:39
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
const int MaxTempListID
C4ID TempListID[MaxTempListID]
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
Definition: C4Def.h:99
int32_t Category
Definition: C4Def.h:117
static const C4ID None
Definition: C4Id.h:39

References C4D_All, C4Id2Def(), C4Def::Category, C4Object::Def, C4ObjectList::First, C4Def::id, Inside(), MaxTempListID, C4ObjectLink::Next, C4ID::None, C4ObjectLink::Obj, C4PropList::Status, and TempListID.

Referenced by C4MainMenu::ActivateRules(), C4RoundResults::EvaluateGoals(), and C4ObjectList::GetNameList().

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

◆ GetNameList()

StdStrBuf C4ObjectList::GetNameList ( C4DefList defs) const
inherited

Definition at line 699 of file C4ObjectList.cpp.

700 {
701  C4ID id;
702  StdStrBuf Buf;
703  for (int i = 0; (id = GetListID(C4D_All, i)); i++)
704  {
705  C4Def *current_def = defs.ID2Def(id);
706  if (current_def)
707  {
708  int idcount = ObjectCount(id);
709  if (i > 0)
710  {
711  Buf.Append(", ");
712  }
713  Buf.AppendFormat("%dx %s", idcount, current_def->GetName());
714  }
715  }
716  return Buf;
717 }
C4Def * ID2Def(C4ID id)
Definition: C4Id.h:26
C4ID GetListID(int32_t dwCategory, int index) const
const char * GetName() const override
Definition: C4PropList.cpp:243
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References StdStrBuf::Append(), StdStrBuf::AppendFormat(), C4D_All, C4ObjectList::GetListID(), C4PropListStatic::GetName(), C4DefList::ID2Def(), and C4ObjectList::ObjectCount().

Referenced by C4Object::GetDataString().

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

◆ GetNextMarker()

uint32_t C4GameObjects::GetNextMarker ( )

Definition at line 630 of file C4GameObjects.cpp.

631 {
632  // Get a new marker.
633  uint32_t marker = ++LastUsedMarker;
634  // If all markers are exceeded, restart marker at 1 and reset all object markers to zero.
635  if (!marker)
636  {
637  for (C4Object *object : *this)
638  {
639  if (object)
640  {
641  object->Marker = 0;
642  }
643  }
644  marker = ++LastUsedMarker;
645  }
646  return marker;
647 }

Referenced by C4FindObject::Count(), CrossCheck(), and C4FindObject::FindMany().

Here is the caller graph for this function:

◆ GetObject()

C4Object * C4ObjectList::GetObject ( int  index = 0) const
inherited

Definition at line 416 of file C4ObjectList.cpp.

417 {
418  int cIdx;
419  C4ObjectLink *link;
420  // Find link and object
421  for (link = First, cIdx = 0; link; link = link->Next)
422  {
423  if (link->Obj->Status)
424  {
425  if (cIdx == index)
426  {
427  return link->Obj;
428  }
429  cIdx++;
430  }
431  }
432  return nullptr;
433 }

References C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, and C4PropList::Status.

Referenced by C4Object::AssignDeath(), C4Object::DirectComContents(), C4Object::DoCon(), C4MouseControl::LeftUpDragNone(), ObjectActionThrow(), ObjectComDrop(), ObjectComPut(), ObjectComPutTake(), ObjectComThrow(), C4Command::Put(), C4Player::RemoveCrewObjects(), C4MouseControl::RightUpDragNone(), C4Object::ShiftContents(), and C4MouseControl::UpdateSingleSelection().

Here is the caller graph for this function:

◆ GRBroadcast()

C4Value C4GameObjects::GRBroadcast ( const char *  function_name,
C4AulParSet parameters,
bool  pass_error,
bool  reject_test 
)

Definition at line 412 of file C4GameObjects.cpp.

413 {
414  // Call objects first - scenario script might overwrite hostility, etc...
415  for (C4Object *object : *this)
416  {
417  if (object && (object->Category & (C4D_Goal | C4D_Rule | C4D_Environment)) && object->Status)
418  {
419  C4Value vResult = object->Call(function_name, parameters, pass_error);
420  // Rejection tests abort on first nonzero result
421  if (reject_test && !!vResult)
422  {
423  return vResult;
424  }
425  }
426  }
427  return C4Value();
428 }
const int32_t C4D_Goal
Definition: C4Def.h:46
const int32_t C4D_Rule
Definition: C4Def.h:47
const int32_t C4D_Environment
Definition: C4Def.h:48

References C4D_Environment, C4D_Goal, C4D_Rule, C4Object::Category, and C4PropList::Status.

Referenced by C4Game::GRBroadcast().

Here is the caller graph for this function:

◆ Init()

void C4GameObjects::Init ( int32_t  width,
int32_t  height 
)

Definition at line 49 of file C4GameObjects.cpp.

50 {
51  // Init sectors
52  Sectors.Init(width, height);
53 }
void Init(int Wdt, int Hgt)
Definition: C4Sector.cpp:58

References C4LSectors::Init(), and Sectors.

Here is the call graph for this function:

◆ InsertLink()

void C4NotifyingObjectList::InsertLink ( C4ObjectLink link,
C4ObjectLink after_link 
)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 888 of file C4ObjectList.cpp.

889 {
890  C4ObjectList::InsertLink(link, after_link);
892 }
C4ObjectListChangeListener & ObjectListChangeListener
virtual void OnObjectAdded(C4ObjectList *list, C4ObjectLink *link)
Definition: C4ObjectList.h:36

References C4ObjectList::InsertLink(), ObjectListChangeListener, and C4ObjectListChangeListener::OnObjectAdded().

Here is the call graph for this function:

◆ InsertLinkBefore()

void C4NotifyingObjectList::InsertLinkBefore ( C4ObjectLink link,
C4ObjectLink before_link 
)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 882 of file C4ObjectList.cpp.

883 {
884  C4ObjectList::InsertLinkBefore(link, before_link);
886 }
virtual void InsertLinkBefore(C4ObjectLink *link, C4ObjectLink *before_link)

References C4ObjectList::InsertLinkBefore(), ObjectListChangeListener, and C4ObjectListChangeListener::OnObjectAdded().

Here is the call graph for this function:

◆ IsClear()

bool C4ObjectList::IsClear ( ) const
inherited

Definition at line 572 of file C4ObjectList.cpp.

573 {
574  return ObjectCount() == 0;
575 }

References C4ObjectList::ObjectCount().

Here is the call graph for this function:

◆ IsContained()

bool C4ObjectList::IsContained ( const C4Object obj) const
inherited

Definition at line 559 of file C4ObjectList.cpp.

560 {
561  C4ObjectLink *link;
562  for (link = First; link; link = link->Next)
563  {
564  if (link->Obj == obj)
565  {
566  return true;
567  }
568  }
569  return false;
570 }

References C4ObjectList::First, C4ObjectLink::Next, and C4ObjectLink::Obj.

Referenced by C4LSectors::AssertObjectNotInList(), C4Object::IsPlayerObject(), C4Player::NotifyOwnedObjects(), and C4Player::SetObjectCrewStatus().

Here is the caller graph for this function:

◆ ListIDCount()

int C4ObjectList::ListIDCount ( int32_t  dwCategory) const
inherited

Definition at line 116 of file C4ObjectList.cpp.

117 {
118  C4ObjectLink *link;
119 
120  // Create a temporary list of all id's and counts
121  for (int clid = 0; clid < MaxTempListID; clid++)
122  {
123  TempListID[clid] = C4ID::None;
124  }
125  for (link = First; link && link->Obj; link = link->Next)
126  {
127  if (link->Obj->Status)
128  {
129  C4Def *def;
130  if ((dwCategory == C4D_All) || ( (def = C4Id2Def(link->Obj->Def->id)) && (def->Category & dwCategory) ))
131  {
132  for (int clid = 0; clid < MaxTempListID; clid++)
133  {
134  // Already there
135  if (TempListID[clid] == link->Obj->Def->id)
136  {
137  break;
138  }
139  // End of list, add id
140  if (TempListID[clid] == C4ID::None)
141  {
142  TempListID[clid] = link->Obj->Def->id;
143  break;
144  }
145  }
146  }
147  }
148  }
149 
150  // Count different id's
151  for (int i = 0; i < MaxTempListID; i++)
152  {
153  if (TempListID[i] == C4ID::None)
154  {
155  return i;
156  }
157  }
158 
159  return MaxTempListID;
160 }

◆ MassCount()

int C4ObjectList::MassCount ( )
inherited

Definition at line 466 of file C4ObjectList.cpp.

467 {
468  C4ObjectLink *link;
469  int mass = 0;
470  for (link = First; link; link = link->Next)
471  {
472  if (link->Obj->Status)
473  {
474  mass += link->Obj->Mass;
475  }
476  }
477  Mass = mass;
478  return mass;
479 }

References C4ObjectList::First, C4Object::Mass, C4ObjectList::Mass, C4ObjectLink::Next, C4ObjectLink::Obj, and C4PropList::Status.

Referenced by C4Object::UpdateMass().

Here is the caller graph for this function:

◆ ObjectCount()

int C4ObjectList::ObjectCount ( C4ID  id = C4ID::None) const
inherited

Definition at line 452 of file C4ObjectList.cpp.

453 {
454  C4ObjectLink *link;
455  int count = 0;
456  for (link = First; link; link = link->Next)
457  {
458  if (link->Obj->Status && (id == C4ID::None || link->Obj->Def->id == id))
459  {
460  count++;
461  }
462  }
463  return count;
464 }

References C4Object::Def, C4ObjectList::First, C4Def::id, C4ObjectLink::Next, C4ID::None, C4ObjectLink::Obj, and C4PropList::Status.

Referenced by C4Object::AssignDeath(), C4ObjectList::CompileFunc(), C4Game::CompileRuntimeData(), C4FindObject::Count(), C4EditCursor::DoContextMenu(), C4ObjectMenu::DoRefillInternal(), C4ObjectMenu::Execute(), C4Network2Stats::ExecuteFrame(), C4Object::GetDataString(), C4ObjectList::GetNameList(), C4Game::InitGameFinal(), C4ObjectList::IsClear(), PostLoad(), C4ControlSyncCheck::Set(), and C4MouseControl::UpdateSingleSelection().

Here is the caller graph for this function:

◆ ObjectPointer()

C4Object * C4GameObjects::ObjectPointer ( int32_t  object_number)

Definition at line 220 of file C4GameObjects.cpp.

221 {
222  // Search own list
223  C4PropList *object = C4PropListNumbered::GetByNumber(object_number);
224  if (object)
225  {
226  return object->GetObject();
227  }
228  return nullptr;
229 }
static C4PropList * GetByNumber(int32_t iNumber)
Definition: C4PropList.cpp:51

References C4PropListNumbered::GetByNumber().

Referenced by C4ObjectList::DenumeratePointers(), C4ObjectPtr::DenumeratePointers(), and SafeObjectPointer().

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

◆ OnSynchronized()

void C4GameObjects::OnSynchronized ( )

Definition at line 596 of file C4GameObjects.cpp.

597 {
598  for (C4Object *object : *this)
599  {
600  if (object)
601  {
602  object->Call(PSF_OnSynchronized);
603  }
604  }
605 }
#define PSF_OnSynchronized
Definition: C4GameScript.h:79

References PSF_OnSynchronized.

Referenced by C4TransferZones::Synchronize().

Here is the caller graph for this function:

◆ PostLoad()

int C4GameObjects::PostLoad ( bool  keep_inactive_objects,
C4ValueNumbers numbers 
)

Definition at line 273 of file C4GameObjects.cpp.

274 {
275  // Process objects
276  int32_t max_object_number = 0;
277  for (C4Object *object : reverse())
278  {
279  // Keep track of numbers
280  max_object_number = std::max(max_object_number, object->Number);
281  // Add to list of foreobjects
282  if (object->Category & C4D_Foreground)
283  {
284  ForeObjects.Add(object, C4ObjectList::stMain, this);
285  }
286  // Unterminate end
287  }
288 
289  // Denumerate pointers:
290  // On section load, inactive object numbers will be adjusted afterwards,
291  // so fake inactive object list empty meanwhile.
292  // Note: this has to be done to prevent an assertion fail when denumerating
293  // non-enumerated inactive objects, even if object numbers did not collide.
294  C4ObjectList inactiveObjectsCopy;
295  if (keep_inactive_objects)
296  {
297  inactiveObjectsCopy.Copy(InactiveObjects);
299  }
300  // Denumerate pointers
301  Denumerate(numbers);
302  // Update object enumeration index now, because calls like OnSynchronized might create objects
303  C4PropListNumbered::SetEnumerationIndex(max_object_number);
304  // end faking and adjust object numbers
305  if (keep_inactive_objects)
306  {
307  InactiveObjects.Copy(inactiveObjectsCopy);
308  inactiveObjectsCopy.Clear();
310  }
311 
312  // Special checks:
313  // -contained/contents-consistency
314  // -StaticBack-objects zero speed
315  for (C4Object *object : *this)
316  {
317  if (object->Status)
318  {
319  // Staticback must not have speed
320  if (object->Category & C4D_StaticBack)
321  {
322  object->xdir = object->ydir = 0;
323  }
324  // contained must be in contents list
325  if (object->Contained)
326  {
327  if (!object->Contained->Contents.GetLink(object))
328  {
329  DebugLogF("Error in Objects.txt: Container of #%d is #%d, but not found in contents list!", object->Number, object->Contained->Number);
330  object->Contained->Contents.Add(object, C4ObjectList::stContents);
331  }
332  }
333  // All contents must have contained set; otherwise, remove them!
334  auto contents_iterator = object->Contents.begin();
335  while (!contents_iterator.atEnd())
336  {
337  C4Object* contained_object = *contents_iterator;
338  // Check double links
339  auto contents_iterator2 = object->Contents.begin();
340  if (contents_iterator2.find(contained_object) && contents_iterator2 != contents_iterator)
341  {
342  DebugLogF("Error in Objects.txt: Double containment of #%d by #%d!", contained_object->Number, object->Number);
343  // This remove-call will only remove the previous (doubled) link, so cLnkCont should be save
344  object->Contents.Remove(contained_object);
345  // Contents checked already
346  continue;
347  }
348  // Check contents/contained-relation
349  if (contained_object->Status && contained_object->Contained != object)
350  {
351  DebugLogF("Error in Objects.txt: Object #%d not in container #%d as referenced!", contained_object->Number, object->Number);
352  contained_object->Contained = object;
353  }
354  contents_iterator++;
355  }
356  }
357  }
358  // Sort out inactive objects
359  for (C4Object *object : *this)
360  {
361  if (object->Status == C4OS_INACTIVE)
362  {
363  Remove(object);
365  }
366  }
367 
368  {
369  C4DebugRecOff DBGRECOFF; // - script callbacks that would kill DebugRec-sync for runtime start
370  // Update graphics
371  UpdateGraphics(false);
372  // Update faces
373  UpdateFaces(false);
374  // Update ocf
375  SetOCF();
376  }
377 
378  // Make sure list is sorted by category - after sorting out inactives, because inactives aren't sorted into the main list
379  FixObjectOrder();
380 
381  // Misc updates
382  for (C4Object *object : *this)
383  {
384  if (object->Status)
385  {
386  // Add to plrview
387  object->UpdateLight();
388  // Update flipdir (for old objects.txt with no flipdir defined),
389  // assigns Action.DrawDir as well
390  object->UpdateFlipDir();
391  // Initial OCF update
392  object->SetOCF();
393  }
394  }
395  // Done
396  return ObjectCount();
397 }
bool Remove(C4Object *game_object) override
void Denumerate(C4ValueNumbers *)
C4NotifyingObjectList Contents
Definition: C4Object.h:151
void UpdateFaces(bool update_shape)
void UpdateGraphics(bool graphics_changed)
void Copy(const C4ObjectList &list)
iterator begin() const
static void UnshelveNumberedPropLists()
Definition: C4PropList.cpp:99
static void SetEnumerationIndex(int32_t iMaxObjectNumber)
Definition: C4PropList.cpp:69

References C4ObjectList::Add(), C4ObjectList::begin(), C4D_Foreground, C4D_StaticBack, C4OS_INACTIVE, C4Object::Category, C4ObjectList::Clear(), C4Object::Contained, C4Object::Contents, C4ObjectList::Copy(), DebugLogF(), Denumerate(), FixObjectOrder(), ForeObjects, C4ObjectList::GetLink(), InactiveObjects, C4PropListNumbered::Number, C4ObjectList::ObjectCount(), Remove(), C4ObjectList::reverse(), C4PropListNumbered::SetEnumerationIndex(), SetOCF(), C4PropList::Status, C4ObjectList::stContents, C4ObjectList::stMain, C4ObjectList::stNone, C4PropListNumbered::UnshelveNumberedPropLists(), C4ObjectList::UpdateFaces(), and C4ObjectList::UpdateGraphics().

Here is the call graph for this function:

◆ Remove()

bool C4GameObjects::Remove ( C4Object game_object)
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 76 of file C4GameObjects.cpp.

77 {
78  // If it's an inactive object, simply remove it from the inactive list
79  if (object->Status == C4OS_INACTIVE)
80  {
81  return InactiveObjects.Remove(object);
82  }
83  // Remove from sectors
84  Sectors.Remove(object);
85  // Remove from forelist
86  ForeObjects.Remove(object);
87  // Manipulate main list
88  return C4ObjectList::Remove(object);
89 }
void Remove(C4Object *pObj)
Definition: C4Sector.cpp:151

References C4OS_INACTIVE, ForeObjects, InactiveObjects, C4ObjectList::Remove(), C4LSectors::Remove(), Sectors, and C4PropList::Status.

Referenced by C4Game::ObjectRemovalCheck(), PostLoad(), ResortUnsorted(), and C4Object::StatusDeactivate().

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

◆ RemoveIter()

void C4ObjectList::RemoveIter ( iterator iter) const
protectedinherited

Definition at line 1244 of file C4ObjectList.cpp.

1245 {
1246  if (iter == FirstIter)
1247  {
1248  FirstIter = iter->Next;
1249  }
1250  else
1251  {
1252  iterator * i = FirstIter;
1253  while (i->Next && i->Next != iter)
1254  {
1255  i = i->Next;
1256  }
1257  i->Next = iter->Next;
1258  }
1259 }

References C4ObjectList::FirstIter.

◆ RemoveLink()

void C4NotifyingObjectList::RemoveLink ( C4ObjectLink link)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 894 of file C4ObjectList.cpp.

895 {
898 }
virtual void OnObjectRemove(C4ObjectList *list, C4ObjectLink *link)
Definition: C4ObjectList.h:35
virtual void RemoveLink(C4ObjectLink *link)

References ObjectListChangeListener, C4ObjectListChangeListener::OnObjectRemove(), and C4ObjectList::RemoveLink().

Here is the call graph for this function:

◆ ResetAudibility()

void C4GameObjects::ResetAudibility ( )

Definition at line 607 of file C4GameObjects.cpp.

608 {
609  for (C4Object *object : *this)
610  {
611  if (object)
612  {
613  object->Audible = object->AudiblePan = 0;
614  object->AudiblePlayer = NO_OWNER;
615  }
616  }
617 }
const int NO_OWNER
Definition: C4Constants.h:137

References NO_OWNER.

Referenced by C4GraphicsSystem::Execute().

Here is the caller graph for this function:

◆ ResortUnsorted()

void C4GameObjects::ResortUnsorted ( )

Definition at line 532 of file C4GameObjects.cpp.

533 {
534  for (C4Object *object : *this)
535  {
536  if (object->Unsorted)
537  {
538  // Readd to main object list
539  Remove(object);
540  // Reset flag so that Add correctly sorts this object
541  object->Unsorted = false;
542  if (!Add(object))
543  {
544  // readd failed: Better kill object to prevent leaking...
545  Game.ClearPointers(object);
546  delete object;
547  }
548  }
549  }
550 }
virtual bool Add(C4Object *new_obj, SortType sort_type, C4ObjectList *sorted_list=nullptr)

References Add(), C4Game::ClearPointers(), Game, Remove(), and C4Object::Unsorted.

Referenced by C4Game::ExecObjects(), and Synchronize().

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

◆ reverse()

const ReverseView C4ObjectList::reverse ( ) const
inlineinherited

Definition at line 104 of file C4ObjectList.h.

104 { return ReverseView(*this); }

Referenced by AssignLightRange(), C4PropertyCollection::CollectPropLists(), C4Game::ExecObjects(), C4ObjectList::iterator::operator++(), C4ObjectList::iterator::operator=(), C4ObjectList::iterator::operator==(), PostLoad(), C4ObjectList::iterator::reset(), and C4Object::ShiftContents().

Here is the caller graph for this function:

◆ SafeObjectPointer()

C4Object * C4GameObjects::SafeObjectPointer ( int32_t  object_number)

Definition at line 231 of file C4GameObjects.cpp.

232 {
233  C4Object *object = ObjectPointer(object_number);
234  if (object && !object->Status)
235  {
236  return nullptr;
237  }
238  return object;
239 }

References ObjectPointer(), and C4PropList::Status.

Referenced by FnObject(), C4EditCursor::PerformDuplication(), and C4EditCursor::PerformDuplicationLegacy().

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

◆ SetOCF()

void C4GameObjects::SetOCF ( )

Definition at line 619 of file C4GameObjects.cpp.

620 {
621  for (C4Object *object : *this)
622  {
623  if (object->Status)
624  {
625  object->SetOCF();
626  }
627  }
628 }

References C4PropList::Status.

Referenced by PostLoad().

Here is the caller graph for this function:

◆ ShiftContents()

bool C4ObjectList::ShiftContents ( C4Object new_first)
inherited

Definition at line 960 of file C4ObjectList.cpp.

961 {
962  // Get link of new first (this ensures list is not empty)
963  C4ObjectLink *new_first_link = GetLink(new_first_obj);
964  if (!new_first_link)
965  {
966  return false;
967  }
968  // Already at front?
969  if (new_first_link == First)
970  {
971  return true;
972  }
973  // Sort it there:
974  // 1. Make cyclic list
975  Last->Next = First;
976  First->Prev = Last;
977  // 2. Re-set first and last
978  First = new_first_link;
979  Last = new_first_link->Prev;
980  // 3. Uncycle list
981  First->Prev = Last->Next = nullptr;
982  // Done, success
983  return true;
984 }

References C4ObjectList::First, C4ObjectList::GetLink(), C4ObjectList::Last, C4ObjectLink::Next, and C4ObjectLink::Prev.

Referenced by C4Object::DirectComContents().

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

◆ Sort()

void C4ObjectList::Sort ( )
inherited

Definition at line 760 of file C4ObjectList.cpp.

761 {
762  C4ObjectLink *link;
763  bool is_sorted;
764  // Sort by id
765  do
766  {
767  is_sorted = true;
768  for (link = First; link && link->Next; link = link->Next)
769  {
770  if (link->Obj->id > link->Next->Obj->id)
771  {
772  RemoveLink(link);
773  InsertLink(link, link->Next);
774  is_sorted = false;
775  break;
776  }
777  }
778  }
779  while (!is_sorted);
780 }

References C4ObjectList::First, C4Object::id, C4ObjectList::InsertLink(), C4ObjectLink::Next, C4ObjectLink::Obj, and C4ObjectList::RemoveLink().

Here is the call graph for this function:

◆ SyncClearance()

void C4GameObjects::SyncClearance ( )

Definition at line 585 of file C4GameObjects.cpp.

586 {
587  for (C4Object *object : *this)
588  {
589  if (object)
590  {
591  object->SyncClearance();
592  }
593  }
594 }

Referenced by C4Game::SyncClearance().

Here is the caller graph for this function:

◆ Synchronize()

void C4GameObjects::Synchronize ( )

Definition at line 212 of file C4GameObjects.cpp.

213 {
214  // Synchronize unsorted objects
215  ResortUnsorted();
216  // Synchronize solidmasks
218 }
void UpdateSolidMasks()

References ResortUnsorted(), and UpdateSolidMasks().

Referenced by C4Game::Synchronize().

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

◆ UpdateFaces()

void C4ObjectList::UpdateFaces ( bool  update_shape)
inherited

Definition at line 912 of file C4ObjectList.cpp.

913 {
914  C4ObjectLink *link;
915  for (link = First; link; link = link->Next)
916  {
917  if (link->Obj->Status)
918  {
919  link->Obj->UpdateFace(update_shapes);
920  }
921  }
922 }
void UpdateFace(bool bUpdateShape, bool fTemp=false)

References C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, C4PropList::Status, and C4Object::UpdateFace().

Referenced by PostLoad().

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

◆ UpdateGraphics()

void C4ObjectList::UpdateGraphics ( bool  graphics_changed)
inherited

Definition at line 900 of file C4ObjectList.cpp.

901 {
902  C4ObjectLink *link;
903  for (link = First; link; link = link->Next)
904  {
905  if (link->Obj->Status)
906  {
907  link->Obj->UpdateGraphics(graphics_changed);
908  }
909  }
910 }
void UpdateGraphics(bool fGraphicsChanged, bool fTemp=false)

References C4ObjectList::First, C4ObjectLink::Next, C4ObjectLink::Obj, C4PropList::Status, and C4Object::UpdateGraphics().

Referenced by PostLoad().

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

◆ UpdatePos()

void C4GameObjects::UpdatePos ( C4Object game_object)

Definition at line 430 of file C4GameObjects.cpp.

431 {
432  // Position might have changed. Update sector lists
433  Sectors.Update(object, this);
434 }
void Update(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:109

References Sectors, and C4LSectors::Update().

Referenced by C4Object::UpdatePos().

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

◆ UpdatePosResort()

void C4GameObjects::UpdatePosResort ( C4Object game_object)

Definition at line 436 of file C4GameObjects.cpp.

437 {
438  // Object order for this object was changed. Readd object to sectors
439  Sectors.Remove(object);
440  Sectors.Add(object, this);
441 }

References C4LSectors::Add(), C4LSectors::Remove(), and Sectors.

Here is the call graph for this function:

◆ UpdateScriptPointers()

void C4GameObjects::UpdateScriptPointers ( )

Definition at line 405 of file C4GameObjects.cpp.

406 {
407  // Call in sublists
410 }
void UpdateScriptPointers()

References InactiveObjects, and C4ObjectList::UpdateScriptPointers().

Referenced by C4Game::ReLinkScriptEngine().

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

◆ UpdateSolidMasks()

void C4GameObjects::UpdateSolidMasks ( )

Definition at line 241 of file C4GameObjects.cpp.

242 {
243  for (C4Object *object : *this)
244  {
245  if (object->Status)
246  {
247  object->UpdateSolidMask(false);
248  }
249  }
250 }

References C4PropList::Status.

Referenced by Synchronize().

Here is the caller graph for this function:

◆ ValidateOwners()

bool C4GameObjects::ValidateOwners ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 552 of file C4GameObjects.cpp.

553 {
554  // Validate in sublists
555  // Note: Both functions need to be called,
556  // before the evaluation. Do not call foo() && bar()
557  // because then only foo() will be evaluated.
558  bool object_list_valid = C4ObjectList::ValidateOwners();
559  bool inactive_objects_valid = InactiveObjects.ValidateOwners();
560  return object_list_valid && inactive_objects_valid;
561 }
virtual bool ValidateOwners()

References InactiveObjects, and C4ObjectList::ValidateOwners().

Referenced by C4Game::InitGameFinal(), and C4PlayerList::Remove().

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

◆ Write()

bool C4ObjectList::Write ( char *  szTarget)
inherited

Definition at line 594 of file C4ObjectList.cpp.

595 {
596  char ostr[25];
597  szTarget[0] = 0;
598  C4ObjectLink *link;
599  for (link = First; link && link->Obj; link = link->Next)
600  {
601  if (link->Obj->Status)
602  {
603  sprintf(ostr, "%d;", link->Obj->Number);
604  SAppend(ostr, szTarget);
605  }
606  }
607  return true;
608 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263
#define sprintf
Definition: Standard.h:162

References C4ObjectList::First, C4ObjectLink::Next, C4PropListNumbered::Number, C4ObjectLink::Obj, SAppend(), sprintf, and C4PropList::Status.

Here is the call graph for this function:

Member Data Documentation

◆ First

◆ FirstIter

iterator* C4ObjectList::FirstIter {nullptr}
mutableprotectedinherited

◆ ForeObjects

◆ InactiveObjects

◆ Last

◆ Mass

◆ pEnumerated

std::list<int32_t>* C4ObjectList::pEnumerated
inherited

◆ Sectors


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