From 0de1bec554573cf59a682ecc0606c26a7a39a1b8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 26 Jul 2024 23:29:28 -0400 Subject: [PATCH] Fixed #10046 --- core/src/mindustry/ai/ControlPathfinder.java | 6 ++++++ core/src/mindustry/ai/RtsAI.java | 14 ++++++++------ core/src/mindustry/entities/bullet/BulletType.java | 11 +++++++++-- .../entities/bullet/PointLaserBulletType.java | 1 + core/src/mindustry/entities/comp/UnitComp.java | 2 +- .../blocks/defense/turrets/ContinuousTurret.java | 6 ++++++ gradle.properties | 2 +- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/src/mindustry/ai/ControlPathfinder.java b/core/src/mindustry/ai/ControlPathfinder.java index 261d1073b2..be200eecda 100644 --- a/core/src/mindustry/ai/ControlPathfinder.java +++ b/core/src/mindustry/ai/ControlPathfinder.java @@ -1017,6 +1017,12 @@ public class ControlPathfinder implements Runnable{ var nodePath = clusterAstar(request, costId, node, dest); + //no result found, bail out. + if(nodePath == null){ + request.notFound = true; + return; + } + FieldCache cache = fields.get(Pack.longInt(goalPos, costId)); //if true, extra values are added on the sides of existing field cells that face new cells. boolean addingFrontier = true; diff --git a/core/src/mindustry/ai/RtsAI.java b/core/src/mindustry/ai/RtsAI.java index 92025da099..16fcf3ec7a 100644 --- a/core/src/mindustry/ai/RtsAI.java +++ b/core/src/mindustry/ai/RtsAI.java @@ -19,6 +19,7 @@ import mindustry.logic.*; import mindustry.ui.*; import mindustry.world.*; import mindustry.world.blocks.defense.turrets.BaseTurret.*; +import mindustry.world.blocks.defense.turrets.*; import mindustry.world.blocks.storage.*; import mindustry.world.blocks.storage.CoreBlock.*; import mindustry.world.meta.*; @@ -111,7 +112,8 @@ public class RtsAI{ for(var unit : data.units){ if(used.add(unit.id) && unit.isCommandable() && !unit.command().hasCommand() && !unit.command().isAttacking()){ squad.clear(); - data.tree().intersect(unit.x - squadRadius/2f, unit.y - squadRadius/2f, squadRadius, squadRadius, squad); + float rad = squadRadius + unit.hitSize*1.5f; + data.tree().intersect(unit.x - rad/2f, unit.y - rad/2f, rad, rad, squad); squad.truncate(data.team.rules().rtsMaxSquad); @@ -245,7 +247,7 @@ public class RtsAI{ } } - var build = anyDefend ? null : findTarget(ax, ay, units.size, dps, health, units.first().flag == 0); + var build = anyDefend ? null : findTarget(ax, ay, units.size, dps, health, units.first().flag == 0, units.first().isFlying()); if(build != null || anyDefend){ for(var unit : units){ @@ -268,7 +270,7 @@ public class RtsAI{ return anyDefend; } - @Nullable Building findTarget(float x, float y, int total, float dps, float health, boolean checkWeight){ + @Nullable Building findTarget(float x, float y, int total, float dps, float health, boolean checkWeight, boolean air){ if(total < data.team.rules().rtsMinSquad) return null; //flag priority? @@ -290,7 +292,7 @@ public class RtsAI{ targets.truncate(maxTargetsChecked); for(var target : targets){ - weights.put(target, estimateStats(x, y, target.x, target.y, dps, health)); + weights.put(target, estimateStats(x, y, target.x, target.y, dps, health, air)); } var result = targets.min( @@ -312,12 +314,12 @@ public class RtsAI{ } //TODO extremely slow especially with many squads. - float estimateStats(float fromX, float fromY, float x, float y, float selfDps, float selfHealth){ + float estimateStats(float fromX, float fromY, float x, float y, float selfDps, float selfHealth, boolean air){ float[] health = {0f}, dps = {0f}; float extraRadius = 50f; for(var turret : Vars.indexer.getEnemy(data.team, BlockFlag.turret)){ - if(turret instanceof BaseTurretBuild t && Intersector.distanceSegmentPoint(fromX, fromY, x, y, t.x, t.y) <= t.range() + extraRadius){ + if(turret instanceof BaseTurretBuild t && turret.block instanceof Turret tb && ((tb.targetAir && air) || (tb.targetGround && !air)) && Intersector.distanceSegmentPoint(fromX, fromY, x, y, t.x, t.y) <= t.range() + extraRadius){ health[0] += t.health; dps[0] += t.estimateDps(); } diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 85bd903395..74fb8a7365 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -309,6 +309,8 @@ public class BulletType extends Content implements Cloneable{ /** Color of light emitted by this bullet. */ public Color lightColor = Pal.powerLight; + protected float cachedDps = -1; + public BulletType(float speed, float damage){ this.speed = speed; this.damage = damage; @@ -338,15 +340,20 @@ public class BulletType extends Content implements Cloneable{ /** @return estimated damage per shot. this can be very inaccurate. */ public float estimateDPS(){ + if(cachedDps >= 0f) return cachedDps; + if(spawnUnit != null){ return spawnUnit.estimateDps(); } - float sum = damage + splashDamage*0.75f; + float sum = damage * (pierce ? pierceCap == -1 ? 2 : Mathf.clamp(pierceCap, 1, 2) : 1f) * splashDamage*0.75f; if(fragBullet != null && fragBullet != this){ sum += fragBullet.estimateDPS() * fragBullets / 2f; } - return sum; + for(var other : spawnBullets){ + sum += other.estimateDPS(); + } + return cachedDps = sum; } /** @return maximum distance the bullet this bullet type has can travel. */ diff --git a/core/src/mindustry/entities/bullet/PointLaserBulletType.java b/core/src/mindustry/entities/bullet/PointLaserBulletType.java index 8e96579a5b..ca81ce7ad7 100644 --- a/core/src/mindustry/entities/bullet/PointLaserBulletType.java +++ b/core/src/mindustry/entities/bullet/PointLaserBulletType.java @@ -118,6 +118,7 @@ public class PointLaserBulletType extends BulletType{ } } + @Override public void updateBulletInterval(Bullet b){ if(intervalBullet != null && b.time >= intervalDelay && b.timer.get(2, bulletInterval)){ float ang = b.rotation(); diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 63f30a4fc8..ffa2bc3592 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -792,6 +792,6 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I @Override @Replace public String toString(){ - return "Unit#" + id() + ":" + type; + return "Unit#" + id() + ":" + type + " (" + x + ", " + y + ")"; } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java index e2cbcadffc..cfd5171b41 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java @@ -38,6 +38,12 @@ public class ContinuousTurret extends Turret{ public Seq bullets = new Seq<>(); public float lastLength = size * 4f; + @Override + public float estimateDps(){ + if(!hasAmmo()) return 0f; + return shootType.damage * 60f / (shootType instanceof ContinuousBulletType c ? c.damageInterval : 5f); + } + @Override protected void updateCooling(){ //TODO how does coolant work here, if at all? diff --git a/gradle.properties b/gradle.properties index d3e15e0aac..5c00967a82 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ org.gradle.caching=true org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 android.enableR8.fullMode=false -archash=2986baf556 +archash=1fdfcdc213