Erekir rebalance / RTS AI improvements

This commit is contained in:
Anuken
2022-02-28 18:50:04 -05:00
parent 91a7c9179c
commit b28f027080
3 changed files with 50 additions and 8 deletions

View File

@@ -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;
}

View File

@@ -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<Objective> erekirSector = Seq.with(new OnPlanet(Planets.erekir));

View File

@@ -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){