-
Notifications
You must be signed in to change notification settings - Fork 4
/
DGunController.h
116 lines (96 loc) · 2.64 KB
/
DGunController.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
#ifndef KAIK_DGUNCONTROLLER_HDR
#define KAIK_DGUNCONTROLLER_HDR
#include <list>
#include <map>
#define FRAMERATE 30
#define DGUN_MIN_HEALTH_RATIO 0.25
#define DGUN_MIN_ENERGY_LEVEL (this->commanderWD->energycost)
#define DGUN_MAX_DAMAGE_LEVEL (this->commanderUD->health / 4)
#define DGUN_MIN_METAL_VALUE 500
namespace springLegacyAI {
class IAICallback;
struct UnitDef;
struct WeaponDef;
} // namespace springLegacyAI
struct AIClasses;
struct ControllerState {
CR_DECLARE_STRUCT(ControllerState);
ControllerState(void) {
inited = false;
targetID = -1;
dgunOrderFrame = 0;
reclaimOrderFrame = 0;
captureOrderFrame = 0;
targetSelectionFrame = 0;
}
void Reset(unsigned int currentFrame, bool clearNow) {
if (clearNow) {
dgunOrderFrame = 0;
reclaimOrderFrame = 0;
captureOrderFrame = 0;
targetID = -1;
} else {
if (dgunOrderFrame > 0 && (currentFrame - dgunOrderFrame) > (FRAMERATE >> 0)) {
// one second since last dgun order, mark as expired
dgunOrderFrame = 0;
targetID = -1;
}
if (reclaimOrderFrame > 0 && (currentFrame - reclaimOrderFrame) > (FRAMERATE << 2)) {
// four seconds since last reclaim order, mark as expired
reclaimOrderFrame = 0;
targetID = -1;
}
if (captureOrderFrame > 0 && (currentFrame - captureOrderFrame) > (FRAMERATE << 3)) {
// eight seconds since last capture order, mark as expired
captureOrderFrame = 0;
targetID = -1;
}
}
}
bool inited;
int dgunOrderFrame;
int reclaimOrderFrame;
int captureOrderFrame;
int targetSelectionFrame;
int targetID;
float3 oldTargetPos;
};
class CDGunController {
public:
CR_DECLARE(CDGunController);
CDGunController(AIClasses*);
~CDGunController(void) {}
void PostLoad();
void Init(int);
void HandleEnemyDestroyed(int, int);
void Update(unsigned int);
void Stop(void) const;
bool IsBusy(void) const;
private:
void TrackAttackTarget(unsigned int);
void SelectTarget(unsigned int);
void IssueOrder(int, int, int);
void IssueOrder(const float3&, int, int);
AIClasses* ai;
const UnitDef* commanderUD;
const WeaponDef* commanderWD;
ControllerState state;
int commanderID;
};
class CDGunControllerHandler {
public:
CR_DECLARE(CDGunControllerHandler);
CDGunControllerHandler(AIClasses* aic) {
ai = aic;
}
void PostLoad();
bool AddController(int unitID);
bool DelController(int unitID);
CDGunController* GetController(int unitID) const;
void NotifyEnemyDestroyed(int, int);
void Update(int frame);
private:
std::map<int, CDGunController*> controllers;
AIClasses* ai;
};
#endif