-
Notifications
You must be signed in to change notification settings - Fork 8
/
CUnit.h
146 lines (107 loc) · 3.81 KB
/
CUnit.h
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
#ifndef CUNIT_H
#define CUNIT_H
#include <map>
#include <iostream>
#include "ARegistrar.h"
#include "headers/HEngine.h"
#include "headers/Defines.h"
#include "CAI.h"
struct UnitType;
class CGroup;
/* Building facings, NOTE: this order is important! */
enum facing{ SOUTH, EAST, NORTH, WEST, NONE };
/* Map quadrants */
enum quadrant { NORTH_WEST, NORTH_EAST, SOUTH_WEST, SOUTH_EAST };
class CUnit: public ARegistrar {
public:
CUnit(): ARegistrar() {
def = NULL;
type = NULL;
builtBy = 0;
}
CUnit(AIClasses *_ai, int uid, int bid): ARegistrar(uid) {
ai = _ai;
reset(uid, bid);
}
~CUnit() {}
const UnitDef* def;
UnitType* type;
int builtBy;
unitCategory techlvl;
CGroup* group; // a group unit belongs to
int aliveFrames; // excluding microing time
int microingFrames;
bool waiting;
static bool isMilitary(const UnitDef* ud) { return !ud->weapons.empty(); }
static bool isStatic(const UnitDef* ud) { return ud->speed < EPS; }
static bool isDefense(const UnitDef* ud) { return isStatic(ud) && isMilitary(ud); }
static bool hasAntiAirWeapon(const std::vector<UnitDef::UnitDefWeapon>& weapons);
static bool hasNukeWeapon(const std::vector<UnitDef::UnitDefWeapon>& weapons);
static bool hasParalyzerWeapon(const std::vector<UnitDef::UnitDefWeapon>& weapons);
static bool hasInterceptorWeapon(const std::vector<UnitDef::UnitDefWeapon>& weapons);
static bool hasShield(const std::vector<UnitDef::UnitDefWeapon>& weapons);
static bool hasTorpedoWeapon(const std::vector<UnitDef::UnitDefWeapon>& weapons);
/* Remove the unit from everywhere registered */
void remove();
/* Overloaded */
void remove(ARegistrar ®);
/* Reset this object */
void reset(int uid, int bid);
int queueSize();
/* Determine if this unit belongs to economic tracker */
bool isEconomy();
/* Attack a unit */
bool attack(int target, bool enqueue = false);
/* Move a unit forward by dist */
bool moveForward(float dist, bool enqueue = false);
/* Move random */
bool moveRandom(float radius, bool enqueue = false);
/* Move unit with id uid to position pos */
bool move(const float3& pos, bool enqueue = false);
/* Set a unit (e.g. mmaker) on or off */
bool setOnOff(bool on);
/* Build a unit of "toBuild" type at position "pos" */
bool build(UnitType* toBuild, const float3& pos);
/* Build a unit in a certain factory */
bool factoryBuild(UnitType* toBuild, bool enqueue = false);
/* Repair (or assist) a certain unit */
bool repair(int target);
/* Cloak a unit */
bool cloak(bool on);
/* Guard a certain unit */
bool guard(int target, bool enqueue = false);
bool patrol(const float3& pos, bool enqueue = false);
/* Stop doing what you did */
bool stop();
/* Wait with what you are doing */
bool wait();
/* Undo wait command */
bool unwait();
bool reclaim(float3 pos, float radius);
bool reclaim(int target, bool enqueue = false);
bool stockpile();
int getStockpileReady();
int getStockpileQueued();
bool micro(bool on);
bool isMicroing() const { return microing; }
bool isOn() const { return ai->cb->IsUnitActivated(key); }
bool canPerformTasks() const { return aliveFrames > IDLE_UNIT_TIMEOUT; }
bool isDamaged() const { return (ai->cb->GetUnitMaxHealth(key) - ai->cb->GetUnitHealth(key)) > EPS; }
float3 pos() const { return ai->cb->GetUnitPos(key); }
/* Get best facing */
facing getBestFacing(const float3& pos) const;
/* Get quadrant */
quadrant getQuadrant(const float3& pos) const;
float getRange() const;
float3 getForwardPos(float distance) const;
ARegistrar::NType regtype() const { return ARegistrar::UNIT; }
/* output stream */
friend std::ostream& operator<<(std::ostream& out, const CUnit& unit);
//protected:
AIClasses *ai;
private:
bool microing;
Command createPosCommand(int cmd, float3 pos, float radius = -1.0f, facing f = NONE);
Command createTargetCommand(int cmd, int target);
};
#endif