OpenClonk
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

◆ ComDirLike()

bool ComDirLike ( int32_t  iComDir,
int32_t  iSample 
)

Definition at line 575 of file C4ObjectCom.cpp.

576 {
577  if (iComDir == iSample) return true;
578  if (iComDir % 8 + 1 == iSample) return true;
579  if (iComDir == iSample % 8 + 1 ) return true;
580  return false;
581 }

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

Here is the caller graph for this function:

◆ ObjectActionCornerScale()

bool ObjectActionCornerScale ( C4Object cObj)

Definition at line 210 of file C4ObjectCom.cpp.

211 {
212  int32_t iRangeX = 1;
213  int32_t iRangeY = 1;
214  if (!CornerScaleOkay(cObj, iRangeX, iRangeY))
215  {
216  return false;
217  }
218  // Do corner scale
219  if (!cObj->SetActionByName("KneelUp"))
220  {
221  cObj->SetActionByName("Walk");
222  }
223  cObj->xdir = 0;
224  cObj->ydir = 0;
225  if (cObj->Action.Dir == DIR_Left)
226  {
227  cObj->fix_x -= itofix(iRangeX);
228  }
229  else
230  {
231  cObj->fix_x += itofix(iRangeX);
232  }
233  cObj->fix_y -= itofix(iRangeY);
234  return true;
235 }
#define DIR_Left
Definition: C4Object.h:41
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t Dir
Definition: C4Object.h:80
C4Real ydir
Definition: C4Object.h:124
C4Real fix_y
Definition: C4Object.h:123
C4Real xdir
Definition: C4Object.h:124
C4Real fix_x
Definition: C4Object.h:123
bool SetActionByName(C4String *ActName, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)
C4Action Action
Definition: C4Object.h:145

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

Here is the caller graph for this function:

◆ ObjectActionDig()

bool ObjectActionDig ( C4Object cObj)

Definition at line 175 of file C4ObjectCom.cpp.

176 {
177  if (!cObj->SetActionByName("Dig"))
178  {
179  return false;
180  }
181  cObj->Action.Data = 0; // Material Dig2Object request
182  return true;
183 }
int32_t Data
Definition: C4Object.h:84

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

Referenced by ObjectComDig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionDive()

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

Definition at line 73 of file C4ObjectCom.cpp.

74 {
75  if (!cObj->SetActionByName("Dive"))
76  {
77  return false;
78  }
79  cObj->xdir = xdir;
80  cObj->ydir = ydir;
81  cObj->Mobile = true;
82  // Unstick from ground, because jump command may be issued in an Action-callback,
83  // where attach-values have already been determined for that frame
84  cObj->Action.t_attach &= ~CNAT_Bottom;
85  return true;
86 }
const BYTE CNAT_Bottom
Definition: C4Constants.h:112
int32_t t_attach
Definition: C4Object.h:86
bool Mobile
Definition: C4Object.h:126

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

Referenced by ObjectComJump().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionFlat()

bool ObjectActionFlat ( C4Object cObj,
int32_t  dir 
)

Definition at line 116 of file C4ObjectCom.cpp.

117 {
118  if (!cObj->SetActionByName("FlatUp"))
119  {
120  return false;
121  }
122  cObj->SetDir(dir);
123  return true;
124 }
void SetDir(int32_t tdir)

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

Referenced by C4Object::ContactAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionGetPunched()

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

Definition at line 100 of file C4ObjectCom.cpp.

101 {
102  if (!cObj->SetActionByName("GetPunched"))
103  {
104  return false;
105  }
106  cObj->xdir = xdir;
107  cObj->ydir = ydir;
108  return true;
109 }

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

Referenced by ObjectComPunch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionHangle()

bool ObjectActionHangle ( C4Object cObj)

Definition at line 136 of file C4ObjectCom.cpp.

137 {
138  return cObj->SetActionByName("Hangle");
139 }

References C4Object::SetActionByName().

Referenced by C4Object::ContactAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionJump()

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

