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

Go to the source code of this file.

Classes

struct  ObjectAddWaypoint
 

Functions

const char * CommandName (int32_t iCommand)
 
const char * CommandNameID (int32_t iCommand)
 
bool InitEnumAdaptCommandEntries ()
 
int32_t CommandByName (const char *szCommand)
 
bool FreeMoveTo (C4Object *cObj)
 
void AdjustMoveToTarget (int32_t &rX, int32_t &rY, bool fFreeMove, int32_t iShapeHgt)
 
bool AdjustSolidOffset (int32_t &rX, int32_t &rY, int32_t iXOff, int32_t iYOff)
 
int32_t SolidOnWhichSide (int32_t iX, int32_t iY)
 

Variables

const int32_t MoveToRange =5
 
const int32_t LetGoRange1 =7
 
const int32_t LetGoRange2 =30
 
const int32_t DigRange =1
 
const int32_t FollowRange =6
 
const int32_t PushToRange =10
 
const int32_t DigOutPositionRange =15
 
const int32_t PathRange =20
 
const int32_t MaxPathRange =1000
 
const int32_t JumpAngle =35
 
const int32_t JumpLowAngle =80
 
const int32_t JumpAngleRange =10
 
const int32_t JumpHighAngle =0
 
const int32_t FlightAngleRange =60
 
const int32_t LetGoHangleAngle =110
 
StdEnumAdapt< int32_t >::Entry EnumAdaptCommandEntries [C4CMD_Last - C4CMD_First+2]
 
const bool InitEnumAdaptCommandEntriesDummy = InitEnumAdaptCommandEntries()
 

Function Documentation

◆ AdjustMoveToTarget()

void AdjustMoveToTarget ( int32_t &  rX,
int32_t &  rY,
bool  fFreeMove,
int32_t  iShapeHgt 
)

Definition at line 142 of file C4Command.cpp.

143 {
144  // Above solid (always)
145  int32_t iY=std::min(rY, ::Landscape.GetHeight());
146  while ((iY>=0) && GBackSolid(rX,iY)) iY--;
147  if (iY>=0) rY=iY;
148  // No-free-move adjustments (i.e. if walking)
149  if (!fFreeMove)
150  {
151  // Drop down to bottom of free space
152  if (!GBackSemiSolid(rX,rY))
153  {
154  for (iY=rY; (iY<::Landscape.GetHeight()) && !GBackSemiSolid(rX,iY+1); iY++) {}
155  if (iY<::Landscape.GetHeight()) rY=iY;
156  }
157  // Vertical shape offset above solid
158  if (GBackSolid(rX,rY+1) || GBackSolid(rX,rY+5))
159  if (!GBackSemiSolid(rX,rY-iShapeHgt/2))
160  rY-=iShapeHgt/2;
161  }
162 
163 }
C4Landscape Landscape
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:234
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:229
int32_t GetHeight() const

References GBackSemiSolid(), GBackSolid(), C4Landscape::GetHeight(), and Landscape.

Referenced by C4TransferZone::GetEntryPoint(), C4Command::InitEvaluation(), and C4Command::JumpControl().

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

◆ AdjustSolidOffset()

bool AdjustSolidOffset ( int32_t &  rX,
int32_t &  rY,
int32_t  iXOff,
int32_t  iYOff 
)

Definition at line 165 of file C4Command.cpp.

166 {
167  // In solid: fail
168  if (GBackSolid(rX,rY)) return false;
169  // Y Offset
170  int32_t cnt;
171  for (cnt=1; cnt<iYOff; cnt++)
172  {
173  if (GBackSolid(rX,rY+cnt) && !GBackSolid(rX,rY-cnt)) rY--;
174  if (GBackSolid(rX,rY-cnt) && !GBackSolid(rX,rY+cnt)) rY++;
175  }
176  // X Offset
177  for (cnt=1; cnt<iXOff; cnt++)
178  {
179  if (GBackSolid(rX+cnt,rY) && !GBackSolid(rX-cnt,rY)) rX--;
180  if (GBackSolid(rX-cnt,rY) && !GBackSolid(rX+cnt,rY)) rX++;
181  }
182  // Done
183  return true;
184 }

