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