use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class ChooseSiegeMode method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).UBs.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).UBs) {
if (!((GameState) this.handler).getPlayer().hasResearched(TechType.Tank_Siege_Mode) && u.canResearch(TechType.Tank_Siege_Mode) && !u.isResearching() && !u.isUpgrading()) {
((GameState) this.handler).chosenUnitUpgrader = u;
((GameState) this.handler).chosenResearch = TechType.Tank_Siege_Mode;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.GameState 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.GameState in project Ecgberht by Jabbo16.
the class ChooseStimUpgrade method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).UBs.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).UBs) {
if (!((GameState) this.handler).getPlayer().hasResearched(TechType.Stim_Packs) && u.canResearch(TechType.Stim_Packs) && !u.isResearching() && !u.isUpgrading()) {
((GameState) this.handler).chosenUnitUpgrader = u;
((GameState) this.handler).chosenResearch = TechType.Stim_Packs;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.GameState 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 ecgberht.GameState in project Ecgberht by Jabbo16.
the class CheckVisibleBL method execute.
@Override
public State execute() {
try {
for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), ((GameState) this.handler).chosenBaseLocation.toPosition()) < 300) {
((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;
}
}
if (((GameState) this.handler).getGame().isExplored(((GameState) this.handler).chosenBaseLocation)) {
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations