From b94af05a04f6084e2a4ed15a2211a3ca52faffa1 Mon Sep 17 00:00:00 2001 From: Pan Date: Thu, 9 May 2019 22:37:42 +1200 Subject: [PATCH] h --- enemyAI/combatManagerAI.java | 2 +- enemyAI/defenseManagerAI.java | 16 ++--- enemyAI/harassmentAI.java | 129 +++++++++++++++++++++++++++++++++- entity/lightTank.java | 2 +- gui/MiniMap.java | 4 +- 5 files changed, 138 insertions(+), 15 deletions(-) diff --git a/enemyAI/combatManagerAI.java b/enemyAI/combatManagerAI.java index fce9bc1..7b59429 100644 --- a/enemyAI/combatManagerAI.java +++ b/enemyAI/combatManagerAI.java @@ -70,7 +70,7 @@ public class combatManagerAI { this.theBaseInfo = mainThread.ec.theBaseInfo; standardAttackTime = 500; - rushAttackTime = 250 + gameData.getRandom()/4; + rushAttackTime = 250 + gameData.getRandom()/5; goldMines = mainThread.theAssetManager.goldMines; diff --git a/enemyAI/defenseManagerAI.java b/enemyAI/defenseManagerAI.java index 25910a9..cef179b 100644 --- a/enemyAI/defenseManagerAI.java +++ b/enemyAI/defenseManagerAI.java @@ -128,10 +128,10 @@ public class defenseManagerAI { //if there is no player units in sight, return to patrol position if(i == 0) { if(frameAI%28 < 14) { - xPos = 20f; + xPos = 15.5f; zPos = 30.5f; }else { - xPos = 20f; + xPos = 15.5f; zPos = 24.5f; } @@ -149,12 +149,12 @@ public class defenseManagerAI { if(i == 1) { - if(frameAI%20 < 10) { - xPos = 30f; - zPos = 15f; + if(frameAI%30 < 15) { + xPos = 29.25f; + zPos = 17f; }else { - xPos = 26f; - zPos = 15f; + xPos = 29.25f; + zPos = 10f; } if(frameAI > 1000) { @@ -535,7 +535,7 @@ public class defenseManagerAI { threatToBaseDirection.unit(); if(threatToBaseDirection.dot(direction) > 0.8) { - float currentThreatDistance = Math.max(3f, d - 2f); + float currentThreatDistance = Math.max(3f, d); if(currentThreatDistance < threatDistance) threatDistance = currentThreatDistance; diff --git a/enemyAI/harassmentAI.java b/enemyAI/harassmentAI.java index 9531b30..6dc396f 100644 --- a/enemyAI/harassmentAI.java +++ b/enemyAI/harassmentAI.java @@ -6,6 +6,9 @@ package enemyAI; import core.baseInfo; import core.mainThread; +import entity.rocketTank; +import entity.solidObject; +import entity.stealthTank; public class harassmentAI { @@ -14,12 +17,21 @@ public class harassmentAI { public int frameAI; public int miniFrameAI; + public stealthTank scout; + public rocketTank[] squad; + public int status; + public final int gathering = 0; + public final int positioning = 1; + public final int harasing = 2; + public final int retreating = 3; + public stealthTank[] stealthTanksControlledByCombatAI; + public rocketTank[] rocketTanksControlledByCombatAI; public harassmentAI(){ this.theBaseInfo = mainThread.ec.theBaseInfo; - - + squad = new rocketTank[3]; + status = gathering; } public void processAI(){ @@ -27,10 +39,121 @@ public class harassmentAI { frameAI = mainThread.ec.frameAI; if(miniFrameAI%30 == 29) { - + System.out.println(frameAI + " " + mainThread.ec.theUnitProductionAI.numberOfRocketTanksControlledByCombatAI); } + //only activate this AI after 660 game seconds (about 9 minutes in real time) + if(frameAI < 660) + return; + stealthTanksControlledByCombatAI = mainThread.ec.theUnitProductionAI.stealthTanksControlledByCombatAI; + rocketTanksControlledByCombatAI = mainThread.ec.theUnitProductionAI.rocketTanksControlledByCombatAI; + + if(status == gathering) { + + if(scout == null || scout.currentHP <=0) { + for(int i = 0; i < stealthTanksControlledByCombatAI.length; i++) { + if(stealthTanksControlledByCombatAI[i] != null && stealthTanksControlledByCombatAI[i].currentHP == stealthTank.maxHP && stealthTanksControlledByCombatAI[i].attackStatus != solidObject.isAttacking) { + if(hasRoomToMove(stealthTanksControlledByCombatAI[i])) { + scout = stealthTanksControlledByCombatAI[i]; + stealthTanksControlledByCombatAI[i] = null; + break; + } + } + } + } + + if(scout != null) { + scout.moveTo(mainThread.ec.theUnitProductionAI.rallyPoint.x - 1,mainThread.ec.theUnitProductionAI.rallyPoint.z); + scout.currentCommand = solidObject.move; + scout.secondaryCommand = solidObject.StandBy; + } + + for(int i = 0; i < squad.length; i++) { + if(squad[i] == null || squad[i].currentHP <=0) { + for(int j = 0; j < rocketTanksControlledByCombatAI.length; j++) { + if(rocketTanksControlledByCombatAI[j] != null && rocketTanksControlledByCombatAI[j].currentHP == rocketTank.maxHP && rocketTanksControlledByCombatAI[j].attackStatus != solidObject.isAttacking) { + if(hasRoomToMove(rocketTanksControlledByCombatAI[j])) { + squad[i] = rocketTanksControlledByCombatAI[j]; + rocketTanksControlledByCombatAI[j] = null; + break; + } + } + } + } + } + int numberOfSquad = 0; + for(int i = 0; i < squad.length; i++) { + if(squad[i] != null) { + squad[i].attackMoveTo(mainThread.ec.theUnitProductionAI.rallyPoint.x - 1,mainThread.ec.theUnitProductionAI.rallyPoint.z); + squad[i].currentCommand = solidObject.attackMove; + squad[i].secondaryCommand = solidObject.attackMove; + numberOfSquad++; + } + } + + if(numberOfSquad == squad.length && scout !=null) { + status = positioning; + } + }else if(status == positioning) { + + } } + + public boolean hasRoomToMove(solidObject o) { + float x = o.centre.x; + float z = o.centre.x; + + solidObject[] s1 = mainThread.gridMap.tiles[(int)((x+0.25)*4) + (127 - (int)(z*4))*128]; + boolean hasRoomToMove = true; + for(int i = 0; i < s1.length; i++) { + if(s1[i] != null && s1[i] != o) { + hasRoomToMove = false; + break; + } + } + + if(hasRoomToMove) + return true; + + solidObject[] s2 = mainThread.gridMap.tiles[(int)((x-0.25)*4) + (127 - (int)(z*4))*128]; + hasRoomToMove = true; + for(int i = 0; i < s2.length; i++) { + if(s2[i] != null && s2[i] != o) { + hasRoomToMove = false; + break; + } + } + + if(hasRoomToMove) + return true; + + solidObject[] s3 = mainThread.gridMap.tiles[(int)(x*4) + (127 - (int)((z + 0.25)*4))*128]; + hasRoomToMove = true; + for(int i = 0; i < s3.length; i++) { + if(s3[i] != null && s3[i] != o) { + hasRoomToMove = false; + break; + } + } + + if(hasRoomToMove) + return true; + + solidObject[] s4 = mainThread.gridMap.tiles[(int)(x*4) + (127 - (int)((z - 0.25)*4))*128]; + hasRoomToMove = true; + for(int i = 0; i < s4.length; i++) { + if(s4[i] != null && s4[i] != o) { + hasRoomToMove = false; + break; + } + } + + if(hasRoomToMove) + return true; + + + return false; + } } diff --git a/entity/lightTank.java b/entity/lightTank.java index cf1d1af..2743e3c 100644 --- a/entity/lightTank.java +++ b/entity/lightTank.java @@ -973,7 +973,7 @@ public class lightTank extends solidObject{ int theDamage = myDamage; if(targetObject.type == 7) theDamage*=1.5; - if(targetObject.type == 0) + if(targetObject.type == 0 || targetObject.type == 1) theDamage*=1.2; if(targetObject.type >= 100) theDamage*=0.6; diff --git a/gui/MiniMap.java b/gui/MiniMap.java index 3e0faf8..bf07395 100644 --- a/gui/MiniMap.java +++ b/gui/MiniMap.java @@ -50,8 +50,8 @@ public class MiniMap { drawBackground(screen, minimapBitmap); //remove fog of war for testing - //for(int i = 0; i < minimapBitmap.length; i++) - // minimapBitmap[i] = true; + for(int i = 0; i < minimapBitmap.length; i++) + minimapBitmap[i] = true; //draw unit positions on minimap drawUnit(screen, minimapBitmap, unitsForMiniMap, unitsForMiniMapCount);