Better DefenderAI / Vela building / Anuken/Mindustry-Suggestions/issues/2074
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 338 B After Width: | Height: | Size: 514 B |
Binary file not shown.
|
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 536 B |
Binary file not shown.
|
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 430 B |
@@ -2,7 +2,7 @@ package mindustry.ai.types;
|
|||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.Units.*;
|
import mindustry.entities.comp.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
@@ -12,23 +12,29 @@ public class DefenderAI extends AIController{
|
|||||||
@Override
|
@Override
|
||||||
public void updateMovement(){
|
public void updateMovement(){
|
||||||
if(target != null){
|
if(target != null){
|
||||||
moveTo(target, unit.range(), 5f);
|
moveTo(target, (target instanceof Sized s ? s.hitSize()/2f * 1.1f : 0f) + unit.hitSize/2f + 15f, 50f);
|
||||||
unit.lookAt(target);
|
unit.lookAt(target);
|
||||||
}else{
|
|
||||||
Teamc block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
|
||||||
if(block == null) block = unit.closestCore();
|
|
||||||
moveTo(block, 60f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateTargeting(){
|
protected void updateTargeting(){
|
||||||
if(retarget()) target = findTarget(unit.x, unit.y, 0f, true, true);
|
if(retarget()) target = findTarget(unit.x, unit.y, unit.range(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
||||||
//Sort by max health and closer target.
|
//find unit to follow if not in rally mode
|
||||||
return Units.closest(unit.team, x, y, u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 800f);
|
if(command() != UnitCommand.rally){
|
||||||
|
//Sort by max health and closer target.
|
||||||
|
var result = Units.closest(unit.team, x, y, Math.max(range, 400f), u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 800f);
|
||||||
|
if(result != null) return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//find rally point
|
||||||
|
var block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
||||||
|
if(block != null) return block;
|
||||||
|
//return core if found
|
||||||
|
return unit.closestCore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -405,13 +405,14 @@ public class UnitTypes implements ContentList{
|
|||||||
rotateSpeed = 1.6f;
|
rotateSpeed = 1.6f;
|
||||||
canDrown = false;
|
canDrown = false;
|
||||||
mechFrontSway = 1f;
|
mechFrontSway = 1f;
|
||||||
|
buildSpeed = 3f;
|
||||||
|
|
||||||
mechStepParticles = true;
|
mechStepParticles = true;
|
||||||
mechStepShake = 0.15f;
|
mechStepShake = 0.15f;
|
||||||
ammoType = AmmoTypes.powerHigh;
|
ammoType = AmmoTypes.powerHigh;
|
||||||
|
|
||||||
speed = 0.36f;
|
speed = 0.38f;
|
||||||
boostMultiplier = 2.1f;
|
boostMultiplier = 2.2f;
|
||||||
engineOffset = 12f;
|
engineOffset = 12f;
|
||||||
engineSize = 6f;
|
engineSize = 6f;
|
||||||
lowAltitude = true;
|
lowAltitude = true;
|
||||||
|
|||||||
@@ -266,20 +266,20 @@ public class Units{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the closest ally of this team using a custom comparison function. Filter by predicate. */
|
/** Returns the closest ally of this team in a range. Filter by predicate. */
|
||||||
public static Unit closest(Team team, float x, float y, Boolf<Unit> predicate, Sortf sort){
|
public static Unit closest(Team team, float x, float y, float range, Boolf<Unit> predicate, Sortf sort){
|
||||||
result = null;
|
result = null;
|
||||||
cdist = 0f;
|
cdist = 0f;
|
||||||
|
|
||||||
for(Unit e : Groups.unit){
|
nearby(team, x, y, range, e -> {
|
||||||
if(!predicate.get(e) || e.team() != team) continue;
|
if(!predicate.get(e)) return;
|
||||||
|
|
||||||
float cost = sort.cost(e, x, y);
|
float dist = sort.cost(e, x, y);
|
||||||
if(result == null || cost < cdist){
|
if(result == null || dist < cdist){
|
||||||
result = e;
|
result = e;
|
||||||
cdist = cost;
|
cdist = dist;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user