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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef COMMAND_H
#define COMMAND_H
#include <string>
#include <vector>
#include <limits.h> // for INT_MAX
#include "System/creg/creg_cond.h"
// cmds lower than 0 is 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
#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+uh->MaxUnits() (id>uh->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 DONT_REPEAT (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
#define INTERNAL_ORDER (DONT_REPEAT)
namespace springLegacyAI {
struct Command
{
private:
CR_DECLARE_STRUCT(Command);
public:
Command(const int cmdID)
: id(cmdID)
, aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
{}
Command(const int cmdID, const unsigned char cmdOptions)
: id(cmdID)
, aiCommandId(-1)
, options(cmdOptions)
, tag(0)
, timeOut(INT_MAX)
{}
Command()
: id(0)
, aiCommandId(-1)
, options(0)
, tag(0)
, timeOut(INT_MAX)
{}
~Command() {
params.clear();
}
bool IsAreaCommand() const {
if (id == CMD_REPAIR ||
id == CMD_RECLAIM ||
id == CMD_CAPTURE ||
id == CMD_RESURRECT ||
id == CMD_LOAD_UNITS) {
// params[0..2] always holds the position, params[3] the radius
return (params.size() == 4);
}
if (id == CMD_UNLOAD_UNITS) {
return (params.size() == 5);
}
if (id == CMD_AREA_ATTACK) {
return true;
}
return false;
}
/// adds a value to this commands parameter list
void AddParam(float par) {
params.push_back(par);
}
void SetID(int id) { this->id = id; params.clear(); }
const int& GetID() const { return id; }
public:
/// CMD_xxx code (custom codes can also be used)
int id;
/**
* AI Command callback id (passed in on handleCommand, returned
* in CommandFinished event)
*/
int aiCommandId;
/// option bits
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;
};
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
|