work commit

This commit is contained in:
Pan Hu 2019-01-16 17:10:45 +13:00
parent a322a1d2fa
commit db0cf1d4a2
3 changed files with 136 additions and 13 deletions

View File

@ -251,8 +251,8 @@ public class AssetManager {
for(int i = 0; i < 10; i ++){ for(int i = 0; i < 10; i ++){
for(int j = 0; j < 6; j++){ 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); lightTank l = new lightTank(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0);
addHeavyTank(l); addLightTank(l);
//l.hasMultiShotUpgrade = true; //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); //lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 18.625f + j*0.25f), 90, 0);

View File

@ -3,6 +3,7 @@ package enemyAI;
import core.baseInfo; import core.baseInfo;
import core.mainThread; import core.mainThread;
import core.vector; import core.vector;
import entity.lightTank;
import entity.solidObject; import entity.solidObject;
import entity.stealthTank; import entity.stealthTank;
@ -19,6 +20,7 @@ public class defenseManagerAI {
public solidObject[] observers; public solidObject[] observers;
public solidObject[] stealthTanksControlledByCombatAI; public solidObject[] stealthTanksControlledByCombatAI;
public solidObject[] lightTanksControlledByCombatAI;
public solidObject[] defenders; public solidObject[] defenders;
public int numOfDefenders; public int numOfDefenders;
@ -53,6 +55,7 @@ public class defenseManagerAI {
currentState = mainThread.ec.theCombatManagerAI.currentState; currentState = mainThread.ec.theCombatManagerAI.currentState;
stealthTanksControlledByCombatAI = mainThread.ec.theUnitProductionAI.stealthTanksControlledByCombatAI; 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 //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) { 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 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; return false;
} }
@ -155,13 +276,17 @@ public class defenseManagerAI {
public void addUnitToDefenders(solidObject o) { public void addUnitToDefenders(solidObject o) {
numOfDefenders = 0; numOfDefenders = 0;
boolean defenersInStandbyMode = true;
for(int i = 0; i < defenders.length; i++) { 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++; 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--) for(int i = defenders.length - 1; i > 0; i--)
defenders[i] = defenders[i - 1]; defenders[i] = defenders[i - 1];
defenders[0] = o; defenders[0] = o;
@ -169,6 +294,7 @@ public class defenseManagerAI {
for(int i = 0; i < defenders.length; i++) { for(int i = 0; i < defenders.length; i++) {
if(defenders[i] == null || defenders[i].currentHP <= 0) { if(defenders[i] == null || defenders[i].currentHP <= 0) {
defenders[i] = o; defenders[i] = o;
numOfDefenders++;
break; break;
} }
} }

View File

@ -34,7 +34,7 @@ public class unitProductionAI {
public final int produceHeavyTank = 3; public final int produceHeavyTank = 3;
public vector rallyPoint; public vector rallyPoint;
public int unitProduced; //public int unitProduced;
public int numberOfCombatUnit; public int numberOfCombatUnit;
public int numberOfUnitInCombatRadius; public int numberOfUnitInCombatRadius;
public int numberOfUnitOutsideCombatRadius; public int numberOfUnitOutsideCombatRadius;
@ -252,7 +252,6 @@ public class unitProductionAI {
for(int i = 0; i < lightTanksControlledByCombatAI.length; i++){ for(int i = 0; i < lightTanksControlledByCombatAI.length; i++){
if(lightTanksControlledByCombatAI[i] == null || (lightTanksControlledByCombatAI[i] != null && lightTanksControlledByCombatAI[i].currentHP <=0)){ if(lightTanksControlledByCombatAI[i] == null || (lightTanksControlledByCombatAI[i] != null && lightTanksControlledByCombatAI[i].currentHP <=0)){
lightTanksControlledByCombatAI[i] = o; lightTanksControlledByCombatAI[i] = o;
unitProduced++;
mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o); mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o);
break; break;
} }
@ -268,7 +267,6 @@ public class unitProductionAI {
for(int i = 0; i < rocketTanksControlledByCombatAI.length; i++){ for(int i = 0; i < rocketTanksControlledByCombatAI.length; i++){
if(rocketTanksControlledByCombatAI[i] == null || (rocketTanksControlledByCombatAI[i] != null && rocketTanksControlledByCombatAI[i].currentHP <=0)){ if(rocketTanksControlledByCombatAI[i] == null || (rocketTanksControlledByCombatAI[i] != null && rocketTanksControlledByCombatAI[i].currentHP <=0)){
rocketTanksControlledByCombatAI[i] = o; rocketTanksControlledByCombatAI[i] = o;
unitProduced++;
break; break;
} }
} }
@ -293,7 +291,7 @@ public class unitProductionAI {
for(int i = 0; i < stealthTanksControlledByCombatAI.length; i++){ for(int i = 0; i < stealthTanksControlledByCombatAI.length; i++){
if(stealthTanksControlledByCombatAI[i] == null || (stealthTanksControlledByCombatAI[i] != null && stealthTanksControlledByCombatAI[i].currentHP <=0)){ if(stealthTanksControlledByCombatAI[i] == null || (stealthTanksControlledByCombatAI[i] != null && stealthTanksControlledByCombatAI[i].currentHP <=0)){
stealthTanksControlledByCombatAI[i] = o; stealthTanksControlledByCombatAI[i] = o;
unitProduced++;
mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o); mainThread.ec.theDefenseManagerAI.addUnitToDefenders(o);
break; break;
} }
@ -305,7 +303,6 @@ public class unitProductionAI {
for(int i = 0; i < heavyTanksControlledByCombatAI.length; i++){ for(int i = 0; i < heavyTanksControlledByCombatAI.length; i++){
if(heavyTanksControlledByCombatAI[i] == null || (heavyTanksControlledByCombatAI[i] != null && heavyTanksControlledByCombatAI[i].currentHP <=0)){ if(heavyTanksControlledByCombatAI[i] == null || (heavyTanksControlledByCombatAI[i] != null && heavyTanksControlledByCombatAI[i].currentHP <=0)){
heavyTanksControlledByCombatAI[i] = o; heavyTanksControlledByCombatAI[i] = o;
unitProduced++;
break; break;
} }
} }