Definition at line 50 of file C4ObjectCom.cpp.

51 {
52  // Scripted jump?
53  assert(cObj);
54  C4AulParSet pars(fixtoi(xdir, 100), fixtoi(ydir, 100), fByCom);
55  if (!!cObj->Call(PSF_OnActionJump, &pars))
56  {
57  return true;
58  }
59  // Hardcoded jump by action
60  if (!cObj->SetActionByName("Jump"))
61  {
62  return false;
63  }
64  cObj->xdir = xdir;
65  cObj->ydir = ydir;
66  cObj->Mobile = true;
67  // Unstick from ground, because jump command may be issued in an Action-callback,
68  // where attach-values have already been determined for that frame
69  cObj->Action.t_attach &= ~CNAT_Bottom;
70  return true;
71 }
#define PSF_OnActionJump
Definition: C4GameScript.h:140
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionKneel()

bool ObjectActionKneel ( C4Object cObj)

Definition at line 111 of file C4ObjectCom.cpp.

112 {
113  return cObj->SetActionByName("KneelDown");
114 }

References C4Object::SetActionByName().

Referenced by C4Object::ContactAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionPush()

bool ObjectActionPush ( C4Object cObj,
C4Object target 
)

Definition at line 185 of file C4ObjectCom.cpp.

186 {
187  return cObj->SetActionByName("Push", target);
188 }

References C4Object::SetActionByName().

Referenced by ObjectComGrab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionScale()

bool ObjectActionScale ( C4Object cObj,
int32_t  dir 
)

Definition at line 126 of file C4ObjectCom.cpp.

127 {
128  if (!cObj->SetActionByName("Scale"))
129  {
130  return false;
131  }
132  cObj->SetDir(dir);
133  return true;
134 }

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

Referenced by C4Object::ContactAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionStand()

bool ObjectActionStand ( C4Object cObj)

Definition at line 44 of file C4ObjectCom.cpp.

45 {
46  cObj->Action.ComDir = COMD_Stop;
47  return ObjectActionWalk(cObj);
48 }
#define COMD_Stop
Definition: C4Object.h:50
bool ObjectActionWalk(C4Object *cObj)
Definition: C4ObjectCom.cpp:39
int32_t ComDir
Definition: C4Object.h:82

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionThrow()

bool ObjectActionThrow ( C4Object cObj,
C4Object pThing 
)

Definition at line 141 of file C4ObjectCom.cpp.

142 {
143  // No object specified, first from contents
144  if (!pThing)
145  {
146  pThing = cObj->Contents.GetObject();
147  }
148  // Nothing to throw
149  if (!pThing)
150  {
151  return false;
152  }
153  // TODO: Initialize force and direction AFTER action is set.
154  // Force and direction
155  C4Real pthrow = C4REAL100(cObj->GetPropertyInt(P_ThrowSpeed));
156  int32_t iDir = 1;
157  if (cObj->Action.Dir == DIR_Left)
158  {
159  iDir = -1;
160  }
161  // Set action
162  if (!cObj->SetActionByName("Throw"))
163  {
164  return false;
165  }
166  // Exit object
167  pThing->Exit(cObj->GetX(),
168  cObj->GetY() + cObj->Shape.y - 1,
169  Random(360),
170  pthrow * iDir + cObj->xdir, -pthrow + cObj->ydir, pthrow * iDir);
171  // Success
172  return true;
173 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Real C4REAL100(int x)
Definition: C4Real.h:267
@ P_ThrowSpeed
Definition: C4Real.h:59
int32_t GetX() const
Definition: C4Object.h:285
int32_t GetY() const
Definition: C4Object.h:286
C4NotifyingObjectList Contents
Definition: C4Object.h:151
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)
C4Shape Shape
Definition: C4Object.h:146
C4Object * GetObject(int index=0) const
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:855
int32_t y
Definition: C4Rect.h:30

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionTumble()

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

Definition at line 88 of file C4ObjectCom.cpp.

