OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 iWidth, int32_t iHeight)
 
void Clear (bool fClearInactive)
 
void Clear () override
 
bool Add (C4Object *nObj)
 
bool Remove (C4Object *pObj) override
 
C4ObjectListObjectsAt (int ix, int iy)
 
void CrossCheck ()
 
C4ObjectAtObject (int ctx, int cty, DWORD &ocf, C4Object *exclude=nullptr)
 
void Synchronize ()
 
void UpdateSolidMasks ()
 
C4ObjectObjectPointer (int32_t iNumber)
 
C4ObjectSafeObjectPointer (int32_t iNumber)
 
int PostLoad (bool fKeepInactive, C4ValueNumbers *)
 
void Denumerate (C4ValueNumbers *)
 
void UpdateScriptPointers ()
 
C4Value GRBroadcast (const char *szFunction, C4AulParSet *pPars, bool fPassError, bool fRejectTest)
 
void UpdatePos (C4Object *pObj)
 
void UpdatePosResort (C4Object *pObj)
 
void FixObjectOrder ()
 
void ResortUnsorted ()
 
void DeleteObjects (bool fDeleteInactive)
 
bool ValidateOwners () override
 
bool AssignInfo () override
 
void AssignLightRange ()
 
void SyncClearance ()
 
void ResetAudibility ()
 
void OnSynchronized ()
 
void SetOCF ()
 
uint32_t GetNextMarker ()
 
iterator begin () const
 
const iterator end () const
 
const ReverseView reverse () const
 
void Sort ()
 
void Copy (const C4ObjectList &rList)
 
void DrawIfCategory (C4TargetFacet &cgo, int iPlayer, uint32_t dwCat, bool fInvert)
 
void Draw (C4TargetFacet &cgo, int iPlayer, int MinPlane, int MaxPlane)
 
void DrawSelectMark (C4TargetFacet &cgo) const
 
void CloseMenus ()
 
void UpdateGraphics (bool fGraphicsChanged)
 
void UpdateFaces (bool bUpdateShape)
 
void ClearInfo (C4ObjectInfo *pInfo)
 
virtual bool Add (C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
 
bool AddSortCustom (C4Object *nObj, SortProc &pSortProc)
 
StdStrBuf GetNameList (C4DefList &rDefs) const
 
bool IsClear () const
 
bool DenumeratePointers ()
 
bool Write (char *szTarget)
 
void CompileFunc (StdCompiler *pComp, C4ValueNumbers *=nullptr)
 
void CompileFunc (StdCompiler *pComp, bool fSkipPlayerObjects, C4ValueNumbers *)
 
bool IsContained (const C4Object *pObj) const
 
int ClearPointers (C4Object *pObj)
 
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 iOwner=ANY_OWNER, DWORD dwOCF=OCF_All)
 
C4ObjectFindOther (C4ID id, int iOwner=ANY_OWNER)
 
const C4ObjectLinkGetLink (const C4Object *pObj) const
 
C4ObjectLinkGetLink (const C4Object *pObj)
 
C4ID GetListID (int32_t dwCategory, int Index) const
 
bool ShiftContents (C4Object *pNewFirst)
 
void DeleteObjects ()
 
bool CheckSort (C4ObjectList *pList)
 
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 *pLink, C4ObjectLink *pBefore) override
 
void InsertLink (C4ObjectLink *pLink, C4ObjectLink *pAfter) override
 
void RemoveLink (C4ObjectLink *pLnk) 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

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

Definition at line 118 of file C4ObjectList.h.

Member Enumeration Documentation

enum C4ObjectList::SortType
inherited
Enumerator
stNone 
stMain 
stContents 
stReverse 

Definition at line 55 of file C4ObjectList.h.

Constructor & Destructor Documentation

C4GameObjects::C4GameObjects ( )

Definition at line 32 of file C4GameObjects.cpp.

References Default().

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

Here is the call graph for this function:

C4GameObjects::~C4GameObjects ( )
override

Definition at line 37 of file C4GameObjects.cpp.

References C4LSectors::Clear(), and Sectors.

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

Here is the call graph for this function:

Member Function Documentation

bool C4GameObjects::Add ( C4Object nObj)

Definition at line 55 of file C4GameObjects.cpp.

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

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

56 {
57  // add inactive objects to the inactive list only
58  if (nObj->Status == C4OS_INACTIVE)
60  // if this is a foreground object, add it to the list
61  if (nObj->Category & C4D_Foreground)
63  // manipulate main list
65  return false;
66  // add to sectors
67  Sectors.Add(nObj, this);
68  return true;
69 }
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:91
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
int32_t Status
Definition: C4PropList.h:168
int32_t Category
Definition: C4Object.h:113
C4LSectors Sectors
Definition: C4GameObjects.h:42
#define C4OS_INACTIVE
Definition: C4Object.h:36
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
const int32_t C4D_Foreground
Definition: C4Def.h:53

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectList::Add ( C4Object nObj,
SortType  eSort,
C4ObjectList pLstSorted = nullptr 
)
virtualinherited

Definition at line 123 of file C4ObjectList.cpp.

References C4D_StaticBack, C4Object::Category, C4ObjectList::CheckCategorySort(), C4ObjectList::CheckSort(), C4Object::Def, C4ObjectList::First, C4ObjectList::GetLink(), C4Object::GetPlane(), C4Object::id, C4ObjectList::InsertLink(), C4ObjectList::Last, C4ObjectList::Mass, C4Object::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().

