OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Material.cpp File Reference
Include dependency graph for C4Material.cpp:

Go to the source code of this file.

Classes

struct  ReactionFuncMapEntry
 

Functions

bool mrfInsertCheck (int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
 
bool mrfUserCheck (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 

Variables

int32_t MVehic =MNone
 
int32_t MHalfVehic =MNone
 
int32_t MTunnel =MNone
 
int32_t MWater =MNone
 
int32_t MEarth =MNone
 
BYTE MCVehic =0
 
BYTE MCHalfVehic =0
 
const ReactionFuncMapEntry ReactionFuncMap []
 
C4MaterialMap MaterialMap
 

Class Documentation

struct ReactionFuncMapEntry

Definition at line 42 of file C4Material.cpp.

Collaboration diagram for ReactionFuncMapEntry:
[legend]
Class Members
C4MaterialReactionFunc pFunc
const char * szRFName

Function Documentation

bool mrfInsertCheck ( int32_t &  iX,
int32_t &  iY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
bool *  pfPosChanged,
bool  no_slide = false 
)

Definition at line 667 of file C4Material.cpp.

References Abs(), C4M_Solid, C4REAL10(), C4REAL100(), C4MaterialCore::Density, C4Landscape::FindMatSlide(), fixtoi(), C4Landscape::GetDensity(), GravAccel, C4MaterialCore::Incendiary, itofix(), Landscape, C4MaterialMap::Map, MaterialMap, C4MaterialCore::MaxSlide, Random(), Sign(), and C4MaterialCore::SplashRate.

Referenced by C4MaterialMap::mrfCorrode(), C4MaterialMap::mrfIncinerate(), C4MaterialMap::mrfInsert(), C4MaterialMap::mrfPoof(), and mrfUserCheck().

668 {
669  // always manipulating pos/speed here
670  if (pfPosChanged) *pfPosChanged = true;
671 
672  // Move up by up to 3px to account for moving SolidMasks, other material insertions, etc.
673  int32_t mdens = std::min(::MaterialMap.Map[iPxsMat].Density, C4M_Solid);
674  int32_t max_upwards = 3;
675  bool was_pushed_upwards = false;
676  while (max_upwards-- && (::Landscape.GetDensity(iX, iY) >= mdens))
677  {
678  --iY;
679  was_pushed_upwards = true;
680  }
681 
682  // Rough contact? May splash
683  if (fYDir > itofix(1))
684  if (::MaterialMap.Map[iPxsMat].SplashRate && !Random(::MaterialMap.Map[iPxsMat].SplashRate))
685  {
686  fYDir = -fYDir/8;
687  fXDir = fXDir/8 + C4REAL100(Random(200) - 100);
688  if (fYDir) return false;
689  }
690 
691  // Contact: Stop
692  fYDir = -GravAccel;
693 
694  // Incendiary mats smoke on contact even before doing their slide
695  if (::MaterialMap.Map[iPxsMat].Incendiary)
696  if (!Random(25))
697  {
698  Smoke(iX, iY, 4 + Random(3));
699  }
700 
701  // Move by mat path/slide
702  int32_t iSlideX = iX, iSlideY = iY;
703 
704  if (!no_slide && ::Landscape.FindMatSlide(iSlideX,iSlideY,Sign(GravAccel),mdens,::MaterialMap.Map[iPxsMat].MaxSlide))
705  {
706  // Sliding on equal material: Move directly to optimize insertion of rain onto lakes
707  // Also move directly when shifted upwards to ensure movement on permamently moving SolidMask
708  if (iPxsMat == iLsMat || was_pushed_upwards)
709  {
710  iX = iSlideX;
711  iY = iSlideY;
712  fXDir = 0;
713  if (was_pushed_upwards)
714  {
715  // When pushed upwards and slide was found into a target position, insert directly to allow additional PXS at same location to solidify in next position in same frame
716  if (::Landscape.GetDensity(iX, iY + Sign(GravAccel)) >= mdens)
717  {
718  return true;
719  }
720  }
721  // Continue existing (and fall down next frame)
722  return false;
723  }
724  // Otherwise, just move using xdir/ydir for nice visuals when rain is moving over landscape
725  // Accelerate into the direction
726  fXDir = (fXDir * 10 + Sign(iSlideX - iX)) / 11 + C4REAL10(Random(5)-2);
727  // Slide target in range? Move there directly.
728  if (Abs(iX - iSlideX) <= Abs(fixtoi(fXDir)))
729  {
730  iX = iSlideX;
731  iY = iSlideY;
732  if (fYDir <= 0) fXDir = 0;
733  }
734  // Continue existance
735  return false;
736  }
737  // insertion OK
738  return true;
739 }
uint32_t Random()
Definition: C4Random.cpp:43
int32_t MaxSlide
Definition: C4Material.h:104
C4Material * Map
Definition: C4Material.h:169
#define GravAccel
Definition: C4Physics.h:27
C4Real C4REAL100(int x)
Definition: C4Real.h:267
int Sign(T val)
Definition: Standard.h:45
C4Real C4REAL10(int x)
Definition: C4Real.h:269
int32_t GetDensity(int32_t x, int32_t y) const
C4Landscape Landscape
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
bool FindMatSlide(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
const int32_t C4M_Solid
Definition: C4Constants.h:172
int32_t Density
Definition: C4Material.h:92
int32_t SplashRate
Definition: C4Material.h:131
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
int32_t Incendiary
Definition: C4Material.h:107
T Abs(T val)
Definition: Standard.h:42
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259

Here is the call graph for this function:

Here is the caller graph for this function:

bool mrfUserCheck ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)

Definition at line 741 of file C4Material.cpp.

References C4MaterialReaction::fInsertionCheck, C4MaterialReaction::iExecMask, meePXSMove, and mrfInsertCheck().

Referenced by C4MaterialMap::mrfConvert(), C4MaterialMap::mrfCorrode(), C4MaterialMap::mrfInsert(), C4MaterialMap::mrfPoof(), and C4MaterialMap::mrfScript().

742 {
743  // check execution mask
744  if ((1<<evEvent) & ~pReaction->iExecMask) return false;
745  // do splash/slide check, if desired
746  if (pReaction->fInsertionCheck && evEvent == meePXSMove)
747  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
748  return false;
749  // checks OK; reaction may be applied
750  return true;
751 }
uint32_t iExecMask
Definition: C4Material.h:52
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
Definition: C4Material.cpp:667

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

BYTE MCHalfVehic =0
int32_t MEarth =MNone

Definition at line 36 of file C4Material.cpp.

Referenced by C4MaterialMap::CrossMapMaterials(), and C4Game::PlaceInEarth().

int32_t MHalfVehic =MNone

Definition at line 36 of file C4Material.cpp.

Referenced by C4MaterialMap::CrossMapMaterials().

int32_t MWater =MNone

Definition at line 36 of file C4Material.cpp.

Referenced by C4MaterialMap::CrossMapMaterials(), and C4Object::ExecLife().

const ReactionFuncMapEntry ReactionFuncMap[]
Initial value:
=
{
{ "Script", &C4MaterialMap::mrfScript },
{ "Convert", &C4MaterialMap::mrfConvert},
{ "Poof", &C4MaterialMap::mrfPoof },
{ "Corrode", &C4MaterialMap::mrfCorrode },
{ "Insert", &C4MaterialMap::mrfInsert },
}
static bool NoReaction(struct C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.h:45
static bool mrfPoof(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:790
static bool mrfScript(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:935
static bool mrfCorrode(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:819
static bool mrfInsert(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:908
static bool mrfConvert(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:753

Definition at line 44 of file C4Material.cpp.