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 143 of file C4Command.cpp.

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

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

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

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 166 of file C4Command.cpp.

References GBackSolid().

Referenced by ObjectAddWaypoint::operator()().

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

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 127 of file C4Command.cpp.

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

128 {
129  for (int32_t cnt=C4CMD_First; cnt<=C4CMD_Last; cnt++)
130  if (SEqual(szCommand,CommandName(cnt)))
131  return cnt;
132  return C4CMD_None;
133 }
const char * CommandName(int32_t iCommand)
Definition: C4Command.cpp:47
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
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 47 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().

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

Here is the caller graph for this function:

const char* CommandNameID ( int32_t  iCommand)

Definition at line 81 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().

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

Here is the caller graph for this function:

bool FreeMoveTo ( C4Object cObj)

Definition at line 135 of file C4Command.cpp.

References DFA_FLOAT, and C4Object::GetProcedure().

Referenced by C4Command::InitEvaluation().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool InitEnumAdaptCommandEntries ( )

Definition at line 115 of file C4Command.cpp.

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

116 {
117  for (int32_t i = C4CMD_First; i <= C4CMD_Last; i++)
118  {
121  }
122  EnumAdaptCommandEntries[C4CMD_Last - C4CMD_First + 1].Name = nullptr;
123  return true;
124 }
const char * CommandName(int32_t iCommand)
Definition: C4Command.cpp:47
StdEnumAdapt< int32_t >::Entry EnumAdaptCommandEntries[C4CMD_Last-C4CMD_First+2]
Definition: C4Command.cpp:45
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 187 of file C4Command.cpp.

References GBackSolid().

Referenced by C4Command::JumpControl().

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

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 42 of file C4Command.cpp.

const int32_t DigOutPositionRange =15

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::Get().

const int32_t DigRange =1

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::Dig().

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

Definition at line 45 of file C4Command.cpp.

const int32_t FlightAngleRange =60

Definition at line 41 of file C4Command.cpp.

Referenced by C4Command::FlightControl().

const int32_t FollowRange =6

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::Follow().

const bool InitEnumAdaptCommandEntriesDummy = InitEnumAdaptCommandEntries()

Definition at line 125 of file C4Command.cpp.

const int32_t JumpAngle =35

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpAngleRange =10

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpHighAngle =0

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t JumpLowAngle =80

Definition at line 40 of file C4Command.cpp.

Referenced by C4Command::JumpControl().

const int32_t LetGoHangleAngle =110

Definition at line 43 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t LetGoRange1 =7

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t LetGoRange2 =30

Definition at line 37 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t MaxPathRange =1000

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t MoveToRange =5

Definition at line 37 of file C4Command.cpp.

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

const int32_t PathRange =20

Definition at line 39 of file C4Command.cpp.

Referenced by C4Command::MoveTo().

const int32_t PushToRange =10

Definition at line 38 of file C4Command.cpp.

Referenced by C4Command::PushTo().