From 7e64f1e6509e0b81fa3002cf0349b7af459c12f8 Mon Sep 17 00:00:00 2001 From: Pan Date: Thu, 17 Jan 2019 22:38:57 +1300 Subject: [PATCH] home commit --- core/AssetManager.java | 4 ++-- enemyAI/defenseManagerAI.java | 39 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/AssetManager.java b/core/AssetManager.java index f057008..ef73f32 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++){ - lightTank l = new lightTank(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0); - addLightTank(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 985393e..2eb162a 100644 --- a/enemyAI/defenseManagerAI.java +++ b/enemyAI/defenseManagerAI.java @@ -134,24 +134,32 @@ public class defenseManagerAI { 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; + int numOfHeavyTanks = numOfHeavyTankAroundLocation(mainPlayerForceLocation); + if(numOfHeavyTanks < 1) { + 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)) { - - minorThreatLocation.set(mainPlayerForceLocation); - System.out.println("SOS!"); + if(!attackedByRocketTank && playerForceIsNearBase(mainPlayerForceLocation)) { + if(numOfHeavyTanks < 1) + minorThreatLocation.set(mainPlayerForceLocation); + else { + giveBackControlOfDefendersToCombatAI(); + majorThreatLocation.set(mainPlayerForceLocation); + } } }else if(mainPlayerForceSize >= 5){ //if the size of player unit cluster is bigger or equal to 5 then check if the threat is a big one + //if(playerForceIsNearBase(mainPlayerForceLocation) || playerForceIsMovingTwoardsBase(mainPlayerForceLocation, mainPlayerForceDirection)) + } //take over controls of defenders from combat AI to deal with minor threat @@ -263,15 +271,16 @@ public class defenseManagerAI { return false; } - public boolean playerForceContainsNoHeavyTank(vector location) { + public int numOfHeavyTankAroundLocation(vector location) { solidObject o = null; + int numberOfHeaveyTankNearLocation = 0; for(int i = 0; i < mainThread.ec.theMapAwarenessAI.playerUnitInMinimap.length; i++) { o = mainThread.ec.theMapAwarenessAI.playerUnitInMinimap[i]; if(o !=null && o.currentHP > 0 && o.type == 7 && (o.centre.x - location.x)*(o.centre.x - location.x) + (o.centre.z - location.z)*(o.centre.z - location.z) < 4) - return false; + numberOfHeaveyTankNearLocation++; } - return true; + return numberOfHeaveyTankNearLocation; } public void addUnitToDefenders(solidObject o) {