OpenClonk
C4ObjectAction.cpp File Reference
Include dependency graph for C4ObjectAction.cpp:

Go to the source code of this file.

Functions

void GrabLost (C4Object *cObj, C4Object *prev_target)
 
bool ReduceLineSegments (C4Shape &rShape, bool fAlternate)
 
void StopActionDelayCommand (C4Object *cobj)
 
void Towards (C4Real &val, C4Real target, C4Real step)
 

Function Documentation

◆ GrabLost()

void GrabLost ( C4Object cObj,
C4Object prev_target 
)

Definition at line 34 of file C4ObjectAction.cpp.

35 {
36  // Grab lost script call on target (quite hacky stuff...)
37  if (prev_target && prev_target->Status) prev_target->Call(PSF_GrabLost);
38  // Clear commands down to first PushTo (if any) in command stack
39  for (C4Command *pCom=cObj->Command; pCom; pCom=pCom->Next)
40  if (pCom->Next && pCom->Next->Command==C4CMD_PushTo)
41  {
42  cObj->ClearCommand(pCom);
43  break;
44  }
45 }
@ C4CMD_PushTo
Definition: C4Command.h:43
#define PSF_GrabLost
Definition: C4GameScript.h:75
C4Command * Next
Definition: C4Command.h:90
void ClearCommand(C4Command *pUntil)
C4Command * Command
Definition: C4Object.h:165
int32_t Status
Definition: C4PropList.h:173
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114

References C4CMD_PushTo, C4PropList::Call(), C4Object::ClearCommand(), C4Object::Command, C4Command::Next, PSF_GrabLost, and C4PropList::Status.

Referenced by C4Object::NoAttachAction().

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

◆ ReduceLineSegments()

bool ReduceLineSegments ( C4Shape rShape,
bool  fAlternate 
)

Definition at line 76 of file C4ObjectAction.cpp.

77 {
78  // try if line could go by a path directly when skipping on evertex. If fAlternate is true, try by skipping two vertices
79  for (int32_t cnt=0; cnt+2+fAlternate<rShape.VtxNum; cnt++)
80  if (PathFree(rShape.VtxX[cnt],rShape.VtxY[cnt],
81  rShape.VtxX[cnt+2+fAlternate],rShape.VtxY[cnt+2+fAlternate]))
82  {
83  if (fAlternate) rShape.RemoveVertex(cnt+2);
84  rShape.RemoveVertex(cnt+1);
85  return true;
86  }
87  return false;
88 }
bool PathFree(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
int32_t VtxNum
Definition: C4Shape.h:42
bool RemoveVertex(int32_t iPos)
Definition: C4Shape.cpp:398
int32_t VtxY[C4D_MaxVertex]
Definition: C4Shape.h:44
int32_t VtxX[C4D_MaxVertex]
Definition: C4Shape.h:43

References PathFree(), C4Shape::RemoveVertex(), C4Shape::VtxNum, C4Shape::VtxX, and C4Shape::VtxY.

Here is the call graph for this function:

◆ StopActionDelayCommand()

void StopActionDelayCommand ( C4Object cobj)

Definition at line 90 of file C4ObjectAction.cpp.

91 {
92  ObjectComStop(cobj);
93  cobj->AddCommand(C4CMD_Wait,nullptr,0,0,50);
94 }
@ C4CMD_Wait
Definition: C4Command.h:37
bool ObjectComStop(C4Object *cObj)
bool AddCommand(int32_t iCommand, C4Object *pTarget, C4Value iTx, int32_t iTy=0, int32_t iUpdateInterval=0, C4Object *pTarget2=nullptr, bool fInitEvaluation=true, C4Value iData=C4VNull, bool fAppend=false, int32_t iRetries=0, C4String *szText=nullptr, int32_t iBaseMode=0)

References C4Object::AddCommand(), C4CMD_Wait, and ObjectComStop().

Here is the call graph for this function:

◆ Towards()

void Towards ( C4Real val,
C4Real  target,
C4Real  step 
)

Definition at line 96 of file C4ObjectAction.cpp.

97 {
98  if (val==target) return;
99  if (Abs(val-target)<=step) { val=target; return; }
100  if (val<target) val+=step; else val-=step;
101 }
T Abs(T val)
Definition: Standard.h:42

References Abs().

Here is the call graph for this function: