forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapAwarenessAI.java
More file actions
791 lines (672 loc) · 31.6 KB
/
Copy pathmapAwarenessAI.java
File metadata and controls
791 lines (672 loc) · 31.6 KB
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
package enemyAI;
import core.AssetManager;
import core.baseInfo;
import core.mainThread;
import entity.constructionYard;
import entity.goldMine;
import entity.harvester;
import entity.solidObject;
import core.vector;
//1. scan revealed area for player's units and building
//2. keep track of player's units
//3. create strategic information based on the quantity/location of player's units
public class mapAwarenessAI {
public baseInfo theBaseInfo;
public int frameAI;
public int numberOfLightTanks_player, numberOfLightTanks_AI, numberOfLightTanksOnMinimap_player;
public int numberOfStealthTanks_player, numberOfStealthTanks_AI, numberOfStealthTanksOnMinimap_player;
public int numberOfRocketTanks_player, numberOfRocketTanks_AI, numberOfRocketTanksOnMinimap_player;
public int numberOfHeavyTanks_player, numberOfHeavyTanks_AI, numberOfHeavyTanksOnMinimap_player;
public int numberOfPlayerUnitsOnMinimap;
public int totalNumberOfPlayerUnits;
public int numberOfGunTurret_player;
public int numberOfMissileTurret_player;
public int numberOfFactory_player;
public int numberOfRefinery_player;
public int numberOfConstructionYard_player;
public int numberOfCommunicationCenter_player;
public int numberOfTechCenter_player;
public int numberOfPowerPlant_player;
public int maxNumberOfStealthTanks_playerInLastFiveMinutes;
public int fiveMinuteTimer;
public int numberOfPlayerUnitDestroyed;
public int numberOfPlayerBuildingDestroyed;
public int numberOfPlayerUnitDestroyedInPreviousFrame;
public int numberOfPlayerBuildingDestroyedPreviousFrame;
public int playerAssetDestoryedCountDown;
public boolean playerHasMostlyLightTanks;
public boolean playerHasMostlyHeavyTanks;
public boolean playIsRushingHighTierUnits;
public boolean playerLikelyCanNotProduceHighTierUnits;
public boolean playerDoesntHaveMassHeavyTanks;
public boolean playerArmyCanBeCounteredWithLightTanks;
public boolean playerArmyCanBeCounteredWithStealthTanks;
public boolean playerIsRushingLightTank;
public boolean playerHasManyLightTanksButNoHeavyTank;
public boolean playerHasMostlyHeavyAndStealthTanks;
public boolean playerHasMostlyLightAndStealthTanks;
public boolean canRushPlayer;
public boolean playerIsFastExpanding;
public boolean playerForceNearBase;
public solidObject[] mapAsset;
public boolean[] visionMap;
public AssetManager theAssetManager;
public solidObject[] playerUnitInMinimap;
public solidObject[] playerStaticDefenceInMinimap;
public solidObject[] playerStructures;
public int numOfAIStructures;
public solidObject[] AIStructures;
public goldMine[] goldMines;
public int targetPlayerExpension;
public int[] playerExpensionInfo;
public int numberOfplayerMiningBases;
public vector mainPlayerForceLocation;
public vector mainPlayerForceDirection;
public int mainPlayerForceSize;
public vector[] playerForceLocations;
public vector[] playerForceDirections;
public int[] playerForceSize;
public vector playerNaturalLocation;
public vector[] playerStaticDefenseLocations;
public int[] playerStaticDefenseSize;
public int[] playerStaticDefenseStrength;
public mapAwarenessAI(){
this.theBaseInfo = mainThread.ec.theBaseInfo;
this.visionMap = mainThread.ec.visionMap;
mapAsset = new solidObject[1024];
playerUnitInMinimap = new solidObject[128];
playerStaticDefenceInMinimap = new solidObject[64];
playerStructures = new solidObject[256];
AIStructures = new solidObject[128];
goldMines = mainThread.theAssetManager.goldMines;
playerExpensionInfo = new int[goldMines.length];
playerNaturalLocation = goldMines[1].centre;
mainPlayerForceLocation = new vector(0,0,0);
mainPlayerForceDirection = new vector(0,0,0);
mainPlayerForceSize = 0;
playerForceLocations = new vector[3];
playerForceDirections = new vector[3];
playerForceSize = new int[3];
for(int i = 0; i < playerForceLocations.length; i++) {
playerForceLocations[i] = new vector(0,0,0);
playerForceDirections[i] = new vector(0,0,0);
playerForceSize[i] = 0;
}
playerStaticDefenseLocations = new vector[3];
playerStaticDefenseSize = new int[3];
playerStaticDefenseStrength = new int[3];
for(int i = 0; i < playerStaticDefenseLocations.length; i++) {
playerStaticDefenseLocations[i] = new vector(0,0,0);
playerStaticDefenseSize[i] = 0;
playerStaticDefenseStrength[i] = 0;
}
}
public void processAI(){
frameAI = mainThread.ec.frameAI;
theAssetManager = mainThread.theAssetManager;
//the number of player's military units in AI's vision
numberOfLightTanksOnMinimap_player = 0;
numberOfRocketTanksOnMinimap_player = 0;
numberOfStealthTanksOnMinimap_player = 0;
numberOfHeavyTanksOnMinimap_player = 0;
numberOfPlayerUnitsOnMinimap = 0;
//the total number of player's unit that are detected by AI
numberOfLightTanks_player = 0;
numberOfRocketTanks_player = 0;
numberOfStealthTanks_player = 0;
numberOfHeavyTanks_player = 0;
numberOfGunTurret_player = 0;
numberOfMissileTurret_player = 0;
numberOfFactory_player = 0;
numberOfRefinery_player = 0;
numberOfConstructionYard_player = 0;
numberOfCommunicationCenter_player = 0;
numberOfTechCenter_player = 0;
//the total number of AI military units
numberOfLightTanks_AI = 0;
numberOfRocketTanks_AI = 0;
numberOfStealthTanks_AI = 0;
numberOfHeavyTanks_AI = 0;
//clear info from previous frame
for(int i = 0; i < playerUnitInMinimap.length; i++)
playerUnitInMinimap[i] = null;
for(int i = 0; i < playerStaticDefenceInMinimap.length; i++)
playerStaticDefenceInMinimap[i] = null;
for(int i = 0; i < playerStructures.length; i++)
playerStructures[i] = null;
for(int i = 0; i < AIStructures.length; i++)
AIStructures[i] = null;
numOfAIStructures = 0;
if(playerAssetDestoryedCountDown > 0)
playerAssetDestoryedCountDown--;
for(int i = 0; i < theAssetManager.lightTanks.length; i++){
if(theAssetManager.lightTanks[i] != null && theAssetManager.lightTanks[i].teamNo ==0){
if(visionMap[theAssetManager.lightTanks[i].occupiedTile0]){
numberOfLightTanksOnMinimap_player++;
addPlayerUnitInMinimap(theAssetManager.lightTanks[i]);
if(mapAsset[theAssetManager.lightTanks[i].ID] == null) {
mapAsset[theAssetManager.lightTanks[i].ID] = theAssetManager.lightTanks[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=1;
}
}
}else if(theAssetManager.lightTanks[i] != null && theAssetManager.lightTanks[i].teamNo !=0){
numberOfLightTanks_AI++;
if(mapAsset[theAssetManager.lightTanks[i].ID] == null){
mainThread.ec.theUnitProductionAI.addLightTank(theAssetManager.lightTanks[i]);
mapAsset[theAssetManager.lightTanks[i].ID] = theAssetManager.lightTanks[i];
}
}
}
for(int i = 0; i < theAssetManager.rocketTanks.length; i++){
if(theAssetManager.rocketTanks[i] != null && theAssetManager.rocketTanks[i].teamNo ==0){
if(visionMap[theAssetManager.rocketTanks[i].occupiedTile0]){
numberOfRocketTanksOnMinimap_player++;
addPlayerUnitInMinimap(theAssetManager.rocketTanks[i]);
if(mapAsset[theAssetManager.rocketTanks[i].ID] == null) {
mapAsset[theAssetManager.rocketTanks[i].ID] = theAssetManager.rocketTanks[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=1.5;
}
}
}else if(theAssetManager.rocketTanks[i] != null && theAssetManager.rocketTanks[i].teamNo !=0){
numberOfRocketTanks_AI++;
if(mapAsset[theAssetManager.rocketTanks[i].ID] == null){
mainThread.ec.theUnitProductionAI.addRocketTank(theAssetManager.rocketTanks[i]);
mapAsset[theAssetManager.rocketTanks[i].ID] = theAssetManager.rocketTanks[i];
}
}
}
for(int i = 0; i < theAssetManager.stealthTanks.length; i++){
if(theAssetManager.stealthTanks[i] != null && theAssetManager.stealthTanks[i].teamNo ==0){
if(visionMap[theAssetManager.stealthTanks[i].occupiedTile0] && !theAssetManager.stealthTanks[i].isCloaked){
numberOfStealthTanksOnMinimap_player++;
addPlayerUnitInMinimap(theAssetManager.stealthTanks[i]);
if(mapAsset[theAssetManager.stealthTanks[i].ID] == null) {
mapAsset[theAssetManager.stealthTanks[i].ID] = theAssetManager.stealthTanks[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=2;
}
}
}else if(theAssetManager.stealthTanks[i] != null && theAssetManager.stealthTanks[i].teamNo !=0){
numberOfStealthTanks_AI++;
if(mapAsset[theAssetManager.stealthTanks[i].ID] == null){
mainThread.ec.theUnitProductionAI.addStealthTank(theAssetManager.stealthTanks[i]);
mapAsset[theAssetManager.stealthTanks[i].ID] = theAssetManager.stealthTanks[i];
}
}
}
for(int i = 0; i < theAssetManager.heavyTanks.length; i++){
if(theAssetManager.heavyTanks[i] != null && theAssetManager.heavyTanks[i].teamNo ==0){
if(visionMap[theAssetManager.heavyTanks[i].occupiedTile0]){
numberOfHeavyTanksOnMinimap_player++;
addPlayerUnitInMinimap(theAssetManager.heavyTanks[i]);
if(mapAsset[theAssetManager.heavyTanks[i].ID] == null) {
mapAsset[theAssetManager.heavyTanks[i].ID] = theAssetManager.heavyTanks[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=3.5;
}
}
}else if(theAssetManager.heavyTanks[i] != null && theAssetManager.heavyTanks[i].teamNo !=0){
numberOfHeavyTanks_AI++;
if(mapAsset[theAssetManager.heavyTanks[i].ID] == null){
mainThread.ec.theUnitProductionAI.addHeavyTank(theAssetManager.heavyTanks[i]);
mapAsset[theAssetManager.heavyTanks[i].ID] = theAssetManager.heavyTanks[i];
}
}
}
for(int i = 0; i < theAssetManager.harvesters.length; i++){
if(theAssetManager.harvesters[i] != null && theAssetManager.harvesters[i].teamNo ==0){
if(visionMap[theAssetManager.harvesters[i].occupiedTile0]){
//addPlayerUnitInMinimap(theAssetManager.harvesters[i]);
mapAsset[theAssetManager.harvesters[i].ID] = theAssetManager.harvesters[i];
}
}
}
for(int i = 0; i < theAssetManager.constructionVehicles.length; i++){
if(theAssetManager.constructionVehicles[i] != null && theAssetManager.constructionVehicles[i].teamNo ==0){
if(visionMap[theAssetManager.constructionVehicles[i].occupiedTile0]){
addPlayerUnitInMinimap(theAssetManager.constructionVehicles[i]);
mapAsset[theAssetManager.constructionVehicles[i].ID] = theAssetManager.constructionVehicles[i];
}
}
}
//add revealed player's building to mapAsset
for(int i = 0; i < theAssetManager.gunTurrets.length; i++){
if(theAssetManager.gunTurrets[i] != null && theAssetManager.gunTurrets[i].teamNo ==0){
if(visionMap[theAssetManager.gunTurrets[i].tileIndex[0]]){
if(mapAsset[theAssetManager.gunTurrets[i].ID] == null) {
mapAsset[theAssetManager.gunTurrets[i].ID] = theAssetManager.gunTurrets[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=1;
}
}
}else if(theAssetManager.gunTurrets[i] != null && theAssetManager.gunTurrets[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.gunTurrets[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.missileTurrets.length; i++){
if(theAssetManager.missileTurrets[i] != null && theAssetManager.missileTurrets[i].teamNo ==0){
if(visionMap[theAssetManager.missileTurrets[i].tileIndex[0]]){
if(mapAsset[theAssetManager.missileTurrets[i].ID] == null) {
mapAsset[theAssetManager.missileTurrets[i].ID] = theAssetManager.missileTurrets[i];
mainThread.ec.theCombatManagerAI.unrevealedPlayerForceStrength-=2;
}
}
}else if(theAssetManager.missileTurrets[i] != null && theAssetManager.missileTurrets[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.missileTurrets[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.factories.length; i++){
if(theAssetManager.factories[i] != null && theAssetManager.factories[i].teamNo ==0){
for(int j = 0; j < 6; j++){
if(visionMap[theAssetManager.factories[i].tileIndex[j]]){
if(mapAsset[theAssetManager.factories[i].ID] == null)
mapAsset[theAssetManager.factories[i].ID] = theAssetManager.factories[i];
break;
}
}
}else if(theAssetManager.factories[i] != null && theAssetManager.factories[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.factories[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.refineries.length; i++){
if(theAssetManager.refineries[i] != null && theAssetManager.refineries[i].teamNo ==0){
for(int j = 0; j < 6; j++){
if(visionMap[theAssetManager.refineries[i].tileIndex[j]]){
if(mapAsset[theAssetManager.refineries[i].ID] == null)
mapAsset[theAssetManager.refineries[i].ID] = theAssetManager.refineries[i];
break;
}
}
}else if(theAssetManager.refineries[i] != null && theAssetManager.refineries[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.refineries[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.constructionYards.length; i++){
if(theAssetManager.constructionYards[i] != null && theAssetManager.constructionYards[i].teamNo ==0){
for(int j = 0; j < 9; j++){
if(visionMap[theAssetManager.constructionYards[i].tileIndex[j]]){
if(mapAsset[theAssetManager.constructionYards[i].ID] == null)
mapAsset[theAssetManager.constructionYards[i].ID] = theAssetManager.constructionYards[i];
break;
}
}
}else if(theAssetManager.constructionYards[i] != null && theAssetManager.constructionYards[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.constructionYards[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.communicationCenters.length; i++){
if(theAssetManager.communicationCenters[i] != null && theAssetManager.communicationCenters[i].teamNo ==0){
for(int j = 0; j < 4; j++){
if(visionMap[theAssetManager.communicationCenters[i].tileIndex[j]]){
if(mapAsset[theAssetManager.communicationCenters[i].ID] == null)
mapAsset[theAssetManager.communicationCenters[i].ID] = theAssetManager.communicationCenters[i];
break;
}
}
}else if(theAssetManager.communicationCenters[i] != null && theAssetManager.communicationCenters[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.communicationCenters[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.techCenters.length; i++){
if(theAssetManager.techCenters[i] != null && theAssetManager.techCenters[i].teamNo ==0){
for(int j = 0; j < 4; j++){
if(visionMap[theAssetManager.techCenters[i].tileIndex[j]]){
if(mapAsset[theAssetManager.techCenters[i].ID] == null)
mapAsset[theAssetManager.techCenters[i].ID] = theAssetManager.techCenters[i];
break;
}
}
}else if(theAssetManager.techCenters[i] != null && theAssetManager.techCenters[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.techCenters[i];
numOfAIStructures++;
}
}
for(int i = 0; i < theAssetManager.powerPlants.length; i++){
if(theAssetManager.powerPlants[i] != null && theAssetManager.powerPlants[i].teamNo ==0){
for(int j = 0; j < 4; j++){
if(visionMap[theAssetManager.powerPlants[i].tileIndex[j]]){
if(mapAsset[theAssetManager.powerPlants[i].ID] == null)
mapAsset[theAssetManager.powerPlants[i].ID] = theAssetManager.powerPlants[i];
break;
}
}
}else if(theAssetManager.powerPlants[i] != null && theAssetManager.powerPlants[i].teamNo !=0) {
AIStructures[numOfAIStructures] = theAssetManager.powerPlants[i];
numOfAIStructures++;
}
}
numberOfPlayerUnitDestroyed = 0;
numberOfPlayerBuildingDestroyed = 0;
for(int i = 0; i < mapAsset.length; i++){
if(mapAsset[i] != null && mapAsset[i].teamNo == 0){
if(mapAsset[i].currentHP>0){
if(mapAsset[i].type == 0 )
numberOfLightTanks_player++;
else if(mapAsset[i].type == 1)
numberOfRocketTanks_player++;
else if(mapAsset[i].type == 6)
numberOfStealthTanks_player++;
else if(mapAsset[i].type == 7)
numberOfHeavyTanks_player++;
else{
mapAsset[i].isRevealed_AI = true;
if(mapAsset[i].type == 200){
numberOfGunTurret_player++;
addPlayerStaticDefenceInMinimap(mapAsset[i]);
addPlayerStructure(mapAsset[i]);
}else if(mapAsset[i].type == 199){
addPlayerStaticDefenceInMinimap(mapAsset[i]);
addPlayerStructure(mapAsset[i]);
numberOfMissileTurret_player++;
}else if(mapAsset[i].type == 105){
addPlayerStructure(mapAsset[i]);
numberOfFactory_player++;
}else if(mapAsset[i].type == 102){
numberOfRefinery_player++;
addPlayerStructure(mapAsset[i]);
}else if(mapAsset[i].type == 104){
addPlayerStructure(mapAsset[i]);
numberOfConstructionYard_player++;
}else if(mapAsset[i].type == 106){
addPlayerStructure(mapAsset[i]);
numberOfCommunicationCenter_player++;
}else if(mapAsset[i].type == 107){
addPlayerStructure(mapAsset[i]);
numberOfTechCenter_player++;
}else if(mapAsset[i].type == 101){
addPlayerStructure(mapAsset[i]);
numberOfPowerPlant_player++;
}
}
}else{
if(mapAsset[i].attacker != null && mapAsset[i].attacker.teamNo != 0) {
if(mapAsset[i].type < 100)
numberOfPlayerUnitDestroyed++;
else
numberOfPlayerBuildingDestroyed++;
}
}
}
}
if(numberOfPlayerUnitDestroyed > numberOfPlayerUnitDestroyedInPreviousFrame || numberOfPlayerBuildingDestroyed > numberOfPlayerBuildingDestroyedPreviousFrame) {
playerAssetDestoryedCountDown = 30;
}
numberOfPlayerUnitDestroyedInPreviousFrame = numberOfPlayerUnitDestroyed;
numberOfPlayerBuildingDestroyedPreviousFrame = numberOfPlayerBuildingDestroyed;
//analyze the enemy units composition
totalNumberOfPlayerUnits = numberOfLightTanks_player + numberOfRocketTanks_player + numberOfStealthTanks_player + numberOfHeavyTanks_player;
float lightTankRatio = (float)(numberOfLightTanks_player)/(totalNumberOfPlayerUnits + 1);
playerHasMostlyLightTanks = (numberOfLightTanks_player > 5 && lightTankRatio > 0.8f) || (frameAI < 420 && numberOfLightTanks_player > 1 && lightTankRatio >= 0.75f);
playerHasMostlyHeavyTanks = numberOfHeavyTanks_player > 1 && (float)(numberOfHeavyTanks_player)/(totalNumberOfPlayerUnits) > 0.8f;
playerHasManyLightTanksButNoHeavyTank = lightTankRatio > 0.5 && numberOfHeavyTanks_player < 3;
playIsRushingHighTierUnits = mainThread.gameFrame/30 > 250 && mainThread.gameFrame/30 < 400
&& mainThread.ec.theMapAwarenessAI.numberOfTechCenter_player >0
&& mainThread.ec.theMapAwarenessAI.numberOfMissileTurret_player < 2
&& mainThread.ec.theMapAwarenessAI.numberOfGunTurret_player < 4
&& numberOfLightTanks_player + numberOfRocketTanks_player + numberOfStealthTanks_player < 5;
playerLikelyCanNotProduceHighTierUnits = mainThread.ec.theMapAwarenessAI.numberOfTechCenter_player == 0 && mainThread.ec.theMapAwarenessAI.numberOfHeavyTanks_player == 0;
playerDoesntHaveMassHeavyTanks = (float)numberOfHeavyTanks_player/( 1 + numberOfLightTanks_AI + numberOfRocketTanks_player + numberOfStealthTanks_player) < 0.2f;
playerIsRushingLightTank = mainThread.gameFrame/30 > 300 && mainThread.gameFrame/30 < 600 && ((playerLikelyCanNotProduceHighTierUnits && numberOfStealthTanks_player < 3) || playerHasMostlyLightTanks);
playerHasMostlyHeavyAndStealthTanks = (maxNumberOfStealthTanks_playerInLastFiveMinutes >=3 ) && (float)(numberOfHeavyTanks_player + numberOfStealthTanks_player)/totalNumberOfPlayerUnits > 0.85f;
playerHasMostlyLightAndStealthTanks = numberOfLightTanks_player > 5 && maxNumberOfStealthTanks_playerInLastFiveMinutes >=3 && (float)(numberOfLightTanks_player + numberOfStealthTanks_player)/totalNumberOfPlayerUnits > 0.85f;
if(frameAI < 600)
playerArmyCanBeCounteredWithLightTanks = false;
else {
playerArmyCanBeCounteredWithLightTanks = maxNumberOfStealthTanks_playerInLastFiveMinutes < 6 && (float)(numberOfHeavyTanks_player+ numberOfRocketTanks_player)/(totalNumberOfPlayerUnits + 1) > 0.85f;
}
playerArmyCanBeCounteredWithStealthTanks = (float)(numberOfLightTanks_player+ numberOfRocketTanks_player)/(totalNumberOfPlayerUnits + 1) > 0.85f;
//advanced counting of player units
if(numberOfStealthTanks_player > maxNumberOfStealthTanks_playerInLastFiveMinutes) {
maxNumberOfStealthTanks_playerInLastFiveMinutes = numberOfStealthTanks_player;
fiveMinuteTimer = 300;
}
if(fiveMinuteTimer > 0)
fiveMinuteTimer--;
else
maxNumberOfStealthTanks_playerInLastFiveMinutes = 0;
//if player fast expand then AI can rush the player
canRushPlayer = false;
if(frameAI >= 240 && frameAI < 360) {
for(int i = 0; i < playerStructures.length; i++) {
if(playerStructures[i] != null && playerStructures[i].currentHP > 0) {
float x1 = playerStructures[i].centre.x;
float z1 = playerStructures[i].centre.z;
float x2 = playerNaturalLocation.x;
float z2 = playerNaturalLocation.z;
if(Math.sqrt((x1-x2)*(x1-x2) + (z1-z2)*(z1-z2)) < 3.5f) {
playerIsFastExpanding = true;
break;
}
}
}
harvester[] harvesters = mainThread.theAssetManager.harvesters;
for(int i = 0; i < harvesters.length; i++) {
if(harvesters[i] != null && harvesters[i].currentHP > 0) {
float x1 = harvesters[i].centre.x;
float z1 = harvesters[i].centre.z;
float x2 = playerNaturalLocation.x;
float z2 = playerNaturalLocation.z;
if(Math.sqrt((x1-x2)*(x1-x2) + (z1-z2)*(z1-z2)) < 3.5f) {
playerIsFastExpanding = true;
break;
}
}
}
}
if(playerIsFastExpanding) {
if(mainThread.ec.theCombatManagerAI.checkIfAIHasBiggerForce(0.5f))
canRushPlayer = true;
}
findTheMostVulnerablePlayerBase();
findPlayerForceLocation();
findPlayerStaticDefense();
}
public void addPlayerUnitInMinimap(solidObject o){
for(int i = 0; i < playerUnitInMinimap.length; i++){
if(playerUnitInMinimap[i] == null){
playerUnitInMinimap[i] = o;
numberOfPlayerUnitsOnMinimap++;
break;
}
}
}
public void addPlayerStaticDefenceInMinimap(solidObject o){
for(int i = 0; i < playerStaticDefenceInMinimap.length; i++){
if(playerStaticDefenceInMinimap[i] == null){
playerStaticDefenceInMinimap[i] = o;
break;
}
}
}
public void addPlayerStructure(solidObject o){
for(int i = 0; i < playerStructures.length; i++){
if(playerStructures[i] == null){
playerStructures[i] = o;
break;
}
}
}
public void findTheMostVulnerablePlayerBase(){
//check if there are any player's structure around each gold mine.
for(int i = 0; i < goldMines.length; i++){
playerExpensionInfo[i] = findplayexpensionDefenseScore(goldMines[i], 3.5f);
}
//compute the target player expansion defense score
targetPlayerExpension = -1;
int playExpensionDefenseScore = 999999;
numberOfplayerMiningBases = 0;
for(int i = 0; i < playerExpensionInfo.length; i++){
if(goldMines[i] != null && goldMines[i].goldDeposite > 5000 && playerExpensionInfo[i] != 0){
numberOfplayerMiningBases++;
if(playerExpensionInfo[i] < playExpensionDefenseScore){
playExpensionDefenseScore = playerExpensionInfo[i];
targetPlayerExpension = i;
}
}
}
//if a player expansion exists on the path to the target expansion is already been taken by player's force,
//then mark it as the target expansion instead
if(targetPlayerExpension == 0){
if(playerExpensionInfo[5] >0)
targetPlayerExpension = 5;
else if(playerExpensionInfo[6] >0)
targetPlayerExpension = 6;
else if(playerExpensionInfo[7] >0)
targetPlayerExpension = 7;
else if(playerExpensionInfo[1] > 0)
targetPlayerExpension = 1;
}else if(targetPlayerExpension == 1){
if(playerExpensionInfo[5] >0)
targetPlayerExpension = 5;
else if(playerExpensionInfo[6] >0)
targetPlayerExpension = 6;
else if(playerExpensionInfo[7] >0)
targetPlayerExpension = 7;
}else if(targetPlayerExpension == 7){
if(playerExpensionInfo[5] >0)
targetPlayerExpension = 5;
else if(playerExpensionInfo[6] >0)
targetPlayerExpension = 6;
}else if(targetPlayerExpension == 6){
if(playerExpensionInfo[5] >0)
targetPlayerExpension = 5;
}
//if(targetPlayerExpension != -1)
// return playerExpensionInfo[targetPlayerExpension];
//return 0;
}
public int findplayexpensionDefenseScore(goldMine g, float r){
if(g == null)
return 0;
solidObject[] playerStructures = mainThread.ec.theMapAwarenessAI.playerStructures;
solidObject[] playerStaticDefence = mainThread.ec.theMapAwarenessAI.playerStaticDefenceInMinimap;
float x = g.centre.x;
float z = g.centre.z;
int playexpensionDefenseScore = 0;
for(int i = 0 ; i < playerStructures.length; i++){
if(playerStructures[i]!= null && Math.abs(playerStructures[i].centre.x - x) < r && Math.abs(playerStructures[i].centre.z - z) < r)
playexpensionDefenseScore++;
}
for(int i = 0 ; i < playerStaticDefence.length; i++){
if(playerStaticDefence[i]!= null && Math.abs(playerStructures[i].centre.x - x) < r && Math.abs(playerStructures[i].centre.z - z) < r){
if(playerStaticDefence[i].type == 200) //gun turret will increase player base's defense score
playexpensionDefenseScore+=1000;
if(playerStaticDefence[i].type == 199) //missile turret will increase player base's defense score even futher
playexpensionDefenseScore+=3000;
}
}
//if the player already takes the expansion which the enemy AI plans to expand to, assign zero score to this expansion
if(g == mainThread.ec.theBaseExpentionAI.expensionGoldMine && playexpensionDefenseScore > 0){
return -1;
}
return playexpensionDefenseScore;
}
//find the center of the clusters of player's static defenses. As well as the size of the clusters.
public void findPlayerStaticDefense() {
for(int i = 0; i < playerStaticDefenseLocations.length; i++) {
playerStaticDefenseLocations[i].set(0,0,0);
playerStaticDefenseSize[i] = 0;
playerStaticDefenseStrength[i] = 0;
}
for(int i = 0; i < playerStaticDefenceInMinimap.length; i++) {
if(playerStaticDefenceInMinimap[i] == null)
continue;
float xPos = playerStaticDefenceInMinimap[i].centre.x;
float zPos = playerStaticDefenceInMinimap[i].centre.z;
for(int j = 0; j < playerStaticDefenseLocations.length; j++) {
//always add the player static defense location to the empty list
if(playerStaticDefenseLocations[j].x == 0) {
playerStaticDefenseLocations[j].add(playerStaticDefenceInMinimap[i].centre);
playerStaticDefenseSize[j]++;
if(playerStaticDefenceInMinimap[j].type == 200)
playerStaticDefenseStrength[j]+=2;
if(playerStaticDefenceInMinimap[j].type == 199)
playerStaticDefenseStrength[j]+=6;
break;
}
float centerX = playerStaticDefenseLocations[j].x/playerStaticDefenseSize[j];
float centerZ = playerStaticDefenseLocations[j].z/playerStaticDefenseSize[j];
float d = (centerX - xPos) * (centerX - xPos) + (centerZ - zPos) * (centerZ - zPos);
//if the player static defence is close enough to the cluster center then add it to the list
if(d < 4) {
playerStaticDefenseLocations[j].add(playerStaticDefenceInMinimap[i].centre);
playerStaticDefenseSize[j]++;
if(playerStaticDefenceInMinimap[j].type == 200)
playerStaticDefenseStrength[j]+=2;
if(playerStaticDefenceInMinimap[j].type == 199)
playerStaticDefenseStrength[j]+=6;
break;
}
}
}
for(int i = 0; i < playerStaticDefenseLocations.length; i++) {
if(playerStaticDefenseSize[i] > 0)
playerStaticDefenseLocations[i].set(playerStaticDefenseLocations[i].x/playerStaticDefenseSize[i], 0, playerStaticDefenseLocations[i].z/playerStaticDefenseSize[i]);
}
}
//find the center of the biggest cluster of player units that are visible on the minimap. It will tells the AI which area is in danger of being attacked.
public void findPlayerForceLocation(){
mainPlayerForceLocation.set(0,0,0);
mainPlayerForceDirection.set(0,0,0);
mainPlayerForceSize = 0;
for(int i = 0; i < playerForceLocations.length; i++) {
playerForceLocations[i].set(0,0,0);
playerForceDirections[i].set(0,0,0);
playerForceSize[i] = 0;
}
for(int i = 0; i < playerUnitInMinimap.length; i++) {
if(playerUnitInMinimap[i] == null)
continue;
float xPos = playerUnitInMinimap[i].centre.x;
float zPos = playerUnitInMinimap[i].centre.z;
for(int j = 0; j < playerForceLocations.length; j++) {
//always add the player unit location to the empty list
if(playerForceLocations[j].x == 0) {
playerForceLocations[j].add(playerUnitInMinimap[i].centre);
playerForceSize[j]++;
playerForceDirections[j].add(playerUnitInMinimap[i].movement);
break;
}
float centerX = playerForceLocations[j].x/playerForceSize[j];
float centerZ = playerForceLocations[j].z/playerForceSize[j];
float d = (centerX - xPos) * (centerX - xPos) + (centerZ - zPos) * (centerZ - zPos);
//if the player unit is close enough to the force center then add it to the list
if(d < 4) {
playerForceLocations[j].add(playerUnitInMinimap[i].centre);
playerForceSize[j]++;
playerForceDirections[j].add(playerUnitInMinimap[i].movement);
break;
}
}
}
for(int i = 0; i < playerForceLocations.length; i++) {
if(playerForceSize[i] > mainPlayerForceSize) {
mainPlayerForceSize = playerForceSize[i];
mainPlayerForceLocation.set(playerForceLocations[i].x/mainPlayerForceSize,0,playerForceLocations[i].z/mainPlayerForceSize);
mainPlayerForceDirection.set(playerForceDirections[i].x/mainPlayerForceSize, 0, playerForceDirections[i].z/mainPlayerForceSize);
}
}
if(mainPlayerForceDirection.getLength() < 0.001) {
mainPlayerForceDirection.reset();
}else {
mainPlayerForceDirection.unit();
}
//check if player force is near any of AI's base
playerForceNearBase = false;
float x = mainPlayerForceLocation.x;
float z = mainPlayerForceLocation.z;
constructionYard[] constructionYards = mainThread.theAssetManager.constructionYards;
for(int i = 0; i < constructionYards.length; i++) {
if(constructionYards[i] != null && constructionYards[i].teamNo != 0 && constructionYards[i].currentHP > 0) {
double d = Math.sqrt((constructionYards[i].centre.x - x)*(constructionYards[i].centre.x - x) + (constructionYards[i].centre.z - z)*(constructionYards[i].centre.z - z));
if(d < 4.75) {
playerForceNearBase = true;
break;
}
}
}
}
}