89 {
90  if (!cObj->SetActionByName("Tumble"))
91  {
92  return false;
93  }
94  cObj->SetDir(dir);
95  cObj->xdir = xdir;
96  cObj->ydir = ydir;
97  return true;
98 }

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectActionWalk()

bool ObjectActionWalk ( C4Object cObj)

Definition at line 39 of file C4ObjectCom.cpp.

40 {
41  return cObj->SetActionByName("Walk");
42 }

References C4Object::SetActionByName().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComCancelAttach()

bool ObjectComCancelAttach ( C4Object cObj)

Definition at line 551 of file C4ObjectCom.cpp.

552 {
553  if (cObj->GetProcedure() == DFA_ATTACH)
554  {
555  return cObj->SetAction(nullptr);
556  }
557  return false;
558 }
@ DFA_ATTACH
int32_t GetProcedure() const
bool SetAction(C4PropList *Act, C4Object *pTarget=nullptr, C4Object *pTarget2=nullptr, int32_t iCalls=SAC_StartCall|SAC_AbortCall, bool fForce=false)

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComDig()

bool ObjectComDig ( C4Object cObj)

Definition at line 340 of file C4ObjectCom.cpp.

341 {
342  if (!ObjectActionDig(cObj))
343  {
344  GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NODIG"), cObj->GetName()).getData(), cObj);
345  return false;
346  }
347  return true;
348 }
void GameMsgObjectError(const char *szText, C4Object *pTarget, bool Red)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool ObjectActionDig(C4Object *cObj)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
virtual const char * GetName() const
Definition: C4PropList.cpp:618
const char * getData() const
Definition: StdBuf.h:442

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

Referenced by C4Command::Dig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComDrop()

bool ObjectComDrop ( C4Object cObj,
C4Object pThing 
)

Definition at line 415 of file C4ObjectCom.cpp.

416 {
417  // No object specified, first from contents
418  if (!pThing)
419  {
420  pThing = cObj->Contents.GetObject();
421  }
422  // Nothing to throw
423  if (!pThing)
424  {
425  return false;
426  }
427  // Force and direction
428  // When dropping diagonally, drop from edge of shape
429  // When doing a diagonal forward drop during flight, exit a bit closer to the Clonk to allow planned tumbling
430  // Except when hangling, so you can mine effectively form the ceiling, and when swimming because you cannot tumble then
431  C4Real pthrow = C4REAL100(cObj->GetPropertyInt(P_ThrowSpeed));
432  int32_t tdir = 0;
433  int right = 0;
434  bool isHanglingOrSwimming = false;
435  int32_t iProc = -1;
436  C4PropList* pActionDef = cObj->GetAction();
437  if (pActionDef)
438  {
439  iProc = pActionDef->GetPropertyP(P_Procedure);
440  if (iProc == DFA_HANGLE || iProc == DFA_SWIM)
441  {
442  isHanglingOrSwimming = true;
443  }
444  }
445  int32_t iOutposReduction = 1; // don't exit object too far forward during jump
446  if (iProc != DFA_SCALE) // never diagonal during scaling (can have com into wall during scaling!)
447  {
448  // Table format is OK here
449  if (ComDirLike(cObj->Action.ComDir, COMD_Left)) { tdir = -1; right = 0; if (cObj->xdir < C4REAL10(15) && !isHanglingOrSwimming) --iOutposReduction; }
450  if (ComDirLike(cObj->Action.ComDir, COMD_Right)) { tdir = +1; right = 1; if (cObj->xdir > C4REAL10(-15) && !isHanglingOrSwimming) --iOutposReduction; }
451  }
452  // Exit object
453  pThing->Exit(cObj->GetX() + (cObj->Shape.x + cObj->Shape.Wdt * right) * !!tdir * iOutposReduction,
454  cObj->GetY() + cObj->Shape.y + cObj->Shape.Hgt - (pThing->Shape.y + pThing->Shape.Hgt), 0, pthrow * tdir, Fix0, Fix0);
455  // Update OCF
456  cObj->SetOCF();
457  // Ungrab
458  ObjectComUnGrab(cObj);
459  // Done
460  return true;
461 }
#define COMD_Right
Definition: C4Object.h:53
#define COMD_Left
Definition: C4Object.h:57
bool ObjectComUnGrab(C4Object *cObj)
bool ComDirLike(int32_t iComDir, int32_t iSample)
const C4Real Fix0
Definition: C4Real.h:312
C4Real C4REAL10(int x)
Definition: C4Real.h:269
@ DFA_SWIM
@ DFA_HANGLE
@ P_Procedure
@ DFA_SCALE
C4PropList * GetAction() const
void SetOCF()
Definition: C4ObjectOCF.cpp:30
C4PropertyName GetPropertyP(C4PropertyName k) const
Definition: C4PropList.cpp:824
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30

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, C4ScriptGuiWindowPropertyName::right, C4Object::SetOCF(), C4Object::Shape, C4Rect::Wdt, C4Rect::x, C4Object::xdir, and C4Rect::y.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComGrab()

