diff --git a/core/AssetManager.java b/core/AssetManager.java index 7d38d20..f057008 100644 --- a/core/AssetManager.java +++ b/core/AssetManager.java @@ -251,8 +251,8 @@ public class AssetManager { for(int i = 0; i < 10; i ++){ for(int j = 0; j < 6; j++){ - heavyTank l = new heavyTank(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0); - addHeavyTank(l); + lightTank l = new lightTank(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0); + addLightTank(l); //l.hasMultiShotUpgrade = true; //lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 18.625f + j*0.25f), 90, 0); diff --git a/enemyAI/defenseManagerAI.java b/enemyAI/defenseManagerAI.java index 5df995e..064e5e0 100644 --- a/enemyAI/defenseManagerAI.java +++ b/enemyAI/defenseManagerAI.java @@ -3,6 +3,7 @@ package enemyAI; import core.baseInfo; import core.mainThread; import core.vector; +import entity.lightTank; import entity.solidObject; import entity.stealthTank; @@ -19,6 +20,7 @@ public class defenseManagerAI { public solidObject[] observers; public solidObject[] stealthTanksControlledByCombatAI; + public solidObject[] lightTanksControlledByCombatAI; public solidObject[] defenders; public int numOfDefenders; @@ -53,6 +55,7 @@ public class defenseManagerAI { currentState = mainThread.ec.theCombatManagerAI.currentState; stealthTanksControlledByCombatAI = mainThread.ec.theUnitProductionAI.stealthTanksControlledByCombatAI; + lightTanksControlledByCombatAI = mainThread.ec.theUnitProductionAI.lightTanksControlledByCombatAI; //after 500 seconds mark, borrow 2 stealth tanks from combat manager, and send them to guard western and southern side of the main base if(gameTime >= 480) { @@ -128,16 +131,134 @@ public class defenseManagerAI { // if the size of the player unit cluster is less than 5, and no heavy tanks in the cluster, then borrow some unites from combatAI to deal with the threat - //if(mainPlayerForceSize < 5 && playerForceContainsNoHeavyTank(mainPlayerForceLocation) && playerForceIsNearBase(mainPlayerForceLocation)) { + if(mainPlayerForceSize < 5 && mainPlayerForceSize>0) { + //check if base is attacked by long ranged units + boolean attackedByRocketTank = false; + for(int i = 0; i < mainThread.ec.theMapAwarenessAI.numOfAIStructures; i++) { + if(mainThread.ec.theMapAwarenessAI.AIStructures[i].underAttackCountDown > 0 && + mainThread.ec.theMapAwarenessAI.AIStructures[i].attacker != null && + mainThread.ec.theMapAwarenessAI.AIStructures[i].attacker.currentHP > 0 && + mainThread.ec.theMapAwarenessAI.AIStructures[i].attacker.type == 1) { + attackedByRocketTank = true; + minorThreatLocation.set(mainThread.ec.theMapAwarenessAI.AIStructures[i].attacker.centre); + break; + } + } - //} + if(!attackedByRocketTank && playerForceContainsNoHeavyTank(mainPlayerForceLocation) && playerForceIsNearBase(mainPlayerForceLocation)) { - System.out.println(playerForceContainsNoHeavyTank(mainPlayerForceLocation) + " " + mainThread.ec.theMapAwarenessAI.numOfAIStructures); + minorThreatLocation.set(mainPlayerForceLocation); + System.out.println("SOS!"); + } + }else if(mainPlayerForceSize >= 5){ + //if the size of player unit cluster is bigger or equal to 5 then inform combatAI about the threat + } + + //take over controls of defenders from combat AI to deal with minor threat + if(minorThreatLocation.x != 0 && numOfDefenders > 0) { + takeOverDefendersFromCombatAI(); + + //attack move to threat location + for(int i =0; i < defenders.length; i++) { + if(defenders[i] != null) { + defenders[i].moveTo(minorThreatLocation.x, minorThreatLocation.z); + defenders[i].currentCommand = solidObject.attackMove; + defenders[i].secondaryCommand = solidObject.attackMove; + } + } + } + + //check if the minor threat is being dealt with + if(minorThreatLocation.x == 0) { + boolean defenersInStandbyMode = true; + for(int i = 0; i < defenders.length; i++) { + if(defenders[i] != null && defenders[i].currentHP > 0) { + if(defenders[i].currentCommand != 0) + defenersInStandbyMode = false; + } + } + + //if defenders are idle then make sure that combatAI has control of the defenders. + if(defenersInStandbyMode) { + giveBackControlOfDefendersToCombatAI(); + + //move back to rally point + for(int i =0; i < defenders.length; i++) { + if(defenders[i] != null) { + defenders[i].moveTo(mainThread.ec.theUnitProductionAI.rallyPoint.x, mainThread.ec.theUnitProductionAI.rallyPoint.z); + defenders[i].currentCommand = solidObject.attackMove; + defenders[i].secondaryCommand = solidObject.attackMove; + } + } + } + } + + //System.out.println(numOfDefenders + " " + mainThread.ec.theMapAwarenessAI.numOfAIStructures); } - public boolean playerForceIsNearBase(vector location) { + public void giveBackControlOfDefendersToCombatAI() { + for(int i = 0; i < defenders.length; i++) { + if(defenders[i] == null) + continue; + if(defenders[i].type == 6) { + boolean alreadyControledByCombatAI = false; + for(int j = 0; j < stealthTanksControlledByCombatAI.length; j++) { + if(defenders[i] == stealthTanksControlledByCombatAI[j]) { + alreadyControledByCombatAI = true; + break; + } + } + if(!alreadyControledByCombatAI) + mainThread.ec.theUnitProductionAI.addStealthTank((stealthTank)defenders[i]); + }else if(defenders[i].type == 0) { + boolean alreadyControledByCombatAI = false; + for(int j = 0; j < lightTanksControlledByCombatAI.length; j++) { + if(defenders[i] == lightTanksControlledByCombatAI[j]) { + alreadyControledByCombatAI = true; + break; + } + } + if(!alreadyControledByCombatAI) + mainThread.ec.theUnitProductionAI.addLightTank((lightTank)defenders[i]); + } + } + } + + public void takeOverDefendersFromCombatAI() { + for(int i = 0; i < defenders.length; i++) { + if(defenders[i] == null) + continue; + + if(defenders[i].type == 6) { + for(int j = 0; j < stealthTanksControlledByCombatAI.length; j++) { + if(defenders[i] == stealthTanksControlledByCombatAI[j]) { + stealthTanksControlledByCombatAI[j] = null; + break; + } + } + }else if(defenders[i].type == 0) { + for(int j = 0; j < lightTanksControlledByCombatAI.length; j++) { + if(defenders[i] == lightTanksControlledByCombatAI[j]) { + lightTanksControlledByCombatAI[j] = null; + break; + } + } + } + } + } + + public boolean playerForceIsNearBase(vector location) { + for(int i = 0; i < mainThread.ec.theMapAwarenessAI.AIStructures.length; i++) { + if(mainThread.ec.theMapAwarenessAI.AIStructures[i] == null) + continue; + float xPos = mainThread.ec.theMapAwarenessAI.AIStructures[i].centre.x; + float zPos = mainThread.ec.theMapAwarenessAI.AIStructures[i].centre.z; + float d = (location.x - xPos)*(location.x - xPos) + (location.z - zPos)*(location.z - zPos); + if(d < 9) + return true; + } return false; } @@ -155,13 +276,17 @@ public class defenseManagerAI { public void addUnitToDefenders(solidObject o) { numOfDefenders = 0; + boolean defenersInStandbyMode = true; for(int i = 0; i < defenders.length; i++) { - if(defenders[i] != null && defenders[i].currentHP > 0) + if(defenders[i] != null && defenders[i].currentHP > 0) { numOfDefenders++; + if(defenders[i].currentCommand != 0) + defenersInStandbyMode = false; + } } - if(numOfDefenders == defenders.length && minorThreatLocation.x == 0) { + if(numOfDefenders == defenders.length && minorThreatLocation.x == 0 && defenersInStandbyMode) { for(int i = defenders.length - 1; i > 0; i--) defenders[i] = defenders[i - 1]; defenders[0] = o; @@ -169,6 +294,7 @@ public class defenseManagerAI { for(int i = 0; i < defenders.length; i++) { if(defenders[i] == null || defenders[i].currentHP <= 0) { defenders[i] = o; + numOfDefenders++; break; } } diff --git a/enemyAI/unitProductionAI.java b/enemyAI/unitProductionAI.java index d4896e9..458979d 100644 --- a/enemyAI/unitProductionAI.java +++ b/enemyAI/unitProductionAI.java @@ -34,7 +34,7 @@ public class unitProductionAI { public final int produceHeavyTank = 3; public vector rallyPoint; - public int unitProduced; + //public int unitProduced; public int numberOfCombatUnit; public int numberOfUnitInCombatRadius; public int numberOfUnitOutsideCombatRadius; @@ -252,7 +252,6 @@ public class unitProductionAI { for(int i = 0; i < lightTanksControlledByCombatAI.length; i++){ if(lightTanksControlledByCombatAI[i] == null || (lightTanksControlledByCombatAI[i] != null && lightTanksControlledByCombatAI[i].currentHP <=0)){ lightTanksControlledByCombatAI[i] = o; - unitProduced++; mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o); break; } @@ -268,7 +267,6 @@ public class unitProductionAI { for(int i = 0; i < rocketTanksControlledByCombatAI.length; i++){ if(rocketTanksControlledByCombatAI[i] == null || (rocketTanksControlledByCombatAI[i] != null && rocketTanksControlledByCombatAI[i].currentHP <=0)){ rocketTanksControlledByCombatAI[i] = o; - unitProduced++; break; } } @@ -293,7 +291,7 @@ public class unitProductionAI { for(int i = 0; i < stealthTanksControlledByCombatAI.length; i++){ if(stealthTanksControlledByCombatAI[i] == null || (stealthTanksControlledByCombatAI[i] != null && stealthTanksControlledByCombatAI[i].currentHP <=0)){ stealthTanksControlledByCombatAI[i] = o; - unitProduced++; + mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o); break; } @@ -305,7 +303,6 @@ public class unitProductionAI { for(int i = 0; i < heavyTanksControlledByCombatAI.length; i++){ if(heavyTanksControlledByCombatAI[i] == null || (heavyTanksControlledByCombatAI[i] != null && heavyTanksControlledByCombatAI[i].currentHP <=0)){ heavyTanksControlledByCombatAI[i] = o; - unitProduced++; break; } }