Skip to content

Commit 57228f7

Browse files
author
rt
committed
Command stuff (E323AI)
1 parent 8e7a317 commit 57228f7

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

CE323AI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ int CE323AI::HandleEvent(int msg, const void* data) {
517517
const PlayerCommandEvent* pce = (const PlayerCommandEvent*) data;
518518
bool importantCommand = false;
519519

520-
if(pce->command.id < 0)
520+
if(pce->command.GetID() < 0)
521521
importantCommand = true;
522522
else {
523-
switch(pce->command.id)
523+
switch(pce->command.GetID())
524524
{
525525
case CMD_MOVE:
526526
case CMD_PATROL:

CLogger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void CLogger::log(logLevel level, std::string &msg) {
9696
int frame = ai->cb->GetCurrentFrame();
9797
int sec = (frame / 30) % 60;
9898
int min = ((frame / 30) - sec) / 60;
99-
char time[10];
99+
char time[16];
100100
sprintf(time, "[%2.2d:%2.2d] ", min, sec);
101101
std::string output(time);
102102
output += logLevels[level] + ": " + msg + "\n";

CUnit.cpp

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool CUnit::isEconomy() {
4747

4848
bool CUnit::reclaim(float3 pos, float radius) {
4949
Command c = createPosCommand(CMD_RECLAIM, pos, radius);
50-
if (c.id != 0) {
50+
if (c.GetID() != 0) {
5151
ai->cb->GiveOrder(key, &c);
5252
ai->unittable->idle[key] = false;
5353
return true;
@@ -57,9 +57,9 @@ bool CUnit::reclaim(float3 pos, float radius) {
5757

5858
bool CUnit::reclaim(int target, bool enqueue) {
5959
Command c = createTargetCommand(CMD_RECLAIM, target);
60-
if (c.id != 0) {
60+
if (c.GetID() != 0) {
6161
if (enqueue)
62-
c.options |= SHIFT_KEY;
62+
c.SetOpts(SHIFT_KEY);
6363
ai->cb->GiveOrder(key, &c);
6464
ai->unittable->idle[key] = false;
6565
return true;
@@ -73,9 +73,9 @@ int CUnit::queueSize() {
7373

7474
bool CUnit::attack(int target, bool enqueue) {
7575
Command c = createTargetCommand(CMD_ATTACK, target);
76-
if (c.id != 0) {
76+
if (c.GetID() != 0) {
7777
if (enqueue)
78-
c.options |= SHIFT_KEY;
78+
c.SetOpts(SHIFT_KEY);
7979
ai->cb->GiveOrder(key, &c);
8080
ai->unittable->idle[key] = false;
8181
return true;
@@ -91,7 +91,7 @@ bool CUnit::moveForward(float dist, bool enqueue) {
9191
bool CUnit::setOnOff(bool on) {
9292
Command c = createTargetCommand(CMD_ONOFF, on);
9393

94-
if (c.id != 0) {
94+
if (c.GetID() != 0) {
9595
ai->cb->GiveOrder(key, &c);
9696
return true;
9797
}
@@ -113,9 +113,9 @@ bool CUnit::moveRandom(float radius, bool enqueue) {
113113
bool CUnit::move(const float3 &pos, bool enqueue) {
114114
Command c = createPosCommand(CMD_MOVE, pos);
115115

116-
if (c.id != 0) {
116+
if (c.GetID() != 0) {
117117
if (enqueue)
118-
c.options |= SHIFT_KEY;
118+
c.SetOpts(SHIFT_KEY);
119119
ai->cb->GiveOrder(key, &c);
120120
ai->unittable->idle[key] = false;
121121
return true;
@@ -126,9 +126,9 @@ bool CUnit::move(const float3 &pos, bool enqueue) {
126126
bool CUnit::guard(int target, bool enqueue) {
127127
Command c = createTargetCommand(CMD_GUARD, target);
128128

129-
if (c.id != 0) {
129+
if (c.GetID() != 0) {
130130
if (enqueue)
131-
c.options |= SHIFT_KEY;
131+
c.SetOpts(SHIFT_KEY);
132132
ai->cb->GiveOrder(key, &c);
133133
ai->unittable->idle[key] = false;
134134
return true;
@@ -139,9 +139,9 @@ bool CUnit::guard(int target, bool enqueue) {
139139
bool CUnit::patrol(const float3& pos, bool enqueue) {
140140
Command c = createPosCommand(CMD_PATROL, pos);
141141

142-
if (c.id != 0) {
142+
if (c.GetID() != 0) {
143143
if (enqueue)
144-
c.options |= SHIFT_KEY;
144+
c.SetOpts(SHIFT_KEY);
145145
ai->cb->GiveOrder(key, &c);
146146
ai->unittable->idle[key] = false;
147147
return true;
@@ -152,7 +152,7 @@ bool CUnit::patrol(const float3& pos, bool enqueue) {
152152
bool CUnit::cloak(bool on) {
153153
Command c = createTargetCommand(CMD_CLOAK, on);
154154

155-
if (c.id != 0) {
155+
if (c.GetID() != 0) {
156156
ai->cb->GiveOrder(key, &c);
157157
return true;
158158
}
@@ -162,7 +162,7 @@ bool CUnit::cloak(bool on) {
162162
bool CUnit::repair(int target) {
163163
Command c = createTargetCommand(CMD_REPAIR, target);
164164

165-
if (c.id != 0) {
165+
if (c.GetID() != 0) {
166166
ai->cb->GiveOrder(key, &c);
167167
ai->unittable->idle[key] = false;
168168
return true;
@@ -207,7 +207,7 @@ bool CUnit::build(UnitType* toBuild, const float3& pos) {
207207

208208
// NOTE: using of negative unit id is valid for Legacy C++ API only
209209
Command c = createPosCommand(-(toBuild->def->id), goal, -1.0f, f);
210-
if (c.id != 0) {
210+
if (c.GetID() != 0) {
211211
ai->cb->GiveOrder(key, &c);
212212
ai->unittable->idle[key] = false;
213213
return true;
@@ -217,16 +217,14 @@ bool CUnit::build(UnitType* toBuild, const float3& pos) {
217217
}
218218

219219
bool CUnit::stop() {
220-
Command c;
221-
c.id = CMD_STOP;
220+
Command c(CMD_STOP);
222221
ai->cb->GiveOrder(key, &c);
223222
return true;
224223
}
225224

226225
bool CUnit::wait() {
227226
if (!waiting) {
228-
Command c;
229-
c.id = CMD_WAIT;
227+
Command c(CMD_WAIT);
230228
ai->cb->GiveOrder(key, &c);
231229
waiting = true;
232230
}
@@ -235,8 +233,7 @@ bool CUnit::wait() {
235233

236234
bool CUnit::unwait() {
237235
if (waiting) {
238-
Command c;
239-
c.id = CMD_WAIT;
236+
Command c(CMD_WAIT);
240237
ai->cb->GiveOrder(key, &c);
241238
waiting = false;
242239
}
@@ -247,8 +244,7 @@ bool CUnit::stockpile() {
247244
if (!type->def->stockpileWeaponDef)
248245
return false;
249246

250-
Command c;
251-
c.id = CMD_STOCKPILE;
247+
Command c(CMD_STOCKPILE);
252248
ai->cb->GiveOrder(key, &c);
253249
return true;
254250
}
@@ -273,19 +269,18 @@ bool CUnit::micro(bool on) {
273269
}
274270

275271
bool CUnit::factoryBuild(UnitType *ut, bool enqueue) {
276-
Command c;
272+
Command c(-(ut->def->id));
277273
if (enqueue)
278-
c.options |= SHIFT_KEY;
279-
c.id = -(ut->def->id);
274+
c.SetOpts(SHIFT_KEY);
275+
280276
ai->cb->GiveOrder(key, &c);
281277
ai->unittable->idle[key] = false;
282278
return true;
283279
}
284280

285281
Command CUnit::createTargetCommand(int cmd, int target) {
286-
Command c;
287-
c.id = cmd;
288-
c.params.push_back(target);
282+
Command c(cmd);
283+
c.PushParam(target);
289284
return c;
290285
}
291286

@@ -302,17 +297,14 @@ Command CUnit::createPosCommand(int cmd, float3 pos, float radius, facing f) {
302297
if (pos.y < 0)
303298
pos.y = 0;
304299

305-
Command c;
306-
c.id = cmd;
307-
c.params.push_back(pos.x);
308-
c.params.push_back(pos.y);
309-
c.params.push_back(pos.z);
300+
Command c(cmd);
301+
c.PushPos(pos);
310302

311303
if (f != NONE)
312-
c.params.push_back(f);
304+
c.PushParam(f);
313305

314306
if (radius > 0.0f)
315-
c.params.push_back(radius);
307+
c.PushParam(radius);
316308
return c;
317309
}
318310

0 commit comments

Comments
 (0)