Unit AI fixes / Other general fixes

This commit is contained in:
Anuken
2019-03-28 17:12:49 -04:00
parent e6a24b8ba1
commit 4e5d87104c
7 changed files with 22 additions and 6 deletions
@@ -129,7 +129,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
public void targetClosest(){
target = Units.getClosestTarget(team, x, y, Math.max(getWeapon().bullet.range(), type.range), u -> type.targetAir || !u.isFlying());
TargetTrait newTarget = Units.getClosestTarget(team, x, y, Math.max(getWeapon().bullet.range(), type.range), u -> type.targetAir || !u.isFlying());
if(newTarget != null){
target = newTarget;
}
}
public TileEntity getClosestEnemyCore(){
@@ -47,7 +47,7 @@ public abstract class FlyingUnit extends BaseUnit{
attack(type.attackLength);
if((Angles.near(angleTo(target), rotation, type.shootCone) || getWeapon().ignoreRotation) //bombers and such don't care about rotation
&& dst(target) < Math.max(getWeapon().bullet.range(), type.range)){
&& dst(target) < getWeapon().bullet.range()){
BulletType ammo = getWeapon().bullet;
if(type.rotateWeapon){
@@ -75,8 +75,9 @@ public abstract class FlyingUnit extends BaseUnit{
targetClosest();
targetClosestEnemyFlag(BlockFlag.target);
if(target != null){
if(target != null && !Units.invalidateTarget(target, team, x, y)){
setState(attack);
return;
}
target = getClosestCore();
@@ -54,10 +54,11 @@ public abstract class GroundUnit extends BaseUnit{
patrol = new UnitState(){
public void update(){
TileEntity target = getClosestCore();
if(target != null){
if(dst(target) > 400f){
moveAwayFromCore();
}else{
}else if(!(!Units.invalidateTarget(GroundUnit.this.target, GroundUnit.this) && dst(GroundUnit.this.target) < getWeapon().bullet.range())){
patrol();
}
}
@@ -63,6 +63,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public static void onTileDamage(Tile tile, float health){
if(tile.entity != null){
tile.entity.health = health;
if(tile.entity.damaged()){
world.indexer.notifyTileDamaged(tile.entity);
}
}
}
@@ -151,7 +155,9 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
if(health <= 0){
Call.onTileDestroyed(tile);
}else if(preHealth >= maxHealth() - 0.00001f && health < maxHealth() && world != null){ //when just damaged
}
if(preHealth >= maxHealth() - 0.00001f && health < maxHealth() && world != null){ //when just damaged
world.indexer.notifyTileDamaged(this);
}
}