bool ObjectComGrab ( C4Object cObj,
C4Object pTarget 
)

Definition at line 245 of file C4ObjectCom.cpp.

246 {
247  if (!pTarget)
248  {
249  return false;
250  }
251  if (cObj->GetProcedure() != DFA_WALK)
252  {
253  return false;
254  }
255  if (!ObjectActionPush(cObj, pTarget))
256  {
257  return false;
258  }
259  cObj->Call(PSF_Grab, &C4AulParSet(pTarget, true));
260  if (pTarget->Status && cObj->Status)
261  {
262  pTarget->Call(PSF_Grabbed, &C4AulParSet(cObj, true));
263  }
264  return true;
265 }
#define PSF_Grabbed
Definition: C4GameScript.h:53
#define PSF_Grab
Definition: C4GameScript.h:52
bool ObjectActionPush(C4Object *cObj, C4Object *target)
@ DFA_WALK
int32_t Status
Definition: C4PropList.h:173

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

Referenced by C4Command::Grab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComJump()

bool ObjectComJump ( C4Object cObj)

Definition at line 293 of file C4ObjectCom.cpp.

294 {
295  // Only if walking
296  if (cObj->GetProcedure() != DFA_WALK)
297  {
298  return false;
299  }
300  // Calculate direction & forces
301  C4Real TXDir = Fix0;
302  C4PropList *pActionWalk = cObj->GetAction();
303  C4Real iPhysicalWalk = C4REAL100(pActionWalk->GetPropertyInt(P_Speed)) * itofix(cObj->GetCon(), FullCon);
304  C4Real iPhysicalJump = C4REAL100(cObj->GetPropertyInt(P_JumpSpeed)) * itofix(cObj->GetCon(), FullCon);
305 
306  if (cObj->Action.ComDir == COMD_Left || cObj->Action.ComDir == COMD_UpLeft)
307  {
308  TXDir = -iPhysicalWalk;
309  }
310  else if (cObj->Action.ComDir == COMD_Right || cObj->Action.ComDir == COMD_UpRight)
311  {
312  TXDir = +iPhysicalWalk;
313  }
314  C4Real x = cObj->fix_x;
315  C4Real y = cObj->fix_y;
316  // Find bottom-most vertex, correct starting position for simulation
317  int32_t iBtmVtx = cObj->Shape.GetBottomVertex();
318  if (iBtmVtx != -1)
319  {
320  x += cObj->Shape.GetVertexX(iBtmVtx);
321  y += cObj->Shape.GetVertexY(iBtmVtx);
322  }
323  // Try dive
324  if ((cObj->Shape.ContactDensity > C4M_Liquid)
325  && SimFlightHitsLiquid(x, y, TXDir, -iPhysicalJump)
326  && ObjectActionDive(cObj, TXDir, -iPhysicalJump))
327  {
328  return true;
329  }
330  // Regular jump
331  return ObjectActionJump(cObj, TXDir, -iPhysicalJump, true);
332 }
const int32_t FullCon
Definition: C4Constants.h:181
const int32_t C4M_Liquid
Definition: C4Constants.h:174
#define COMD_UpLeft
Definition: C4Object.h:58
#define COMD_UpRight
Definition: C4Object.h:52
bool ObjectActionJump(C4Object *cObj, C4Real xdir, C4Real ydir, bool fByCom)
Definition: C4ObjectCom.cpp:50
bool ObjectActionDive(C4Object *cObj, C4Real xdir, C4Real ydir)
Definition: C4ObjectCom.cpp:73
bool SimFlightHitsLiquid(C4Real fcx, C4Real fcy, C4Real xdir, C4Real ydir)
Definition: C4Movement.cpp:874
@ P_Speed
@ P_JumpSpeed
int32_t GetCon() const
Definition: C4Object.h:271
int32_t GetVertexY(int32_t iVertex)
Definition: C4Shape.cpp:523
int32_t GetVertexX(int32_t iVertex)
Definition: C4Shape.cpp:514
int32_t ContactDensity
Definition: C4Shape.h:47
int32_t GetBottomVertex()
Definition: C4Shape.cpp:558

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComLetGo()

