From 41128489655c6a88e75b8d16d2234fdfb7a17b4c Mon Sep 17 00:00:00 2001 From: mtroyka Date: Thu, 4 Aug 2016 00:21:31 -0400 Subject: [PATCH] -Reduced the size of influence maps by 4x in each dimension, reducing memory usage and threatmap update times by 16x. -Replaced cached drawing for enemy porc with real-time updates so that raiders won't run away from 1hp llts. -Various other minor tweaks --- src/zkgbai/ZKGraphBasedAI.java | 7 +- src/zkgbai/economy/EconomyManager.java | 40 ++-- src/zkgbai/economy/Factory.java | 5 + src/zkgbai/economy/FactoryManager.java | 31 +++- src/zkgbai/graph/GraphManager.java | 46 ++--- src/zkgbai/military/Enemy.java | 10 +- src/zkgbai/military/MilitaryManager.java | 174 +++++++----------- src/zkgbai/military/UnitClasses.java | 1 - .../fighterhandlers/RaiderHandler.java | 22 --- src/zkgbai/military/unitwrappers/Squad.java | 2 +- 10 files changed, 158 insertions(+), 180 deletions(-) diff --git a/src/zkgbai/ZKGraphBasedAI.java b/src/zkgbai/ZKGraphBasedAI.java index 0357e81..4512479 100644 --- a/src/zkgbai/ZKGraphBasedAI.java +++ b/src/zkgbai/ZKGraphBasedAI.java @@ -17,6 +17,7 @@ import zkgbai.economy.EconomyManager; import zkgbai.economy.FactoryManager; +import zkgbai.economy.tasks.ConstructionTask; import zkgbai.graph.GraphManager; import zkgbai.graph.MetalSpot; import zkgbai.gui.DebugView; @@ -191,7 +192,11 @@ public int update(int frame) { @Override public int message(int player, String message) { - for (Module module : modules) { + /*if (message.equals("kgbdebug")){ + //add debugging code here + }*/ + + for (Module module : modules) { try { module.message(player, message); } catch (Throwable e) { diff --git a/src/zkgbai/economy/EconomyManager.java b/src/zkgbai/economy/EconomyManager.java index f728d5b..0aa6752 100644 --- a/src/zkgbai/economy/EconomyManager.java +++ b/src/zkgbai/economy/EconomyManager.java @@ -35,7 +35,7 @@ public class EconomyManager extends Module { List windTasks; List fusionTasks; List pylonTasks; - List porcTasks; + public List porcTasks; List nanoTasks; List AATasks; List airpadTasks; @@ -225,7 +225,7 @@ public int update(int frame) { // remove finished or invalidated tasks cleanOrders(); - if (effectiveIncome > 30){ + if (defendedFac){ defendLinks(); } } @@ -251,7 +251,7 @@ public int update(int frame) { } } - if (frame % 3 == 0) { + if (frame % 6 == 0) { assignWorkers(); // assign workers to tasks } @@ -339,7 +339,8 @@ public int unitDamaged(Unit h, Unit attacker, float damage, AIFloat3 dir, Weapon } // defender push against enemy porc - if (attacker != null && attacker.getMaxSpeed() == 0 && h.getMaxSpeed() > 0 && frame - lastPorcPushFrame > 15) { + if (attacker != null && attacker.getMaxSpeed() == 0 && h.getMaxSpeed() > 0 + && frame - lastPorcPushFrame > 15 && graphManager.isAllyTerritory(h.getPos())) { lastPorcPushFrame = frame; porcPush(h, attacker); } @@ -608,7 +609,7 @@ public int enemyEnterLOS(Unit e){ } // porc over enemy mexes - if (e.getDef().getName().equals("cormex")){ + if (e.getDef().getName().equals("cormex") && graphManager.isAllyTerritory(e.getPos())){ fortifyMex(e.getPos()); } @@ -976,6 +977,10 @@ void cleanOrders(){ idlers.addAll(idle); invalidtasks.add(rt); } + }else{ + List idle = rt.stopWorkers(frame); + idlers.addAll(idle); + invalidtasks.add(rt); } } reclaimTasks.removeAll(invalidtasks); @@ -1097,7 +1102,7 @@ void generateTasks(Worker worker){ float eRatio; if (effectiveIncomeMetal > 25f && eFac){ - eRatio = 1.5f + (((float)fusions.size())/2f); + eRatio = 2.0f + (((float)fusions.size())/2f); }else if (effectiveIncomeMetal > 20f || eFac) { eRatio = 1.3f + (((float)fusions.size())/2f); }else{ @@ -1245,7 +1250,7 @@ void createFactoryTask(Worker worker){ } /*if (facManager.factories.size() == 0){ - String facName = "factoryshield"; + String facName = "factorycloak"; factory = callback.getUnitDefByName(facName); potentialFacList.remove(facName); }else*/ if ((facManager.factories.size() < 2 && !hasShields) || hasStriders) { @@ -1463,14 +1468,16 @@ void defendLink(AIFloat3 position){ porcTasks.add(ct); } - for (int i = 0; i < 2; i++) { - position = getRadialPoint(position, 100f); - position = callback.getMap().findClosestBuildSite(defender, position, 600f, 3, 0); + if (effectiveIncome > 20) { + for (int i = 0; i < 2; i++) { + position = getRadialPoint(position, 100f); + position = callback.getMap().findClosestBuildSite(defender, position, 600f, 3, 0); - ct = new ConstructionTask(defender, position, 0); - if (buildCheck(ct) && !porcTasks.contains(ct)) { - constructionTasks.add(ct); - porcTasks.add(ct); + ct = new ConstructionTask(defender, position, 0); + if (buildCheck(ct) && !porcTasks.contains(ct)) { + constructionTasks.add(ct); + porcTasks.add(ct); + } } } } @@ -1667,7 +1674,7 @@ void captureMexes(){ void defendLinks(){ for (Link l:graphManager.getLinks()){ - if (l.length < 600){ + if (l.length < 600 && graphManager.isAllyTerritory(l.getPos())){ defendLink(l.getPos()); } } @@ -1930,6 +1937,9 @@ Worker getCaretakerTarget(){ void collectReclaimables(){ List feats = callback.getFeatures(); for (Feature f : feats) { + if (reclaimTasks.size() > facManager.numWorkers){ + break; + } if (f.getDef().getContainedResource(m) > 0){ ReclaimTask rt = new ReclaimTask(f, f.getDef().getContainedResource(m)); if (!reclaimTasks.contains(rt)){ diff --git a/src/zkgbai/economy/Factory.java b/src/zkgbai/economy/Factory.java index c47c915..ac241bf 100644 --- a/src/zkgbai/economy/Factory.java +++ b/src/zkgbai/economy/Factory.java @@ -31,6 +31,11 @@ public Factory(Unit u, boolean firstFac){ raiderSpam = -4; } + if (u.getDef().getName().equals("factoryhover")){ + raiderSpam = -4; + expensiveRaiderSpam = -2; + } + if (u.getDef().getName().equals("factoryspider")){ raiderSpam = -9; } diff --git a/src/zkgbai/economy/FactoryManager.java b/src/zkgbai/economy/FactoryManager.java index 32645f3..4e57ace 100644 --- a/src/zkgbai/economy/FactoryManager.java +++ b/src/zkgbai/economy/FactoryManager.java @@ -39,6 +39,8 @@ public class FactoryManager extends Module { boolean enemyHasAmphs = false; boolean enemyHasHeavyPorc = false; + boolean glaiveSpam = false; + public int numWorkers = 0; float workerValue = 0; float fighterValue = 0; @@ -138,7 +140,7 @@ public int unitCreated(Unit unit, Unit builder) { }else{ fac = new Factory(unit, false); } - if (defName.equals("factoryspider") || defName.equals("factoryamph") || defName.equals("factoryveh")){ + if (defName.equals("factoryspider") || defName.equals("factoryamph") || defName.equals("factoryveh") || defName.equals("factoryhover")){ earlyWorker = true; } factories.put(fac.id, fac); @@ -481,8 +483,12 @@ private Boolean needWorkers(Factory fac){ float metalratio = 4.0f; float workerRatio; - if (facType.equals("factorytank") /*|| facType.equals("factoryamph") || facType.equals("factoryspider")*/){ - workerRatio = 2f + (economyManager.effectiveIncome/200f); + if (facType.equals("factorytank")){ + if (bigMap) { + workerRatio = 1.5f; + }else{ + workerRatio = 2f; + } }else if (bigMap){ workerRatio = 1.5f + (economyManager.effectiveIncome/100f); }else{ @@ -498,6 +504,7 @@ private Boolean needWorkers(Factory fac){ if ((float) numWorkers < Math.floor(economyManager.effectiveIncomeMetal/metalratio) + ((warManager.miscHandler.striders.size() + economyManager.fusions.size() + numFunnels + factories.size() - 1) * 3) && (fighterValue > workerValue * workerRatio || numWorkers == 0 || (economyManager.metal > 400 && economyManager.energy > 100)) || (earlyWorker && numWorkers < 2) + || (bigMap && numWorkers < 3) || (fac.getUnit().getDef().getName().equals("factoryshield") && !smallMap && numWorkers < 2)) { return true; }else if ((fac.raiderSpam >= 0 && numWorkers < 3 && !facType.equals("factorytank")) @@ -522,7 +529,7 @@ private String getCloaky(Factory fac) { fac.expensiveRaiderSpam++; return "spherepole"; } - if ((economyManager.effectiveIncome > 15 && numGlaives > 1 && Math.random() > 0.9)) { + if ((!glaiveSpam && economyManager.effectiveIncome > 15 && numGlaives > 1 && Math.random() > 0.9)) { fac.expensiveRaiderSpam -= (int) Math.min(4, Math.max(2, Math.floor(economyManager.effectiveIncome / 10))) - 1; return "spherepole"; } else { @@ -533,6 +540,10 @@ private String getCloaky(Factory fac) { } } + if (glaiveSpam){ + glaiveSpam = false; + } + if (((enemyHasAir || enemyHasDrones) && warManager.AAs.size() < 3) || (enemyHasAir && Math.random() > 0.70 + (0.05 * ((float) factories.size()-1f)))){ return "armjeth"; @@ -546,6 +557,11 @@ private String getCloaky(Factory fac) { return "armtick"; } + if (economyManager.effectiveIncome > 30 && Math.random() > 0.975){ + glaiveSpam = true; + fac.raiderSpam -= Math.min(12, Math.max(6, (int) Math.floor(economyManager.effectiveIncome/5f))); + } + double rand = Math.random(); if (economyManager.fusions.isEmpty()){ if (numRockos < 2 * (numWarriors + numZeus)) { @@ -691,7 +707,8 @@ private String getAmphs(Factory fac) { } private String getLV(Factory fac) { - if (earlyWorker && needWorkers(fac)) { + if (numWorkers < 2 + || (bigMap && numWorkers < 3)) { return "corned"; } @@ -707,7 +724,7 @@ private String getLV(Factory fac) { return "corgator"; } - if (!earlyWorker && needWorkers(fac)) { + if (needWorkers(fac)) { return "corned"; } @@ -771,7 +788,7 @@ private String getHovers(Factory fac) { } if (fac.raiderSpam < 0) { - if (fac.expensiveRaiderSpam < 0){ + if (fac.expensiveRaiderSpam < 0 && warManager.raiderHandler.soloRaiders.size() > 1){ fac.expensiveRaiderSpam++; return "hoverassault"; } diff --git a/src/zkgbai/graph/GraphManager.java b/src/zkgbai/graph/GraphManager.java index 1f837ab..c0196ee 100644 --- a/src/zkgbai/graph/GraphManager.java +++ b/src/zkgbai/graph/GraphManager.java @@ -91,8 +91,8 @@ public GraphManager(ZKGraphBasedAI ai){ pylonDefs.put("armfus", 150); pylonDefs.put("cafus", 150); - final int width = callback.getMap().getWidth(); - final int height = callback.getMap().getHeight(); + final int width = callback.getMap().getWidth()/4; + final int height = callback.getMap().getHeight()/4; this.frontLineGraphics = new ByteArrayGraphics(width, height); this.allyTerritoryGraphics = new ByteArrayGraphics(width, height); @@ -302,10 +302,10 @@ public int update(int uframe){ List frontLine = getFrontLineSpots(); for (MetalSpot ms: frontLine){ AIFloat3 pos = ms.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; - frontLineGraphics.paintCircle(x, y, 75, 1); + frontLineGraphics.paintCircle(x, y, 20, 1); } calcCenters(); @@ -320,10 +320,10 @@ private void setHostile(MetalSpot ms){ // paint territory circles AIFloat3 pos = ms.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; - enemyTerritoryGraphics.paintCircle(x, y, 100, 1); + enemyTerritoryGraphics.paintCircle(x, y, 25, 1); // set adjacent spots as enemyShadowed if they aren't already hostile for (Link l:ms.links){ @@ -343,10 +343,10 @@ private void setOwned(MetalSpot ms){ // paint territory circles AIFloat3 pos = ms.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; - allyTerritoryGraphics.paintCircle(x, y, 200, 1); + allyTerritoryGraphics.paintCircle(x, y, 50, 1); // set adjacent spots as allyShadowed if they aren't already owned for (Link l:ms.links){ @@ -365,20 +365,20 @@ private void setNeutral(MetalSpot ms){ // unpaint territory circles AIFloat3 pos = ms.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; - allyTerritoryGraphics.unpaintCircle(x, y, 200, 1); + allyTerritoryGraphics.unpaintCircle(x, y, 50, 1); } if (ms.hostile){ ms.enemyShadowed = true; // unpaint territory circles AIFloat3 pos = ms.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; - enemyTerritoryGraphics.unpaintCircle(x, y, 100, 1); + enemyTerritoryGraphics.unpaintCircle(x, y, 25, 1); } ms.hostile = false; ms.owned = false; @@ -604,22 +604,22 @@ public List getLinks(){ } public boolean isAllyTerritory(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return (allyTerritoryGraphics.getValue(x, y) > 0); } public boolean isEnemyTerritory(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return (enemyTerritoryGraphics.getValue(x, y) > 0); } public boolean isFrontLine(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return (frontLineGraphics.getValue(x, y) > 0); } diff --git a/src/zkgbai/military/Enemy.java b/src/zkgbai/military/Enemy.java index ee90156..95b23ea 100644 --- a/src/zkgbai/military/Enemy.java +++ b/src/zkgbai/military/Enemy.java @@ -14,6 +14,7 @@ public class Enemy { float threatRadius = 0; public float value = 0; float speed = 0; + float lastHealth = 0; public int lastSeen = 0; public boolean isPainted = false; boolean visible = false; @@ -151,13 +152,14 @@ public float getDanger(){ return 0; } - if (!isStatic) { + if (unit.getHealth() > 0) { health = unit.getHealth(); - danger = (ud.getPower() + health)/10; - } else { + }else if (lastHealth > 0){ + health = lastHealth; + }else{ health = ud.getHealth(); - danger = (ud.getPower() + health)/10; } + danger = (ud.getPower() + health)/10; if (isFlamer || ud.getName().equals("arm_venom") || ud.getName().equals("amphraider2")){ danger += 100; diff --git a/src/zkgbai/military/MilitaryManager.java b/src/zkgbai/military/MilitaryManager.java index b8aa965..100dc75 100644 --- a/src/zkgbai/military/MilitaryManager.java +++ b/src/zkgbai/military/MilitaryManager.java @@ -29,14 +29,10 @@ public class MilitaryManager extends Module { public java.util.Map AAs; RadarIdentifier radarID; - - int maxUnitPower = 0; - //Image threatmap; - //Graphics threatGraphics; + ArrayGraphics threatGraphics; ArrayGraphics allyThreatGraphics; ArrayGraphics allyPorcGraphics; - ArrayGraphics enemyPorcGraphics; ArrayGraphics aaThreatGraphics; ArrayGraphics aaPorcGraphics; public ArrayList targetMarkers; @@ -90,17 +86,15 @@ public MilitaryManager(ZKGraphBasedAI ai){ this.m = callback.getResourceByName("Metal"); targetMarkers = new ArrayList(); - width = ai.getCallback().getMap().getWidth(); - height = ai.getCallback().getMap().getHeight(); + width = ai.getCallback().getMap().getWidth()/4; + height = ai.getCallback().getMap().getHeight()/4; this.threatGraphics = new ArrayGraphics(width, height); this.allyThreatGraphics = new ArrayGraphics(width, height); this.allyPorcGraphics = new ArrayGraphics(width, height); - this.enemyPorcGraphics = new ArrayGraphics(width, height); this.aaThreatGraphics = new ArrayGraphics(width, height); this.aaPorcGraphics = new ArrayGraphics(width, height); allyPorcGraphics.clear(); - enemyPorcGraphics.clear(); aaPorcGraphics.clear(); try{ @@ -137,27 +131,27 @@ private void paintThreatMap(){ for (Raider r : raiderHandler.soloRaiders) { int power = (int) ((r.getUnit().getPower() + r.getUnit().getMaxHealth())/20); AIFloat3 pos = r.getPos(); - int x = (int) pos.x / 8; - int y = (int) pos.z / 8; - int rad = 50; + int x = (int) pos.x / 32; + int y = (int) pos.z / 32; + int rad = 13; allyThreatGraphics.paintCircle(x, y, rad, power); } for (Raider r : raiderHandler.smallRaiders.values()) { int power = (int) ((r.getUnit().getPower() + r.getUnit().getMaxHealth())/20); AIFloat3 pos = r.getPos(); - int x = (int) pos.x / 8; - int y = (int) pos.z / 8; - int rad = 50; + int x = (int) pos.x / 32; + int y = (int) pos.z / 32; + int rad = 13; allyThreatGraphics.paintCircle(x, y, rad, power); } for (Raider r : raiderHandler.mediumRaiders.values()) { int power = (int) ((r.getUnit().getPower() + r.getUnit().getMaxHealth())/20); AIFloat3 pos = r.getPos(); - int x = (int) pos.x / 8; - int y = (int) pos.z / 8; - int rad = 50; + int x = (int) pos.x / 32; + int y = (int) pos.z / 32; + int rad = 13; allyThreatGraphics.paintCircle(x, y, rad, power); } @@ -165,9 +159,9 @@ private void paintThreatMap(){ for (Fighter f : squadHandler.fighters.values()) { int power = (int) ((f.getUnit().getPower() + f.getUnit().getMaxHealth())/8); AIFloat3 pos = f.getPos(); - int x = (int) pos.x / 8; - int y = (int) pos.z / 8; - int rad = 150; + int x = (int) pos.x / 32; + int y = (int) pos.z / 32; + int rad = 40; allyThreatGraphics.paintCircle(x, y, rad, power); } @@ -176,14 +170,14 @@ private void paintThreatMap(){ for (Strider s : miscHandler.striders.values()) { int power = (int) ((s.getUnit().getPower() + s.getUnit().getMaxHealth())/5); AIFloat3 pos = s.getPos(); - int x = (int) pos.x / 8; - int y = (int) pos.z / 8; - int rad = 150; + int x = (int) pos.x / 32; + int y = (int) pos.z / 32; + int rad = 40; allyThreatGraphics.paintCircle(x, y, rad, power); } - // Note: threat and allythreat for porc are painted separately. + // Note: allythreat for porc is painted separately. for(Enemy t:targets.values()){ int effectivePower = (int) t.getDanger(); @@ -191,19 +185,23 @@ private void paintThreatMap(){ AIFloat3 position = t.position; if (position != null && t.ud != null + && effectivePower > 0 && !unitTypes.planes.contains(t.ud.getName()) && !t.unit.isBeingBuilt()) { - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((t.threatRadius) / 8); + int x = (int) (position.x / 32); + int y = (int) (position.z / 32); + int r = (int) ((t.threatRadius) / 32); - if (t.speed > 0) { + if (!t.isStatic) { // paint enemy threat for mobiles if (t.isAA){ aaThreatGraphics.paintCircle(x, y, (int) (r*1.5f), effectivePower); }else{ threatGraphics.paintCircle(x, y, (int) (r*1.5f), effectivePower); } + }else if (!t.isAA){ + // for statics + threatGraphics.paintCircle(x, y, (int) (r*1.25f), effectivePower); } } } @@ -224,36 +222,36 @@ private void paintThreatMap(){ } public float getThreat(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); - return (threatGraphics.getValue(x, y) + enemyPorcGraphics.getValue(x, y))/500f; + return (threatGraphics.getValue(x, y))/500f; } public float getEffectiveThreat(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); - return ((threatGraphics.getValue(x, y) + enemyPorcGraphics.getValue(x, y)) - (allyThreatGraphics.getValue(x, y) + allyPorcGraphics.getValue(x, y)))/500f; + return ((threatGraphics.getValue(x, y)) - (allyThreatGraphics.getValue(x, y) + allyPorcGraphics.getValue(x, y)))/500f; } public float getFriendlyThreat(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return allyThreatGraphics.getValue(x, y)/500f; } public float getAAThreat(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return (aaThreatGraphics.getValue(x, y) + aaPorcGraphics.getValue(x, y))/500f; } public float getEffectiveAAThreat(AIFloat3 position){ - int x = (int) (position.x/8); - int y = (int) (position.z/8); + int x = (int) (position.x/32); + int y = (int) (position.z/32); return ((aaThreatGraphics.getValue(x, y) + aaPorcGraphics.getValue(x, y)) - (allyThreatGraphics.getValue(x, y) + allyPorcGraphics.getValue(x, y)))/500f; } @@ -599,19 +597,15 @@ private void updateTargets() { // remove targets that aren't where we last saw them. outdated.add(t); - // Unpaint enemy threat for statics - if (t.getDanger() > 0 && t.isPainted) { + // Unpaint enemy threat for aa + if (t.isAA && t.isPainted) { int effectivePower = (int) t.getDanger(); AIFloat3 position = t.position; - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((t.threatRadius) / 8); + int x = (int) (position.x / 32); + int y = (int) (position.z / 32); + int r = (int) ((t.threatRadius) / 32); - if (t.isAA){ - aaPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); - }else { - enemyPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); - } + aaPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); } } } @@ -680,41 +674,15 @@ public int enemyEnterLOS(Unit enemy) { e.updateFromUnitDef(enemy.getDef(), enemy.getDef().getCost(metal)); } - // paint enemy threat for statics - if (e.isStatic && e.getDanger() > 0 && !e.isPainted && !e.unit.isBeingBuilt()) { + // paint enemy threat for aa + if (e.isStatic && e.isAA && !e.isPainted && !e.unit.isBeingBuilt()) { int effectivePower = (int) e.getDanger(); AIFloat3 position = e.position; - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((e.threatRadius) / 8); - - if (e.isAA){ - aaPorcGraphics.paintCircle(x, y, (int) (r*1.2f), effectivePower); - }else { - enemyPorcGraphics.paintCircle(x, y, (int) (r * 1.2f), effectivePower); - } - e.isPainted = true; - } - }else if (!enemy.isBeingBuilt() || !enemy.getDef().isAbleToMove()){ - Enemy e = new Enemy(enemy, enemy.getDef().getCost(metal)); - targets.put(enemy.getUnitId(),e); - e.visible = true; - e.setIdentified(); - e.lastSeen = frame; + int x = (int) (position.x / 32); + int y = (int) (position.z / 32); + int r = (int) ((e.threatRadius) / 32); - // paint enemy threat for statics - if (e.isStatic && e.getDanger() > 0 && !e.ud.getTooltip().contains("Anti-Air") && !e.unit.isBeingBuilt()) { - int effectivePower = (int) e.getDanger(); - AIFloat3 position = e.position; - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((e.threatRadius) / 8); - - if (e.isAA){ - aaPorcGraphics.paintCircle(x, y, (int) (r*1.2f), effectivePower); - }else { - enemyPorcGraphics.paintCircle(x, y, (int) (r * 1.2f), effectivePower); - } + aaPorcGraphics.paintCircle(x, y, (int) (r*1.2f), effectivePower); e.isPainted = true; } } @@ -725,15 +693,15 @@ public int enemyEnterLOS(Unit enemy) { public int enemyFinished(Unit enemy) { if(targets.containsKey(enemy.getUnitId())){ Enemy e = targets.get(enemy.getUnitId()); - // paint enemy threat for statics - if (e.isStatic && e.getDanger() > 0 && !e.ud.getTooltip().contains("Anti-Air") && !e.isPainted) { + // paint enemy threat for aa + if (e.isStatic && e.isAA && !e.isPainted) { int effectivePower = (int) e.getDanger(); AIFloat3 position = e.position; - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((e.threatRadius) / 8); + int x = (int) (position.x / 32); + int y = (int) (position.z / 32); + int r = (int) ((e.threatRadius) / 32); - enemyPorcGraphics.paintCircle(x, y, (int) (r*1.2f), effectivePower); + aaThreatGraphics.paintCircle(x, y, (int) (r*1.2f), effectivePower); e.isPainted = true; } }else{ @@ -794,18 +762,14 @@ public int enemyDestroyed(Unit unit, Unit attacker) { Enemy e = targets.get(unit.getUnitId()); // Unpaint enemy threat for statics - if (e.isStatic && e.getDanger() > 0 && e.isPainted) { + if (e.isStatic && e.isAA && e.isPainted) { int effectivePower = (int) e.getDanger(); AIFloat3 position = e.position; - int x = (int) (position.x / 8); - int y = (int) (position.z / 8); - int r = (int) ((e.threatRadius) / 8); + int x = (int) (position.x / 32); + int y = (int) (position.z / 32); + int r = (int) ((e.threatRadius) / 32); - if (e.isAA){ - aaPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); - }else { - enemyPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); - } + aaPorcGraphics.unpaintCircle(x, y, (int) (r * 1.2f), effectivePower); } e.position = null; @@ -930,9 +894,9 @@ public int unitCreated(Unit unit, Unit builder){ int power = (int) ((unit.getPower() + unit.getMaxHealth())/10); float radius = unit.getMaxRange(); AIFloat3 pos = unit.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; - int rad = (int) radius/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; + int rad = (int) radius/32; allyPorcGraphics.paintCircle(x, y, rad, power); } @@ -957,8 +921,6 @@ public int unitDestroyed(Unit unit, Unit attacker) { defenseTargets.add(dt); } - Fighter dead = null; - // create a defense task, if appropriate. if ((!unit.getDef().isAbleToAttack() || unit.getMaxSpeed() == 0 || distance(unit.getPos(), graphManager.getAllyCenter()) < distance(unit.getPos(), graphManager.getEnemyCenter())) && frame - lastDefenseFrame > 150){ @@ -992,9 +954,9 @@ public int unitDestroyed(Unit unit, Unit attacker) { int power = (int) ((unit.getPower() + unit.getMaxHealth())/10); float radius = unit.getMaxRange(); AIFloat3 pos = unit.getPos(); - int x = (int) pos.x/8; - int y = (int) pos.z/8; - int rad = (int) radius/8; + int x = (int) pos.x/32; + int y = (int) pos.z/32; + int rad = (int) radius/32; allyPorcGraphics.unpaintCircle(x, y, rad, power); } diff --git a/src/zkgbai/military/UnitClasses.java b/src/zkgbai/military/UnitClasses.java index 72d3392..4df0c7b 100644 --- a/src/zkgbai/military/UnitClasses.java +++ b/src/zkgbai/military/UnitClasses.java @@ -53,7 +53,6 @@ private UnitClasses(){ mediumRaiders.add("corgator"); mediumRaiders.add("armkam"); mediumRaiders.add("spherepole"); - mediumRaiders.add("hoverassault"); soloRaiders.add("hoverassault"); soloRaiders.add("logkoda"); diff --git a/src/zkgbai/military/fighterhandlers/RaiderHandler.java b/src/zkgbai/military/fighterhandlers/RaiderHandler.java index f6b01ca..139089e 100644 --- a/src/zkgbai/military/fighterhandlers/RaiderHandler.java +++ b/src/zkgbai/military/fighterhandlers/RaiderHandler.java @@ -128,19 +128,6 @@ public void addMediumRaider(Raider r) { nextScytheSquad.status = 'r'; nextScytheSquad = null; } - }else if (defName.equals("hoverassault")) { - // for scythes - if (nextHalberdSquad == null) { - nextHalberdSquad = new RaiderSquad(); - nextHalberdSquad.raid(warManager.getRaiderRally(r.getPos()), frame); - } - nextHalberdSquad.addUnit(r, frame); - - if (nextHalberdSquad.raiders.size() >= (int) min(4, max(2, floor(ecoManager.effectiveIncome / 10)))) { - raiderSquads.add(nextHalberdSquad); - nextHalberdSquad.status = 'r'; - nextHalberdSquad = null; - } } } @@ -331,15 +318,6 @@ private void assignRaiders(){ nextScytheSquad.sneak(graphManager.getClosestHaven(nextScytheSquad.getPos()), frame); } } - - if (nextHalberdSquad != null && !nextHalberdSquad.raiders.isEmpty()){ - boolean overThreat = (warManager.getEffectiveThreat(nextHalberdSquad.getPos()) > 0); - if (!overThreat) { - nextHalberdSquad.raid(warManager.getRaiderRally(nextHalberdSquad.getPos()), frame); - }else{ - nextHalberdSquad.sneak(graphManager.getClosestHaven(nextHalberdSquad.getPos()), frame); - } - } } // assign soloraid/scout group diff --git a/src/zkgbai/military/unitwrappers/Squad.java b/src/zkgbai/military/unitwrappers/Squad.java index cd27305..bfa31c0 100644 --- a/src/zkgbai/military/unitwrappers/Squad.java +++ b/src/zkgbai/military/unitwrappers/Squad.java @@ -43,7 +43,7 @@ public void addUnit(Fighter f, int frame){ public void removeUnit(Fighter f){ fighters.remove(f); - if (leader.equals(f)){ + if (leader != null && leader.equals(f)){ leader = getNewLeader(); } metalValue -= f.metalValue;