124 {
125  C4ObjectLink *nLnk;
126  if (!nObj || !nObj->Def || !nObj->Status) return false;
127 
128 #ifdef _DEBUG
129  if (eSort==stMain)
130  {
132  if (pLstSorted)
133  assert(CheckSort(pLstSorted));
134  }
135 #endif
136 
137  // dbg: don't do double links
138  assert (!GetLink(nObj));
139 
140  // no self-sort
141  assert(pLstSorted != this);
142 
143  // Allocate new link
144  if (!(nLnk=new C4ObjectLink)) return false;
145  // Set link
146  nLnk->Obj=nObj;
147 
148  // Search insert position (default: end of list)
149  C4ObjectLink *cLnk = nullptr, *cPrev = Last;
150 
151  // Should sort?
152  if (eSort == stReverse)
153  {
154  // reverse sort: Add to beginning of list
155  cLnk = First; cPrev = nullptr;
156  }
157  else if (eSort)
158  {
159  // Sort override? Leave default as is.
160  bool fUnsorted = nObj->Unsorted;
161  if (!fUnsorted)
162  {
163  // Sort by master list?
164  if (pLstSorted)
165  {
166  cPrev = nullptr; cLnk = First;
167  while(cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;
168 
169 #ifndef _DEBUG
170  if(cLnk)
171 #endif
172  {
173  C4ObjectLink* cLnk2;
174  for(cLnk2 = pLstSorted->First; cLnk2; cLnk2 = cLnk2->Next)
175  {
176  if(cLnk2->Obj->Status && !cLnk2->Obj->Unsorted)
177  {
178  if(cLnk2->Obj == nObj)
179  {
180  assert(!cLnk || cLnk->Obj != nObj);
181  break;
182  }
183 
184  if(cLnk && cLnk2->Obj == cLnk->Obj)
185  {
186  cPrev = cLnk;
187  cLnk = cLnk->Next;
188  while(cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;
189 
190 #ifndef _DEBUG
191  if(!cLnk) break;
192 #endif
193  }
194  }
195  }
196 
197  assert(cLnk2 != nullptr);
198  }
199  }
200  else
201  {
202  // No master list: Find successor by matching Plane / id
203  // Sort by matching Plane/id is necessary for inventory shifting.
204  // It is not done for static back to allow multiobject outside structure.
205  // Unsorted objects are ignored in comparison.
206  if (!(nObj->Category & C4D_StaticBack))
207  for (cPrev=nullptr,cLnk=First; cLnk; cLnk=cLnk->Next)
208  if (cLnk->Obj->Status && !cLnk->Obj->Unsorted)
209  {
210  if (cLnk->Obj->GetPlane() == nObj->GetPlane())
211  if (cLnk->Obj->id == nObj->id)
212  break;
213  cPrev=cLnk;
214  }
215 
216  // Find successor by relative category
217  if(!cLnk)
218  for (cPrev=nullptr, cLnk=First; cLnk; cLnk=cLnk->Next)
219  if (cLnk->Obj->Status && !cLnk->Obj->Unsorted)
220  {
221  if (cLnk->Obj->GetPlane() <= nObj->GetPlane())
222  break;
223  cPrev=cLnk;
224  }
225  }
226 
227  cLnk = cPrev ? cPrev->Next : First;
228  }
229  }
230 
231  assert(!cPrev || cPrev->Next == cLnk);
232  assert(!cLnk || cLnk->Prev == cPrev);
233 
234  // Insert new link after predecessor
235  InsertLink(nLnk, cPrev);
236 
237 #ifdef _DEBUG
238  // Debug: Check sort
239  if (eSort == stMain)
240  {
242  if (pLstSorted)
243  assert(CheckSort(pLstSorted));
244  }
245 #endif
246 
247  // Add mass
248  Mass+=nObj->Mass;
249 
250  return true;
251 }
C4ID id
Definition: C4Object.h:108
int32_t Mass
Definition: C4Object.h:115
C4ObjectLink * First
Definition: C4ObjectList.h:51
int32_t GetPlane() const
Definition: C4Object.h:180
const C4ObjectLink * GetLink(const C4Object *pObj) const
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
void CheckCategorySort()
virtual void InsertLink(C4ObjectLink *pLink, C4ObjectLink *pAfter)
int32_t Status
Definition: C4PropList.h:168
const int32_t C4D_StaticBack
Definition: C4Def.h:40
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
bool Unsorted
Definition: C4Object.h:129
int32_t Category
Definition: C4Object.h:113
C4ObjectLink * Last
Definition: C4ObjectList.h:51
bool CheckSort(C4ObjectList *pList)
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 952 of file C4ObjectList.cpp.

References C4ObjectList::FirstIter.

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

953 {
954  iterator * r = FirstIter;
955  FirstIter = iter;
956  return r;
957 }
iterator * FirstIter
Definition: C4ObjectList.h:165
friend class iterator
Definition: C4ObjectList.h:169

Here is the caller graph for this function:

bool C4ObjectList::AddSortCustom ( C4Object nObj,
SortProc pSortProc 
)
inherited
bool C4GameObjects::AssignInfo ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 474 of file C4GameObjects.cpp.

References C4ObjectList::AssignInfo(), and InactiveObjects.

Referenced by C4Game::InitGameFinal().

475 {
476  // assign in sublists
477  bool fSucc = true;
478  if (!C4ObjectList::AssignInfo()) fSucc = false;
479  if (!InactiveObjects.AssignInfo()) fSucc = false;
480  return fSucc;
481 }
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
virtual bool AssignInfo()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::AssignLightRange ( )

Definition at line 483 of file C4GameObjects.cpp.

References C4ObjectList::reverse().

Referenced by C4Game::InitGameFinal().

484 {
485  for (C4Object *obj : reverse())
486  if (obj->Status)
487  obj->AssignLightRange();
488 }
const ReverseView reverse() const
Definition: C4ObjectList.h:104

Here is the call graph for this function:

Here is the caller graph for this function:

C4Object * C4GameObjects::AtObject ( int  ctx,
int  cty,
DWORD ocf,
C4Object exclude = nullptr 
)

Definition at line 155 of file C4GameObjects.cpp.

References C4Object::Layer, ObjectsAt(), and OCF_Exclusive.

156 {
157  DWORD cocf;
158  for (C4Object *cObj : ObjectsAt(ctx,cty))
159  if (!exclude || (cObj!=exclude && exclude->Layer == cObj->Layer)) if (cObj->Status)
160  {
161  cocf=ocf | OCF_Exclusive;
162  if (cObj->At(ctx,cty,cocf))
163  {
164  // Search match
165  if (cocf & ocf) { ocf=cocf; return cObj; }
166  // EXCLUSIVE block
167  else return nullptr;
168  }
169  }
170  return nullptr;
171 }
C4ObjectPtr Layer
Definition: C4Object.h:136
const uint32_t OCF_Exclusive
Definition: C4Constants.h:89
uint32_t DWORD
C4ObjectList & ObjectsAt(int ix, int iy)

Here is the call graph for this function:

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

Definition at line 944 of file C4ObjectList.cpp.

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

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

945 {
946  return iterator(*this, First, false);
947 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
friend class iterator
Definition: C4ObjectList.h:169

Here is the caller graph for this function:

void C4ObjectList::CheckCategorySort ( )
inherited

Definition at line 846 of file C4ObjectList.cpp.

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

Referenced by C4ObjectList::Add().

847 {
848  // debug: Check whether object list is sorted correctly
849  C4ObjectLink *cLnk, *cPrev=nullptr;
850  for (cLnk=First; cLnk; cLnk=cLnk->Next)
851  if (!cLnk->Obj->Unsorted && cLnk->Obj->Status)
852  {
853  if (cPrev) assert(cPrev->Obj->GetPlane() >= cLnk->Obj->GetPlane());
854  cPrev = cLnk;
855  }
856 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
int32_t GetPlane() const
Definition: C4Object.h:180
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
bool Unsorted
Definition: C4Object.h:129
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectList::CheckSort ( C4ObjectList pList)
inherited

Definition at line 820 of file C4ObjectList.cpp.

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

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

821 {
822  C4ObjectLink *cLnk = First, *cLnk2 = pList->First;
823  while (cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;
824 
825  while (cLnk)
826  if (!cLnk2)
827  {
828  Log("CheckSort failure");
829  C4ValueNumbers numbers;
830  LogSilent(DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(C4ObjectListDumpHelper(this, &numbers), "SectorList")).getData());
831  LogSilent(DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(C4ObjectListDumpHelper(pList, &numbers), "MainList")).getData());
832  return false;
833  }
834  else
835  {
836  if (cLnk->Obj == cLnk2->Obj)
837  {
838  cLnk = cLnk->Next;
839  while (cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;
840  }
841  cLnk2 = cLnk2->Next;
842  }
843  return true;
844 }
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:114
C4ObjectLink * First
Definition: C4ObjectList.h:51
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
bool Unsorted
Definition: C4Object.h:129
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Clear ( bool  fClearInactive)

Definition at line 211 of file C4GameObjects.cpp.

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

Referenced by C4Game::CompileRuntimeData().

212 {
213  DeleteObjects(fClearInactive);
214  if (fClearInactive)
216  LastUsedMarker = 0;
217 }
void DeleteObjects()
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
virtual void Clear()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Clear ( )
inlineoverridevirtual

Reimplemented from C4ObjectList.

Definition at line 36 of file C4GameObjects.h.

References Clear().

Referenced by Clear().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::ClearInfo ( C4ObjectInfo pInfo)
inherited

Definition at line 561 of file C4ObjectList.cpp.

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

Referenced by C4ObjectInfoList::DetachFromObjects().

562 {
563  C4ObjectLink *cLnk;
564  for (cLnk=First; cLnk; cLnk=cLnk->Next)
565  if (cLnk->Obj->Status)
566  cLnk->Obj->ClearInfo(pInfo);
567 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28
void ClearInfo(C4ObjectInfo *pInfo)
Definition: C4Object.cpp:2424

Here is the call graph for this function:

Here is the caller graph for this function:

int C4ObjectList::ClearPointers ( C4Object pObj)
inherited

Definition at line 366 of file C4ObjectList.cpp.

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

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

367 {
368  int rval=0;
369  // Clear all primary list pointers
370  while (Remove(pObj)) rval++;
371  // Clear all sub pointers
372  C4Object *cobj; C4ObjectLink *clnk;
373  for (clnk=First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
374  cobj->ClearPointers(pObj);
375  return rval;
376 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Object * Obj
Definition: C4ObjectList.h:28
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::CloseMenus ( )
inherited

Definition at line 697 of file C4ObjectList.cpp.

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

698 {
699  C4Object *cobj; C4ObjectLink *clnk;
700  for (clnk=First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
701  cobj->CloseMenu(true);
702 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Object * Obj
Definition: C4ObjectList.h:28
void C4ObjectList::CompileFunc ( StdCompiler pComp,
C4ValueNumbers numbers = nullptr 
)
inherited

Definition at line 507 of file C4ObjectList.cpp.

References C4ObjectList::First, StdCompiler::isDeserializer(), mkSTLContainerAdapt(), C4ObjectLink::Next, C4ObjectList::pEnumerated, StdCompiler::SEP_SEP2, and StdCompiler::Value().

508 {
509  // (Re)create list
510  delete pEnumerated; pEnumerated = new std::list<int32_t>();
511  // Decompiling: Build list
512  if (!pComp->isDeserializer())
513  for (C4ObjectLink *pPos = First; pPos; pPos = pPos->Next)
514  if (pPos->Obj->Status)
515  pEnumerated->push_back(pPos->Obj->Number);
516  // Compile list
518  // Decompiling: Delete list
519  if (!pComp->isDeserializer())
520  { delete pEnumerated; pEnumerated = nullptr; }
521  // Compiling: Nothing to do - list will be denumerated later
522 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:681
std::list< int32_t > * pEnumerated
Definition: C4ObjectList.h:53

Here is the call graph for this function:

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

Definition at line 464 of file C4ObjectList.cpp.

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

465 {
466  // "Object" section count
467  int32_t iObjCnt = ObjectCount();
468  pComp->Value(mkNamingCountAdapt(iObjCnt, "Object"));
469  if (pComp->isSerializer())
470  {
471  // skipping player objects would screw object counting in non-naming compilers
472  assert(!fSkipPlayerObjects || pComp->hasNaming());
473  // Decompile all objects in reverse order
474  for (C4ObjectLink *pPos = Last; pPos; pPos = pPos->Prev)
475  if (pPos->Obj->Status)
476  if (!fSkipPlayerObjects || !pPos->Obj->IsUserPlayerObject())
477  pComp->Value(mkNamingAdapt(mkParAdapt(*pPos->Obj, numbers), "Object"));
478  }
479  else
480  {
481  // FIXME: Check that no PlayerObjects are loaded when fSkipPlayerObjects is true
482  // i.e. that loading and saving was done with the same flag.
483  // Remove previous data
484  Clear();
485  // Load objects, add them to the list.
486  for (int i = 0; i < iObjCnt; i++)
487  {
488  C4Object *pObj = nullptr;
489  try
490  {
491  pComp->Value(mkNamingAdapt(mkParAdapt(mkPtrAdaptNoNull(pObj), numbers), "Object"));
492  Add(pObj, stReverse);
493  }
494  catch (StdCompiler::Exception *pExc)
495  {
496  // Failsafe object loading: If an error occurs during object loading, just skip that object and load the next one
497  if (!pExc->Pos.getLength())
498  LogF("ERROR: Object loading: %s", pExc->Msg.getData());
499  else
500  LogF("ERROR: Object loading(%s): %s", pExc->Pos.getData(), pExc->Msg.getData());
501  delete pExc;
502  }
503  }
504  }
505 }
const char * getData() const
Definition: StdBuf.h:442
virtual bool hasNaming()
Definition: StdCompiler.h:58
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:976
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
bool isSerializer()
Definition: StdCompiler.h:54
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:606
void Value(const T &rStruct)
Definition: StdCompiler.h:161
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
int ObjectCount(C4ID id=C4ID::None) const
C4ObjectLink * Last
Definition: C4ObjectList.h:51
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
size_t getLength() const
Definition: StdBuf.h:445
virtual void Clear()
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250

Here is the call graph for this function:

void C4ObjectList::Copy ( const C4ObjectList rList)
inherited

Definition at line 704 of file C4ObjectList.cpp.

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

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

705 {
706  Clear(); Default();
707  C4ObjectLink *cLnk;
708  for (cLnk=rList.First; cLnk; cLnk=cLnk->Next) Add(cLnk->Obj, C4ObjectList::stNone);
709 }
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
virtual void Default()
virtual void Clear()
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::CrossCheck ( )

Definition at line 89 of file C4GameObjects.cpp.

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(), 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().

90 {
91  DWORD focf,tocf;
92 
93  // Reverse area check: Checks for all obj2 at obj1
94 
95  focf = tocf = OCF_None;
96  // High level: Collection, Hit
97  if (!::Game.iTick3)
98  tocf |= OCF_Carryable;
99  focf |= OCF_Collection; focf |= OCF_Alive; tocf |= OCF_HitSpeed2;
100 
101  for (C4Object* obj1 : *this)
102  if (obj1->Status && !obj1->Contained && (obj1->OCF & focf))
103  {
104  uint32_t Marker = GetNextMarker();
105  C4LSector *pSct;
106  for (C4ObjectList *pLst = obj1->Area.FirstObjects(&pSct); pLst; pLst = obj1->Area.NextObjects(pLst, &pSct))
107  for (C4Object* obj2 : *pLst)
108  if ((obj2 != obj1) && obj2->Status && !obj2->Contained && (obj2->OCF & tocf) &&
109  Inside<int32_t>(obj2->GetX() - (obj1->GetX() + obj1->Shape.x), 0, obj1->Shape.Wdt - 1) &&
110  Inside<int32_t>(obj2->GetY() - (obj1->GetY() + obj1->Shape.y), 0, obj1->Shape.Hgt - 1) &&
111  obj1->Layer == obj2->Layer)
112  {
113  // handle collision only once
114  if (obj2->Marker == Marker) continue;
115  obj2->Marker = Marker;
116  // Only hit if target is alive and projectile is an object
117  if ((obj1->OCF & OCF_Alive) && (obj2->Category & C4D_Object))
118  {
119  C4Real dXDir = obj2->xdir - obj1->xdir, dYDir = obj2->ydir - obj1->ydir;
120  C4Real speed = dXDir * dXDir + dYDir * dYDir;
121  // Only hit if obj2's speed and relative speeds are larger than HitSpeed2
122  if ((obj2->OCF & OCF_HitSpeed2) && speed > HitSpeed2 &&
123  !obj1->Call(PSF_QueryCatchBlow, &C4AulParSet(obj2)))
124  {
125  int32_t iHitEnergy = fixtoi(speed * obj2->Mass / 5);
126  // Hit energy reduced to 1/3rd, but do not drop to zero because of this division
127  iHitEnergy = std::max<int32_t>(iHitEnergy/3, !!iHitEnergy);
128  obj1->DoEnergy(-iHitEnergy / 5, false, C4FxCall_EngObjHit, obj2->Controller);
129  int tmass = std::max<int32_t>(obj1->Mass, 50);
130  C4PropList* pActionDef = obj1->GetAction();
131  if (!::Game.iTick3 || (pActionDef && pActionDef->GetPropertyP(P_Procedure) != DFA_FLIGHT))
132  obj1->Fling(obj2->xdir * 50 / tmass, -Abs(obj2->ydir / 2) * 50 / tmass, false);
133  obj1->Call(PSF_CatchBlow, &C4AulParSet(-iHitEnergy / 5, obj2));
134  // obj1 might have been tampered with
135  if (!obj1->Status || obj1->Contained || !(obj1->OCF & focf))
136  goto out1;
137  continue;
138  }
139  }
140  // Collection
141  if ((obj1->OCF & OCF_Collection) && (obj2->OCF & OCF_Carryable) &&
142  Inside<int32_t>(obj2->GetX() - (obj1->GetX() + obj1->Def->Collection.x), 0, obj1->Def->Collection.Wdt - 1) &&
143  Inside<int32_t>(obj2->GetY() - (obj1->GetY() + obj1->Def->Collection.y), 0, obj1->Def->Collection.Hgt - 1))
144  {
145  obj1->Collect(obj2);
146  // obj1 might have been tampered with
147  if (!obj1->Status || obj1->Contained || !(obj1->OCF & focf))
148  goto out1;
149  }
150  }
151  out1: ;
152  }
153 }
int32_t GetY() const
Definition: C4Object.h:287
C4LArea Area
Definition: C4Object.h:114
const uint32_t OCF_Alive
Definition: C4Constants.h:103
const uint32_t OCF_Collection
Definition: C4Constants.h:93
C4Game Game
Definition: C4Globals.cpp:52
#define PSF_CatchBlow
Definition: C4GameScript.h:72
int32_t Mass
Definition: C4Object.h:115
C4PropList * GetAction() const
Definition: C4Object.cpp:2674
const C4Real HitSpeed2
Definition: C4Movement.cpp:37
C4ObjectPtr Layer
Definition: C4Object.h:136
Definition: C4Real.h:58
int32_t Wdt
Definition: C4Rect.h:30
const uint32_t OCF_HitSpeed2
Definition: C4Constants.h:91
const int32_t C4D_Object
Definition: C4Def.h:44
C4Def * Def
Definition: C4Object.h:143
int32_t y
Definition: C4Rect.h:30
C4Rect Collection
Definition: C4Def.h:106
int32_t GetX() const
Definition: C4Object.h:286
uint32_t GetNextMarker()
C4ObjectList * FirstObjects(C4LSector **ppSct)
Definition: C4Sector.h:118
int32_t iTick3
Definition: C4Game.h:129
int32_t Status
Definition: C4PropList.h:168
bool Collect(C4Object *pObj)
Definition: C4Object.cpp:4167
int32_t x
Definition: C4Rect.h:30
void DoEnergy(int32_t iChange, bool fExact, int32_t iCause, int32_t iCausedByPlr)
Definition: C4Object.cpp:1106
const uint32_t OCF_Carryable
Definition: C4Constants.h:82
#define PSF_QueryCatchBlow
Definition: C4GameScript.h:73
#define C4FxCall_EngObjHit
Definition: C4Effect.h:57
C4ObjectPtr Contained
Definition: C4Object.h:144
int32_t Hgt
Definition: C4Rect.h:30
T Abs(T val)
Definition: Standard.h:42
C4Shape Shape
Definition: C4Object.h:148
uint32_t OCF
Definition: C4Object.h:134
void Fling(C4Real txdir, C4Real tydir, bool fAddSpeed)
Definition: C4Object.cpp:1336
uint32_t DWORD
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Real xdir
Definition: C4Object.h:126
const uint32_t OCF_None
Definition: C4Constants.h:77
C4ObjectList * NextObjects(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:303
C4Real ydir
Definition: C4Object.h:126
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Default ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 42 of file C4GameObjects.cpp.

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

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

43 {
44  Sectors.Clear();
45  LastUsedMarker = 0;
47 }
void Clear()
Definition: C4Sector.cpp:74
C4LSectors Sectors
Definition: C4GameObjects.h:42
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
virtual void Default()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::DeleteObjects ( bool  fDeleteInactive)

Definition at line 203 of file C4GameObjects.cpp.

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

Referenced by C4Game::DeleteObjects().

204 {
207  ForeObjects.Clear();
208  if (fDeleteInactive) InactiveObjects.DeleteObjects();
209 }
void DeleteObjects()
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
C4LSectors Sectors
Definition: C4GameObjects.h:42
void ClearObjects()
Definition: C4Sector.cpp:225
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
virtual void Clear()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::DeleteObjects ( )
inherited

Definition at line 737 of file C4ObjectList.cpp.

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

Referenced by Clear(), and DeleteObjects().

738 {
739  // delete links and objects
740  while (First)
741  {
742  C4Object *pObj = First->Obj;
743  if (pObj->Status) Game.ClearPointers(pObj); // clear pointers to removed objects that weren't deleted (game end or section change)
744  pObj->Status = C4OS_DELETED;
745  Remove(pObj);
746  delete pObj;
747  }
748  // reset mass
749  Mass=0;
750 }
C4Game Game
Definition: C4Globals.cpp:52
C4ObjectLink * First
Definition: C4ObjectList.h:51
#define C4OS_DELETED
Definition: C4Object.h:34
int32_t Status
Definition: C4PropList.h:168
void ClearPointers(C4Object *cobj)
Definition: C4Game.cpp:921
C4Object * Obj
Definition: C4ObjectList.h:28
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Denumerate ( C4ValueNumbers numbers)

Definition at line 337 of file C4GameObjects.cpp.

References C4ObjectList::Denumerate(), and InactiveObjects.

Referenced by PostLoad().

338 {
339  C4ObjectList::Denumerate(numbers);
340  InactiveObjects.Denumerate(numbers);
341 }
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
void Denumerate(C4ValueNumbers *)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectList::DenumeratePointers ( )
inherited

Definition at line 431 of file C4ObjectList.cpp.

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

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

432 {
433  if (!pEnumerated) return false;
434  // Denumerate all object pointers
435  for (std::list<int32_t>::const_iterator pNum = pEnumerated->begin(); pNum != pEnumerated->end(); ++pNum)
436  Add(::Objects.ObjectPointer(*pNum), stNone); // Add to tail, unsorted
437  // Delete old list
438  delete pEnumerated; pEnumerated = nullptr;
439  return true;
440 }
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
std::list< int32_t > * pEnumerated
Definition: C4ObjectList.h:53
C4Object * ObjectPointer(int32_t iNumber)
C4GameObjects Objects
Definition: C4Globals.cpp:48

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 378 of file C4ObjectList.cpp.

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

Referenced by C4Viewport::Draw().

379 {
380  C4ObjectLink * clnk, * first;
381  for (first=Last; first; first=first->Prev)
382  if (first->Obj->GetPlane() >= MinPlane)
383  break;
384  // Draw objects (base)
385  for (clnk=first; clnk; clnk=clnk->Prev)
386  {
387  if (clnk->Obj->GetPlane() > MaxPlane)
388  break;
389  if (clnk->Obj->Category & C4D_Foreground)
390  continue;
391  clnk->Obj->Draw(cgo, iPlayer);
392  }
393  // Draw objects (top face)
394  for (clnk=first; clnk; clnk=clnk->Prev)
395  {
396  if (clnk->Obj->GetPlane() > MaxPlane)
397  break;
398  if (clnk->Obj->Category & C4D_Foreground)
399  continue;
400  clnk->Obj->DrawTopFace(cgo, iPlayer);
401  }
402 }
void Draw(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
Definition: C4Object.cpp:1785
int32_t GetPlane() const
Definition: C4Object.h:180
void DrawTopFace(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
Definition: C4Object.cpp:2045
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
int32_t Category
Definition: C4Object.h:113
C4ObjectLink * Last
Definition: C4ObjectList.h:51
C4Object * Obj
Definition: C4ObjectList.h:28
const int32_t C4D_Foreground
Definition: C4Def.h:53

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::DrawIfCategory ( C4TargetFacet cgo,
int  iPlayer,
uint32_t  dwCat,
bool  fInvert 
)
inherited

Definition at line 404 of file C4ObjectList.cpp.

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

Referenced by C4Viewport::Draw().

405 {
406  C4ObjectLink *clnk;
407  // Draw objects (base)
408  for (clnk=Last; clnk; clnk=clnk->Prev)
409  if (!(clnk->Obj->Category & dwCat) == fInvert)
410  clnk->Obj->Draw(cgo, iPlayer);
411  // Draw objects (top face)
412  for (clnk=Last; clnk; clnk=clnk->Prev)
413  if (!(clnk->Obj->Category & dwCat) == fInvert)
414  clnk->Obj->DrawTopFace(cgo, iPlayer);
415 }
void Draw(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
Definition: C4Object.cpp:1785
void DrawTopFace(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
Definition: C4Object.cpp:2045
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
int32_t Category
Definition: C4Object.h:113
C4ObjectLink * Last
Definition: C4ObjectList.h:51
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::DrawSelectMark ( C4TargetFacet cgo) const
inherited

Definition at line 690 of file C4ObjectList.cpp.

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

Referenced by C4MouseControl::Draw().

691 {
692  C4ObjectLink *cLnk;
693  for (cLnk=Last; cLnk; cLnk=cLnk->Prev)
694  cLnk->Obj->DrawSelectMark(cgo);
695 }
void DrawSelectMark(C4TargetFacet &cgo) const
Definition: C4Object.cpp:2510
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
C4ObjectLink * Last
Definition: C4ObjectList.h:51
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 948 of file C4ObjectList.cpp.

References C4ObjectList::iterator.

Referenced by C4ObjectListIterator::GetNext().

949 {
950  return iterator(*this, nullptr, false);
951 }
friend class iterator
Definition: C4ObjectList.h:169

Here is the caller graph for this function:

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

Definition at line 296 of file C4ObjectList.cpp.

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().

297 {
298  C4ObjectLink *cLnk;
299  // Find link and object
300  for (cLnk=First; cLnk; cLnk=cLnk->Next)
301  if (cLnk->Obj->Status)
302  if (cLnk->Obj->Def==def)
303  if ((owner==ANY_OWNER) || (cLnk->Obj->Owner==owner))
304  if (dwOCF & cLnk->Obj->OCF)
305  return cLnk->Obj;
306  return nullptr;
307 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
const int ANY_OWNER
Definition: C4Constants.h:138
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
int32_t Owner
Definition: C4Object.h:110
int32_t Status
Definition: C4PropList.h:168
uint32_t OCF
Definition: C4Object.h:134
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

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

Definition at line 309 of file C4ObjectList.cpp.

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

310 {
311  C4ObjectLink *cLnk;
312  // Find link and object
313  for (cLnk=First; cLnk; cLnk=cLnk->Next)
314  if (cLnk->Obj->Status)
315  if (cLnk->Obj->Def->id!=id)
316  if ((owner==ANY_OWNER) || (cLnk->Obj->Owner==owner))
317  return cLnk->Obj;
318  return nullptr;
319 }
C4ID id
Definition: C4Def.h:101
C4ObjectLink * First
Definition: C4ObjectList.h:51
const int ANY_OWNER
Definition: C4Constants.h:138
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
int32_t Owner
Definition: C4Object.h:110
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28
void C4GameObjects::FixObjectOrder ( )

Definition at line 376 of file C4GameObjects.cpp.

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

Referenced by PostLoad().

377 {
378  // fixes the object order so it matches the global object order sorting constraints
379  C4ObjectLink *pLnk0=First, *pLnkL=Last;
380  while (pLnk0 != pLnkL)
381  {
382  C4ObjectLink *pLnk1stUnsorted=nullptr, *pLnkLastUnsorted=nullptr, *pLnkPrev=nullptr, *pLnk;
383  C4Object *pLastWarnObj = nullptr;
384  // forward fix
385  int lastPlane = 2147483647; //INT32_MAX;
386  for (pLnk = pLnk0; pLnk!=pLnkL->Next; pLnk=pLnk->Next)
387  {
388  C4Object *pObj = pLnk->Obj;
389  if (pObj->Unsorted || !pObj->Status) continue;
390  int currentPlane = pObj->GetPlane();
391  // must have nonzero Plane
392  if (!currentPlane)
393  {
394  DebugLogF("Objects.txt: Object #%d has zero Plane!", (int) pObj->Number);
395  pObj->SetPlane(lastPlane); currentPlane = lastPlane;
396  }
397  // fix order
398  if (currentPlane > lastPlane)
399  {
400  // SORT ERROR! (note that pLnkPrev can't be 0)
401  if (pLnkPrev->Obj != pLastWarnObj)
402  {
403  DebugLogF("Objects.txt: Wrong object order of #%d-#%d! (down)", (int) pObj->Number, (int) pLnkPrev->Obj->Number);
404  pLastWarnObj = pLnkPrev->Obj;
405  }
406  pLnk->Obj = pLnkPrev->Obj;
407  pLnkPrev->Obj = pObj;
408  pLnkLastUnsorted = pLnkPrev;
409  }
410  else
411  lastPlane = currentPlane;
412  pLnkPrev = pLnk;
413  }
414  if (!pLnkLastUnsorted) break; // done
415  pLnkL = pLnkLastUnsorted;
416  // backwards fix
417  lastPlane = -2147483647-1; //INT32_MIN;
418  for (pLnk = pLnkL; pLnk!=pLnk0->Prev; pLnk=pLnk->Prev)
419  {
420  C4Object *pObj = pLnk->Obj;
421  if (pObj->Unsorted || !pObj->Status) continue;
422  int currentPlane = pObj->GetPlane();
423  if (currentPlane < lastPlane)
424  {
425  // SORT ERROR! (note that pLnkPrev can't be 0)
426  if (pLnkPrev->Obj != pLastWarnObj)
427  {
428  DebugLogF("Objects.txt: Wrong object order of #%d-#%d! (up)", (int) pObj->Number, (int) pLnkPrev->Obj->Number);
429  pLastWarnObj = pLnkPrev->Obj;
430  }
431  pLnk->Obj = pLnkPrev->Obj;
432  pLnkPrev->Obj = pObj;
433  pLnk1stUnsorted = pLnkPrev;
434  }
435  else
436  lastPlane = currentPlane;
437  pLnkPrev = pLnk;
438  }
439  if (!pLnk1stUnsorted) break; // done
440  pLnk0 = pLnk1stUnsorted;
441  }
442  // objects fixed!
443 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
int32_t GetPlane() const
Definition: C4Object.h:180
void SetPlane(int32_t z)
Definition: C4Object.h:179
C4ObjectLink * Next
Definition: C4ObjectList.h:29
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
int32_t Status
Definition: C4PropList.h:168
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
bool Unsorted
Definition: C4Object.h:129
C4ObjectLink * Last
Definition: C4ObjectList.h:51

Here is the call graph for this function:

Here is the caller graph for this function:

C4Object* C4ObjectList::GetFirstObject ( ) const
inlineinherited

Definition at line 141 of file C4ObjectList.h.

References C4ObjectLink::Obj.

Referenced by C4Player::CheckElimination().

141 { return First ? First->Obj : nullptr; }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

C4Object* C4ObjectList::GetLastObject ( ) const
inlineinherited

Definition at line 142 of file C4ObjectList.h.

References C4ObjectLink::Obj.

Referenced by C4Object::PutAwayUnusedObject().

142 { return Last ? Last->Obj : nullptr; }
C4ObjectLink * Last
Definition: C4ObjectList.h:51
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

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

Definition at line 335 of file C4ObjectList.cpp.

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().

336 {
337  if (!pObj) return nullptr;
338  C4ObjectLink *cLnk;
339  for (cLnk=First; cLnk; cLnk=cLnk->Next)
340  if (cLnk->Obj==pObj)
341  return cLnk;
342  return nullptr;
343 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

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

Definition at line 147 of file C4ObjectList.h.

References C4ObjectList::GetLink().

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

Here is the call graph for this function:

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

Definition at line 69 of file C4ObjectList.cpp.

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

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

70 {
71  int clid;
72  C4ObjectLink *clnk;
73  C4Def *cdef;
74 
75  // Create a temporary list of all id's and counts
76  for (clid=0; clid<MaxTempListID; clid++) TempListID[clid]=C4ID::None;
77  for (clnk=First; clnk && clnk->Obj; clnk=clnk->Next)
78  if (clnk->Obj->Status)
79  if ((dwCategory==C4D_All) || ( (cdef=C4Id2Def(clnk->Obj->Def->id)) && (cdef->Category & dwCategory) ))
80  for (clid=0; clid<MaxTempListID; clid++)
81  {
82  // Already there
83  if (TempListID[clid]==clnk->Obj->Def->id) break;
84  // End of list, add id
85  if (TempListID[clid]==C4ID::None) { TempListID[clid]=clnk->Obj->Def->id; break; }
86  }
87 
88  // Returns indexed id
89  if (Inside(Index,0,MaxTempListID-1)) return TempListID[Index];
90 
91  return C4ID::None;
92 }
C4ID id
Definition: C4Def.h:101
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
static const C4ID None
Definition: C4Id.h:39
const int MaxTempListID
const int32_t C4D_All
Definition: C4Def.h:39
Definition: C4Def.h:98
int32_t Status
Definition: C4PropList.h:168
C4ID TempListID[MaxTempListID]
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
int32_t Category
Definition: C4Def.h:117
C4Object * Obj
Definition: C4ObjectList.h:28
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4ObjectList::GetNameList ( C4DefList rDefs) const
inherited

Definition at line 524 of file C4ObjectList.cpp.

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

Referenced by C4Object::GetDataString().

525 {
526  int cpos,idcount;
527  C4ID c_id;
528  C4Def *cdef;
529  StdStrBuf Buf;
530  for (cpos=0; (c_id=GetListID(C4D_All,cpos)); cpos++)
531  if ((cdef=rDefs.ID2Def(c_id)))
532  {
533  idcount=ObjectCount(c_id);
534  if (cpos>0) Buf.Append(", ");
535  Buf.AppendFormat("%dx %s",idcount,cdef->GetName());
536  }
537  return Buf;
538 }
C4Def * ID2Def(C4ID id)
const char * GetName() const override
Definition: C4PropList.cpp:267
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
const int32_t C4D_All
Definition: C4Def.h:39
Definition: C4Def.h:98
Definition: C4Id.h:25
int ObjectCount(C4ID id=C4ID::None) const
C4ID GetListID(int32_t dwCategory, int Index) const

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t C4GameObjects::GetNextMarker ( )

Definition at line 521 of file C4GameObjects.cpp.

References C4Object::Marker.

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

522 {
523  // Get a new marker.
524  uint32_t marker = ++LastUsedMarker;
525  // If all markers are exceeded, restart marker at 1 and reset all object markers to zero.
526  if (!marker)
527  {
528  for (C4Object *cobj : *this)
529  {
530  if (cobj)
531  cobj->Marker = 0;
532  }
533  marker = ++LastUsedMarker;
534  }
535  return marker;
536 }
uint32_t Marker
Definition: C4Object.h:135

Here is the caller graph for this function:

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

Definition at line 321 of file C4ObjectList.cpp.

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().

322 {
323  int cIdx;
324  C4ObjectLink *cLnk;
325  // Find link and object
326  for (cLnk=First,cIdx=0; cLnk; cLnk=cLnk->Next)
327  if (cLnk->Obj->Status)
328  {
329  if (cIdx==Index) return cLnk->Obj;
330  cIdx++;
331  }
332  return nullptr;
333 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

C4Value C4GameObjects::GRBroadcast ( const char *  szFunction,
C4AulParSet pPars,
bool  fPassError,
bool  fRejectTest 
)

Definition at line 350 of file C4GameObjects.cpp.

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

Referenced by C4Game::GRBroadcast().

351 {
352  // call objects first - scenario script might overwrite hostility, etc...
353  for (C4Object *pObj : *this)
354  if (pObj && (pObj->Category & (C4D_Goal | C4D_Rule | C4D_Environment)) && pObj->Status)
355  {
356  C4Value vResult = pObj->Call(szFunction, pPars, fPassError);
357  // rejection tests abort on first nonzero result
358  if (fRejectTest && !!vResult) return vResult;
359  }
360  return C4Value();
361 }
const int32_t C4D_Environment
Definition: C4Def.h:48
int32_t Status
Definition: C4PropList.h:168
const int32_t C4D_Rule
Definition: C4Def.h:47
int32_t Category
Definition: C4Object.h:113
const int32_t C4D_Goal
Definition: C4Def.h:46
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Init ( int32_t  iWidth,
int32_t  iHeight 
)

Definition at line 49 of file C4GameObjects.cpp.

References C4LSectors::Init(), and Sectors.

Referenced by C4Game::InitGame().

50 {
51  // init sectors
52  Sectors.Init(iWidth, iHeight);
53 }
void Init(int Wdt, int Hgt)
Definition: C4Sector.cpp:58
C4LSectors Sectors
Definition: C4GameObjects.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void C4NotifyingObjectList::InsertLink ( C4ObjectLink pLink,
C4ObjectLink pAfter 
)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 662 of file C4ObjectList.cpp.

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

663 {
664  C4ObjectList::InsertLink(pLink, pAfter);
666 }
virtual void OnObjectAdded(C4ObjectList *pList, C4ObjectLink *pLnk)
Definition: C4ObjectList.h:36
virtual void InsertLink(C4ObjectLink *pLink, C4ObjectLink *pAfter)
C4ObjectListChangeListener & ObjectListChangeListener

Here is the call graph for this function:

void C4NotifyingObjectList::InsertLinkBefore ( C4ObjectLink pLink,
C4ObjectLink pBefore 
)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 656 of file C4ObjectList.cpp.

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

657 {
658  C4ObjectList::InsertLinkBefore(pLink, pBefore);
660 }
virtual void InsertLinkBefore(C4ObjectLink *pLink, C4ObjectLink *pBefore)
virtual void OnObjectAdded(C4ObjectList *pList, C4ObjectLink *pLnk)
Definition: C4ObjectList.h:36
C4ObjectListChangeListener & ObjectListChangeListener

Here is the call graph for this function:

bool C4ObjectList::IsClear ( ) const
inherited

Definition at line 426 of file C4ObjectList.cpp.

References C4ObjectList::ObjectCount().

427 {
428  return (ObjectCount()==0);
429 }
int ObjectCount(C4ID id=C4ID::None) const

Here is the call graph for this function:

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

Definition at line 417 of file C4ObjectList.cpp.

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

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

418 {
419  C4ObjectLink *cLnk;
420  for (cLnk=First; cLnk; cLnk=cLnk->Next)
421  if (cLnk->Obj==pObj)
422  return true;
423  return false;
424 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

int C4ObjectList::ListIDCount ( int32_t  dwCategory) const
inherited

Definition at line 94 of file C4ObjectList.cpp.

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

95 {
96  int clid;
97  C4ObjectLink *clnk;
98  C4Def *cdef;
99 
100  // Create a temporary list of all id's and counts
101  for (clid=0; clid<MaxTempListID; clid++) TempListID[clid]=C4ID::None;
102  for (clnk=First; clnk && clnk->Obj; clnk=clnk->Next)
103  if (clnk->Obj->Status)
104  if ((dwCategory==C4D_All) || ( (cdef=C4Id2Def(clnk->Obj->Def->id)) && (cdef->Category & dwCategory) ))
105  for (clid=0; clid<MaxTempListID; clid++)
106  {
107  // Already there
108  if (TempListID[clid]==clnk->Obj->Def->id) break;
109  // End of list, add id
110  if (TempListID[clid]==C4ID::None) { TempListID[clid]=clnk->Obj->Def->id; break; }
111  }
112 
113  // Count different id's
114  for (clid=0; clid<MaxTempListID; clid++)
115  if (TempListID[clid]==C4ID::None)
116  return clid;
117 
118  return MaxTempListID;
119 }
C4ID id
Definition: C4Def.h:101
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
static const C4ID None
Definition: C4Id.h:39
const int MaxTempListID
const int32_t C4D_All
Definition: C4Def.h:39
Definition: C4Def.h:98
int32_t Status
Definition: C4PropList.h:168
C4ID TempListID[MaxTempListID]
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
int32_t Category
Definition: C4Def.h:117
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

int C4ObjectList::MassCount ( )
inherited

Definition at line 355 of file C4ObjectList.cpp.

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

Referenced by C4Object::UpdateMass().

356 {
357  C4ObjectLink *cLnk;
358  int iMass=0;
359  for (cLnk=First; cLnk; cLnk=cLnk->Next)
360  if (cLnk->Obj->Status)
361  iMass+=cLnk->Obj->Mass;
362  Mass=iMass;
363  return iMass;
364 }
int32_t Mass
Definition: C4Object.h:115
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

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

Definition at line 345 of file C4ObjectList.cpp.

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().

346 {
347  C4ObjectLink *cLnk;
348  int iCount=0;
349  for (cLnk=First; cLnk; cLnk=cLnk->Next)
350  if (cLnk->Obj->Status && (id==C4ID::None || cLnk->Obj->Def->id==id))
351  iCount++;
352  return iCount;
353 }
C4ID id
Definition: C4Def.h:101
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4Def * Def
Definition: C4Object.h:143
static const C4ID None
Definition: C4Id.h:39
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the caller graph for this function:

C4Object * C4GameObjects::ObjectPointer ( int32_t  iNumber)

Definition at line 181 of file C4GameObjects.cpp.

References C4PropListNumbered::GetByNumber(), and C4PropList::GetObject().

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

182 {
183  // search own list
185  if (pObj) return pObj->GetObject();
186  return nullptr;
187 }
static C4PropList * GetByNumber(int32_t iNumber)
Definition: C4PropList.cpp:75
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667

Here is the call graph for this function:

Here is the caller graph for this function:

C4ObjectList & C4GameObjects::ObjectsAt ( int  ix,
int  iy 
)

Definition at line 84 of file C4GameObjects.cpp.

References C4LSector::ObjectShapes, C4LSectors::SectorAt(), and Sectors.

Referenced by AtObject().

85 {
86  return Sectors.SectorAt(ix, iy)->ObjectShapes;
87 }
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSectors Sectors
Definition: C4GameObjects.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::OnSynchronized ( )

Definition at line 497 of file C4GameObjects.cpp.

References C4PropList::Call(), and PSF_OnSynchronized.

Referenced by C4TransferZones::Synchronize().

498 {
499  for (C4Object *obj : *this)
500  if (obj)
501  obj->Call(PSF_OnSynchronized);
502 }
#define PSF_OnSynchronized
Definition: C4GameScript.h:79
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 219 of file C4GameObjects.cpp.

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::Remove(), C4ObjectList::reverse(), C4PropListNumbered::SetEnumerationIndex(), SetOCF(), C4Object::SetOCF(), C4PropList::Status, C4ObjectList::stContents, C4ObjectList::stMain, C4ObjectList::stNone, C4PropListNumbered::UnshelveNumberedPropLists(), C4ObjectList::UpdateFaces(), C4Object::UpdateFlipDir(), C4ObjectList::UpdateGraphics(), C4Object::UpdateLight(), C4Object::xdir, and C4Object::ydir.

Referenced by C4Game::InitGame().

220 {
221  // Process objects
222  int32_t iMaxObjectNumber = 0;
223  for (C4Object *pObj : reverse())
224  {
225  // keep track of numbers
226  iMaxObjectNumber = std::max(iMaxObjectNumber, pObj->Number);
227  // add to list of foreobjects
228  if (pObj->Category & C4D_Foreground)
229  ForeObjects.Add(pObj, C4ObjectList::stMain, this);
230  // Unterminate end
231  }
232 
233  // Denumerate pointers
234  // on section load, inactive object numbers will be adjusted afterwards
235  // so fake inactive object list empty meanwhile
236  // note this has to be done to prevent even if object numbers did not collide
237  // to prevent an assertion fail when denumerating non-enumerated inactive objects
238  C4ObjectList inactiveObjectsCopy;
239  if (fKeepInactive)
240  {
241  inactiveObjectsCopy.Copy(InactiveObjects);
243  }
244  // denumerate pointers
245  Denumerate(numbers);
246  // update object enumeration index now, because calls like OnSynchronized might create objects
247  C4PropListNumbered::SetEnumerationIndex(iMaxObjectNumber);
248  // end faking and adjust object numbers
249  if (fKeepInactive)
250  {
251  InactiveObjects.Copy(inactiveObjectsCopy);
252  inactiveObjectsCopy.Clear();
254  }
255 
256  // special checks:
257  // -contained/contents-consistency
258  // -StaticBack-objects zero speed
259  for (C4Object *pObj : *this)
260  if (pObj->Status)
261  {
262  // staticback must not have speed
263  if (pObj->Category & C4D_StaticBack)
264  {
265  pObj->xdir = pObj->ydir = 0;
266  }
267  // contained must be in contents list
268  if (pObj->Contained)
269  if (!pObj->Contained->Contents.GetLink(pObj))
270  {
271  DebugLogF("Error in Objects.txt: Container of #%d is #%d, but not found in contents list!", pObj->Number, pObj->Contained->Number);
273  }
274  // all contents must have contained set; otherwise, remove them!
275  auto contentsIt = pObj->Contents.begin();
276  while (!contentsIt.atEnd())
277  {
278  C4Object* pObj2 = *contentsIt;
279  // check double links
280  auto it2 = pObj->Contents.begin();
281  if (it2.find(pObj2) && it2 != contentsIt)
282  {
283  DebugLogF("Error in Objects.txt: Double containment of #%d by #%d!", pObj2->Number, pObj->Number);
284  // this remove-call will only remove the previous (dobuled) link, so cLnkCont should be save
285  pObj->Contents.Remove(pObj2);
286  // contents checked already
287  continue;
288  }
289  // check contents/contained-relation
290  if (pObj2->Status && pObj2->Contained != pObj)
291  {
292  DebugLogF("Error in Objects.txt: Object #%d not in container #%d as referenced!", pObj2->Number, pObj->Number);
293  pObj2->Contained = pObj;
294  }
295  contentsIt++;
296  }
297  }
298  // sort out inactive objects
299  for (C4Object *obj : *this)
300  {
301  if (obj->Status == C4OS_INACTIVE)
302  {
303  Remove(obj);
305  }
306  }
307 
308  {
309  C4DebugRecOff DBGRECOFF; // - script callbacks that would kill DebugRec-sync for runtime start
310  // update graphics
311  UpdateGraphics(false);
312  // Update faces
313  UpdateFaces(false);
314  // Update ocf
315  SetOCF();
316  }
317 
318  // make sure list is sorted by category - after sorting out inactives, because inactives aren't sorted into the main list
319  FixObjectOrder();
320 
321  // misc updates
322  for (C4Object *pObj : *this)
323  if (pObj->Status)
324  {
325  // add to plrview
326  pObj->UpdateLight();
327  // update flipdir (for old objects.txt with no flipdir defined)
328  // assigns Action.DrawDir as well
329  pObj->UpdateFlipDir();
330  // initial OCF update
331  pObj->SetOCF();
332  }
333  // Done
334  return ObjectCount();
335 }
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
void UpdateFaces(bool bUpdateShape)
bool Remove(C4Object *pObj) override
static void SetEnumerationIndex(int32_t iMaxObjectNumber)
Definition: C4PropList.cpp:93
void Copy(const C4ObjectList &rList)
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
const C4ObjectLink * GetLink(const C4Object *pObj) const
C4NotifyingObjectList Contents
Definition: C4Object.h:152
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
void UpdateFlipDir()
Definition: C4Object.cpp:441
void UpdateGraphics(bool fGraphicsChanged)
static void UnshelveNumberedPropLists()
Definition: C4PropList.cpp:123
int32_t Status
Definition: C4PropList.h:168
const int32_t C4D_StaticBack
Definition: C4Def.h:40
int32_t Category
Definition: C4Object.h:113
void Denumerate(C4ValueNumbers *)
const ReverseView reverse() const
Definition: C4ObjectList.h:104
#define C4OS_INACTIVE
Definition: C4Object.h:36
int ObjectCount(C4ID id=C4ID::None) const
iterator begin() const
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
void UpdateLight()
Definition: C4Object.cpp:4028
void SetOCF()
Definition: C4Object.cpp:667
C4ObjectPtr Contained
Definition: C4Object.h:144
virtual void Clear()
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126
const int32_t C4D_Foreground
Definition: C4Def.h:53
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameObjects::Remove ( C4Object pObj)
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 72 of file C4GameObjects.cpp.

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

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

73 {
74  // if it's an inactive object, simply remove from the inactiv elist
75  if (pObj->Status == C4OS_INACTIVE) return InactiveObjects.Remove(pObj);
76  // remove from sectors
77  Sectors.Remove(pObj);
78  // remove from forelist
79  ForeObjects.Remove(pObj);
80  // manipulate main list
81  return C4ObjectList::Remove(pObj);
82 }
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
int32_t Status
Definition: C4PropList.h:168
C4LSectors Sectors
Definition: C4GameObjects.h:42
#define C4OS_INACTIVE
Definition: C4Object.h:36
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
void Remove(C4Object *pObj)
Definition: C4Sector.cpp:151
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::RemoveIter ( iterator iter) const
protectedinherited

Definition at line 958 of file C4ObjectList.cpp.

References C4ObjectList::FirstIter.

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

959 {
960  if (iter == FirstIter)
961  FirstIter = iter->Next;
962  else
963  {
964  iterator * i = FirstIter;
965  while (i->Next && i->Next != iter)
966  i = i->Next;
967  i->Next = iter->Next;
968  }
969 }
iterator * FirstIter
Definition: C4ObjectList.h:165
friend class iterator
Definition: C4ObjectList.h:169

Here is the caller graph for this function:

void C4NotifyingObjectList::RemoveLink ( C4ObjectLink pLnk)
overrideprotectedvirtualinherited

Reimplemented from C4ObjectList.

Definition at line 668 of file C4ObjectList.cpp.

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

669 {
672 }
virtual void RemoveLink(C4ObjectLink *pLnk)
C4ObjectListChangeListener & ObjectListChangeListener
virtual void OnObjectRemove(C4ObjectList *pList, C4ObjectLink *pLnk)
Definition: C4ObjectList.h:35

Here is the call graph for this function:

void C4GameObjects::ResetAudibility ( )

Definition at line 504 of file C4GameObjects.cpp.

References C4Object::Audible, C4Object::AudiblePan, C4Object::AudiblePlayer, and NO_OWNER.

Referenced by C4GraphicsSystem::Execute().

505 {
506  for (C4Object *obj : *this)
507  if (obj)
508  {
509  obj->Audible = obj->AudiblePan = 0;
510  obj->AudiblePlayer = NO_OWNER;
511  }
512 }
int32_t AudiblePlayer
Definition: C4Object.h:121
int32_t AudiblePan
Definition: C4Object.h:121
const int NO_OWNER
Definition: C4Constants.h:137
int32_t Audible
Definition: C4Object.h:121

Here is the caller graph for this function:

void C4GameObjects::ResortUnsorted ( )

Definition at line 445 of file C4GameObjects.cpp.

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

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

446 {
447  for (C4Object *cObj : *this)
448  {
449  if (cObj->Unsorted)
450  {
451  // readd to main object list
452  Remove(cObj);
453  // reset flag so that Add correctly sorts this object
454  cObj->Unsorted=false;
455  if (!Add(cObj))
456  {
457  // readd failed: Better kill object to prevent leaking...
458  Game.ClearPointers(cObj);
459  delete cObj;
460  }
461  }
462  }
463 }
bool Add(C4Object *nObj)
C4Game Game
Definition: C4Globals.cpp:52
bool Remove(C4Object *pObj) override
bool Unsorted
Definition: C4Object.h:129
void ClearPointers(C4Object *cobj)
Definition: C4Game.cpp:921

Here is the call graph for this function:

Here is the caller graph for this function:

const ReverseView C4ObjectList::reverse ( ) const
inlineinherited

Definition at line 104 of file C4ObjectList.h.

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

104 { return ReverseView(*this); }

Here is the caller graph for this function:

C4Object * C4GameObjects::SafeObjectPointer ( int32_t  iNumber)

Definition at line 189 of file C4GameObjects.cpp.

References ObjectPointer(), and C4PropList::Status.

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

190 {
191  C4Object *pObj = ObjectPointer(iNumber);
192  if (pObj) if (!pObj->Status) return nullptr;
193  return pObj;
194 }
int32_t Status
Definition: C4PropList.h:168
C4Object * ObjectPointer(int32_t iNumber)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::SetOCF ( )

Definition at line 514 of file C4GameObjects.cpp.

References C4Object::SetOCF(), and C4PropList::Status.

Referenced by PostLoad().

515 {
516  for (C4Object *obj : *this)
517  if (obj->Status)
518  obj->SetOCF();
519 }
int32_t Status
Definition: C4PropList.h:168
void SetOCF()
Definition: C4Object.cpp:667

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectList::ShiftContents ( C4Object pNewFirst)
inherited

Definition at line 718 of file C4ObjectList.cpp.

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

Referenced by C4Object::DirectComContents().

719 {
720  // get link of new first (this ensures list is not empty)
721  C4ObjectLink *pNewFirstLnk = GetLink(pNewFirst);
722  if (!pNewFirstLnk) return false;
723  // already at front?
724  if (pNewFirstLnk == First) return true;
725  // sort it there:
726  // 1. Make cyclic list
727  Last->Next = First; First->Prev = Last;
728  // 2. Re-set first and last
729  First = pNewFirstLnk;
730  Last = pNewFirstLnk->Prev;
731  // 3. Uncycle list
732  First->Prev = Last->Next = nullptr;
733  // done, success
734  return true;
735 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
const C4ObjectLink * GetLink(const C4Object *pObj) const
C4ObjectLink * Next
Definition: C4ObjectList.h:29
C4ObjectLink * Prev
Definition: C4ObjectList.h:29
C4ObjectLink * Last
Definition: C4ObjectList.h:51

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::Sort ( )
inherited

Definition at line 569 of file C4ObjectList.cpp.

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

570 {
571  C4ObjectLink *cLnk;
572  bool fSorted;
573  // Sort by id
574  do
575  {
576  fSorted = true;
577  for (cLnk=First; cLnk && cLnk->Next; cLnk=cLnk->Next)
578  if (cLnk->Obj->id > cLnk->Next->Obj->id)
579  {
580  RemoveLink(cLnk);
581  InsertLink(cLnk,cLnk->Next);
582  fSorted = false;
583  break;
584  }
585  }
586  while (!fSorted);
587 }
C4ID id
Definition: C4Object.h:108
virtual void RemoveLink(C4ObjectLink *pLnk)
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
virtual void InsertLink(C4ObjectLink *pLink, C4ObjectLink *pAfter)
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

void C4GameObjects::SyncClearance ( )

Definition at line 490 of file C4GameObjects.cpp.

References C4Object::SyncClearance().

Referenced by C4Game::SyncClearance().

491 {
492  for (C4Object *obj : *this)
493  if (obj)
494  obj->SyncClearance();
495 }
void SyncClearance()
Definition: C4Object.cpp:2491

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::Synchronize ( )

Definition at line 173 of file C4GameObjects.cpp.

References ResortUnsorted(), and UpdateSolidMasks().

Referenced by C4Game::Synchronize().

174 {
175  // synchronize unsorted objects
176  ResortUnsorted();
177  // synchronize solidmasks
179 }
void UpdateSolidMasks()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::UpdateFaces ( bool  bUpdateShape)
inherited

Definition at line 682 of file C4ObjectList.cpp.

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

Referenced by PostLoad().

683 {
684  C4ObjectLink *cLnk;
685  for (cLnk=First; cLnk; cLnk=cLnk->Next)
686  if (cLnk->Obj->Status)
687  cLnk->Obj->UpdateFace(bUpdateShapes);
688 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
void UpdateFace(bool bUpdateShape, bool fTemp=false)
Definition: C4Object.cpp:378
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ObjectList::UpdateGraphics ( bool  fGraphicsChanged)
inherited

Definition at line 674 of file C4ObjectList.cpp.

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

Referenced by PostLoad().

675 {
676  C4ObjectLink *cLnk;
677  for (cLnk=First; cLnk; cLnk=cLnk->Next)
678  if (cLnk->Obj->Status)
679  cLnk->Obj->UpdateGraphics(fGraphicsChanged);
680 }
C4ObjectLink * First
Definition: C4ObjectList.h:51
void UpdateGraphics(bool fGraphicsChanged, bool fTemp=false)
Definition: C4Object.cpp:404
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::UpdatePos ( C4Object pObj)

Definition at line 363 of file C4GameObjects.cpp.

References Sectors, and C4LSectors::Update().

Referenced by C4Object::UpdatePos().

364 {
365  // Position might have changed. Update sector lists
366  Sectors.Update(pObj, this);
367 }
void Update(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:109
C4LSectors Sectors
Definition: C4GameObjects.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::UpdatePosResort ( C4Object pObj)

Definition at line 369 of file C4GameObjects.cpp.

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

370 {
371  // Object order for this object was changed. Readd object to sectors
372  Sectors.Remove(pObj);
373  Sectors.Add(pObj, this);
374 }
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:91
C4LSectors Sectors
Definition: C4GameObjects.h:42
void Remove(C4Object *pObj)
Definition: C4Sector.cpp:151

Here is the call graph for this function:

void C4GameObjects::UpdateScriptPointers ( )

Definition at line 343 of file C4GameObjects.cpp.

References InactiveObjects, and C4ObjectList::UpdateScriptPointers().

Referenced by C4Game::ReLinkScriptEngine().

344 {
345  // call in sublists
348 }
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43
void UpdateScriptPointers()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameObjects::UpdateSolidMasks ( )

Definition at line 196 of file C4GameObjects.cpp.

References C4PropList::Status, and C4Object::UpdateSolidMask().

Referenced by Synchronize().

197 {
198  for (C4Object *obj : *this)
199  if (obj->Status)
200  obj->UpdateSolidMask(false);
201 }
int32_t Status
Definition: C4PropList.h:168
void UpdateSolidMask(bool fRestoreAttachedObjects)
Definition: C4Object.cpp:4141

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameObjects::ValidateOwners ( )
overridevirtual

Reimplemented from C4ObjectList.

Definition at line 465 of file C4GameObjects.cpp.

References InactiveObjects, and C4ObjectList::ValidateOwners().

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

466 {
467  // validate in sublists
468  bool fSucc = true;
469  if (!C4ObjectList::ValidateOwners()) fSucc = false;
470  if (!InactiveObjects.ValidateOwners()) fSucc = false;
471  return fSucc;
472 }
virtual bool ValidateOwners()
C4ObjectList InactiveObjects
Definition: C4GameObjects.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ObjectList::Write ( char *  szTarget)
inherited

Definition at line 442 of file C4ObjectList.cpp.

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

443 {
444  char ostr[25];
445  szTarget[0]=0;
446  C4ObjectLink *cLnk;
447  for (cLnk=First; cLnk && cLnk->Obj; cLnk=cLnk->Next)
448  if (cLnk->Obj->Status)
449  {
450  sprintf(ostr,"%d;",cLnk->Obj->Number);
451  SAppend(ostr,szTarget);
452  }
453  return true;
454 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
#define sprintf
Definition: Standard.h:164
C4ObjectLink * First
Definition: C4ObjectList.h:51
C4ObjectLink * Next
Definition: C4ObjectList.h:29
int32_t Status
Definition: C4PropList.h:168
C4Object * Obj
Definition: C4ObjectList.h:28

Here is the call graph for this function:

Member Data Documentation

iterator* C4ObjectList::FirstIter {nullptr}
mutableprotectedinherited
std::list<int32_t>* C4ObjectList::pEnumerated
inherited

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