use of bwapi.Unit 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.Unit in project Ecgberht by Jabbo16.
the class Squad method getHealTarget.
private Unit getHealTarget(final Unit u, final Set<Unit> marinesToHeal) {
Set<Unit> marines = getMarines();
Unit chosen = null;
double dist = Double.MAX_VALUE;
for (Unit m : marines) {
if (m.getHitPoints() == m.getType().maxHitPoints() || marinesToHeal.contains(m)) {
continue;
}
double distA = getGs().broodWarDistance(m.getPosition(), u.getPosition());
if (chosen == null || distA < dist) {
chosen = m;
dist = distA;
}
}
return chosen;
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChoosePosition method execute.
@Override
public State execute() {
try {
Game juego = ((GameState) this.handler).getGame();
Player jugador = ((GameState) this.handler).getPlayer();
TilePosition origin = null;
if (((GameState) this.handler).chosenToBuild.isRefinery()) {
if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
if (!g.second) {
((GameState) this.handler).chosenPosition = g.first.first.getTilePosition();
return State.SUCCESS;
}
}
}
} else {
if (!((GameState) this.handler).workerBuild.isEmpty()) {
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
((GameState) this.handler).testMap.updateMap(w.second.second, w.second.first, false);
}
}
if (!((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Bunker) && !((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (((GameState) this.handler).strat.proxy && ((GameState) this.handler).chosenToBuild == UnitType.Terran_Barracks) {
origin = new TilePosition(((GameState) this.handler).getGame().mapWidth() / 2, ((GameState) this.handler).getGame().mapHeight() / 2);
} else {
// origin = BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition();
origin = jugador.getStartLocation();
}
} else {
if (((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (((GameState) this.handler).DBs.isEmpty()) {
origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
} else {
for (Unit b : ((GameState) this.handler).DBs.keySet()) {
origin = b.getTilePosition();
break;
}
}
} else {
if (((GameState) this.handler).EI.naughty && ((GameState) this.handler).enemyRace == Race.Zerg) {
TilePosition raxTile = ((GameState) this.handler).MBs.iterator().next().getTilePosition();
origin = ((GameState) this.handler).testMap.findBunkerPositionAntiPool(raxTile.toPosition(), ((GameState) this.handler).closestChoke);
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = ((GameState) this.handler).getBunkerPositionAntiPool();
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = raxTile;
}
}
} else {
if (((GameState) this.handler).Ts.isEmpty()) {
if (((GameState) this.handler).closestChoke != null) {
origin = ((GameState) this.handler).testMap.findBunkerPosition(((GameState) this.handler).closestChoke);
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = ((GameState) this.handler).closestChoke.getCenter().toTilePosition();
}
}
// else {
// origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
// }
} else {
for (Unit b : ((GameState) this.handler).Ts) {
origin = b.getTilePosition();
break;
}
}
}
}
}
TilePosition posicion = ((GameState) this.handler).testMap.findPosition(((GameState) this.handler).chosenToBuild, origin);
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
if (posicion != null) {
((GameState) this.handler).chosenPosition = posicion;
return State.SUCCESS;
}
}
TilePosition posicion = juego.getBuildLocation(((GameState) this.handler).chosenToBuild, BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition(), 500);
if (posicion != null) {
if (juego.canBuildHere(posicion, ((GameState) this.handler).chosenToBuild)) {
((GameState) this.handler).chosenPosition = posicion;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseRefinery method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).getPlayer().supplyUsed() < ((GameState) this.handler).strat.supplyForFirstRefinery || ((GameState) this.handler).getCash().second >= 300) {
return State.FAILURE;
}
if (((GameState) this.handler).refineriesAssigned.size() == 1) {
boolean found = false;
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
if (w.second.first == UnitType.Terran_Barracks) {
found = true;
break;
}
}
for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
if (w.second.getType() == UnitType.Terran_Barracks) {
found = true;
break;
}
}
if (((GameState) this.handler).MBs.isEmpty() && found == false) {
return State.FAILURE;
}
}
int count = 0;
Unit geyser = null;
for (Pair<Pair<Unit, Integer>, Boolean> r : ((GameState) this.handler).refineriesAssigned) {
if (r.second) {
count++;
} else {
geyser = r.first.first;
}
}
if (count == ((GameState) this.handler).refineriesAssigned.size()) {
return State.FAILURE;
}
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
if (w.second.first == UnitType.Terran_Refinery) {
return State.FAILURE;
}
}
for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
if (w.second.getType() == UnitType.Terran_Refinery && w.second.getPosition().equals(geyser.getPosition())) {
return State.FAILURE;
}
}
((GameState) this.handler).chosenToBuild = UnitType.Terran_Refinery;
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class CheckBuildingFlames method execute.
@Override
public State execute() {
try {
boolean isBeingRepaired = false;
for (Unit w : ((GameState) this.handler).DBs.keySet()) {
if (w.getType().maxHitPoints() != w.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (w.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = w;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Ts) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).MBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Fs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).UBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).SBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).CCs.values()) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).CSs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Ps) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations