OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MassMoverSet Class Reference

#include <C4MassMover.h>

Collaboration diagram for C4MassMoverSet:
[legend]

Public Member Functions

 C4MassMoverSet ()
 
 ~C4MassMoverSet ()
 
void Copy (C4MassMoverSet &rSet)
 
void Synchronize ()
 
void Default ()
 
void Clear ()
 
void Draw ()
 
void Execute ()
 
bool Create (int32_t x, int32_t y, bool fExecute=false)
 
bool Load (C4Group &hGroup)
 
bool Save (C4Group &hGroup)
 

Public Attributes

int32_t Count
 
int32_t CreatePtr
 

Protected Member Functions

void Consolidate ()
 

Protected Attributes

C4MassMover Set [C4MassMoverChunk]
 

Detailed Description

Definition at line 37 of file C4MassMover.h.

Constructor & Destructor Documentation

C4MassMoverSet::C4MassMoverSet ( )

Definition at line 40 of file C4MassMover.cpp.

References Default().

41 {
42  Default();
43 }

Here is the call graph for this function:

C4MassMoverSet::~C4MassMoverSet ( )

Definition at line 45 of file C4MassMover.cpp.

References Clear().

46 {
47  Clear();
48 }

Here is the call graph for this function:

Member Function Documentation

void C4MassMoverSet::Clear ( )

Definition at line 50 of file C4MassMover.cpp.

Referenced by Copy(), C4Game::InitGame(), Load(), and ~C4MassMoverSet().

51 {
52 
53 }

Here is the caller graph for this function:

void C4MassMoverSet::Consolidate ( )
protected

Definition at line 227 of file C4MassMover.cpp.

References C4MassMoverChunk, CreatePtr, C4MassMover::Mat, MNone, and Set.

Referenced by Save(), and Synchronize().

228 {
229  // Consolidate set
230  int32_t iSpot,iPtr,iConsolidated;
231  for (iSpot=-1,iPtr=0,iConsolidated=0; iPtr<C4MassMoverChunk; iPtr++)
232  {
233  // Empty: set new spot if needed
234  if (Set[iPtr].Mat==MNone)
235  {
236  if (iSpot==-1) iSpot=iPtr;
237  }
238  // Full: move down to empty spot if possible
239  else if (iSpot!=-1)
240  {
241  // Move to spot
242  Set[iSpot]=Set[iPtr];
243  Set[iPtr].Mat=MNone;
244  iConsolidated++;
245  // Advance empty spot (as far as ptr)
246  for (; iSpot<iPtr; iSpot++)
247  if (Set[iSpot].Mat==MNone)
248  break;
249  // No empty spot below ptr
250  if (iSpot==iPtr) iSpot=-1;
251  }
252  }
253  // Reset create ptr
254  CreatePtr=0;
255 }
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
const int32_t MNone
Definition: C4Constants.h:178
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
int32_t Mat
Definition: C4MassMover.h:29
int32_t CreatePtr
Definition: C4MassMover.h:44

Here is the caller graph for this function:

void C4MassMoverSet::Copy ( C4MassMoverSet rSet)

Definition at line 262 of file C4MassMover.cpp.

References C4MassMoverChunk, Clear(), Count, CreatePtr, and Set.

Referenced by C4Game::LoadScenarioSection().

263 {
264  Clear();
265  Count=rSet.Count;
266  CreatePtr=rSet.CreatePtr;
267  for (int32_t cnt=0; cnt<C4MassMoverChunk; cnt++) Set[cnt]=rSet.Set[cnt];
268 }
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
int32_t Count
Definition: C4MassMover.h:43
int32_t CreatePtr
Definition: C4MassMover.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MassMoverSet::Create ( int32_t  x,
int32_t  y,
bool  fExecute = false 
)

Definition at line 70 of file C4MassMover.cpp.

References AddDbgRec(), C4MassMoverChunk, Config, Count, CreatePtr, C4ConfigGeneral::DebugRec, C4MassMover::Execute(), C4Config::General, MNone, RCT_MMC, Set, C4RCMassMover::x, and C4RCMassMover::y.

Referenced by C4Landscape::CheckInstability(), and C4MassMover::Execute().

71 {
72  if (Count == C4MassMoverChunk) return false;
74  {
75  C4RCMassMover rc;
76  rc.x=x; rc.y=y;
77  AddDbgRec(RCT_MMC, &rc, sizeof(rc));
78  }
79  int32_t cptr=CreatePtr;
80  do
81  {
82  cptr++;
83  if (cptr>=C4MassMoverChunk) cptr=0;
84  if (Set[cptr].Mat==MNone)
85  {
86  if (!Set[cptr].Init(x,y)) return false;
87  CreatePtr=cptr;
88  if (fExecute) Set[cptr].Execute();
89  return true;
90  }
91  }
92  while (cptr!=CreatePtr);
93  return false;
94 }
C4Config Config
Definition: C4Config.cpp:833
C4ConfigGeneral General
Definition: C4Config.h:251
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
const int32_t MNone
Definition: C4Constants.h:178
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
bool Execute()
int32_t DebugRec
Definition: C4Config.h:60
int32_t Count
Definition: C4MassMover.h:43
int32_t CreatePtr
Definition: C4MassMover.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MassMoverSet::Default ( )

