use of bwapi.Position in project Ecgberht by Jabbo16.
the class Squad method microUpdateOrder.
public void microUpdateOrder() {
try {
if (members.isEmpty()) {
return;
}
Set<Unit> enemy = getGs().enemyCombatUnitMemory;
int frameCount = getGs().frameCount;
Position start = getGame().self().getStartLocation().toPosition();
Set<Unit> marinesToHeal = new HashSet<>();
Position sCenter = getGs().getSquadCenter(this);
for (Unit u : members) {
if (u.getType() == UnitType.Terran_Siege_Tank_Siege_Mode) {
continue;
}
if (u.getType() == UnitType.Terran_Siege_Tank_Tank_Mode && u.getOrder() == Order.Sieging) {
continue;
}
Position lastTarget = (u.getTargetPosition() == null ? u.getOrderTargetPosition() : u.getTargetPosition());
if (lastTarget != null) {
if (lastTarget.equals(attack)) {
continue;
}
}
if (!getGs().DBs.isEmpty()) {
Unit bunker = getGs().DBs.keySet().iterator().next();
if (status == Status.IDLE && getGs().broodWarDistance(bunker.getPosition(), sCenter) >= 130 && getGs().getArmySize() < getGs().strat.armyForAttack && !getGs().expanding) {
if (u.getOrder() != Order.Move) {
u.move(bunker.getPosition());
}
continue;
}
} else if (getGs().closestChoke != null && !getGs().EI.naughty) {
if (status == Status.IDLE && getGs().broodWarDistance(getGs().closestChoke.getCenter(), sCenter) >= 130 && getGs().getArmySize() < getGs().strat.armyForAttack && !getGs().expanding) {
if (u.getOrder() != Order.Move) {
u.move(getGs().closestChoke.getCenter());
}
continue;
}
}
if (status == Status.IDLE && getGs().broodWarDistance(u.getPosition(), sCenter) >= 100 && u.getOrder() != Order.Move) {
if (getGame().isWalkable(sCenter.toWalkPosition())) {
u.move(sCenter);
continue;
}
}
if (u.getType() == UnitType.Terran_Medic && u.getOrder() != Order.MedicHeal) {
Unit chosen = getHealTarget(u, marinesToHeal);
if (chosen != null) {
u.useTech(TechType.Healing, chosen);
marinesToHeal.add(chosen);
continue;
}
}
if (u.isIdle() && attack != Position.None && frameCount != u.getLastCommandFrame() && getGs().broodWarDistance(attack, u.getPosition()) > 500) {
u.attack(attack);
continue;
}
if (u.isAttacking() && attack == Position.None && frameCount != u.getLastCommandFrame() && getGs().broodWarDistance(sCenter, u.getPosition()) > 500) {
u.move(sCenter);
continue;
}
int framesToOrder = 18;
if (u.getType() == UnitType.Terran_Vulture) {
framesToOrder = 12;
}
if (frameCount - u.getLastCommandFrame() >= framesToOrder) {
if (u.isIdle() && attack != Position.None && status != Status.IDLE) {
u.attack(attack);
continue;
}
// Experimental storm dodging?
if (u.isUnderStorm()) {
u.move(start);
continue;
}
Set<Unit> enemyToKite = new HashSet<>();
if (u.getGroundWeaponCooldown() > 0) {
for (Unit e : enemy) {
if (!e.getType().isFlyer() && e.getType().groundWeapon().maxRange() <= 32 && e.getType() != UnitType.Terran_Medic) {
if (e.isAttacking()) {
if (u.getUnitsInRadius(u.getType().groundWeapon().maxRange()).contains(e)) {
// u.move(start);
enemyToKite.add(e);
}
}
}
}
if (!enemyToKite.isEmpty()) {
Position run = getGs().kiteAway(u, enemyToKite);
if (run.isValid()) {
u.move(run);
continue;
} else {
u.move(getGs().getPlayer().getStartLocation().toPosition());
continue;
}
// Position run = getGs().getPlayer().getStartLocation().toPosition();
}
} else if (attack != Position.None && !u.isStartingAttack() && !u.isAttacking() && u.getOrder() == Order.Move) {
u.attack(attack);
continue;
}
}
}
} catch (Exception e) {
System.err.println("microUpdateOrder Error");
System.err.println(e);
}
}
use of bwapi.Position 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 bwapi.Position in project BWJSAL by RobinsonMann.
the class EnhancedUi method drawBases.
private void drawBases() {
for (BaseLocation baseLocation : bwtaWrapper.getBaseLocations()) {
Position basePosition = baseLocation.getPosition();
drawUtils.highlightBaseLocation(baseLocation, BASE_BOX_COLOR);
for (Unit mineral : baseLocation.getMinerals()) {
drawUtils.highlightMineralField(mineral, MINERAL_CIRCLE_COLOR);
}
// Highlight vespene geysers
for (Unit geyser : baseLocation.getGeysers()) {
drawUtils.highlightGeyser(geyser, GEYSER_COLOR);
}
// Draw a yellow circle around the base location if it is an island expansion
if (baseLocation.isIsland()) {
drawUtils.highlightIslandBaseLocation(baseLocation, BASE_ISLAND_COLOR);
}
}
}
use of bwapi.Position in project Ecgberht by Jabbo16.
the class SendDefenders method execute.
@Override
public State execute() {
try {
boolean air_only = true;
boolean cannon_rush = false;
for (Unit u : ((GameState) this.handler).enemyInBase) {
if (u.isFlying() || u.isCloaked()) {
continue;
}
if (!cannon_rush) {
if (u.getType() == UnitType.Protoss_Pylon || u.getType() == UnitType.Protoss_Photon_Cannon) {
cannon_rush = true;
}
}
air_only = false;
}
Set<Unit> friends = new HashSet<Unit>();
for (Squad s : ((GameState) this.handler).squads.values()) {
for (Unit u : s.members) {
friends.add(u);
}
}
boolean bunker = false;
if (!((GameState) this.handler).DBs.isEmpty()) {
for (Unit u : ((GameState) this.handler).DBs.keySet()) {
friends.add(u);
}
bunker = true;
}
int defenders = 6;
Iterator<Unit> it = ((GameState) this.handler).enemyInBase.iterator();
if (((GameState) this.handler).enemyInBase.size() == 1 && it.next().getType().isWorker()) {
defenders = 1;
}
Pair<Boolean, Boolean> battleWin = new Pair<>(true, false);
if (defenders != 1) {
if (((GameState) this.handler).enemyInBase.size() + friends.size() < 25) {
battleWin = ((GameState) this.handler).simulateDefenseBattle(friends, ((GameState) this.handler).enemyInBase, 150, bunker);
}
if (((GameState) this.handler).enemyInBase.size() >= 2 * friends.size()) {
battleWin.first = false;
}
}
if (cannon_rush) {
battleWin.first = false;
}
int frame = ((GameState) this.handler).frameCount;
if (!air_only && ((!battleWin.first || battleWin.second) || defenders == 1)) {
while (((GameState) this.handler).workerDefenders.size() < defenders && !((GameState) this.handler).workerIdle.isEmpty()) {
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).attackPosition;
for (Unit u : ((GameState) this.handler).workerIdle) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen) < ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen))) {
closestWorker = u;
}
}
if (closestWorker != null) {
((GameState) this.handler).workerDefenders.add(closestWorker);
((GameState) this.handler).workerIdle.remove(closestWorker);
}
}
while (((GameState) this.handler).workerDefenders.size() < defenders && !((GameState) this.handler).workerMining.isEmpty()) {
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).attackPosition;
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
if (closestWorker != null) {
if (((GameState) this.handler).workerMining.containsKey(closestWorker)) {
Unit mineral = ((GameState) this.handler).workerMining.get(closestWorker);
((GameState) this.handler).workerDefenders.add(closestWorker);
if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
((GameState) this.handler).mining--;
((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
}
((GameState) this.handler).workerMining.remove(closestWorker);
}
}
}
for (Unit u : ((GameState) this.handler).workerDefenders) {
if (frame == u.getLastCommandFrame()) {
continue;
}
if (((GameState) this.handler).attackPosition != null) {
if (u.isIdle()) {
if (((GameState) this.handler).enemyInBase.size() == 1) {
u.attack(((GameState) this.handler).enemyInBase.iterator().next());
} else {
Unit toAttack = ((GameState) this.handler).getUnitToAttack(u, ((GameState) this.handler).enemyInBase);
if (toAttack != null) {
Unit lastTarget = u.getOrderTarget();
if (lastTarget != null && lastTarget.exists()) {
if (lastTarget.equals(toAttack)) {
continue;
}
}
UnitCommand lastUnitCommand = u.getLastCommand();
if (lastUnitCommand != null) {
if (lastUnitCommand.getTarget() != null && lastUnitCommand.getTarget().exists())
if (lastUnitCommand.getTarget().equals(toAttack)) {
continue;
}
}
u.attack(toAttack);
} else {
u.attack(((GameState) this.handler).attackPosition);
}
continue;
}
}
}
}
} else {
if (((GameState) this.handler).strat.name != "ProxyBBS") {
for (Entry<String, Squad> u : ((GameState) this.handler).squads.entrySet()) {
if (((GameState) this.handler).attackPosition != null) {
// if(u.getValue().estado == Status.IDLE || !((GameState)this.handler).attackPosition.equals(u.getValue().attack)) {
u.getValue().giveAttackOrder(((GameState) this.handler).attackPosition);
u.getValue().status = Status.DEFENSE;
continue;
// }
} else {
u.getValue().status = Status.IDLE;
u.getValue().attack = Position.None;
continue;
}
}
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Position in project Ecgberht by Jabbo16.
the class Vulture method attack.
private void attack() {
Position newAttackPos = null;
if (attackPos == Position.None) {
newAttackPos = selectNewAttack();
attackPos = newAttackPos;
if (attackPos == null || !attackPos.isValid()) {
attackUnit = null;
attackPos = Position.None;
return;
}
unit.attack(newAttackPos);
attackUnit = null;
return;
} else if (attackPos.equals(newAttackPos)) {
return;
}
}
Aggregations