bool ObjectComLetGo ( C4Object cObj,
int32_t  xdirf 
)

Definition at line 334 of file C4ObjectCom.cpp.

335 {
336  // by ACTSCALE, ACTHANGLE or ExecCMDFMoveTo
337  return ObjectActionJump(cObj, itofix(xdirf), Fix0, true);
338 }

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComPunch()

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

Definition at line 507 of file C4ObjectCom.cpp.

508 {
509  if (!cObj || !pTarget)
510  {
511  return false;
512  }
513  if (!punch)
514  {
515  return true;
516  }
517  bool fBlowStopped = !!pTarget->Call(PSF_QueryCatchBlow, &C4AulParSet(cObj));
518  if (fBlowStopped && punch > 1)
519  {
520  punch = punch / 2; // Half damage for caught blow, so shield+armor help in fistfight and vs monsters
521  }
522  pTarget->DoEnergy(-punch, false, C4FxCall_EngGetPunched, cObj->Controller);
523  int32_t tdir = +1;
524  if (cObj->Action.Dir == DIR_Left)
525  {
526  tdir = -1;
527  }
528  pTarget->Action.ComDir = COMD_Stop;
529  // No tumbles when blow was caught
530  if (fBlowStopped)
531  {
532  return false;
533  }
534  // Hard punch
535  if (punch >= 10 && ObjectActionTumble(pTarget, pTarget->Action.Dir, C4REAL100(150) * tdir, itofix(-2)))
536  {
537  pTarget->Call(PSF_CatchBlow, &C4AulParSet(punch, cObj));
538  return true;
539  }
540 
541  // Regular punch
542  if (ObjectActionGetPunched(pTarget, C4REAL100(250) * tdir, Fix0))
543  {
544  pTarget->Call(PSF_CatchBlow,&C4AulParSet(punch, cObj));
545  return true;
546  }
547 
548  return false;
549 }
#define C4FxCall_EngGetPunched
Definition: C4Effect.h:63
#define PSF_CatchBlow
Definition: C4GameScript.h:72
#define PSF_QueryCatchBlow
Definition: C4GameScript.h:73
bool ObjectActionGetPunched(C4Object *cObj, C4Real xdir, C4Real ydir)
bool ObjectActionTumble(C4Object *cObj, int32_t dir, C4Real xdir, C4Real ydir)
Definition: C4ObjectCom.cpp:88
int32_t Controller
Definition: C4Object.h:109
void DoEnergy(int32_t iChange, bool fExact, int32_t iCause, int32_t iCausedByPlr)
Definition: C4Object.cpp:585

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.

Here is the call graph for this function:

◆ ObjectComPut()

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

Definition at line 350 of file C4ObjectCom.cpp.