References GBackSolid().

Referenced by ObjectAddWaypoint::operator()().

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

◆ CommandByName()

int32_t CommandByName ( const char *  szCommand)

Definition at line 126 of file C4Command.cpp.

127 {
128  for (int32_t cnt=C4CMD_First; cnt<=C4CMD_Last; cnt++)
129  if (SEqual(szCommand,CommandName(cnt)))
130  return cnt;
131  return C4CMD_None;
132 }
const char * CommandName(int32_t iCommand)
Definition: C4Command.cpp:46
@ C4CMD_None
Definition: C4Command.h:28
const int32_t C4CMD_Last
Definition: C4Command.h:57
const int32_t C4CMD_First
Definition: C4Command.h:56
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

References C4CMD_First, C4CMD_Last, C4CMD_None, CommandName(), and SEqual().

Here is the call graph for this function:

◆ CommandName()

const char* CommandName ( int32_t  iCommand)

Definition at line 46 of file C4Command.cpp.

47 {
48  switch (iCommand)
49  {
50  case C4CMD_None: return "None";
51  case C4CMD_Follow: return "Follow";
52  case C4CMD_MoveTo: return "MoveTo";
53  case C4CMD_Enter: return "Enter";
54  case C4CMD_Exit: return "Exit";
55  case C4CMD_Grab: return "Grab";
56  case C4CMD_Throw: return "Throw";
57  case C4CMD_UnGrab: return "UnGrab";
58  case C4CMD_Jump: return "Jump";
59  case C4CMD_Wait: return "Wait";
60  case C4CMD_Get: return "Get";
61  case C4CMD_Put: return "Put";
62  case C4CMD_Drop: return "Drop";
63  case C4CMD_Dig: return "Dig";
64  case C4CMD_Activate: return "Activate";
65  case C4CMD_PushTo: return "PushTo";
66  case C4CMD_Transfer: return "Transfer";
67  case C4CMD_Attack: return "Attack";
68  case C4CMD_Buy: return "Buy";
69  case C4CMD_Sell: return "Sell";
70  case C4CMD_Acquire: return "Acquire";
71  case C4CMD_Retry: return "Retry";
72  case C4CMD_Home: return "Home";
73  case C4CMD_Call: return "Call";
74  case C4CMD_Take: return "Take";
75  case C4CMD_Take2: return "Take2";
76  default: return "None";
77  }
78 }
@ C4CMD_Acquire
Definition: C4Command.h:48
@ C4CMD_Call
Definition: C4Command.h:51
@ C4CMD_Home
Definition: C4Command.h:50
@ C4CMD_Sell
Definition: C4Command.h:47
@ C4CMD_Drop
Definition: C4Command.h:40
@ C4CMD_Transfer
Definition: C4Command.h:44
@ C4CMD_Follow
Definition: C4Command.h:29
@ C4CMD_Activate
Definition: C4Command.h:42
@ C4CMD_Take
Definition: C4Command.h:52
@ C4CMD_Wait
Definition: C4Command.h:37
@ C4CMD_Attack
Definition: C4Command.h:45
@ C4CMD_Retry
Definition: C4Command.h:49
@ C4CMD_Get
Definition: C4Command.h:38
@ C4CMD_MoveTo
Definition: C4Command.h:30
@ C4CMD_Take2
Definition: C4Command.h:53
@ C4CMD_Jump
Definition: C4Command.h:36
@ C4CMD_Put
Definition: C4Command.h:39
@ C4CMD_Enter
Definition: C4Command.h:31
@ C4CMD_PushTo
Definition: C4Command.h:43
@ C4CMD_Exit
Definition: C4Command.h:32
@ C4CMD_UnGrab
Definition: C4Command.h:35
@ C4CMD_Buy
Definition: C4Command.h:46
@ C4CMD_Throw
Definition: C4Command.h:34
@ C4CMD_Dig
Definition: C4Command.h:41
@ C4CMD_Grab
Definition: C4Command.h:33

