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

Definition at line 663 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().

664 {
665  // always manipulating pos/speed here
666  if (pfPosChanged) *pfPosChanged = true;
667 
668  // Move up by up to 3px to account for moving SolidMasks, other material insertions, etc.
669  int32_t mdens = std::min(::MaterialMap.Map[iPxsMat].Density, C4M_Solid);
670  int32_t max_upwards = 3;
671  bool was_pushed_upwards = false;
672  while (max_upwards-- && (::Landscape.GetDensity(iX, iY) >= mdens))
673  {
674  --iY;
675  was_pushed_upwards = true;
676  }
677 
678  // Rough contact? May splash
679  if (fYDir > itofix(1))
680  if (::MaterialMap.Map[iPxsMat].SplashRate && !Random(::MaterialMap.Map[iPxsMat].SplashRate))
681  {
682  fYDir = -fYDir/8;
683  fXDir = fXDir/8 + C4REAL100(Random(200) - 100);
684  if (fYDir) return false;
685  }
686 
687  // Contact: Stop
688  fYDir = -GravAccel;
689 
690  // Incendiary mats smoke on contact even before doing their slide
691  if (::MaterialMap.Map[iPxsMat].Incendiary)
692  if (!Random(25))
693  {
694  Smoke(iX, iY, 4 + Random(3));
695  }
696 
697  // Move by mat path/slide
698  int32_t iSlideX = iX, iSlideY = iY;
699 
700  if (::Landscape.FindMatSlide(iSlideX,iSlideY,Sign(GravAccel),mdens,::MaterialMap.Map[iPxsMat].MaxSlide))
701  {
702  // Sliding on equal material: Move directly to optimize insertion of rain onto lakes
703  // Also move directly when shifted upwards to ensure movement on permamently moving SolidMask
704  if (iPxsMat == iLsMat || was_pushed_upwards)
705  {
706  iX = iSlideX;
707  iY = iSlideY;
708  fXDir = 0;
709  if (was_pushed_upwards)
710  {
711  // 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
712  if (::Landscape.GetDensity(iX, iY + Sign(GravAccel)) >= mdens)
713  {
714  return true;
715  }
716  }
717  // Continue existing (and fall down next frame)
718  return false;
719  }
720  // Otherwise, just move using xdir/ydir for nice visuals when rain is moving over landscape
721  // Accelerate into the direction
722  fXDir = (fXDir * 10 + Sign(iSlideX - iX)) / 11 + C4REAL10(Random(5)-2);
723  // Slide target in range? Move there directly.
724  if (Abs(iX - iSlideX) <= Abs(fixtoi(fXDir)))
725  {
726  iX = iSlideX;
727  iY = iSlideY;
728  if (fYDir <= 0) fXDir = 0;
729  }
730  // Continue existance
731  return false;
732  }
733  // insertion OK
734  return true;
735 }
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:969
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 737 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().

738 {
739  // check execution mask
740  if ((1<<evEvent) & ~pReaction->iExecMask) return false;
741  // do splash/slide check, if desired
742  if (pReaction->fInsertionCheck && evEvent == meePXSMove)
743  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
744  return false;
745  // checks OK; reaction may be applied
746  return true;
747 }
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)
Definition: C4Material.cpp:663

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:786
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:930
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:814
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:903
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:749

Definition at line 44 of file C4Material.cpp.