From b28f027080f81419b5dfaa60b650953ff0837cc2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 28 Feb 2022 18:50:04 -0500 Subject: [PATCH] Erekir rebalance / RTS AI improvements --- core/src/mindustry/ai/RtsAI.java | 17 ++++---- .../src/mindustry/content/ErekirTechTree.java | 39 +++++++++++++++++++ core/src/mindustry/input/DesktopInput.java | 2 + 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/ai/RtsAI.java b/core/src/mindustry/ai/RtsAI.java index 675cbd4daa..56643587b3 100644 --- a/core/src/mindustry/ai/RtsAI.java +++ b/core/src/mindustry/ai/RtsAI.java @@ -28,7 +28,7 @@ public class RtsAI{ static final float squadRadius = 120f; static final int timeUpdate = 0, timerSpawn = 1; //TODO make configurable - static final float minWeight = 1.1f; + static final float minWeight = 1f; //in order of priority?? static final BlockFlag[] flags = {BlockFlag.generator, BlockFlag.factory, BlockFlag.core, BlockFlag.battery}; @@ -232,7 +232,7 @@ public class RtsAI{ weights.clear(); for(var target : targets){ - weights.put(target, estimateStats(target.x, target.y, dps, health)); + weights.put(target, estimateStats(x, y, target.x, target.y, dps, health)); } var result = targets.min( @@ -253,21 +253,22 @@ public class RtsAI{ return result; } - float estimateStats(float x, float y, float selfDps, float selfHealth){ + float estimateStats(float fromX, float fromY, float x, float y, float selfDps, float selfHealth){ float[] health = {0f}, dps = {0f}; - float extraRadius = 15f; + float extraRadius = 30f; - //TODO this does not take into account the path to this object for(var turret : Vars.indexer.getEnemy(data.team, BlockFlag.turret)){ - if(turret.within(x, y, ((TurretBuild)turret).range() + extraRadius)){ + if(Intersector.distanceSegmentPoint(fromX, fromY, x, y, turret.x, turret.y) <= ((TurretBuild)turret).range() + extraRadius){ health[0] += turret.health; dps[0] += ((TurretBuild)turret).estimateDps(); } } + Tmp.r1.set(fromX, fromY, x - fromX, y - fromY).normalize().grow(140f * 2f); + //add on extra radius, assume unit range is below that...? - Units.nearbyEnemies(data.team, x, y, extraRadius + 140f, other -> { - if(other.within(x, y, other.range() + extraRadius)){ + Units.nearbyEnemies(data.team, Tmp.r1, other -> { + if(Intersector.distanceSegmentPoint(fromX, fromY, x, y, other.x, other.y) <= other.range() + extraRadius){ health[0] += other.health; dps[0] += other.type.dpsEstimate; } diff --git a/core/src/mindustry/content/ErekirTechTree.java b/core/src/mindustry/content/ErekirTechTree.java index 73c11adf3e..19d588d2b2 100644 --- a/core/src/mindustry/content/ErekirTechTree.java +++ b/core/src/mindustry/content/ErekirTechTree.java @@ -1,16 +1,55 @@ package mindustry.content; import arc.struct.*; +import arc.util.*; +import mindustry.entities.bullet.*; import mindustry.game.Objectives.*; import mindustry.type.*; +import mindustry.type.unit.*; +import mindustry.world.blocks.defense.turrets.*; +import static mindustry.Vars.*; import static mindustry.content.Blocks.*; import static mindustry.content.SectorPresets.*; import static mindustry.content.TechTree.*; public class ErekirTechTree{ + static IntSet balanced = new IntSet(); + + static void rebalanceBullet(BulletType bullet){ + if(balanced.add(bullet.id)){ + bullet.damage *= 0.7f; + } + } + + //TODO remove this + public static void rebalance(){ + for(var unit : content.units().select(u -> u instanceof ErekirUnitType)){ + for(var weapon : unit.weapons){ + rebalanceBullet(weapon.bullet); + } + } + + for(var block : content.blocks()){ + if(block instanceof Turret turret && Structs.contains(block.requirements, i -> !Items.serpuloItems.contains(i.item))){ + if(turret instanceof ItemTurret item){ + for(var bullet : item.ammoTypes.values()){ + rebalanceBullet(bullet); + } + }else if(turret instanceof ContinuousTurret cont){ + rebalanceBullet(cont.shootType); + }else if(turret instanceof ContinuousLiquidTurret cont){ + for(var bullet : cont.ammoTypes.values()){ + rebalanceBullet(bullet); + } + } + } + } + } public static void load(){ + rebalance(); + //TODO might be unnecessary with no asteroids Seq erekirSector = Seq.with(new OnPlanet(Planets.erekir)); diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 03ebd3d80d..0482c1c1fa 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -115,6 +115,8 @@ public class DesktopInput extends InputHandler{ } if(commandMode){ + //happens sometimes + selectedUnits.removeAll(u -> !u.isCommandable()); //draw command overlay UI for(Unit unit : selectedUnits){