Ground unit retreat attacking / Patrol attacking
This commit is contained in:
@@ -58,6 +58,12 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
if(target == null){
|
if(target == null){
|
||||||
retarget(() -> {
|
retarget(() -> {
|
||||||
targetClosest();
|
targetClosest();
|
||||||
|
|
||||||
|
if(target == null && isCommanded() && getCommand() == UnitCommand.patrol){
|
||||||
|
setState(patrol);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(target == null) targetClosestEnemyFlag(BlockFlag.target);
|
if(target == null) targetClosestEnemyFlag(BlockFlag.target);
|
||||||
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
|
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
|
||||||
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
|
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
|
||||||
@@ -82,9 +88,18 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
},
|
},
|
||||||
patrol = new UnitState(){
|
patrol = new UnitState(){
|
||||||
public void update(){
|
public void update(){
|
||||||
target = getClosestCore();
|
retarget(() -> {
|
||||||
|
targetClosest();
|
||||||
|
|
||||||
|
if(target != null){
|
||||||
|
setState(attack);
|
||||||
|
}
|
||||||
|
|
||||||
|
target = getClosestCore();
|
||||||
|
});
|
||||||
|
|
||||||
if(target != null){
|
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
|
@Override
|
||||||
public void onCommand(UnitCommand command){
|
public void onCommand(UnitCommand command){
|
||||||
state.set(command == UnitCommand.retreat ? retreat :
|
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){
|
if(core != null && dst < getWeapon().getAmmo().getRange() / 1.1f){
|
||||||
target = core;
|
target = core;
|
||||||
}else{
|
|
||||||
retarget(() -> targetClosest());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(target != null){
|
if(dst > getWeapon().getAmmo().getRange() * 0.5f){
|
||||||
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{
|
|
||||||
moveToCore();
|
moveToCore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
patrol = new UnitState(){
|
patrol = new UnitState(){
|
||||||
public void update(){
|
public void update(){
|
||||||
target = getClosestCore();
|
TileEntity target = getClosestCore();
|
||||||
if(target != null){
|
if(target != null){
|
||||||
if(distanceTo(target) > 400f){
|
if(distanceTo(target) > 400f){
|
||||||
moveAwayFromCore();
|
moveAwayFromCore();
|
||||||
@@ -214,6 +190,20 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
if(health <= health * type.retreatPercent && !isCommanded()){
|
if(health <= health * type.retreatPercent && !isCommanded()){
|
||||||
setState(retreat);
|
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
|
@Override
|
||||||
@@ -223,6 +213,8 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
if(Units.invalidateTarget(target, team, x, y, Float.MAX_VALUE)){
|
if(Units.invalidateTarget(target, team, x, y, Float.MAX_VALUE)){
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retarget(this::targetClosest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class PowerNode extends PowerBlock{
|
|||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||||
public static void linkPowerNodes(Player player, Tile tile, Tile other){
|
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();
|
TileEntity entity = tile.entity();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user