OpenClonk
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

◆ Cease()

void C4MassMover::Cease ( )
protected

Definition at line 112 of file C4MassMover.cpp.

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:930
const int32_t MNone
Definition: C4Constants.h:177
C4MassMoverSet MassMover
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
@ RCT_MMD
Definition: C4Record.h:61
int32_t DebugRec
Definition: C4Config.h:63
C4ConfigGeneral General
Definition: C4Config.h:255
int32_t x
Definition: C4MassMover.h:29
int32_t Mat
Definition: C4MassMover.h:29
int32_t y
Definition: C4MassMover.h:29
int32_t Count
Definition: C4MassMover.h:43

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

Referenced by Execute().

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

◆ Corrosion()

bool C4MassMover::Corrosion ( int32_t  dx,
int32_t  dy 
)
protected

Definition at line 169 of file C4MassMover.cpp.

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 }
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:219
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
@ meeMassMove
Definition: C4Material.h:38
const C4Real Fix0
Definition: C4Real.h:312
Definition: C4Real.h:59
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:191
C4MaterialReactionFunc pFunc
Definition: C4Material.h:47

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

Referenced by Execute().

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

◆ Execute()

bool C4MassMover::Execute ( )
protected

Definition at line 124 of file C4MassMover.cpp.

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 }
C4Landscape Landscape
uint32_t Random()
Definition: C4Random.cpp:43
int32_t ExtractMaterial(int32_t fx, int32_t fy, bool distant_first)
bool FindMatPath(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
bool InsertDeadMaterial(int32_t mat, int32_t tx, int32_t ty)
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
bool Corrosion(int32_t dx, int32_t dy)
bool Create(int32_t x, int32_t y, bool fExecute=false)
Definition: C4MassMover.cpp:70
int32_t Density
Definition: C4Material.h:92
int32_t MaxSlide
Definition: C4Material.h:104
C4Material * Map
Definition: C4Material.h:169

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

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

◆ Init()

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

Definition at line 100 of file C4MassMover.cpp.

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 GetWidth() const
int32_t GetHeight() const

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

Here is the call graph for this function:

Friends And Related Function Documentation

◆ C4MassMoverSet

friend class C4MassMoverSet
friend

Definition at line 27 of file C4MassMover.h.

Member Data Documentation

◆ Mat

int32_t C4MassMover::Mat
protected

◆ x

int32_t C4MassMover::x
protected

Definition at line 29 of file C4MassMover.h.

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

◆ y

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: