mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-25 05:58:14 +07:00
Better DefenderAI / Vela building / Anuken/Mindustry-Suggestions/issues/2074
This commit is contained in:
parent
0c28bb7dcf
commit
b6c645b701
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 mindustry.entities.*;
|
||||
import mindustry.entities.Units.*;
|
||||
import mindustry.entities.comp.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.meta.*;
|
||||
@ -12,23 +12,29 @@ public class DefenderAI extends AIController{
|
||||
@Override
|
||||
public void updateMovement(){
|
||||
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);
|
||||
}else{
|
||||
Teamc block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
||||
if(block == null) block = unit.closestCore();
|
||||
moveTo(block, 60f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
||||
//Sort by max health and closer target.
|
||||
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);
|
||||
//find unit to follow if not in rally mode
|
||||
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;
|
||||
canDrown = false;
|
||||
mechFrontSway = 1f;
|
||||
buildSpeed = 3f;
|
||||
|
||||
mechStepParticles = true;
|
||||
mechStepShake = 0.15f;
|
||||
ammoType = AmmoTypes.powerHigh;
|
||||
|
||||
speed = 0.36f;
|
||||
boostMultiplier = 2.1f;
|
||||
speed = 0.38f;
|
||||
boostMultiplier = 2.2f;
|
||||
engineOffset = 12f;
|
||||
engineSize = 6f;
|
||||
lowAltitude = true;
|
||||
|
@ -266,20 +266,20 @@ public class Units{
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Returns the closest ally of this team using a custom comparison function. Filter by predicate. */
|
||||
public static Unit closest(Team team, float x, float y, Boolf<Unit> predicate, Sortf sort){
|
||||
/** Returns the closest ally of this team in a range. Filter by predicate. */
|
||||
public static Unit closest(Team team, float x, float y, float range, Boolf<Unit> predicate, Sortf sort){
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
for(Unit e : Groups.unit){
|
||||
if(!predicate.get(e) || e.team() != team) continue;
|
||||
nearby(team, x, y, range, e -> {
|
||||
if(!predicate.get(e)) return;
|
||||
|
||||
float cost = sort.cost(e, x, y);
|
||||
if(result == null || cost < cdist){
|
||||
float dist = sort.cost(e, x, y);
|
||||
if(result == null || dist < cdist){
|
||||
result = e;
|
||||
cdist = cost;
|
||||
cdist = dist;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user