References C4CMD_Acquire, C4CMD_Activate, C4CMD_Attack, C4CMD_Buy, C4CMD_Call, C4CMD_Dig, C4CMD_Drop, C4CMD_Enter, C4CMD_Exit, C4CMD_Follow, C4CMD_Get, C4CMD_Grab, C4CMD_Home, C4CMD_Jump, C4CMD_MoveTo, C4CMD_None, C4CMD_PushTo, C4CMD_Put, C4CMD_Retry, C4CMD_Sell, C4CMD_Take, C4CMD_Take2, C4CMD_Throw, C4CMD_Transfer, C4CMD_UnGrab, and C4CMD_Wait.

Referenced by CommandByName(), C4Object::Draw(), C4Object::ExecuteCommand(), C4Command::Fail(), InitEnumAdaptCommandEntries(), and C4Object::SetCommand().

Here is the caller graph for this function:

◆ CommandNameID()

const char* CommandNameID ( int32_t  iCommand)

Definition at line 80 of file C4Command.cpp.

81 {
82  switch (iCommand)
83  {
84  case C4CMD_None: return "IDS_COMM_NONE";
85  case C4CMD_Follow: return "IDS_COMM_FOLLOW";
86  case C4CMD_MoveTo: return "IDS_COMM_MOVETO";
87  case C4CMD_Enter: return "IDS_COMM_ENTER";
88  case C4CMD_Exit: return "IDS_COMM_EXIT";
89  case C4CMD_Grab: return "IDS_COMM_GRAB";
90  case C4CMD_Throw: return "IDS_COMM_THROW";
91  case C4CMD_UnGrab: return "IDS_COMM_UNGRAB";
92  case C4CMD_Jump: return "IDS_COMM_JUMP";
93  case C4CMD_Wait: return "IDS_COMM_WAIT";
94  case C4CMD_Get: return "IDS_COMM_GET";
95  case C4CMD_Put: return "IDS_COMM_PUT";
96  case C4CMD_Drop: return "IDS_COMM_DROP";
97  case C4CMD_Dig: return "IDS_COMM_DIG";
98  case C4CMD_Activate: return "IDS_COMM_ACTIVATE";
99  case C4CMD_PushTo: return "IDS_COMM_PUSHTO";
100  case C4CMD_Transfer: return "IDS_COMM_TRANSFER";
101  case C4CMD_Attack: return "IDS_COMM_ATTACK";
102  case C4CMD_Buy: return "IDS_COMM_BUY";
103  case C4CMD_Sell: return "IDS_COMM_SELL";
104  case C4CMD_Acquire: return "IDS_COMM_ACQUIRE";
105  case C4CMD_Retry: return "IDS_COMM_RETRY";
106  case C4CMD_Home: return "IDS_CON_HOME";
107  case C4CMD_Call: return "IDS_COMM_CALL";
108  case C4CMD_Take: return "IDS_COMM_TAKE";
109  case C4CMD_Take2: return "IDS_COMM_TAKE2";
110  default: return "IDS_COMM_NONE";
111  }
112 }

References C4CMD_Acquire, C4CMD_Activate, C4CMD_Attack, C4CMD_Buy, C4CMD_Call, C4CMD_Dig, C4CMD_Drop, C4CMD_Enter, C4CMD_Exit, C4CMD_Follow, C4CMD_Get, C4CMD_Grab, C4CMD_Home, C4CMD_Jump, C4CMD_MoveTo, C4CMD_None, C4CMD_PushTo, C4CMD_Put, C4CMD_Retry, C4CMD_Sell, C4CMD_Take, C4CMD_Take2, C4CMD_Throw, C4CMD_Transfer, C4CMD_UnGrab, and C4CMD_Wait.

