1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* The command stack controls an object's complex and independent behavior */
19 
20 #ifndef INC_C4Command
21 #define INC_C4Command
22 
23 #include "object/C4ObjectPtr.h"
24 #include "script/C4Value.h"
25 
26 enum C4CMD
27 {
28 	C4CMD_None,
29 	C4CMD_Follow,
30 	C4CMD_MoveTo,
31 	C4CMD_Enter,
32 	C4CMD_Exit,
33 	C4CMD_Grab,
34 	C4CMD_Throw,
35 	C4CMD_UnGrab,
36 	C4CMD_Jump,
37 	C4CMD_Wait,
38 	C4CMD_Get,
39 	C4CMD_Put,
40 	C4CMD_Drop,
41 	C4CMD_Dig,
42 	C4CMD_Activate,
43 	C4CMD_PushTo,
44 	C4CMD_Transfer,
45 	C4CMD_Attack,
46 	C4CMD_Buy,
47 	C4CMD_Sell,
48 	C4CMD_Acquire,
49 	C4CMD_Retry,
50 	C4CMD_Home,
51 	C4CMD_Call,
52 	C4CMD_Take,
53 	C4CMD_Take2,
54 };
55 
56 const int32_t C4CMD_First     = C4CMD_Follow,
57               C4CMD_Last      = C4CMD_Take2; // carlo
58 
59 const int32_t C4CMD_Mode_SilentSub  = 0, // subcommand; failure will cause base to fail (no message in case of failure)
60               C4CMD_Mode_Base       = 1, // regular base command
61               C4CMD_Mode_SilentBase = 2, // silent base command (no message in case of failure)
62               C4CMD_Mode_Sub    = 3; // subcommand; failure will cause base to fail
63 
64 // MoveTo and Enter command options: Include push target
65 const int32_t C4CMD_MoveTo_NoPosAdjust = 1,
66     C4CMD_MoveTo_PushTarget  = 2;
67 
68 const int32_t C4CMD_Enter_PushTarget   = 2;
69 
70 const char *CommandName(int32_t iCommand);
71 const char* CommandNameID(int32_t iCommand);
72 int32_t CommandByName(const char *szCommand);
73 
74 class C4Command
75 {
76 public:
77 	C4Command();
78 	~C4Command();
79 public:
80 	C4Object *cObj;
81 	int32_t Command;
82 	C4Value Tx;
83 	int32_t Ty;
84 	C4ObjectPtr Target,Target2;
85 	C4Value Data;
86 	int32_t UpdateInterval;
87 	int32_t Evaluated,PathChecked,Finished;
88 	int32_t Failures,Retries,Permit;
89 	C4String *Text;
90 	C4Command *Next;
91 	int32_t iExec; // 0 = not executing, 1 = executing, 2 = executing, command should delete himself on finish
92 	int32_t BaseMode; // 0: subcommand/unmarked base (if failing, base will fail, too); 1: base command; 2: silent base command
93 public:
94 	void Set(int32_t iCommand, C4Object *pObj, C4Object *pTarget, C4Value iTx, int32_t iTy, C4Object *pTarget2, C4Value iData, int32_t iUpdateInterval, bool fEvaluated, int32_t iRetries, C4String *szText, int32_t iBaseMode);
95 	void Clear();
96 	void Execute();
97 	void ClearPointers(C4Object *pObj);
98 	void Default();
99 	void Denumerate(C4ValueNumbers *);
100 	void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
101 protected:
102 	void Call();
103 	void Home();
104 	void Retry();
105 	void Fail(const char *szFailMessage=nullptr);
106 	void Acquire();
107 	void Sell();
108 	void Buy();
109 	void Attack();
110 	void Transfer();
111 	void Finish(bool fSuccess=false, const char *szFailMessage=nullptr);
112 	void Follow();
113 	void MoveTo();
114 	void Enter();
115 	void Exit();
116 	void Grab();
117 	void UnGrab();
118 	void Throw();
119 	void Jump();
120 	void Wait();
121 	void Take();
122 	void Take2();
123 	bool GetTryEnter(); // at object pos during get-command: Try entering it
124 	void Get();
125 	void Put();
126 	void Drop();
127 	void Dig();
128 	void Activate();
129 	void PushTo();
130 	int32_t CallFailed();
131 	bool JumpControl();
132 	bool FlightControl();
133 	bool InitEvaluation();
134 	int32_t GetExpGain(); // get control counts gained by this command; 1EXP=5 ControlCounts
135 };
136 
137 #endif
138