use of ecgberht.EnemyBuilding in project Ecgberht by Jabbo16.
the class CheckPerimeter method execute.
@Override
public State execute() {
try {
((GameState) this.handler).enemyInBase.clear();
((GameState) this.handler).defense = false;
List<Unit> enemyInvaders = new ArrayList<>();
enemyInvaders.addAll(((GameState) this.handler).enemyCombatUnitMemory);
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (u.type.canAttack() || u.type == UnitType.Protoss_Pylon || u.type.canProduce() || u.type.isRefinery()) {
enemyInvaders.add(u.unit);
}
}
for (Unit u : enemyInvaders) {
if ((u.getType().canAttack() || u.getType() == UnitType.Protoss_Pylon) && u.getType() != UnitType.Zerg_Scourge && u.getType() != UnitType.Protoss_Corsair) {
for (Unit c : ((GameState) this.handler).CCs.values()) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 500) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).DBs.keySet()) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).SBs) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).MBs) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
}
}
boolean overlordCheck = true;
for (Unit u : ((GameState) this.handler).enemyInBase) {
if (u.getType().canAttack() || u.getType() == UnitType.Protoss_Shuttle || u.getType() == UnitType.Terran_Dropship) {
overlordCheck = false;
break;
}
}
if (!((GameState) this.handler).enemyInBase.isEmpty() && !overlordCheck) {
if ((((GameState) this.handler).getArmySize() >= 50 && ((GameState) this.handler).getArmySize() / ((GameState) this.handler).enemyInBase.size() > 10)) {
return State.FAILURE;
}
((GameState) this.handler).defense = true;
return State.SUCCESS;
}
int cFrame = ((GameState) this.handler).frameCount;
for (Unit u : ((GameState) this.handler).workerDefenders) {
if (u.getLastCommandFrame() == cFrame) {
continue;
}
Position closestCC = ((GameState) this.handler).getNearestCC(u.getPosition());
if (closestCC != null) {
if (!BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(closestCC).getCenter())) {
u.move(closestCC);
}
}
}
for (Squad u : ((GameState) this.handler).squads.values()) {
if (u.status == Status.DEFENSE) {
Position closestCC = ((GameState) this.handler).getNearestCC(((GameState) this.handler).getSquadCenter(u));
if (closestCC != null) {
Region squad = BWTA.getRegion(((GameState) this.handler).getSquadCenter(u));
Region regCC = BWTA.getRegion(closestCC);
if (squad != null && regCC != null) {
if (!squad.getCenter().equals(regCC.getCenter())) {
if (!((GameState) this.handler).DBs.isEmpty() && ((GameState) this.handler).CCs.size() == 1) {
u.giveMoveOrder(((GameState) this.handler).DBs.keySet().iterator().next().getPosition());
} else {
u.giveMoveOrder(BWTA.getNearestChokepoint(((GameState) this.handler).getSquadCenter(u)).getCenter());
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
}
((GameState) this.handler).defense = false;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.EnemyBuilding in project Ecgberht by Jabbo16.
the class ChooseBaseLocation method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenBaseLocation != null) {
return State.SUCCESS;
}
TilePosition main = null;
if (((GameState) this.handler).MainCC != null) {
main = ((GameState) this.handler).MainCC.getTilePosition();
} else {
main = ((GameState) this.handler).getPlayer().getStartLocation();
}
List<BaseLocation> valid = new ArrayList<>();
for (BaseLocation b : ((GameState) this.handler).BLs) {
if (!((GameState) this.handler).CCs.containsKey(b.getRegion().getCenter()) && BWTA.isConnected(b.getTilePosition(), main)) {
valid.add(b);
}
}
List<BaseLocation> remove = new ArrayList<>();
for (BaseLocation b : valid) {
for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
if (BWTA.getRegion(u.getPosition()) == null || !u.getType().canAttack() || u.getType().isWorker()) {
continue;
}
if (BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
remove.add(b);
break;
}
}
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (BWTA.getRegion(u.pos) == null) {
continue;
}
if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
remove.add(b);
break;
}
}
}
valid.removeAll(remove);
if (valid.isEmpty()) {
System.out.println("wut");
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).movingToExpand = false;
((GameState) this.handler).chosenBuilderBL.stop();
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
((GameState) this.handler).chosenBuilderBL = null;
((GameState) this.handler).expanding = false;
((GameState) this.handler).deltaCash.first -= UnitType.Terran_Command_Center.mineralPrice();
((GameState) this.handler).deltaCash.second -= UnitType.Terran_Command_Center.gasPrice();
return State.FAILURE;
}
((GameState) this.handler).chosenBaseLocation = valid.get(0).getTilePosition();
// System.out.println("----------------------------");
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.EnemyBuilding in project Ecgberht by Jabbo16.
the class Vulture method getNewStatus.
private void getNewStatus() {
Position myPos = unit.getPosition();
if (getGs().enemyCombatUnitMemory.isEmpty()) {
status = Status.ATTACK;
return;
}
for (Unit u : getGs().enemyCombatUnitMemory) {
if (u.getType().isWorker() && !u.isAttacking()) {
closeWorkers.add(u);
}
if (getGs().broodWarDistance(u.getPosition(), myPos) < 600) {
closeEnemies.add(u);
}
}
for (EnemyBuilding u : getGs().enemyBuildingMemory.values()) {
if ((u.type.canAttack() || u.type == UnitType.Terran_Bunker) && u.unit.isCompleted()) {
if (getGs().broodWarDistance(myPos, u.pos.toPosition()) <= 600) {
closeEnemies.add(u.unit);
}
}
}
if (closeEnemies.isEmpty()) {
status = Status.ATTACK;
return;
} else {
boolean meleeOnly = checkOnlyMelees();
int sim = 80;
if (meleeOnly) {
sim = 5;
}
if (!getGs().simulateHarass(unit, closeEnemies, sim)) {
status = Status.RETREAT;
return;
}
int cd = unit.getGroundWeaponCooldown();
if (status == Status.COMBAT || status == Status.ATTACK) {
if (attackUnit != null) {
if (attackUnit.getType().groundWeapon().maxRange() > type.groundWeapon().maxRange()) {
return;
}
}
if (cd > 0) {
status = Status.KITE;
return;
}
}
if (status == Status.KITE) {
if (attackUnit == null) {
Unit closest = getUnitToAttack(unit, closeEnemies);
if (closest != null) {
double dist = getGs().broodWarDistance(unit.getPosition(), closest.getPosition());
double speed = type.topSpeed();
double timeToEnter = 0.0;
if (speed > .00001) {
timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
}
if (timeToEnter >= cd) {
status = Status.COMBAT;
return;
}
}
} else {
double dist = getGs().broodWarDistance(unit.getPosition(), attackUnit.getPosition());
double speed = type.topSpeed();
double timeToEnter = 0.0;
if (speed > .00001) {
timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
}
if (timeToEnter >= cd) {
status = Status.COMBAT;
return;
}
}
if (cd == 0) {
status = Status.COMBAT;
return;
}
}
}
}
use of ecgberht.EnemyBuilding in project Ecgberht by Jabbo16.
the class ChooseBuildingToHarass method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenUnitToHarass != null) {
return State.FAILURE;
}
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (((GameState) this.handler).enemyBase != null) {
if (u.type.isBuilding()) {
if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(((GameState) this.handler).enemyBase.getPosition()).getCenter())) {
((GameState) this.handler).chosenUnitToHarass = u.unit;
return State.SUCCESS;
}
}
}
}
if (((GameState) this.handler).chosenHarasser.isIdle()) {
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
((GameState) this.handler).chosenHarasser.stop();
((GameState) this.handler).chosenHarasser = null;
((GameState) this.handler).chosenUnitToHarass = null;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations