OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 DigOutDirectRange =130
 
const int32_t LetGoHangleAngle =110
 
StdEnumAdapt< int32_t >::Entry EnumAdaptCommandEntries [C4CMD_Last-C4CMD_First+2]
 
const bool InitEnumAdaptCommandEntriesDummy = InitEnumAdaptCommandEntries()
 

Function Documentation

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

Definition at line 144 of file C4Command.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 167 of file C4Command.cpp.

References GBackSolid().

Referenced by ObjectAddWaypoint::operator()().

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

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t CommandByName ( const char *  szCommand)

Definition at line 128 of file C4Command.cpp.

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

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

Here is the call graph for this function:

const char* CommandName ( int32_t  iCommand)

Definition at line 48 of file C4Command.cpp.

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

49 {
50  switch (iCommand)
51  {
52  case C4CMD_None: return "None";
53  case C4CMD_Follow: return "Follow";
54  case C4CMD_MoveTo: return "MoveTo";
55  case C4CMD_Enter: return "Enter";
56  case C4CMD_Exit: return "Exit";
57  case C4CMD_Grab: return "Grab";
58  case C4CMD_Throw: return "Throw";
59  case C4CMD_UnGrab: return "UnGrab";
60  case C4CMD_Jump: return "Jump";
61  case C4CMD_Wait: return "Wait";
62  case C4CMD_Get: return "Get";
63  case C4CMD_Put: return "Put";
64  case C4CMD_Drop: return "Drop";
65  case C4CMD_Dig: return "Dig";
66  case C4CMD_Activate: return "Activate";
67  case C4CMD_PushTo: return "PushTo";
68  case C4CMD_Transfer: return "Transfer";
69  case C4CMD_Attack: return "Attack";
70  case C4CMD_Buy: return "Buy";
71  case C4CMD_Sell: return "Sell";
72  case C4CMD_Acquire: return "Acquire";
73  case C4CMD_Retry: return "Retry";
74  case C4CMD_Home: return "Home";
75  case C4CMD_Call: return "Call";
76  case C4CMD_Take: return "Take";
77  case C4CMD_Take2: return "Take2";
78  default: return "None";
79  }
80 }

Here is the caller graph for this function:

const char* CommandNameID ( int32_t  iCommand)

Definition at line 82 of file C4Command.cpp.

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

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

Here is the caller graph for this function:

bool FreeMoveTo ( C4Object cObj)

Definition at line 136 of file C4Command.cpp.

References DFA_FLOAT, and C4Object::GetProcedure().

Referenced by C4Command::InitEvaluation().

137 {
138  // Floating: we accept any move-to target
139  if (cObj->GetProcedure()==DFA_FLOAT) return true;
140  // Assume we're walking: move-to targets are adjusted
141  return false;
142 }
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 InitEnumAdaptCommandEntries ( )

Definition at line 116 of file C4Command.cpp.

References C4CMD_First, C4CMD_Last, CommandName(), StdEnumEntry< T >::Name, and StdEnumEntry< T >::Val.

117 {
118  for (int32_t i = C4CMD_First; i <= C4CMD_Last; i++)
119  {
122  }
123  EnumAdaptCommandEntries[C4CMD_Last - C4CMD_First + 1].Name = nullptr;
124  return true;
125 }
const char * CommandName(int32_t iCommand)
Definition: C4Command.cpp:48
StdEnumAdapt< int32_t >::Entry EnumAdaptCommandEntries[C4CMD_Last-C4CMD_First+2]
Definition: C4Command.cpp:46
const int32_t C4CMD_First
Definition: C4Command.h:56
const int32_t C4CMD_Last
Definition: C4Command.h:57

Here is the call graph for this function:

int32_t SolidOnWhichSide ( int32_t  iX,
int32_t  iY 
)

Definition at line 188 of file C4Command.cpp.

References GBackSolid().

Referenced by C4Command::JumpControl().

189 {
190  for (int32_t cx=1; cx<10; cx++)
191  for (int32_t cy=0; cy<10; cy++)
192  {
193  if (GBackSolid(iX-cx,iY-cy) || GBackSolid(iX-cx,iY+cy)) return -1;
194  if (GBackSolid(iX+cx,iY-cy) || GBackSolid(iX+cx,iY+cy)) return +1;
195  }
196  return 0;
197 }
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:232

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const int32_t DigOutDirectRange =130

Definition at line 43 of file C4Command.cpp.

const int32_t DigOutPositionRange =15

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::Get().

const int32_t DigRange =1

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::Dig().

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

Definition at line 46 of file C4Command.cpp.

const int32_t FlightAngleRange =60

Definition at line 42 of file C4Command.cpp.

Referenced by C4Command::FlightControl().

const int32_t FollowRange =6

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::Follow().

const bool InitEnumAdaptCommandEntriesDummy = InitEnumAdaptCommandEntries()

Definition at line 126 of file C4Command.cpp.

const int32_t JumpAngle =35

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpAngleRange =10

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpHighAngle =0

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpLowAngle =80

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t LetGoHangleAngle =110

Definition at line 44 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t LetGoRange1 =7

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t LetGoRange2 =30

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t MaxPathRange =1000

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t MoveToRange =5

Definition at line 38 of file C4Command.cpp.

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

const int32_t PathRange =20

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t PushToRange =10

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::PushTo().