16
17
selector.push_back(ARTILLERY);
17
18
selector.push_back(ANTIAIR);
18
19
selector.push_back(AIR);
19
21
for (size_t i = 0; i < selector.size(); i++)
20
22
counts[selector[i]] = 1;
24
enemyvector = float3(1.0f, 1.0f, 1.0f);
26
targets[ENGAGE].push_back(&commanders);
27
targets[ENGAGE].push_back(&attackers);
28
targets[ENGAGE].push_back(&energyMakers);
29
targets[ENGAGE].push_back(&metalMakers);
30
targets[ENGAGE].push_back(&defenseAntiAir);
31
targets[ENGAGE].push_back(&defenseGround);
32
targets[ENGAGE].push_back(&mobileBuilders);
33
targets[ENGAGE].push_back(&factories);
34
targets[ENGAGE].push_back(&restUnarmedUnits);
36
targets[SCOUT].push_back(&mobileBuilders);
37
targets[SCOUT].push_back(&metalMakers);
38
targets[SCOUT].push_back(&energyMakers);
39
targets[SCOUT].push_back(&restUnarmedUnits);
41
targets[BOMBER].push_back(&defenseAntiAir);
42
targets[BOMBER].push_back(&defenseGround);
43
targets[BOMBER].push_back(&commanders);
44
targets[BOMBER].push_back(&factories);
45
targets[BOMBER].push_back(&energyMakers);
46
targets[BOMBER].push_back(&metalMakers);
49
strategyTechUp = false;
24
52
float3 CIntel::getEnemyVector() {
28
56
void CIntel::init() {
29
numUnits = ai->cbc->GetEnemyUnits(units, MAX_UNITS);
31
enemyvector = float3(0.0f, 0.0f, 0.0f);
32
for (int i = 0; i < numUnits; i++) {
33
enemyvector += ai->cbc->GetUnitPos(units[i]);
35
enemyvector /= numUnits;
36
LOG_II("Number of enemies: " << numUnits)
57
if (initialized) return;
59
int numUnits = ai->cbc->GetEnemyUnits(units, MAX_UNITS);
60
// FIXME: when commanders are spawned with wrap gate option enabled then assert raises
62
enemyvector = ZeroVector;
63
for (int i = 0; i < numUnits; i++) {
64
enemyvector += ai->cbc->GetUnitPos(units[i]);
66
enemyvector /= numUnits;
69
LOG_II("CIntel::init Number of enemy units: " << numUnits)
72
I faced situation that on maps with less land there is a direct
73
path to enemy unit, but algo below starts to play a non-land game.
74
I could not think up an apporpiate algo to avoid this. I though tracing
75
a path in the beginning of the game from my commander to enemy would
76
be ok, but commander is an amphibious unit. It is not trivial stuff
77
without external helpers in config files.
79
if(ai->gamemap->IsWaterMap()) {
80
allowedFactories.push_back(NAVAL);
81
allowedFactories.push_back(HOVER);
84
unitCategory nextFactory;
85
if (ai->gamemap->IsKbotMap()) {
86
allowedFactories.push_back(KBOT);
87
nextFactory = VEHICLE;
90
allowedFactories.push_back(VEHICLE);
94
if (ai->gamemap->IsHooverMap()) {
95
if (ai->gamemap->GetAmountOfWater() > 0.5) {
96
allowedFactories.push_back(HOVER);
99
allowedFactories.push_back(nextFactory);
104
allowedFactories.push_back(nextFactory);
106
// TODO: do not build air on too small maps?
107
allowedFactories.push_back(AIRCRAFT);
109
// vary first factory among allied AIs...
110
int i = ai->allyAITeam;
112
allowedFactories.push_back(allowedFactories.front());
113
allowedFactories.pop_front();
117
// FIXME: engineer better decision algo
118
if (ai->gamemap->IsMetalMap())
119
strategyTechUp = true;
121
// NOTE: clock() gives much better results than rng.RndFloat() (at least under MSVC)
122
strategyTechUp = ((clock() % 3) == 0);
124
LOG_II("CIntel::init Tech-up strategy: " << strategyTechUp)
39
129
void CIntel::update(int frame) {
42
132
attackers.clear();
43
133
metalMakers.clear();
44
134
energyMakers.clear();
136
underwaterUnits.clear();
45
137
restUnarmedUnits.clear();
139
defenseGround.clear();
140
defenseAntiAir.clear();
49
numUnits = ai->cbc->GetEnemyUnits(units, MAX_UNITS);
145
int numUnits = ai->cbc->GetEnemyUnits(units, MAX_UNITS);
51
147
for (int i = 0; i < numUnits; i++) {
52
const UnitDef *ud = ai->cbc->GetUnitDef(units[i]);
148
const int uid = units[i];
149
const UnitDef *ud = ai->cbc->GetUnitDef(uid);
53
150
UnitType *ut = UT(ud->id);
54
151
unsigned int c = ut->cats;
55
152
bool armed = !ud->weapons.empty();
57
154
/* Ignore units being built and cloaked units */
58
if ((ai->cbc->UnitBeingBuilt(units[i]) && (armed || !(c&STATIC)))
59
|| ai->cbc->IsUnitCloaked(units[i]))
155
if ((ai->cbc->UnitBeingBuilt(uid) && (armed || !(c&STATIC)))
156
|| ai->cbc->IsUnitCloaked(uid))
62
if (c&ATTACKER && !(c&AIR)) {
63
attackers.push_back(units[i]);
160
commanders.push_back(uid);
162
else if (c&SEA && ai->cbc->GetUnitPos(uid).y < 0.0f) {
163
underwaterUnits.push_back(uid);
165
else if (!(c&(LAND|AIR)) && c&SEA) {
166
navalUnits.push_back(uid);
168
else if ((c&STATIC) && (c&ANTIAIR)) {
169
defenseAntiAir.push_back(uid);
171
else if ((c&STATIC) && (c&DEFENSE)) {
172
defenseGround.push_back(uid);
174
else if ((c&ATTACKER) && !(c&AIR)) {
175
attackers.push_back(uid);
65
177
else if (c&FACTORY) {
66
factories.push_back(units[i]);
178
factories.push_back(uid);
68
180
else if (c&BUILDER && c&MOBILE && !(c&AIR)) {
69
mobileBuilders.push_back(units[i]);
181
mobileBuilders.push_back(uid);
71
else if (c&MEXTRACTOR || c&MMAKER) {
72
metalMakers.push_back(units[i]);
183
else if (c&(MEXTRACTOR|MMAKER)) {
184
metalMakers.push_back(uid);
74
186
else if (c&EMAKER) {
75
energyMakers.push_back(units[i]);
187
energyMakers.push_back(uid);
78
restUnarmedUnits.push_back(units[i]);
190
restUnarmedUnits.push_back(uid);
80
rest.push_back(units[i]);
83
if (c&ATTACKER && c&MOBILE)
195
if ((c&ATTACKER) && (c&MOBILE))