OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Movement.cpp File Reference
#include "C4Include.h"
#include "game/C4Physics.h"
#include "landscape/C4Landscape.h"
#include "landscape/C4SolidMask.h"
#include "object/C4Def.h"
#include "object/C4Object.h"
#include "script/C4Effect.h"
Include dependency graph for C4Movement.cpp:

Go to the source code of this file.

Functions

void RedirectForce (C4Real &from, C4Real &to, int32_t tdir)
 
void ApplyFriction (C4Real &tval, int32_t percent)
 
bool ContactVtxCNAT (C4Object *cobj, BYTE cnat_dir)
 
int32_t ContactVtxWeight (C4Object *cobj)
 
int32_t ContactVtxFriction (C4Object *cobj)
 
const char * CNATName (int32_t cnat)
 
bool SimFlight (C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
 
bool SimFlightHitsLiquid (C4Real fcx, C4Real fcy, C4Real xdir, C4Real ydir)
 

Variables

const C4Real FRedirect =C4REAL100(50)
 
const C4Real FFriction =C4REAL100(30)
 
const C4Real FixFullCircle =itofix(360)
 
const C4Real FixHalfCircle =FixFullCircle/2
 
const C4Real FloatFriction =C4REAL100(2)
 
const C4Real RotateAccel =C4REAL100(20)
 
const C4Real HitSpeed1 =C4REAL100(150)
 
const C4Real HitSpeed2 =itofix(2)
 
const C4Real HitSpeed3 =itofix(6)
 
const C4Real HitSpeed4 =itofix(8)
 
const C4Real DefaultGravAccel =C4REAL100(20)
 

Function Documentation

void ApplyFriction ( C4Real tval,
int32_t  percent 
)

Definition at line 52 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

53 {
54  C4Real ffric=FFriction*percent/100;
55  if (tval>+ffric) { tval-=ffric; return; }
56  if (tval<-ffric) { tval+=ffric; return; }
57  tval=0;
58 }
const C4Real FFriction
Definition: C4Movement.cpp:32
Definition: C4Real.h:58

Here is the caller graph for this function:

const char* CNATName ( int32_t  cnat)

Definition at line 100 of file C4Movement.cpp.

References CNAT_Bottom, CNAT_Center, CNAT_Left, CNAT_None, CNAT_Right, and CNAT_Top.

Referenced by C4Object::Contact().

101 {
102  switch (cnat)
103  {
104  case CNAT_None: return "None";
105  case CNAT_Left: return "Left";
106  case CNAT_Right: return "Right";
107  case CNAT_Top: return "Top";
108  case CNAT_Bottom: return "Bottom";
109  case CNAT_Center: return "Center";
110  }
111  return "Undefined";
112 }
const BYTE CNAT_None
Definition: C4Constants.h:109
const BYTE CNAT_Top
Definition: C4Constants.h:112
const BYTE CNAT_Right
Definition: C4Constants.h:111
const BYTE CNAT_Left
Definition: C4Constants.h:110
const BYTE CNAT_Bottom
Definition: C4Constants.h:113
const BYTE CNAT_Center
Definition: C4Constants.h:114

Here is the caller graph for this function:

bool ContactVtxCNAT ( C4Object cobj,
BYTE  cnat_dir 
)

Definition at line 63 of file C4Movement.cpp.

References C4Object::Shape, C4Shape::VtxContactCNAT, and C4Shape::VtxNum.

Referenced by C4Object::DoMovement().

64 {
65  int32_t cnt;
66  bool fcontact=false;
67  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
68  if (cobj->Shape.VtxContactCNAT[cnt] & cnat_dir)
69  fcontact=true;
70  return fcontact;
71 }
int32_t VtxContactCNAT[C4D_MaxVertex]
Definition: C4Shape.h:52
int32_t VtxNum
Definition: C4Shape.h:43
C4Shape Shape
Definition: C4Object.h:148

Here is the caller graph for this function:

int32_t ContactVtxFriction ( C4Object cobj)

Definition at line 91 of file C4Movement.cpp.

References C4Object::Shape, C4Shape::VtxContactCNAT, C4Shape::VtxFriction, and C4Shape::VtxNum.

Referenced by C4Object::DoMovement().

92 {
93  int32_t cnt;
94  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
95  if (cobj->Shape.VtxContactCNAT[cnt])
96  return cobj->Shape.VtxFriction[cnt];
97  return 0;
98 }
int32_t VtxFriction[C4D_MaxVertex]
Definition: C4Shape.h:47
int32_t VtxContactCNAT[C4D_MaxVertex]
Definition: C4Shape.h:52
int32_t VtxNum
Definition: C4Shape.h:43
C4Shape Shape
Definition: C4Object.h:148

Here is the caller graph for this function:

int32_t ContactVtxWeight ( C4Object cobj)

Definition at line 76 of file C4Movement.cpp.

References C4Object::Shape, C4Shape::VtxContactCNAT, C4Shape::VtxNum, and C4Shape::VtxX.

Referenced by C4Object::DoMovement().

77 {
78  int32_t cnt;
79  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
80  if (cobj->Shape.VtxContactCNAT[cnt])
81  {
82  if (cobj->Shape.VtxX[cnt]<0) return -1;
83  if (cobj->Shape.VtxX[cnt]>0) return +1;
84  }
85  return 0;
86 }
int32_t VtxContactCNAT[C4D_MaxVertex]
Definition: C4Shape.h:52
int32_t VtxNum
Definition: C4Shape.h:43
int32_t VtxX[C4D_MaxVertex]
Definition: C4Shape.h:44
C4Shape Shape
Definition: C4Object.h:148

Here is the caller graph for this function:

void RedirectForce ( C4Real from,
C4Real to,
int32_t  tdir 
)

Definition at line 44 of file C4Movement.cpp.

References Abs(), and Sign().

Referenced by C4Object::DoMovement().

45 {
46  C4Real fred;
47  fred=std::min(Abs(from), FRedirect);
48  from-=fred*Sign(from);
49  to+=fred*tdir;
50 }
int Sign(T val)
Definition: Standard.h:45
const C4Real FRedirect
Definition: C4Movement.cpp:31
Definition: C4Real.h:58
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

bool SimFlight ( C4Real x,
C4Real y,
C4Real xdir,
C4Real ydir,
int32_t  iDensityMin,
int32_t  iDensityMax,
int32_t &  iIter 
)

Definition at line 610 of file C4Movement.cpp.

References fixtoi(), GBackDensity(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), GravAccel, Inside(), itofix(), Landscape, and Sign().

Referenced by InitGameFunctionMap(), and SimFlightHitsLiquid().

611 {
612  bool hitOnTime = true;
613  bool fBreak = false;
614  int32_t ctcox,ctcoy,cx,cy,i;
615  cx = fixtoi(x); cy = fixtoi(y);
616  i = iIter;
617  do
618  {
619  if (!--i) {hitOnTime = false; break;}
620  // If the object isn't moving and there is no gravity either, abort
621  if (xdir == 0 && ydir == 0 && GravAccel == 0)
622  return false;
623  // If the object is above the landscape flying upwards in no/negative gravity, abort
624  if (ydir <= 0 && GravAccel <= 0 && cy < 0)
625  return false;
626  // Set target position by momentum
627  x+=xdir; y+=ydir;
628  // Movement to target
629  ctcox=fixtoi(x); ctcoy=fixtoi(y);
630  // Bounds
631  if (!Inside<int32_t>(ctcox,0,::Landscape.GetWidth()) || (ctcoy>=::Landscape.GetHeight()))
632  return false;
633  // Move to target
634  do
635  {
636  // Set next step target
637  cx+=Sign(ctcox-cx); cy+=Sign(ctcoy-cy);
638  // Contact check
639  if (Inside(GBackDensity(cx,cy), iDensityMin, iDensityMax))
640  { fBreak = true; break; }
641  }
642  while ((cx!=ctcox) || (cy!=ctcoy));
643  // Adjust GravAccel once per frame
644  ydir+=GravAccel;
645  }
646  while (!fBreak);
647  // write position back
648  x = itofix(cx); y = itofix(cy);
649 
650  // how many steps did it take to get here?
651  iIter -= i;
652 
653  return hitOnTime;
654 }
#define GravAccel
Definition: C4Physics.h:27
int Sign(T val)
Definition: Standard.h:45
C4Landscape Landscape
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t GetHeight() const
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool SimFlightHitsLiquid ( C4Real  fcx,
C4Real  fcy,
C4Real  xdir,
C4Real  ydir 
)

Definition at line 656 of file C4Movement.cpp.

References C4M_Liquid, DensityLiquid(), fixtoi(), GBackDensity(), GBackLiquid(), and SimFlight().

Referenced by ObjectComJump().

657 {
658  // Start in water?
659  int temp;
660  if (DensityLiquid(GBackDensity(fixtoi(fcx), fixtoi(fcy))))
661  if (!SimFlight(fcx, fcy, xdir, ydir, 0, C4M_Liquid - 1, temp=10))
662  return false;
663  // Hits liquid?
664  if (!SimFlight(fcx, fcy, xdir, ydir, C4M_Liquid, 100, temp=-1))
665  return false;
666  // liquid & deep enough?
667  return GBackLiquid(fixtoi(fcx), fixtoi(fcy)) && GBackLiquid(fixtoi(fcx), fixtoi(fcy) + 9);
668 }
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:208
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
Definition: C4Movement.cpp:610
const int32_t C4M_Liquid
Definition: C4Constants.h:175
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:241

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const C4Real DefaultGravAccel =C4REAL100(20)

Definition at line 40 of file C4Movement.cpp.

Referenced by C4Landscape::CompileFunc(), and C4Landscape::ScenarioInit().

const C4Real FFriction =C4REAL100(30)

Definition at line 32 of file C4Movement.cpp.

const C4Real FixFullCircle =itofix(360)

Definition at line 33 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

const C4Real FixHalfCircle =FixFullCircle/2

Definition at line 33 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

const C4Real FloatFriction =C4REAL100(2)

Definition at line 34 of file C4Movement.cpp.

const C4Real FRedirect =C4REAL100(50)

Definition at line 31 of file C4Movement.cpp.

const C4Real HitSpeed1 =C4REAL100(150)

Definition at line 36 of file C4Movement.cpp.

Referenced by C4Object::SetOCF(), and C4Object::UpdateOCF().

const C4Real HitSpeed2 =itofix(2)

Definition at line 37 of file C4Movement.cpp.

Referenced by C4GameObjects::CrossCheck(), C4Object::SetOCF(), and C4Object::UpdateOCF().

const C4Real HitSpeed3 =itofix(6)

Definition at line 38 of file C4Movement.cpp.

Referenced by C4Object::SetOCF(), and C4Object::UpdateOCF().

const C4Real HitSpeed4 =itofix(8)

Definition at line 39 of file C4Movement.cpp.

Referenced by C4Object::SetOCF(), and C4Object::UpdateOCF().

const C4Real RotateAccel =C4REAL100(20)

Definition at line 35 of file C4Movement.cpp.

Referenced by C4Object::Push().