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

Go to the source code of this file.

Functions

bool SimFlightHitsLiquid (C4Real fcx, C4Real fcy, C4Real xdir, C4Real ydir)
 
bool ObjectActionWalk (C4Object *cObj)
 
bool ObjectActionStand (C4Object *cObj)
 
bool ObjectActionJump (C4Object *cObj, C4Real xdir, C4Real ydir, bool fByCom)
 
bool ObjectActionDive (C4Object *cObj, C4Real xdir, C4Real ydir)
 
bool ObjectActionTumble (C4Object *cObj, int32_t dir, C4Real xdir, C4Real ydir)
 
bool ObjectActionGetPunched (C4Object *cObj, C4Real xdir, C4Real ydir)
 
bool ObjectActionKneel (C4Object *cObj)
 
bool ObjectActionFlat (C4Object *cObj, int32_t dir)
 
bool ObjectActionScale (C4Object *cObj, int32_t dir)
 
bool ObjectActionHangle (C4Object *cObj)
 
bool ObjectActionThrow (C4Object *cObj, C4Object *pThing)
 
bool ObjectActionDig (C4Object *cObj)
 
bool ObjectActionPush (C4Object *cObj, C4Object *target)
 
bool ObjectActionCornerScale (C4Object *cObj)
 
bool ObjectComStop (C4Object *cObj)
 
bool ObjectComGrab (C4Object *cObj, C4Object *pTarget)
 
bool ObjectComUnGrab (C4Object *cObj)
 
bool ObjectComJump (C4Object *cObj)
 
bool ObjectComLetGo (C4Object *cObj, int32_t xdirf)
 
bool ObjectComDig (C4Object *cObj)
 
bool ObjectComPut (C4Object *cObj, C4Object *pTarget, C4Object *pThing)
 
bool ObjectComThrow (C4Object *cObj, C4Object *pThing)
 
bool ObjectComDrop (C4Object *cObj, C4Object *pThing)
 
bool ObjectComPutTake (C4Object *cObj, C4Object *pTarget, C4Object *pThing)
 
bool ObjectComTake (C4Object *cObj)
 
bool ObjectComTake2 (C4Object *cObj)
 
bool ObjectComPunch (C4Object *cObj, C4Object *pTarget, int32_t punch)
 
bool ObjectComCancelAttach (C4Object *cObj)
 
void ObjectComStopDig (C4Object *cObj)
 
bool ComDirLike (int32_t iComDir, int32_t iSample)
 

Function Documentation

bool ComDirLike ( int32_t  iComDir,
int32_t  iSample 
)

Definition at line 426 of file C4ObjectCom.cpp.

Referenced by C4Object::ContactAction(), C4Object::NoAttachAction(), and ObjectComDrop().

427 {
428  if (iComDir == iSample) return true;
429  if (iComDir % 8 + 1 == iSample) return true;
430  if (iComDir == iSample % 8 + 1 ) return true;
431  return false;
432 }

Here is the caller graph for this function:

bool ObjectActionCornerScale ( C4Object cObj)

Definition at line 168 of file C4ObjectCom.cpp.

References C4Object::Action, C4Action::Dir, DIR_Left, C4Object::fix_x, C4Object::fix_y, itofix(), C4Object::SetActionByName(), C4Object::xdir, and C4Object::ydir.

Referenced by C4Object::ContactAction(), and C4Object::NoAttachAction().

