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

View File

@@ -180,6 +180,7 @@ public class UnitTypes implements ContentList{
isFlying = true; isFlying = true;
health = 75; health = 75;
engineOffset = 5.5f; engineOffset = 5.5f;
range = 140f;
weapon = new Weapon("chain-blaster"){{ weapon = new Weapon("chain-blaster"){{
length = 1.5f; length = 1.5f;
reload = 28f; reload = 28f;
@@ -198,6 +199,7 @@ public class UnitTypes implements ContentList{
isFlying = true; isFlying = true;
targetAir = false; targetAir = false;
engineOffset = 7.8f; engineOffset = 7.8f;
range = 140f;
weapon = new Weapon("bomber"){{ weapon = new Weapon("bomber"){{
length = 0f; length = 0f;
width = 2f; width = 2f;

View File

@@ -248,6 +248,7 @@ public class NetClient implements ApplicationListener{
for(int i = 0; i < cores; i++){ for(int i = 0; i < cores; i++){
int pos = input.readInt(); int pos = input.readInt();
Tile tile = world.tile(pos); Tile tile = world.tile(pos);
if(tile != null && tile.entity != null){ if(tile != null && tile.entity != null){
tile.entity.items.read(input); tile.entity.items.read(input);
}else{ }else{

View File

@@ -129,7 +129,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
} }
public void targetClosest(){ 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(){ public TileEntity getClosestEnemyCore(){

View File

@@ -47,7 +47,7 @@ public abstract class FlyingUnit extends BaseUnit{
attack(type.attackLength); attack(type.attackLength);
if((Angles.near(angleTo(target), rotation, type.shootCone) || getWeapon().ignoreRotation) //bombers and such don't care about rotation 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; BulletType ammo = getWeapon().bullet;
if(type.rotateWeapon){ if(type.rotateWeapon){
@@ -75,8 +75,9 @@ public abstract class FlyingUnit extends BaseUnit{
targetClosest(); targetClosest();
targetClosestEnemyFlag(BlockFlag.target); targetClosestEnemyFlag(BlockFlag.target);
if(target != null){ if(target != null && !Units.invalidateTarget(target, team, x, y)){
setState(attack); setState(attack);
return;
} }
target = getClosestCore(); target = getClosestCore();

View File

@@ -54,10 +54,11 @@ public abstract class GroundUnit extends BaseUnit{
patrol = new UnitState(){ patrol = new UnitState(){
public void update(){ public void update(){
TileEntity target = getClosestCore(); TileEntity target = getClosestCore();
if(target != null){ if(target != null){
if(dst(target) > 400f){ if(dst(target) > 400f){
moveAwayFromCore(); moveAwayFromCore();
}else{ }else if(!(!Units.invalidateTarget(GroundUnit.this.target, GroundUnit.this) && dst(GroundUnit.this.target) < getWeapon().bullet.range())){
patrol(); patrol();
} }
} }

View File

@@ -63,6 +63,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public static void onTileDamage(Tile tile, float health){ public static void onTileDamage(Tile tile, float health){
if(tile.entity != null){ if(tile.entity != null){
tile.entity.health = health; 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){ if(health <= 0){
Call.onTileDestroyed(tile); 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); world.indexer.notifyTileDamaged(this);
} }
} }

View File

@@ -229,7 +229,9 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
Draw.color(); Draw.color();
}else{ }else{
float rad = (tile.block().size * tilesize / 2f - 1) * request.scale; float rad = Math.max((tile.block().size * tilesize / 2f - 1) * request.scale, 1f);
if(rad <= 1.01f) return;
Draw.mixcol(); Draw.mixcol();
//draw removing request //draw removing request
Draw.tint(Pal.removeBack); Draw.tint(Pal.removeBack);