Definition at line 183 of file C4MassMover.cpp.

References C4MassMoverChunk, Count, CreatePtr, MNone, and Set.

Referenced by C4MassMoverSet(), C4Game::Default(), and Load().

184 {
185  int32_t cnt;
186  for (cnt=0; cnt<C4MassMoverChunk; cnt++) Set[cnt].Mat=MNone;
187  Count=0;
188  CreatePtr=0;
189 }
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
const int32_t MNone
Definition: C4Constants.h:178
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
int32_t Count
Definition: C4MassMover.h:43
int32_t CreatePtr
Definition: C4MassMover.h:44

Here is the caller graph for this function:

void C4MassMoverSet::Draw ( )

Definition at line 96 of file C4MassMover.cpp.

97 {
98 }
void C4MassMoverSet::Execute ( )

Definition at line 55 of file C4MassMover.cpp.

References C4MassMoverChunk, Count, C4MassMover::Execute(), C4MassMover::Mat, MNone, and Set.

Referenced by C4Game::Execute().

56 {
57  C4MassMover *cmm;
58  // Init counts
59  Count=0;
60  // Execute & count
61  for (int32_t speed = 2; speed>0; speed--)
62  {
63  cmm = &(Set[C4MassMoverChunk-1]);
64  for (int32_t cnt = 0; cnt<C4MassMoverChunk; cnt++,cmm--)
65  if (cmm->Mat!=MNone)
66  { Count++; cmm->Execute(); }
67  }
68 }
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
const int32_t MNone
Definition: C4Constants.h:178
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
bool Execute()
int32_t Mat
Definition: C4MassMover.h:29
int32_t Count
Definition: C4MassMover.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MassMoverSet::Load ( C4Group hGroup)

Definition at line 214 of file C4MassMover.cpp.

References C4Group::AccessEntry(), C4CFN_MassMover, Clear(), Count, Default(), C4Group::Read(), and Set.

Referenced by C4Game::InitGame().

215 {
216  // clear previous
217  Clear(); Default();
218  size_t iBinSize,iMoverSize=sizeof(C4MassMover);
219  if (!hGroup.AccessEntry(C4CFN_MassMover,&iBinSize)) return false;
220  if ((iBinSize % iMoverSize)!=0) return false;
221  // load new
222  Count = iBinSize / iMoverSize;
223  if (!hGroup.Read(Set,iBinSize)) return false;
224  return true;
225 }
#define C4CFN_MassMover
Definition: C4Components.h:76
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
int32_t Count
Definition: C4MassMover.h:43
bool Read(void *pBuffer, size_t iSize) override
Definition: C4Group.cpp:1125

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MassMoverSet::Save ( C4Group hGroup)

Definition at line 191 of file C4MassMover.cpp.

References C4Group::Add(), C4CFN_MassMover, C4MassMoverChunk, Consolidate(), Count, C4Group::Delete(), MNone, and Set.

Referenced by C4Game::LoadScenarioSection().

192 {
193  int32_t cnt;
194  // Consolidate
195  Consolidate();
196  // Recount
197  Count=0;
198  for (cnt=0; cnt<C4MassMoverChunk; cnt++)
199  if (Set[cnt].Mat!=MNone)
200  Count++;
201  // All empty: delete component
202  if (!Count)
203  {
204  hGroup.Delete(C4CFN_MassMover);
205  return true;
206  }
207  // Save set
208  if (!hGroup.Add(C4CFN_MassMover,Set,Count*sizeof(C4MassMover)))
209  return false;
210  // Success
211  return true;
212 }
#define C4CFN_MassMover
Definition: C4Components.h:76
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
const int32_t MNone
Definition: C4Constants.h:178
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
int32_t Count
Definition: C4MassMover.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MassMoverSet::Synchronize ( )

Definition at line 257 of file C4MassMover.cpp.

References Consolidate().

Referenced by C4Game::Synchronize().

258 {
259  Consolidate();
260 }

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int32_t C4MassMoverSet::Count
int32_t C4MassMoverSet::CreatePtr

Definition at line 44 of file C4MassMover.h.

Referenced by Consolidate(), Copy(), Create(), Default(), and C4ControlSyncCheck::Set().

C4MassMover C4MassMoverSet::Set[C4MassMoverChunk]
protected

Definition at line 46 of file C4MassMover.h.

Referenced by Consolidate(), Copy(), Create(), Default(), Execute(), Load(), and Save().


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