Referenced by C4Command::Fail().

Here is the caller graph for this function:

◆ FreeMoveTo()

bool FreeMoveTo ( C4Object cObj)

Definition at line 134 of file C4Command.cpp.

135 {
136  // Floating: we accept any move-to target
137  if (cObj->GetProcedure()==DFA_FLOAT) return true;
138  // Assume we're walking: move-to targets are adjusted
139  return false;
140 }
@ DFA_FLOAT
int32_t GetProcedure() const

References DFA_FLOAT, and C4Object::GetProcedure().

Referenced by C4Command::InitEvaluation().

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

◆ InitEnumAdaptCommandEntries()

bool InitEnumAdaptCommandEntries ( )

Definition at line 114 of file C4Command.cpp.

115 {
116  for (int32_t i = C4CMD_First; i <= C4CMD_Last; i++)
117  {
120  }
121  EnumAdaptCommandEntries[C4CMD_Last - C4CMD_First + 1].Name = nullptr;
122  return true;
123 }
StdEnumAdapt< int32_t >::Entry EnumAdaptCommandEntries[C4CMD_Last - C4CMD_First+2]
Definition: C4Command.cpp:44

References C4CMD_First, C4CMD_Last, CommandName(), and EnumAdaptCommandEntries.

Here is the call graph for this function:

◆ SolidOnWhichSide()

int32_t SolidOnWhichSide ( int32_t  iX,
int32_t  iY 
)

Definition at line 186 of file C4Command.cpp.

187 {
188  for (int32_t cx=1; cx<10; cx++)
189  for (int32_t cy=0; cy<10; cy++)
190  {
191  if (GBackSolid(iX-cx,iY-cy) || GBackSolid(iX-cx,iY+cy)) return -1;
192  if (GBackSolid(iX+cx,iY-cy) || GBackSolid(iX+cx,iY+cy)) return +1;
193  }
194  return 0;
195 }

References GBackSolid().

Referenced by C4Command::JumpControl().

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

Variable Documentation

◆ DigOutPositionRange

const int32_t DigOutPositionRange =15

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::Get().

◆ DigRange

const int32_t DigRange =1

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::Dig().

◆ EnumAdaptCommandEntries

StdEnumAdapt<int32_t>::Entry EnumAdaptCommandEntries[C4CMD_Last - C4CMD_First+2]

Definition at line 44 of file C4Command.cpp.

Referenced by C4Command::CompileFunc(), and InitEnumAdaptCommandEntries().

◆ FlightAngleRange

const int32_t FlightAngleRange =60

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::FlightControl().

◆ FollowRange

const int32_t FollowRange =6

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::Follow().

◆ InitEnumAdaptCommandEntriesDummy

const bool InitEnumAdaptCommandEntriesDummy = InitEnumAdaptCommandEntries()

Definition at line 124 of file C4Command.cpp.

◆ JumpAngle

const int32_t JumpAngle =35

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

◆ JumpAngleRange

const int32_t JumpAngleRange =10

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

◆ JumpHighAngle

const int32_t JumpHighAngle =0

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

◆ JumpLowAngle

const int32_t JumpLowAngle =80

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

◆ LetGoHangleAngle

const int32_t LetGoHangleAngle =110

Definition at line 42 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

◆ LetGoRange1

const int32_t LetGoRange1 =7

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

◆ LetGoRange2

const int32_t LetGoRange2 =30

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

◆ MaxPathRange

const int32_t MaxPathRange =1000

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

◆ MoveToRange

const int32_t MoveToRange =5

Definition at line 37 of file C4Command.cpp.

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

◆ PathRange

const int32_t PathRange =20

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

◆ PushToRange

const int32_t PushToRange =10

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::PushTo().