169 {
170  int32_t iRangeX = 1, iRangeY = 1;
171  if (!CornerScaleOkay(cObj,iRangeX,iRangeY)) return false;
172  // Do corner scale
173  if (!cObj->SetActionByName("KneelUp"))
174  cObj->SetActionByName("Walk");
175  cObj->xdir=cObj->ydir=0;
176  if (cObj->Action.Dir==DIR_Left) cObj->fix_x-=itofix(iRangeX);
177  else cObj->fix_x+=itofix(iRangeX);
178  cObj->fix_y-=itofix(iRangeY);
179  return true;
180 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
#define DIR_Left
Definition: C4Object.h:41
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4Real fix_x
Definition: C4Object.h:125
int32_t Dir
Definition: C4Object.h:80
C4Real fix_y
Definition: C4Object.h:125
C4Action Action
Definition: C4Object.h:147
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionDig ( C4Object cObj)

Definition at line 141 of file C4ObjectCom.cpp.

References C4Object::Action, C4Action::Data, and C4Object::SetActionByName().

Referenced by ObjectComDig().

142 {
143  if (!cObj->SetActionByName("Dig")) return false;
144  cObj->Action.Data=0; // Material Dig2Object request
145  return true;
146 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
int32_t Data
Definition: C4Object.h:84
C4Action Action
Definition: C4Object.h:147

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionDive ( C4Object cObj,
C4Real  xdir,
C4Real  ydir 
)

Definition at line 69 of file C4ObjectCom.cpp.

References C4Object::Action, CNAT_Bottom, C4Object::Mobile, C4Object::SetActionByName(), C4Action::t_attach, C4Object::xdir, and C4Object::ydir.

Referenced by ObjectComJump().

70 {
71  if (!cObj->SetActionByName("Dive")) return false;
72  cObj->xdir=xdir; cObj->ydir=ydir;
73  cObj->Mobile=1;
74  // unstick from ground, because jump command may be issued in an Action-callback,
75  // where attach-values have already been determined for that frame
76  cObj->Action.t_attach&=~CNAT_Bottom;
77  return true;
78 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
bool Mobile
Definition: C4Object.h:128
int32_t t_attach
Definition: C4Object.h:86
C4Action Action
Definition: C4Object.h:147
C4Real xdir
Definition: C4Object.h:126
const BYTE CNAT_Bottom
Definition: C4Constants.h:113
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionFlat ( C4Object cObj,
int32_t  dir 
)

Definition at line 101 of file C4ObjectCom.cpp.

References C4Object::SetActionByName(), and C4Object::SetDir().

Referenced by C4Object::ContactAction().

102 {
103  if (!cObj->SetActionByName("FlatUp")) return false;
104  cObj->SetDir(dir);
105  return true;
106 }
void SetDir(int32_t tdir)
Definition: C4Object.cpp:2855
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionGetPunched ( C4Object cObj,
C4Real  xdir,
C4Real  ydir 
)

Definition at line 88 of file C4ObjectCom.cpp.

References C4Object::SetActionByName(), C4Object::xdir, and C4Object::ydir.

Referenced by ObjectComPunch().

89 {
90  if (!cObj->SetActionByName("GetPunched")) return false;
91  cObj->xdir=xdir; cObj->ydir=ydir;
92  return true;
93 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionHangle ( C4Object cObj)

Definition at line 115 of file C4ObjectCom.cpp.

References C4Object::SetActionByName().

Referenced by C4Object::ContactAction().

116 {
117  if (!cObj->SetActionByName("Hangle")) return false;
118  return true;
119 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionJump ( C4Object cObj,
C4Real  xdir,
C4Real  ydir,
bool  fByCom 
)

Definition at line 53 of file C4ObjectCom.cpp.

References C4Object::Action, C4PropList::Call(), CNAT_Bottom, fixtoi(), C4Object::Mobile, PSF_OnActionJump, C4Object::SetActionByName(), C4Action::t_attach, C4Object::xdir, and C4Object::ydir.

Referenced by C4Object::ContactAction(), C4Object::Fling(), C4Object::NoAttachAction(), ObjectComJump(), and ObjectComLetGo().

54 {
55  // scripted jump?
56  assert(cObj);
57  C4AulParSet pars(fixtoi(xdir, 100), fixtoi(ydir, 100), fByCom);
58  if (!!cObj->Call(PSF_OnActionJump, &pars)) return true;
59  // hardcoded jump by action
60  if (!cObj->SetActionByName("Jump")) return false;
61  cObj->xdir=xdir; cObj->ydir=ydir;
62  cObj->Mobile=1;
63  // unstick from ground, because jump command may be issued in an Action-callback,
64  // where attach-values have already been determined for that frame
65  cObj->Action.t_attach&=~CNAT_Bottom;
66  return true;
67 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
bool Mobile
Definition: C4Object.h:128
int32_t t_attach
Definition: C4Object.h:86
#define PSF_OnActionJump
Definition: C4GameScript.h:140
C4Action Action
Definition: C4Object.h:147
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Real xdir
Definition: C4Object.h:126
const BYTE CNAT_Bottom
Definition: C4Constants.h:113
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionKneel ( C4Object cObj)

Definition at line 95 of file C4ObjectCom.cpp.

References C4Object::SetActionByName().

Referenced by C4Object::ContactAction().

96 {
97  if (!cObj->SetActionByName("KneelDown")) return false;
98  return true;
99 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionPush ( C4Object cObj,
C4Object target 
)

Definition at line 148 of file C4ObjectCom.cpp.

References C4Object::SetActionByName().

Referenced by ObjectComGrab().

149 {
150  return cObj->SetActionByName("Push",target);
151 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionScale ( C4Object cObj,
int32_t  dir 
)

Definition at line 108 of file C4ObjectCom.cpp.

References C4Object::SetActionByName(), and C4Object::SetDir().

Referenced by C4Object::ContactAction().

109 {
110  if (!cObj->SetActionByName("Scale")) return false;
111  cObj->SetDir(dir);
112  return true;
113 }
void SetDir(int32_t tdir)
Definition: C4Object.cpp:2855
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionStand ( C4Object cObj)

Definition at line 46 of file C4ObjectCom.cpp.

References C4Object::Action, COMD_Stop, C4Action::ComDir, and ObjectActionWalk().

Referenced by C4Object::ContactAction(), DoBridge(), ObjectComStop(), ObjectComStopDig(), and ObjectComUnGrab().

47 {
48  cObj->Action.ComDir=COMD_Stop;
49  if (!ObjectActionWalk(cObj)) return false;
50  return true;
51 }
bool ObjectActionWalk(C4Object *cObj)
Definition: C4ObjectCom.cpp:40
#define COMD_Stop
Definition: C4Object.h:50
C4Action Action
Definition: C4Object.h:147
int32_t ComDir
Definition: C4Object.h:82

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionThrow ( C4Object cObj,
C4Object pThing 
)

Definition at line 121 of file C4ObjectCom.cpp.

References C4Object::Action, C4REAL100(), C4Object::Contents, C4Action::Dir, DIR_Left, C4Object::Exit(), C4ObjectList::GetObject(), C4PropList::GetPropertyInt(), C4Object::GetX(), C4Object::GetY(), P_ThrowSpeed, Random(), C4Object::SetActionByName(), C4Object::Shape, C4Object::xdir, C4Rect::y, and C4Object::ydir.

Referenced by ObjectComThrow().

122 {
123  // No object specified, first from contents
124  if (!pThing) pThing = cObj->Contents.GetObject();
125  // Nothing to throw
126  if (!pThing) return false;
127  // Force and direction
129  int32_t iDir=1; if (cObj->Action.Dir==DIR_Left) iDir=-1;
130  // Set action
131  if (!cObj->SetActionByName("Throw")) return false;
132  // Exit object
133  pThing->Exit(cObj->GetX(),
134  cObj->GetY()+cObj->Shape.y-1,
135  Random(360),
136  pthrow*iDir+cObj->xdir,-pthrow+cObj->ydir,pthrow*iDir);
137  // Success
138  return true;
139 }
int32_t GetY() const
Definition: C4Object.h:287
uint32_t Random()
Definition: C4Random.cpp:43
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
C4Real C4REAL100(int x)
Definition: C4Real.h:267
Definition: C4Real.h:58
C4NotifyingObjectList Contents
Definition: C4Object.h:152
#define DIR_Left
Definition: C4Object.h:41
int32_t y
Definition: C4Rect.h:32
bool Exit(int32_t iX=0, int32_t iY=0, int32_t iR=0, C4Real iXDir=Fix0, C4Real iYDir=Fix0, C4Real iRDir=Fix0, bool fCalls=true)
Definition: C4Object.cpp:1239
int32_t GetX() const
Definition: C4Object.h:286
C4Object * GetObject(int Index=0) const
int32_t Dir
Definition: C4Object.h:80
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:841
C4Action Action
Definition: C4Object.h:147
C4Shape Shape
Definition: C4Object.h:148
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionTumble ( C4Object cObj,
int32_t  dir,
C4Real  xdir,
C4Real  ydir 
)

Definition at line 80 of file C4ObjectCom.cpp.

References C4Object::SetActionByName(), C4Object::SetDir(), C4Object::xdir, and C4Object::ydir.

Referenced by C4Object::ContactAction(), C4Object::Fling(), and ObjectComPunch().

81 {
82  if (!cObj->SetActionByName("Tumble")) return false;
83  cObj->SetDir(dir);
84  cObj->xdir=xdir; cObj->ydir=ydir;
85  return true;
86 }
void SetDir(int32_t tdir)
Definition: C4Object.cpp:2855
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectActionWalk ( C4Object cObj)

Definition at line 40 of file C4ObjectCom.cpp.

References C4Object::SetActionByName().

Referenced by C4Object::ContactAction(), C4Object::ExecAction(), and ObjectActionStand().

41 {
42  if (!cObj->SetActionByName("Walk")) return false;
43  return true;
44 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComCancelAttach ( C4Object cObj)

Definition at line 407 of file C4ObjectCom.cpp.

References DFA_ATTACH, C4Object::GetProcedure(), and C4Object::SetAction().

Referenced by C4Object::Collect(), and C4Command::InitEvaluation().

408 {
409  if (cObj->GetProcedure()==DFA_ATTACH)
410  return cObj->SetAction(0);
411  return false;
412 }
bool SetAction(C4PropList *Act, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2696
int32_t GetProcedure() const
Definition: C4Object.cpp:2875

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComDig ( C4Object cObj)

Definition at line 254 of file C4ObjectCom.cpp.

References FormatString(), GameMsgObjectError(), C4PropList::GetName(), LoadResStr(), and ObjectActionDig().

Referenced by C4Command::Dig().

255 {
256  if (!ObjectActionDig(cObj))
257  {
258  GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NODIG"),cObj->GetName()).getData(),cObj);
259  return false;
260  }
261  return true;
262 }
void GameMsgObjectError(const char *szText, C4Object *pTarget, bool Red)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
virtual const char * GetName() const
Definition: C4PropList.cpp:604
bool ObjectActionDig(C4Object *cObj)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComDrop ( C4Object cObj,
C4Object pThing 
)

Definition at line 307 of file C4ObjectCom.cpp.

References C4Object::Action, C4REAL10(), C4REAL100(), COMD_Left, COMD_Right, C4Action::ComDir, ComDirLike(), C4Object::Contents, DFA_HANGLE, DFA_SCALE, DFA_SWIM, C4Object::Exit(), Fix0, C4Object::GetAction(), C4ObjectList::GetObject(), C4PropList::GetPropertyInt(), C4PropList::GetPropertyP(), C4Object::GetX(), C4Object::GetY(), C4Rect::Hgt, ObjectComUnGrab(), P_Procedure, P_ThrowSpeed, right, C4Object::SetOCF(), C4Object::Shape, C4Rect::Wdt, C4Rect::x, C4Object::xdir, and C4Rect::y.

Referenced by C4Command::Drop(), and C4Object::PutAwayUnusedObject().

308 {
309  // No object specified, first from contents
310  if (!pThing) pThing = cObj->Contents.GetObject();
311  // Nothing to throw
312  if (!pThing) return false;
313  // Force and direction
314  // When dropping diagonally, drop from edge of shape
315  // When doing a diagonal forward drop during flight, exit a bit closer to the Clonk to allow planned tumbling
316  // Except when hangling, so you can mine effectively form the ceiling, and when swimming because you cannot tumble then
318  int32_t tdir=0; int right=0;
319  bool isHanglingOrSwimming = false;
320  int32_t iProc = -1;
321  C4PropList* pActionDef = cObj->GetAction();
322  if (pActionDef)
323  {
324  iProc = pActionDef->GetPropertyP(P_Procedure);
325  if (iProc == DFA_HANGLE || iProc == DFA_SWIM) isHanglingOrSwimming = true;
326  }
327  int32_t iOutposReduction = 1; // don't exit object too far forward during jump
328  if (iProc != DFA_SCALE) // never diagonal during scaling (can have com into wall during scaling!)
329  {
330  if (ComDirLike(cObj->Action.ComDir, COMD_Left)) { tdir=-1; right = 0; if (cObj->xdir < C4REAL10(15) && !isHanglingOrSwimming) --iOutposReduction; }
331  if (ComDirLike(cObj->Action.ComDir, COMD_Right)) { tdir=+1; right = 1; if (cObj->xdir > C4REAL10(-15) && !isHanglingOrSwimming) --iOutposReduction; }
332  }
333  // Exit object
334  pThing->Exit(cObj->GetX() + (cObj->Shape.x + cObj->Shape.Wdt * right) * !!tdir * iOutposReduction,
335  cObj->GetY()+cObj->Shape.y+cObj->Shape.Hgt-(pThing->Shape.y+pThing->Shape.Hgt),0,pthrow*tdir,Fix0,Fix0);
336  // Update OCF
337  cObj->SetOCF();
338  // Ungrab
339  ObjectComUnGrab(cObj);
340  // Done
341  return true;
342 }
C4PropertyName GetPropertyP(C4PropertyName k) const
Definition: C4PropList.cpp:810
int32_t GetY() const
Definition: C4Object.h:287
bool ObjectComUnGrab(C4Object *cObj)
C4PropList * GetAction() const
Definition: C4Object.cpp:2689
C4Real C4REAL100(int x)
Definition: C4Real.h:267
Definition: C4Real.h:58
int32_t Wdt
Definition: C4Rect.h:32
C4NotifyingObjectList Contents
Definition: C4Object.h:152
C4Real C4REAL10(int x)
Definition: C4Real.h:269
int32_t y
Definition: C4Rect.h:32
bool Exit(int32_t iX=0, int32_t iY=0, int32_t iR=0, C4Real iXDir=Fix0, C4Real iYDir=Fix0, C4Real iRDir=Fix0, bool fCalls=true)
Definition: C4Object.cpp:1239
bool ComDirLike(int32_t iComDir, int32_t iSample)
int32_t GetX() const
Definition: C4Object.h:286
C4Object * GetObject(int Index=0) const
#define COMD_Right
Definition: C4Object.h:53
int32_t x
Definition: C4Rect.h:32
#define COMD_Left
Definition: C4Object.h:57
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:841
void SetOCF()
Definition: C4Object.cpp:670
int32_t Hgt
Definition: C4Rect.h:32
C4Action Action
Definition: C4Object.h:147
C4Shape Shape
Definition: C4Object.h:148
C4Real xdir
Definition: C4Object.h:126
int32_t ComDir
Definition: C4Object.h:82
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComGrab ( C4Object cObj,
C4Object pTarget 
)

Definition at line 190 of file C4ObjectCom.cpp.

References C4PropList::Call(), DFA_WALK, C4Object::GetProcedure(), ObjectActionPush(), PSF_Grab, PSF_Grabbed, and C4PropList::Status.

Referenced by C4Command::Grab().

191 {
192  if (!pTarget) return false;
193  if (cObj->GetProcedure()!=DFA_WALK) return false;
194  if (!ObjectActionPush(cObj,pTarget)) return false;
195  cObj->Call(PSF_Grab, &C4AulParSet(pTarget, true));
196  if (pTarget->Status && cObj->Status)
197  pTarget->Call(PSF_Grabbed, &C4AulParSet(cObj, true));
198  return true;
199 }
#define PSF_Grabbed
Definition: C4GameScript.h:53
bool ObjectActionPush(C4Object *cObj, C4Object *target)
int32_t Status
Definition: C4PropList.h:169
#define PSF_Grab
Definition: C4GameScript.h:52
int32_t GetProcedure() const
Definition: C4Object.cpp:2875
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComJump ( C4Object cObj)

Definition at line 224 of file C4ObjectCom.cpp.

References C4Object::Action, C4M_Liquid, C4REAL100(), COMD_Left, COMD_Right, COMD_UpLeft, COMD_UpRight, C4Action::ComDir, C4Shape::ContactDensity, DFA_WALK, Fix0, C4Object::fix_x, C4Object::fix_y, FullCon, C4Object::GetAction(), C4Shape::GetBottomVertex(), C4Object::GetCon(), C4Object::GetProcedure(), C4PropList::GetPropertyInt(), C4Shape::GetVertexX(), C4Shape::GetVertexY(), itofix(), ObjectActionDive(), ObjectActionJump(), P_JumpSpeed, P_Speed, C4Object::Shape, and SimFlightHitsLiquid().

Referenced by C4Command::Exit(), and C4Command::InitEvaluation().

225 {
226  // Only if walking
227  if (cObj->GetProcedure()!=DFA_WALK) return false;
228  // Calculate direction & forces
229  C4Real TXDir=Fix0;
230  C4PropList *pActionWalk = cObj->GetAction();
231  C4Real iPhysicalWalk = C4REAL100(pActionWalk->GetPropertyInt(P_Speed)) * itofix(cObj->GetCon(), FullCon);
232  C4Real iPhysicalJump = C4REAL100(cObj->GetPropertyInt(P_JumpSpeed)) * itofix(cObj->GetCon(), FullCon);
233 
234  if (cObj->Action.ComDir==COMD_Left || cObj->Action.ComDir==COMD_UpLeft) TXDir=-iPhysicalWalk;
235  else if (cObj->Action.ComDir==COMD_Right || cObj->Action.ComDir==COMD_UpRight) TXDir=+iPhysicalWalk;
236  C4Real x = cObj->fix_x, y = cObj->fix_y;
237  // find bottom-most vertex, correct starting position for simulation
238  int32_t iBtmVtx = cObj->Shape.GetBottomVertex();
239  if (iBtmVtx != -1) { x += cObj->Shape.GetVertexX(iBtmVtx); y += cObj->Shape.GetVertexY(iBtmVtx); }
240  // Try dive
241  if (cObj->Shape.ContactDensity > C4M_Liquid)
242  if (SimFlightHitsLiquid(x,y,TXDir,-iPhysicalJump))
243  if (ObjectActionDive(cObj,TXDir,-iPhysicalJump))
244  return true;
245  // Regular jump
246  return ObjectActionJump(cObj,TXDir,-iPhysicalJump,true);
247 }
#define COMD_UpRight
Definition: C4Object.h:52
int32_t GetCon() const
Definition: C4Object.h:272
C4PropList * GetAction() const
Definition: C4Object.cpp:2689
int32_t ContactDensity
Definition: C4Shape.h:48
C4Real C4REAL100(int x)
Definition: C4Real.h:267
int32_t GetBottomVertex()
Definition: C4Shape.cpp:460
int32_t GetVertexX(int32_t iVertex)
Definition: C4Shape.cpp:424
Definition: C4Real.h:58
const int32_t FullCon
Definition: C4Constants.h:182
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
#define COMD_Right
Definition: C4Object.h:53
C4Real fix_x
Definition: C4Object.h:125
#define COMD_Left
Definition: C4Object.h:57
int32_t GetProcedure() const
Definition: C4Object.cpp:2875
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:841
C4Real fix_y
Definition: C4Object.h:125
int32_t GetVertexY(int32_t iVertex)
Definition: C4Shape.cpp:430
C4Action Action
Definition: C4Object.h:147
C4Shape Shape
Definition: C4Object.h:148
const int32_t C4M_Liquid
Definition: C4Constants.h:175
bool SimFlightHitsLiquid(C4Real fcx, C4Real fcy, C4Real xdir, C4Real ydir)
Definition: C4Movement.cpp:657
bool ObjectActionDive(C4Object *cObj, C4Real xdir, C4Real ydir)
Definition: C4ObjectCom.cpp:69
bool ObjectActionJump(C4Object *cObj, C4Real xdir, C4Real ydir, bool fByCom)
Definition: C4ObjectCom.cpp:53
#define COMD_UpLeft
Definition: C4Object.h:58
int32_t ComDir
Definition: C4Object.h:82
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComLetGo ( C4Object cObj,
int32_t  xdirf 
)

Definition at line 249 of file C4ObjectCom.cpp.

References Fix0, itofix(), and ObjectActionJump().

Referenced by C4Command::Dig(), C4Command::Grab(), and C4Command::MoveTo().

250 { // by ACTSCALE, ACTHANGLE or ExecCMDFMoveTo
251  return ObjectActionJump(cObj,itofix(xdirf),Fix0,true);
252 }
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
bool ObjectActionJump(C4Object *cObj, C4Real xdir, C4Real ydir, bool fByCom)
Definition: C4ObjectCom.cpp:53
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComPunch ( C4Object cObj,
C4Object pTarget,
int32_t  punch 
)

Definition at line 378 of file C4ObjectCom.cpp.

References C4Object::Action, C4FxCall_EngGetPunched, C4REAL100(), C4PropList::Call(), COMD_Stop, C4Action::ComDir, C4Object::Controller, C4Action::Dir, DIR_Left, C4Object::DoEnergy(), Fix0, itofix(), ObjectActionGetPunched(), ObjectActionTumble(), PSF_CatchBlow, and PSF_QueryCatchBlow.

379 {
380  if (!cObj || !pTarget) return false;
381  if (!punch) return true;
382  bool fBlowStopped = !!pTarget->Call(PSF_QueryCatchBlow,&C4AulParSet(cObj));
383  if (fBlowStopped && punch>1) punch=punch/2; // half damage for caught blow, so shield+armor help in fistfight and vs monsters
384  pTarget->DoEnergy(-punch, false, C4FxCall_EngGetPunched, cObj->Controller);
385  int32_t tdir=+1; if (cObj->Action.Dir==DIR_Left) tdir=-1;
386  pTarget->Action.ComDir=COMD_Stop;
387  // No tumbles when blow was caught
388  if (fBlowStopped) return false;
389  // Hard punch
390  if (punch>=10)
391  if (ObjectActionTumble(pTarget,pTarget->Action.Dir,C4REAL100(150)*tdir,itofix(-2)))
392  {
393  pTarget->Call(PSF_CatchBlow,&C4AulParSet(punch, cObj));
394  return true;
395  }
396 
397  // Regular punch
398  if (ObjectActionGetPunched(pTarget,C4REAL100(250)*tdir,Fix0))
399  {
400  pTarget->Call(PSF_CatchBlow,&C4AulParSet(punch, cObj));
401  return true;
402  }
403 
404  return false;
405 }
#define PSF_CatchBlow
Definition: C4GameScript.h:72
C4Real C4REAL100(int x)
Definition: C4Real.h:267
#define DIR_Left
Definition: C4Object.h:41
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
#define COMD_Stop
Definition: C4Object.h:50
int32_t Dir
Definition: C4Object.h:80
#define C4FxCall_EngGetPunched
Definition: C4Effect.h:63
void DoEnergy(int32_t iChange, bool fExact, int32_t iCause, int32_t iCausedByPlr)
Definition: C4Object.cpp:1121
#define PSF_QueryCatchBlow
Definition: C4GameScript.h:73
C4Action Action
Definition: C4Object.h:147
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112
bool ObjectActionTumble(C4Object *cObj, int32_t dir, C4Real xdir, C4Real ydir)
Definition: C4ObjectCom.cpp:80
int32_t Controller
Definition: C4Object.h:111
bool ObjectActionGetPunched(C4Object *cObj, C4Real xdir, C4Real ydir)
Definition: C4ObjectCom.cpp:88
int32_t ComDir
Definition: C4Object.h:82
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

bool ObjectComPut ( C4Object cObj,
C4Object pTarget,
C4Object pThing 
)

Definition at line 264 of file C4ObjectCom.cpp.

References C4D_Grab_Put, C4PropList::Call(), C4Object::Contained, C4Object::Contents, C4Object::Def, C4Object::Enter(), C4ObjectList::GetObject(), C4Def::GrabPutGet, C4Object::OCF, OCF_FullCon, PSF_Collection, and PSF_Put.

Referenced by ObjectComPutTake(), C4Command::Put(), and C4Object::PutAwayUnusedObject().

265 {
266  // No object specified, first from contents
267  if (!pThing) pThing = cObj->Contents.GetObject();
268  // Nothing to put
269  if (!pThing) return false;
270  // No target
271  if (!pTarget) return false;
272  // Grabbing: check C4D_Grab_Put
273  if (pTarget!=cObj->Contained)
274  if (!(pTarget->Def->GrabPutGet & C4D_Grab_Put))
275  {
276  // No grab put: fail
277  return false;
278  }
279  // Target no fullcon
280  if (!(pTarget->OCF & OCF_FullCon)) return false;
281  // Transfer thing
282  bool fRejectCollect;
283  if (!pThing->Enter(pTarget, true, true, &fRejectCollect)) return false;
284  // Put call to object script
285  cObj->Call(PSF_Put);
286  // Target collection call
287  pTarget->Call(PSF_Collection,&C4AulParSet(pThing, true));
288  // Success
289  return true;
290 }
bool Enter(C4Object *pTarget, bool fCalls=true, bool fCopyMotion=true, bool *pfRejectCollect=nullptr)
Definition: C4Object.cpp:1275
const uint32_t OCF_FullCon
Definition: C4Constants.h:85
const int32_t C4D_Grab_Put
Definition: C4Def.h:64
C4NotifyingObjectList Contents
Definition: C4Object.h:152
C4Def * Def
Definition: C4Object.h:143
C4Object * GetObject(int Index=0) const
int32_t GrabPutGet
Definition: C4Def.h:126
#define PSF_Collection
Definition: C4GameScript.h:56
C4ObjectPtr Contained
Definition: C4Object.h:144
uint32_t OCF
Definition: C4Object.h:134
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112
#define PSF_Put
Definition: C4GameScript.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComPutTake ( C4Object cObj,
C4Object pTarget,
C4Object pThing 
)

Definition at line 344 of file C4ObjectCom.cpp.

References C4Object::ActivateMenu(), C4D_Grab_Get, C4MN_Get, C4Object::Contained, C4Object::Contents, C4Object::Def, C4ObjectList::GetObject(), C4Def::GrabPutGet, ObjectComPut(), and ObjectComTake().

Referenced by C4Command::Drop(), and C4Command::Throw().

345 { // by C4CMD_Drop
346  // Valid checks
347  if (!pTarget) return false;
348  // No object specified, first from contents
349  if (!pThing) pThing = cObj->Contents.GetObject();
350  // Has thing, put to target
351  if (pThing)
352  return ObjectComPut(cObj,pTarget,pThing);
353  // If target is own container, activate activation menu
354  if (pTarget==cObj->Contained)
355  return ObjectComTake(cObj); // carlo
356  // Assuming target is grabbed, check for grab get
357  if (pTarget->Def->GrabPutGet & C4D_Grab_Get)
358  {
359  // Activate get menu
360  return cObj->ActivateMenu(C4MN_Get,0,0,0,pTarget);
361  }
362  // Failure
363  return false;
364 }
const int32_t C4D_Grab_Get
Definition: C4Def.h:65
bool ObjectComPut(C4Object *cObj, C4Object *pTarget, C4Object *pThing)
C4NotifyingObjectList Contents
Definition: C4Object.h:152
C4Def * Def
Definition: C4Object.h:143
C4Object * GetObject(int Index=0) const
bool ObjectComTake(C4Object *cObj)
bool ActivateMenu(int32_t iMenu, int32_t iMenuSelect=0, int32_t iMenuData=0, int32_t iMenuPosition=0, C4Object *pTarget=nullptr)
Definition: C4Object.cpp:1491
int32_t GrabPutGet
Definition: C4Def.h:126
C4ObjectPtr Contained
Definition: C4Object.h:144

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComStop ( C4Object cObj)

Definition at line 182 of file C4ObjectCom.cpp.

References ObjectActionStand(), and C4Object::SetActionByName().

Referenced by C4Command::Activate(), C4Command::Dig(), C4Command::Drop(), C4Command::Enter(), C4Command::Get(), C4Command::Grab(), C4Command::MoveTo(), C4Command::PushTo(), C4Command::Put(), StopActionDelayCommand(), C4Command::Throw(), and C4Command::Wait().

183 {
184  // Cease current action
185  cObj->SetActionByName("Idle");
186  // Action walk if possible
187  return ObjectActionStand(cObj);
188 }
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
Definition: C4Object.cpp:2829
bool ObjectActionStand(C4Object *cObj)
Definition: C4ObjectCom.cpp:46

Here is the call graph for this function:

Here is the caller graph for this function:

void ObjectComStopDig ( C4Object cObj)

Definition at line 414 of file C4ObjectCom.cpp.

References C4CMD_Dig, C4Object::ClearCommand(), C4Command::Command, C4Object::Command, ObjectActionStand(), C4Object::xdir, and C4Object::ydir.

Referenced by C4Object::ExecAction().

415 {
416  // Stand - but keep momentum to allow more dyanamic digging
417  C4Real o_xdir = cObj->xdir, o_ydir = cObj->ydir;
418  ObjectActionStand(cObj);
419  cObj->xdir = o_xdir; cObj->ydir = o_ydir;
420  // Clear digging command
421  if (cObj->Command)
422  if (cObj->Command->Command == C4CMD_Dig)
423  cObj->ClearCommand(cObj->Command);
424 }
C4Command * Command
Definition: C4Object.h:166
void ClearCommand(C4Command *pUntil)
Definition: C4Object.cpp:2560
Definition: C4Real.h:58
int32_t Command
Definition: C4Command.h:81
bool ObjectActionStand(C4Object *cObj)
Definition: C4ObjectCom.cpp:46
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComTake ( C4Object cObj)

Definition at line 367 of file C4ObjectCom.cpp.

References C4Object::ActivateMenu(), and C4MN_Activate.

Referenced by ObjectComPutTake(), and C4Command::Take().

368 {
369  return cObj->ActivateMenu(C4MN_Activate);
370 }
bool ActivateMenu(int32_t iMenu, int32_t iMenuSelect=0, int32_t iMenuData=0, int32_t iMenuPosition=0, C4Object *pTarget=nullptr)
Definition: C4Object.cpp:1491

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComTake2 ( C4Object cObj)

Definition at line 373 of file C4ObjectCom.cpp.

References C4Object::ActivateMenu(), C4MN_Get, and C4Object::Contained.

Referenced by C4Command::Take2().

374 {
375  return cObj->ActivateMenu(C4MN_Get,0,0,0,cObj->Contained);
376 }
bool ActivateMenu(int32_t iMenu, int32_t iMenuSelect=0, int32_t iMenuData=0, int32_t iMenuPosition=0, C4Object *pTarget=nullptr)
Definition: C4Object.cpp:1491
C4ObjectPtr Contained
Definition: C4Object.h:144

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComThrow ( C4Object cObj,
C4Object pThing 
)

Definition at line 292 of file C4ObjectCom.cpp.

References C4Object::Contents, DFA_WALK, C4ObjectList::GetObject(), C4Object::GetProcedure(), and ObjectActionThrow().

Referenced by C4Command::Throw().

293 {
294  // No object specified, first from contents
295  if (!pThing) pThing = cObj->Contents.GetObject();
296  // Nothing to throw
297  if (!pThing) return false;
298  // Throw com
299  switch (cObj->GetProcedure())
300  {
301  case DFA_WALK: return ObjectActionThrow(cObj,pThing);
302  }
303  // Failure
304  return false;
305 }
C4NotifyingObjectList Contents
Definition: C4Object.h:152
C4Object * GetObject(int Index=0) const
bool ObjectActionThrow(C4Object *cObj, C4Object *pThing)
int32_t GetProcedure() const
Definition: C4Object.cpp:2875

Here is the call graph for this function:

Here is the caller graph for this function:

bool ObjectComUnGrab ( C4Object cObj)

Definition at line 201 of file C4ObjectCom.cpp.

References C4Object::Action, C4PropList::Call(), C4Object::CloseMenu(), DFA_PUSH, C4Object::GetProcedure(), ObjectActionStand(), PSF_Grab, PSF_Grabbed, C4PropList::Status, and C4Action::Target.

Referenced by ObjectComDrop(), and C4Command::UnGrab().

202 {
203  // Only if pushing, -> stand
204  if (cObj->GetProcedure() == DFA_PUSH)
205  {
206  C4Object *pTarget = cObj->Action.Target;
207  if (ObjectActionStand(cObj))
208  {
209  if (!cObj->CloseMenu(false)) return false;
210  cObj->Call(PSF_Grab, &C4AulParSet(pTarget, false));
211  // clear action target
212  cObj->Action.Target = nullptr;
213  if (pTarget && pTarget->Status && cObj->Status)
214  {
215  pTarget->Call(PSF_Grabbed, &C4AulParSet(cObj, false));
216  }
217  return true;
218  }
219  }
220 
221  return false;
222 }
#define PSF_Grabbed
Definition: C4GameScript.h:53
bool CloseMenu(bool fForce)
Definition: C4Object.cpp:1585
int32_t Status
Definition: C4PropList.h:169
#define PSF_Grab
Definition: C4GameScript.h:52
bool ObjectActionStand(C4Object *cObj)
Definition: C4ObjectCom.cpp:46
C4ObjectPtr Target
Definition: C4Object.h:87
int32_t GetProcedure() const
Definition: C4Object.cpp:2875
C4Action Action
Definition: C4Object.h:147
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112

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: