mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 23:28:52 +07:00
Ground unit retreat attacking / Patrol attacking
This commit is contained in:
parent
db3dac261a
commit
b74ae302ec
@ -58,6 +58,12 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
if(target == null){
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
|
||||
if(target == null && isCommanded() && getCommand() == UnitCommand.patrol){
|
||||
setState(patrol);
|
||||
return;
|
||||
}
|
||||
|
||||
if(target == null) targetClosestEnemyFlag(BlockFlag.target);
|
||||
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
|
||||
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
|
||||
@ -82,9 +88,18 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
},
|
||||
patrol = new UnitState(){
|
||||
public void update(){
|
||||
target = getClosestCore();
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
|
||||
if(target != null){
|
||||
setState(attack);
|
||||
}
|
||||
|
||||
target = getClosestCore();
|
||||
});
|
||||
|
||||
if(target != null){
|
||||
circle(60f + Mathf.absin(Timers.time() + id*23525, 70f, 1200f));
|
||||
circle(60f + Mathf.absin(Timers.time() + id * 23525, 70f, 1200f));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -107,11 +122,6 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
}
|
||||
};
|
||||
|
||||
//instantiation only
|
||||
public FlyingUnit(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(UnitCommand command){
|
||||
state.set(command == UnitCommand.retreat ? retreat :
|
||||
|
@ -46,40 +46,16 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
if(core != null && dst < getWeapon().getAmmo().getRange() / 1.1f){
|
||||
target = core;
|
||||
}else{
|
||||
retarget(() -> targetClosest());
|
||||
}
|
||||
|
||||
if(target != null){
|
||||
if(core != null){
|
||||
if(dst > getWeapon().getAmmo().getRange() * 0.5f){
|
||||
moveToCore();
|
||||
}
|
||||
|
||||
}else{
|
||||
moveToCore();
|
||||
}
|
||||
|
||||
if(distanceTo(target) < getWeapon().getAmmo().getRange()){
|
||||
rotate(angleTo(target));
|
||||
|
||||
if(Mathf.angNear(angleTo(target), rotation, 13f)){
|
||||
AmmoType ammo = getWeapon().getAmmo();
|
||||
|
||||
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
|
||||
|
||||
getWeapon().update(GroundUnit.this, to.x, to.y);
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
if(dst > getWeapon().getAmmo().getRange() * 0.5f){
|
||||
moveToCore();
|
||||
}
|
||||
}
|
||||
},
|
||||
patrol = new UnitState(){
|
||||
public void update(){
|
||||
target = getClosestCore();
|
||||
TileEntity target = getClosestCore();
|
||||
if(target != null){
|
||||
if(distanceTo(target) > 400f){
|
||||
moveAwayFromCore();
|
||||
@ -214,6 +190,20 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
if(health <= health * type.retreatPercent && !isCommanded()){
|
||||
setState(retreat);
|
||||
}
|
||||
|
||||
if(!Units.invalidateTarget(target, this)){
|
||||
if(distanceTo(target) < getWeapon().getAmmo().getRange()){
|
||||
rotate(angleTo(target));
|
||||
|
||||
if(Mathf.angNear(angleTo(target), rotation, 13f)){
|
||||
AmmoType ammo = getWeapon().getAmmo();
|
||||
|
||||
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
|
||||
|
||||
getWeapon().update(GroundUnit.this, to.x, to.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -223,6 +213,8 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
if(Units.invalidateTarget(target, team, x, y, Float.MAX_VALUE)){
|
||||
target = null;
|
||||
}
|
||||
|
||||
retarget(this::targetClosest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class PowerNode extends PowerBlock{
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
public static void linkPowerNodes(Player player, Tile tile, Tile other){
|
||||
if(tile.entity.power == null) return;
|
||||
if(tile.entity.power == null || !((PowerNode)tile.block()).linkValid(tile, other)) return;
|
||||
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user