1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef COMMAND_H
#define COMMAND_H
#include <string>
#include <climits> // for INT_MAX
#include "System/creg/creg_cond.h"
#include "System/float3.h"
#include <vector>
// ID's lower than 0 are reserved for build options (cmd -x = unitdefs[x])
#define CMD_STOP 0
#define CMD_INSERT 1
#define CMD_REMOVE 2
#define CMD_WAIT 5
#define CMD_TIMEWAIT 6
#define CMD_DEATHWAIT 7
#define CMD_SQUADWAIT 8
#define CMD_GATHERWAIT 9
#define CMD_MOVE 10
#define CMD_PATROL 15
#define CMD_FIGHT 16
#define CMD_ATTACK 20
#define CMD_AREA_ATTACK 21
#define CMD_GUARD 25
#define CMD_AISELECT 30 //FIXME REMOVE
#define CMD_GROUPSELECT 35
#define CMD_GROUPADD 36
#define CMD_GROUPCLEAR 37
#define CMD_REPAIR 40
#define CMD_FIRE_STATE 45
#define CMD_MOVE_STATE 50
#define CMD_SETBASE 55
#define CMD_INTERNAL 60
#define CMD_SELFD 65
#define CMD_SET_WANTED_MAX_SPEED 70
#define CMD_LOAD_UNITS 75
#define CMD_LOAD_ONTO 76
#define CMD_UNLOAD_UNITS 80
#define CMD_UNLOAD_UNIT 81
#define CMD_ONOFF 85
#define CMD_RECLAIM 90
#define CMD_CLOAK 95
#define CMD_STOCKPILE 100
#define CMD_DGUN 105
#define CMD_RESTORE 110
#define CMD_REPEAT 115
#define CMD_TRAJECTORY 120
#define CMD_RESURRECT 125
#define CMD_CAPTURE 130
#define CMD_AUTOREPAIRLEVEL 135
#define CMD_LOOPBACKATTACK 140
#define CMD_IDLEMODE 145
#define CMD_FAILED 150
#define CMDTYPE_ICON 0 // expect 0 parameters in return
#define CMDTYPE_ICON_MODE 5 // expect 1 parameter in return (number selected mode)
#define CMDTYPE_ICON_MAP 10 // expect 3 parameters in return (mappos)
#define CMDTYPE_ICON_AREA 11 // expect 4 parameters in return (mappos+radius)
#define CMDTYPE_ICON_UNIT 12 // expect 1 parameters in return (unitid)
#define CMDTYPE_ICON_UNIT_OR_MAP 13 // expect 1 parameters in return (unitid) or 3 parameters in return (mappos)
#define CMDTYPE_ICON_FRONT 14 // expect 3 or 6 parameters in return (middle of front and right side of front if a front was defined)
#define CMDTYPE_COMBO_BOX 15 // expect 1 parameter in return (number selected option)
#define CMDTYPE_ICON_UNIT_OR_AREA 16 // expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)
#define CMDTYPE_NEXT 17 // used with CMD_INTERNAL
#define CMDTYPE_PREV 18 // used with CMD_INTERNAL
#define CMDTYPE_ICON_UNIT_FEATURE_OR_AREA 19 // expect 1 parameter in return (unitid or featureid+unitHandler->MaxUnits() (id>unitHandler->MaxUnits()=feature)) or 4 parameters in return (mappos+radius)
#define CMDTYPE_ICON_BUILDING 20 // expect 3 parameters in return (mappos)
#define CMDTYPE_CUSTOM 21 // used with CMD_INTERNAL
#define CMDTYPE_ICON_UNIT_OR_RECTANGLE 22 // expect 1 parameter in return (unitid)
// or 3 parameters in return (mappos)
// or 6 parameters in return (startpos+endpos)
#define CMDTYPE_NUMBER 23 // expect 1 parameter in return (number)
// wait codes
#define CMD_WAITCODE_TIMEWAIT 1.0f
#define CMD_WAITCODE_DEATHWAIT 2.0f
#define CMD_WAITCODE_SQUADWAIT 3.0f
#define CMD_WAITCODE_GATHERWAIT 4.0f
// bits for the option field of Command
#define META_KEY (1 << 2) // 4
#define INTERNAL_ORDER (1 << 3) // 8
#define RIGHT_MOUSE_KEY (1 << 4) // 16
#define SHIFT_KEY (1 << 5) // 32
#define CONTROL_KEY (1 << 6) // 64
#define ALT_KEY (1 << 7) // 128
enum {
MOVESTATE_NONE = -1,
MOVESTATE_HOLDPOS = 0,
MOVESTATE_MANEUVER = 1,
MOVESTATE_ROAM = 2,
};
enum {
FIRESTATE_NONE = -1,
FIRESTATE_HOLDFIRE = 0,
FIRESTATE_RETURNFIRE = 1,
FIRESTATE_FIREATWILL = 2,
};
namespace springLegacyAI {
struct Command
{
private:
CR_DECLARE_STRUCT(Command)
/*
TODO check if usage of System/MemPool.h for this struct improves performance
*/
public:
Command()
: aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
, id(0)
{}
Command(const Command& c) {
*this = c;
}
Command& operator = (const Command& c) {
id = c.id;
aiCommandId = c.aiCommandId;
options = c.options;
tag = c.tag;
timeOut = c.timeOut;
params = c.params;
return *this;
}
Command(const float3& pos)
: aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
, id(0)
{
PushPos(pos);
}
Command(const int cmdID)
: aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{}
Command(const int cmdID, const float3& pos)
: aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{
PushPos(pos);
}
Command(const int cmdID, const unsigned char cmdOptions)
: aiCommandId(-1)
, options(cmdOptions)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{}
Command(const int cmdID, const unsigned char cmdOptions, const float param)
: aiCommandId(-1)
, options(cmdOptions)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{
PushParam(param);
}
Command(const int cmdID, const unsigned char cmdOptions, const float3& pos)
: aiCommandId(-1)
, options(cmdOptions)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{
PushPos(pos);
}
Command(const int cmdID, const unsigned char cmdOptions, const float param, const float3& pos)
: aiCommandId(-1)
, options(cmdOptions)
, tag(0)
, timeOut(INT_MAX)
, id(cmdID)
{
PushParam(param);
PushPos(pos);
}
~Command() { params.clear(); }
// returns true if the command references another object and
// in this case also returns the param index of the object in cpos
bool IsObjectCommand(int& cpos) const {
const int psize = params.size();
switch (id) {
case CMD_ATTACK:
case CMD_FIGHT:
case CMD_DGUN:
cpos = 0;
return (1 <= psize && psize < 3);
case CMD_GUARD:
case CMD_LOAD_ONTO:
cpos = 0;
return (psize >= 1);
case CMD_CAPTURE:
case CMD_LOAD_UNITS:
case CMD_RECLAIM:
case CMD_REPAIR:
case CMD_RESURRECT:
cpos = 0;
return (1 <= psize && psize < 4);
case CMD_UNLOAD_UNIT:
cpos = 3;
return (psize >= 4);
case CMD_INSERT: {
if (psize < 3)
return false;
Command icmd((int)params[1], (unsigned char)params[2]);
for (int p = 3; p < (int)psize; p++)
icmd.params.push_back(params[p]);
if (!icmd.IsObjectCommand(cpos))
return false;
cpos += 3;
return true;
}
}
return false;
}
bool IsAreaCommand() const {
switch(id) {
case CMD_CAPTURE:
case CMD_LOAD_UNITS:
case CMD_RECLAIM:
case CMD_REPAIR:
case CMD_RESURRECT:
// params[0..2] always holds the position, params[3] the radius
return (params.size() == 4);
case CMD_UNLOAD_UNITS:
return (params.size() == 5);
case CMD_AREA_ATTACK:
return true;
}
return false;
}
void PushParam(float par) { params.push_back(par); }
const float& GetParam(size_t idx) const { return params[idx]; }
/// const safe_vector<float>& GetParams() const { return params; }
size_t GetParamsCount() const { return params.size(); }
void SetID(int id)
#ifndef _MSC_VER
__attribute__ ((deprecated))
#endif
{ this->id = id; params.clear(); }
const int& GetID() const { return id; }
void PushPos(const float3& pos)
{
params.push_back(pos.x);
params.push_back(pos.y);
params.push_back(pos.z);
}
void PushPos(const float* pos)
{
params.push_back(pos[0]);
params.push_back(pos[1]);
params.push_back(pos[2]);
}
float3 GetPos(const int idx) const {
float3 p;
p.x = params[idx ];
p.y = params[idx + 1];
p.z = params[idx + 2];
return p;
}
void SetPos(const int idx, const float3& p) {
params[idx ] = p.x;
params[idx + 1] = p.y;
params[idx + 2] = p.z;
}
public:
/**
* AI Command callback id (passed in on handleCommand, returned
* in CommandFinished event)
*/
int aiCommandId;
/// option bits (RIGHT_MOUSE_KEY, ...)
unsigned char options;
/// command parameters
std::vector<float> params;
/// unique id within a CCommandQueue
unsigned int tag;
/**
* Remove this command after this frame (absolute).
* This can only be set locally and is not sent over the network.
* (used for temporary orders)
* Examples:
* - 0
* - MAX_INT
* - currenFrame + 60
*/
int timeOut;
//private:
/// CMD_xxx code (custom codes can also be used)
int id;
};
struct CommandDescription {
private:
CR_DECLARE_STRUCT(CommandDescription)
public:
CommandDescription():
id(0),
type(CMDTYPE_ICON),
hidden(false),
disabled(false),
showUnique(false),
onlyTexture(false) {}
/// CMD_xxx code (custom codes can also be used)
int id;
/// CMDTYPE_xxx code
int type;
/// command name
std::string name;
/// the associated command action binding name
std::string action;
/// button texture
std::string iconname;
/// mouse cursor
std::string mouseicon;
/// tooltip text
std::string tooltip;
/// if true dont show a button for the command
bool hidden;
/// for greying-out commands
bool disabled;
/// command only applies to single units
bool showUnique;
/// do not draw the name if the texture is available
bool onlyTexture;
std::vector<std::string> params;
};
} // namespace springLegacyAI
#endif // COMMAND_H
|