351 {
352  // No object specified, first from contents
353  if (!pThing)
354  {
355  pThing = cObj->Contents.GetObject();
356  }
357  // Nothing to put
358  if (!pThing)
359  {
360  return false;
361  }
362  // No target
363  if (!pTarget)
364  {
365  return false;
366  }
367  // Grabbing: check C4D_Grab_Put
368  if (pTarget != cObj->Contained
369  && !(pTarget->Def->GrabPutGet & C4D_Grab_Put))
370  {
371  // No grab put: fail
372  return false;
373  }
374  // Target no fullcon
375  if (!(pTarget->OCF & OCF_FullCon))
376  {
377  return false;
378  }
379  // Transfer thing
380  bool fRejectCollect;
381  if (!pThing->Enter(pTarget, true, true, &fRejectCollect))
382  {
383  return false;
384  }
385  // Put call to object script
386  cObj->Call(PSF_Put);
387  // Target collection call
388  pTarget->Call(PSF_Collection,&C4AulParSet(pThing, true));
389  // Success
390  return true;
391 }
const uint32_t OCF_FullCon
Definition: C4Constants.h:85
const int32_t C4D_Grab_Put
Definition: C4Def.h:62
#define PSF_Put
Definition: C4GameScript.h:55
#define PSF_Collection
Definition: C4GameScript.h:56
int32_t GrabPutGet
Definition: C4Def.h:124
bool Enter(C4Object *pTarget, bool fCalls=true, bool fCopyMotion=true, bool *pfRejectCollect=nullptr)
uint32_t OCF
Definition: C4Object.h:132
C4ObjectPtr Contained
Definition: C4Object.h:142
C4Def * Def
Definition: C4Object.h:141

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComPutTake()

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

Definition at line 463 of file C4ObjectCom.cpp.

464 { // by C4CMD_Drop
465  // Valid checks
466  if (!pTarget)
467  {
468  return false;
469  }
470  // No object specified, first from contents
471  if (!pThing)
472  {
473  pThing = cObj->Contents.GetObject();
474  }
475  // Has thing, put to target
476  if (pThing)
477  {
478  return ObjectComPut(cObj, pTarget, pThing);
479  }
480  // If target is own container, activate activation menu
481  if (pTarget == cObj->Contained)
482  {
483  return ObjectComTake(cObj); // carlo
484  }
485  // Assuming target is grabbed, check for grab get
486  if (pTarget->Def->GrabPutGet & C4D_Grab_Get)
487  {
488  // Activate get menu
489  return cObj->ActivateMenu(C4MN_Get, 0, 0, 0, pTarget);
490  }
491  // Failure
492  return false;
493 }
const int32_t C4D_Grab_Get
Definition: C4Def.h:63
bool ObjectComTake(C4Object *cObj)
bool ObjectComPut(C4Object *cObj, C4Object *pTarget, C4Object *pThing)
@ C4MN_Get
Definition: C4ObjectMenu.h:39
bool ActivateMenu(int32_t iMenu, int32_t iMenuSelect=0, int32_t iMenuData=0, int32_t iMenuPosition=0, C4Object *pTarget=nullptr)

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComStop()

bool ObjectComStop ( C4Object cObj)

Definition at line 237 of file C4ObjectCom.cpp.

238 {
239  // Cease current action
240  cObj->SetActionByName("Idle");
241  // Action walk if possible
242  return ObjectActionStand(cObj);
243 }
bool ObjectActionStand(C4Object *cObj)
Definition: C4ObjectCom.cpp:44

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComStopDig()

void ObjectComStopDig ( C4Object cObj)

Definition at line 560 of file C4ObjectCom.cpp.

