Unit enemy spawnpoint camping

This commit is contained in:
Anuken
2019-09-20 23:09:11 -04:00
parent 025386af53
commit dda1f18f67
14 changed files with 1581 additions and 1500 deletions
@@ -174,8 +174,15 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
}
public TileEntity getClosestEnemyCore(){
public Tile getClosest(BlockFlag flag){
return Geometry.findClosest(x, y, indexer.getAllied(team, flag));
}
public Tile getClosestSpawner(){
return Geometry.findClosest(x, y, Vars.spawner.getGroundSpawns());
}
public TileEntity getClosestEnemyCore(){
for(Team enemy : Vars.state.teams.enemiesOf(team)){
Tile tile = Geometry.findClosest(x, y, Vars.state.teams.get(enemy).cores);
if(tile != null){
@@ -5,6 +5,7 @@ import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*;
import io.anuke.arc.math.geom.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.bullet.*;
import io.anuke.mindustry.entities.units.*;
@@ -35,13 +36,15 @@ public abstract class FlyingUnit extends BaseUnit{
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
if(target == null){
setState(patrol);
}
}
if(target != null){
if(target == null){
target = getSpawner();
}
if(target == getSpawner() && getSpawner() != null){
circle(80f + Mathf.randomSeed(id) * 120);
}else if(target != null){
attack(type.attackLength);
if((Angles.near(angleTo(target), rotation, type.shootCone) || getWeapon().ignoreRotation) //bombers and such don't care about rotation
@@ -64,22 +67,24 @@ public abstract class FlyingUnit extends BaseUnit{
getWeapon().update(FlyingUnit.this, to.x, to.y);
}
}
}else{
target = getClosestSpawner();
moveTo(Vars.state.rules.dropZoneRadius + 80f);
}
}
},
patrol = new UnitState(){
rally = new UnitState(){
public void update(){
if(retarget()){
targetClosestAllyFlag(BlockFlag.rally);
targetClosest();
targetClosestEnemyFlag(BlockFlag.core);
if(target != null && !Units.invalidateTarget(target, team, x, y)){
setState(attack);
return;
}
target = getSpawner();
if(target == null) target = getClosestCore();
if(target == null) target = getSpawner();
}
if(target != null){
@@ -109,7 +114,7 @@ public abstract class FlyingUnit extends BaseUnit{
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
command == UnitCommand.attack ? attack :
command == UnitCommand.patrol ? patrol :
command == UnitCommand.rally ? rally :
null);
}
@@ -14,6 +14,7 @@ import io.anuke.mindustry.game.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.*;
@@ -35,31 +36,30 @@ public abstract class GroundUnit extends BaseUnit{
TileEntity core = getClosestEnemyCore();
if(core == null){
setState(patrol);
return;
}
Tile closestSpawn = getClosestSpawner();
if(closestSpawn == null || !withinDst(closestSpawn, Vars.state.rules.dropZoneRadius + 75f)){
moveToCore(PathTarget.enemyCores);
}
}else{
float dst = dst(core);
float dst = dst(core);
if(dst < getWeapon().bullet.range() / 1.1f){
target = core;
}
if(dst < getWeapon().bullet.range() / 1.1f){
target = core;
}
if(dst > getWeapon().bullet.range() * 0.5f){
moveToCore();
if(dst > getWeapon().bullet.range() * 0.5f){
moveToCore(PathTarget.enemyCores);
}
}
}
},
patrol = new UnitState(){
rally = new UnitState(){
public void update(){
TileEntity target = getClosestCore();
Tile target = getClosest(BlockFlag.rally);
if(target != null){
if(dst(target) > 400f){
moveAwayFromCore();
}else if(!(!Units.invalidateTarget(GroundUnit.this.target, GroundUnit.this) && dst(GroundUnit.this.target) < getWeapon().bullet.range())){
patrol();
}
if(target != null && dst(target) > 100f){
moveToCore(PathTarget.rallyPoints);
}
}
},
@@ -77,7 +77,7 @@ public abstract class GroundUnit extends BaseUnit{
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
command == UnitCommand.attack ? attack :
command == UnitCommand.patrol ? patrol :
command == UnitCommand.rally ? rally :
null);
}
@@ -221,10 +221,10 @@ public abstract class GroundUnit extends BaseUnit{
velocity.add(vec);
}
protected void moveToCore(){
protected void moveToCore(PathTarget path){
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = pathfinder.getTargetTile(tile, team, PathTarget.enemyCores);
Tile targetTile = pathfinder.getTargetTile(tile, team, path);
if(tile == targetTile) return;
@@ -3,7 +3,7 @@ package io.anuke.mindustry.entities.units;
import io.anuke.arc.*;
public enum UnitCommand{
attack, retreat, patrol;
attack, retreat, rally;
private final String localized;
public static final UnitCommand[] all = values();