From eb21e15d5152754dc8aa6dbecc8d877a7120be81 Mon Sep 17 00:00:00 2001
From: Pan Hu
Date: Fri, 18 Jan 2019 16:53:00 +1300
Subject: [PATCH] work commit
---
core/AssetManager.java | 4 ++--
enemyAI/defenseManagerAI.java | 35 ++++++++++++++++++++++++++++++++++-
enemyAI/mapAwarenessAI.java | 1 +
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/core/AssetManager.java b/core/AssetManager.java
index ef73f32..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++){
- //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 2eb162a..9c3acea 100644
--- a/enemyAI/defenseManagerAI.java
+++ b/enemyAI/defenseManagerAI.java
@@ -26,10 +26,12 @@ public class defenseManagerAI {
public int numOfDefenders;
public vector direction;
+ public vector threatToBaseDirection;
public vector minorThreatLocation;
public vector majorThreatLocation;
+
public defenseManagerAI(baseInfo theBaseInfo){
this.theBaseInfo = theBaseInfo;
@@ -38,6 +40,7 @@ public class defenseManagerAI {
defenders = new solidObject[5];
direction = new vector(0,0,0);
+ threatToBaseDirection = new vector(0,0,0);
minorThreatLocation = new vector(0,0,0);
majorThreatLocation = new vector(0,0,0);
@@ -129,6 +132,7 @@ public class defenseManagerAI {
minorThreatLocation.reset();
majorThreatLocation.reset();
+ System.out.println(playerForceIsMovingTwoardsBase(mainPlayerForceLocation, mainPlayerForceDirection));
// 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 && mainPlayerForceSize>0) {
@@ -158,7 +162,17 @@ public class defenseManagerAI {
}
}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))
+ if(playerForceIsNearBase(mainPlayerForceLocation)) {
+ giveBackControlOfDefendersToCombatAI();
+ majorThreatLocation.set(mainPlayerForceLocation);
+ }else {
+ float d = playerForceIsMovingTwoardsBase(mainPlayerForceLocation, mainPlayerForceDirection);
+ if(d != -1) {
+ giveBackControlOfDefendersToCombatAI();
+ majorThreatLocation.set(mainPlayerForceLocation);
+ majorThreatLocation.add(mainPlayerForceDirection, d);
+ }
+ }
}
@@ -205,6 +219,25 @@ public class defenseManagerAI {
}
+ public float playerForceIsMovingTwoardsBase(vector location, vector direction) {
+ for(int i = 0; i < mainThread.theAssetManager.refineries.length;i++) {
+ if(mainThread.theAssetManager.refineries[i] != null && mainThread.theAssetManager.refineries[i].teamNo != 0) {
+ float xPos = mainThread.theAssetManager.refineries[i].nearestGoldMine.centre.x;
+ float zPos = mainThread.theAssetManager.refineries[i].nearestGoldMine.centre.z;
+
+ threatToBaseDirection.set(xPos - location.x, 0, zPos - location.z);
+ float d = threatToBaseDirection.getLength();
+ threatToBaseDirection.unit();
+ if(threatToBaseDirection.dot(direction) > 0.8) {
+
+ return Math.max(3f, d - 3f);
+ }
+ }
+ }
+
+ return -1;
+ }
+
public void giveBackControlOfDefendersToCombatAI() {
for(int i = 0; i < defenders.length; i++) {
if(defenders[i] == null)
diff --git a/enemyAI/mapAwarenessAI.java b/enemyAI/mapAwarenessAI.java
index 05f6d2a..c71f8f1 100644
--- a/enemyAI/mapAwarenessAI.java
+++ b/enemyAI/mapAwarenessAI.java
@@ -611,6 +611,7 @@ public class mapAwarenessAI {
}
}
+ mainPlayerForceDirection.unit();
//System.out.println(mainPlayerForceSize + " " + mainPlayerForceLocation + " " + mainPlayerForceDirection);
}