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

#include <C4MassMover.h>

Protected Member Functions

void Cease ()
 
bool Execute ()
 
bool Init (int32_t tx, int32_t ty)
 
bool Corrosion (int32_t dx, int32_t dy)
 

Protected Attributes

int32_t Mat
 
int32_t x
 
int32_t y
 

Friends

class C4MassMoverSet
 

Detailed Description

Definition at line 25 of file C4MassMover.h.

Member Function Documentation

void C4MassMover::Cease ( )
protected

Definition at line 112 of file C4MassMover.cpp.

References AddDbgRec(), Config, C4MassMoverSet::Count, C4ConfigGeneral::DebugRec, C4Config::General, MassMover, Mat, MNone, RCT_MMD, x, C4RCMassMover::x, y, and C4RCMassMover::y.

Referenced by Execute().

113 {
114  if (Config.General.DebugRec)
115  {
116  C4RCMassMover rc;
117  rc.x=x; rc.y=y;
118  AddDbgRec(RCT_MMD, &rc, sizeof(rc));
119  }
120  ::MassMover.Count--;
121  Mat=MNone;
122 }
C4Config Config
Definition: C4Config.cpp:833
int32_t y
Definition: C4MassMover.h:29
C4ConfigGeneral General
Definition: C4Config.h:251
const int32_t MNone
Definition: C4Constants.h:177
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
C4MassMoverSet MassMover
int32_t x
Definition: C4MassMover.h:29
int32_t DebugRec
Definition: C4Config.h:60
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 C4MassMover::Corrosion ( int32_t  dx,
int32_t  dy 
)
protected

Definition at line 169 of file C4MassMover.cpp.

References Fix0, GBackMat(), C4MaterialMap::GetReactionUnsafe(), Mat, MaterialMap, meeMassMove, C4MaterialReaction::pFunc, x, and y.

Referenced by Execute().

170 {
171  // check reaction map of massmover-mat to target mat
172  int32_t tmat=GBackMat(x+dx,y+dy);
174  if (pReact)
175  {
176  C4Real xdir=Fix0, ydir=Fix0;
177  if ((*pReact->pFunc)(pReact, x,y, x+dx,y+dy, xdir,ydir, Mat,tmat, meeMassMove, nullptr))
178  return true;
179  }
180  return false;
181 }
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:191
int32_t y
Definition: C4MassMover.h:29
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:47
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
int32_t x
Definition: C4MassMover.h:29
int32_t Mat
Definition: C4MassMover.h:29
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:221
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MassMover::Execute ( )
protected

Definition at line 124 of file C4MassMover.cpp.

References Cease(), Corrosion(), C4MassMoverSet::Create(), C4MaterialCore::Density, C4Landscape::ExtractMaterial(), C4Landscape::FindMatPath(), GBackMat(), C4Landscape::InsertDeadMaterial(), C4Landscape::InsertMaterial(), Landscape, C4MaterialMap::Map, MassMover, Mat, MaterialMap, C4MaterialCore::MaxSlide, Random(), x, and y.

Referenced by C4MassMoverSet::Create(), and C4MassMoverSet::Execute().

125 {
126  int32_t tx,ty;
127 
128  // Lost target material
129  if (GBackMat(x,y)!=Mat) { Cease(); return false; }
130 
131  // Check for transfer target space
133  tx=x; ty=y;
134  if (!::Landscape.FindMatPath(tx,ty,+1,pMat->Density,pMat->MaxSlide))
135  {
136  // Contact material reaction check: corrosion/evaporation/inflammation/etc.
137  if (Corrosion(+0,+1) || Corrosion(-1,+0) || Corrosion(+1,+0))
138  {
139  // material has been used up
141  return true;
142  }
143 
144  // No space, die
145  Cease(); return false;
146  }
147 
148  // do check at this pos for conversion check
149  /* if (Corrosion(0,0))
150  {
151  // material has been used up by conversion
152  ::Landscape.ExtractMaterial(x,y);
153  return true;
154  }*/
155 
156  // Transfer mass
157  int32_t mat = ::Landscape.ExtractMaterial(x,y,false);
158  if (Random(10))
159  ::Landscape.InsertDeadMaterial(mat, tx, ty);
160  else
161  ::Landscape.InsertMaterial(mat, &tx, &ty, 0, 1); // modifies tx/ty to actual insertion position
162 
163  // Create new mover at target
164  ::MassMover.Create(tx,ty,!Random(3));
165 
166  return true;
167 }
int32_t y
Definition: C4MassMover.h:29
uint32_t Random()
Definition: C4Random.cpp:43
int32_t MaxSlide
Definition: C4Material.h:104
bool InsertDeadMaterial(int32_t mat, int32_t tx, int32_t ty)
C4Material * Map
Definition: C4Material.h:169
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
bool Create(int32_t x, int32_t y, bool fExecute=false)
Definition: C4MassMover.cpp:70
C4Landscape Landscape
bool Corrosion(int32_t dx, int32_t dy)
int32_t Density
Definition: C4Material.h:92
C4MassMoverSet MassMover
int32_t ExtractMaterial(int32_t fx, int32_t fy, bool distant_first)
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
bool FindMatPath(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
int32_t x
Definition: C4MassMover.h:29
int32_t Mat
Definition: C4MassMover.h:29
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:221

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MassMover::Init ( int32_t  tx,
int32_t  ty 
)
protected

Definition at line 100 of file C4MassMover.cpp.

References C4MassMoverSet::Count, GBackMat(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), Landscape, MassMover, Mat, MNone, x, and y.

101 {
102  // Out of bounds check
103  if (!Inside<int32_t>(tx,0,::Landscape.GetWidth()-1) || !Inside<int32_t>(ty,0,::Landscape.GetHeight()-1))
104  return false;
105  // Check mat
106  Mat=GBackMat(tx,ty);
107  x=tx; y=ty;
108  ::MassMover.Count++;
109  return (Mat!=MNone);
110 }
int32_t y
Definition: C4MassMover.h:29
const int32_t MNone
Definition: C4Constants.h:177
C4Landscape Landscape
int32_t GetHeight() const
C4MassMoverSet MassMover
int32_t x
Definition: C4MassMover.h:29
int32_t Mat
Definition: C4MassMover.h:29
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:221
int32_t GetWidth() const
int32_t Count
Definition: C4MassMover.h:43

Here is the call graph for this function:

Friends And Related Function Documentation

friend class C4MassMoverSet
friend

Definition at line 27 of file C4MassMover.h.

Member Data Documentation

int32_t C4MassMover::Mat
protected
int32_t C4MassMover::x
protected

Definition at line 29 of file C4MassMover.h.

Referenced by Cease(), Corrosion(), Execute(), and Init().

int32_t C4MassMover::y
protected

Definition at line 29 of file C4MassMover.h.

Referenced by Cease(), Corrosion(), Execute(), and Init().


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