OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Movement.cpp File Reference
#include "C4Include.h"
#include "object/C4Def.h"
#include "object/C4Object.h"
#include "script/C4Effect.h"
#include "game/C4Physics.h"
#include "landscape/C4SolidMask.h"
#include "landscape/C4Landscape.h"
#include "game/C4Game.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 53 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

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

Here is the caller graph for this function:

const char* CNATName ( int32_t  cnat)

Definition at line 101 of file C4Movement.cpp.

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

Referenced by C4Object::Contact().

102 {
103  switch (cnat)
104  {
105  case CNAT_None: return "None";
106  case CNAT_Left: return "Left";
107  case CNAT_Right: return "Right";
108  case CNAT_Top: return "Top";
109  case CNAT_Bottom: return "Bottom";
110  case CNAT_Center: return "Center";
111  }
112  return "Undefined";
113 }
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 64 of file C4Movement.cpp.

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

Referenced by C4Object::DoMovement().

65 {
66  int32_t cnt;
67  bool fcontact=false;
68  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
69  if (cobj->Shape.VtxContactCNAT[cnt] & cnat_dir)
70  fcontact=true;
71  return fcontact;
72 }
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 92 of file C4Movement.cpp.

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

Referenced by C4Object::DoMovement().

93 {
94  int32_t cnt;
95  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
96  if (cobj->Shape.VtxContactCNAT[cnt])
97  return cobj->Shape.VtxFriction[cnt];
98  return 0;
99 }
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 77 of file C4Movement.cpp.

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

Referenced by C4Object::DoMovement().

78 {
79  int32_t cnt;
80  for (cnt=0; cnt<cobj->Shape.VtxNum; cnt++)
81  if (cobj->Shape.VtxContactCNAT[cnt])
82  {
83  if (cobj->Shape.VtxX[cnt]<0) return -1;
84  if (cobj->Shape.VtxX[cnt]>0) return +1;
85  }
86  return 0;
87 }
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 45 of file C4Movement.cpp.

References Abs(), and Sign().

Referenced by C4Object::DoMovement().

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

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 611 of file C4Movement.cpp.

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

Referenced by InitGameFunctionMap(), and SimFlightHitsLiquid().

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

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

Referenced by ObjectComJump().

658 {
659  // Start in water?
660  int temp;
661  if (DensityLiquid(GBackDensity(fixtoi(fcx), fixtoi(fcy))))
662  if (!SimFlight(fcx, fcy, xdir, ydir, 0, C4M_Liquid - 1, temp=10))
663  return false;
664  // Hits liquid?
665  if (!SimFlight(fcx, fcy, xdir, ydir, C4M_Liquid, 100, temp=-1))
666  return false;
667  // liquid & deep enough?
668  return GBackLiquid(fixtoi(fcx), fixtoi(fcy)) && GBackLiquid(fixtoi(fcx), fixtoi(fcy) + 9);
669 }
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:209
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
Definition: C4Movement.cpp:611
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:242

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 41 of file C4Movement.cpp.

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

const C4Real FFriction =C4REAL100(30)

Definition at line 33 of file C4Movement.cpp.

const C4Real FixFullCircle =itofix(360)

Definition at line 34 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

const C4Real FixHalfCircle =FixFullCircle/2

Definition at line 34 of file C4Movement.cpp.

Referenced by C4Object::DoMovement().

const C4Real FloatFriction =C4REAL100(2)

Definition at line 35 of file C4Movement.cpp.

const C4Real FRedirect =C4REAL100(50)

Definition at line 32 of file C4Movement.cpp.

const C4Real HitSpeed1 =C4REAL100(150)

Definition at line 37 of file C4Movement.cpp.

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

const C4Real HitSpeed2 =itofix(2)

Definition at line 38 of file C4Movement.cpp.

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

const C4Real HitSpeed3 =itofix(6)

Definition at line 39 of file C4Movement.cpp.

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

const C4Real HitSpeed4 =itofix(8)

Definition at line 40 of file C4Movement.cpp.

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

const C4Real RotateAccel =C4REAL100(20)

Definition at line 36 of file C4Movement.cpp.

Referenced by C4Object::Push().