mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-12-22 23:34:00 +07:00
Fixed #10046
This commit is contained in:
parent
3a1a06e57f
commit
0de1bec554
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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. */
|
||||
|
@ -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();
|
||||
|
@ -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 + ")";
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,12 @@ public class ContinuousTurret extends Turret{
|
||||
public Seq<BulletEntry> 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?
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user