561 {
562  // Stand - but keep momentum to allow more dynamic digging
563  C4Real o_xdir = cObj->xdir;
564  C4Real o_ydir = cObj->ydir;
565  ObjectActionStand(cObj);
566  cObj->xdir = o_xdir;
567  cObj->ydir = o_ydir;
568  // Clear digging command
569  if (cObj->Command && cObj->Command->Command == C4CMD_Dig)
570  {
571  cObj->ClearCommand(cObj->Command);
572  }
573 }
@ C4CMD_Dig
Definition: C4Command.h:41
int32_t Command
Definition: C4Command.h:81
void ClearCommand(C4Command *pUntil)
C4Command * Command
Definition: C4Object.h:165

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

Here is the call graph for this function:

◆ ObjectComTake()

bool ObjectComTake ( C4Object cObj)

Definition at line 496 of file C4ObjectCom.cpp.

497 {
498  return cObj->ActivateMenu(C4MN_Activate);
499 }
@ C4MN_Activate
Definition: C4ObjectMenu.h:33

References C4Object::ActivateMenu(), and C4MN_Activate.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComTake2()

bool ObjectComTake2 ( C4Object cObj)

Definition at line 502 of file C4ObjectCom.cpp.

503 {
504  return cObj->ActivateMenu(C4MN_Get, 0, 0, 0, cObj->Contained);
505 }

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

Referenced by C4Command::Take2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComThrow()

bool ObjectComThrow ( C4Object cObj,
C4Object pThing 
)

Definition at line 393 of file C4ObjectCom.cpp.

394 {
395  // No object specified, first from contents
396  if (!pThing)
397  {
398  pThing = cObj->Contents.GetObject();
399  }
400  // Nothing to throw
401  if (!pThing)
402  {
403  return false;
404  }
405  // Throw com
406  switch (cObj->GetProcedure())
407  {
408  case DFA_WALK:
409  return ObjectActionThrow(cObj, pThing);
410  }
411  // Failure
412  return false;
413 }
bool ObjectActionThrow(C4Object *cObj, C4Object *pThing)

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

Referenced by C4Command::Throw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectComUnGrab()

bool ObjectComUnGrab ( C4Object cObj)

Definition at line 267 of file C4ObjectCom.cpp.

268 {
269  // Only if pushing, -> stand
270  if (cObj->GetProcedure() == DFA_PUSH)
271  {
272  C4Object *pTarget = cObj->Action.Target;
273  if (ObjectActionStand(cObj))
274  {
275  if (!cObj->CloseMenu(false))
276  {
277  return false;
278  }
279  cObj->Call(PSF_Grab, &C4AulParSet(pTarget, false));
280  // Clear action target
281  cObj->Action.Target = nullptr;
282  if (pTarget && pTarget->Status && cObj->Status)
283  {
284  pTarget->Call(PSF_Grabbed, &C4AulParSet(cObj, false));
285  }
286  return true;
287  }
288  }
289 
290  return false;
291 }
@ DFA_PUSH
C4ObjectPtr Target
Definition: C4Object.h:87
bool CloseMenu(bool fForce)

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SimFlightHitsLiquid()

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

Definition at line 874 of file C4Movement.cpp.

875 {
876  // Start in water?
877  if (DensityLiquid(GBackDensity(fixtoi(start_x), fixtoi(start_y))))
878  {
879  int temp = 10;
880  if (!SimFlight(start_x, start_y, xdir, ydir, 0, C4M_Liquid - 1, temp))
881  {
882  return false;
883  }
884  }
885  // Hits liquid?
886  int temp = -1;
887  if (!SimFlight(start_x, start_y, xdir, ydir, C4M_Liquid, C4M_Vehicle, temp))
888  {
889  return false;
890  }
891  // Liquid & deep enough?
892  return GBackLiquid(fixtoi(start_x), fixtoi(start_y)) && GBackLiquid(fixtoi(start_x), fixtoi(start_y) + 9);
893 }
const int32_t C4M_Vehicle
Definition: C4Constants.h:171
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:239
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:206
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:224
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t min_density, int32_t max_density, int32_t &iterations)
Definition: C4Movement.cpp:810

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

Referenced by ObjectComJump().

Here is the call graph for this function:
Here is the caller graph for this function: