use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class ChooseBuilderBL method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenBuilderBL != null) {
return State.SUCCESS;
}
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).chosenBaseLocation.toPosition();
if (!((GameState) this.handler).workerIdle.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerIdle) {
double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
if (closestWorker == null) {
closestWorker = u;
} else {
double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
if (unitChosen < closestChosen) {
closestWorker = u;
}
}
}
}
if (!((GameState) this.handler).workerMining.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
if (closestWorker == null) {
closestWorker = u;
} else {
double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
if (unitChosen < closestChosen) {
closestWorker = u;
}
}
}
}
if (closestWorker != null) {
if (!((GameState) this.handler).workerTask.isEmpty() && ((GameState) this.handler).workerIdle.contains(closestWorker)) {
((GameState) this.handler).workerIdle.remove(closestWorker);
} else if (!((GameState) this.handler).workerMining.isEmpty()) {
if (((GameState) this.handler).workerMining.containsKey(closestWorker)) {
Unit mineral = ((GameState) this.handler).workerMining.get(closestWorker);
((GameState) this.handler).workerMining.remove(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);
}
}
}
if (((GameState) this.handler).chosenWorker != null && ((GameState) this.handler).chosenWorker.equals(closestWorker)) {
((GameState) this.handler).chosenWorker = null;
}
((GameState) this.handler).chosenBuilderBL = closestWorker;
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 Expand method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenBuilderBL;
if (!chosen.build(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)) {
((GameState) this.handler).movingToExpand = false;
((GameState) this.handler).expanding = false;
((GameState) this.handler).checkUnitsBL(((GameState) this.handler).chosenBaseLocation, chosen);
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
((GameState) this.handler).chosenBuilderBL.stop();
((GameState) this.handler).chosenBuilderBL = null;
((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).movingToExpand = false;
((GameState) this.handler).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)));
((GameState) this.handler).expanding = false;
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).chosenBuilderBL = null;
return State.SUCCESS;
} 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 ChooseBuildingLot method execute.
@Override
public State execute() {
try {
Unit savedTurret = null;
List<Unit> aux = new ArrayList<Unit>();
for (Unit b : ((GameState) this.handler).buildingLot) {
if (!b.isUnderAttack()) {
if (b.getType() == UnitType.Terran_Bunker) {
((GameState) this.handler).chosenBuildingLot = b;
return State.SUCCESS;
}
if (b.getType() == UnitType.Terran_Missile_Turret) {
savedTurret = b;
}
((GameState) this.handler).chosenBuildingLot = b;
} else {
if ((double) b.getHitPoints() / (double) b.getType().maxHitPoints() <= 0.1) {
b.cancelConstruction();
aux.add(b);
}
}
}
((GameState) this.handler).buildingLot.removeAll(aux);
if (savedTurret != null) {
((GameState) this.handler).chosenBuildingLot = savedTurret;
return State.SUCCESS;
}
if (((GameState) this.handler).chosenBuildingLot != null) {
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 FinishBuilding method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenWorker;
if (chosen.rightClick(((GameState) this.handler).chosenBuildingLot)) {
if (((GameState) this.handler).workerIdle.contains(chosen)) {
((GameState) this.handler).workerIdle.remove(chosen);
} else {
if (((GameState) this.handler).workerMining.containsKey(chosen)) {
Unit mineral = ((GameState) this.handler).workerMining.get(chosen);
((GameState) this.handler).workerMining.remove(chosen);
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).workerTask.add(new Pair<Unit, Unit>(chosen, ((GameState) this.handler).chosenBuildingLot));
((GameState) this.handler).chosenWorker = null;
((GameState) this.handler).buildingLot.remove(((GameState) this.handler).chosenBuildingLot);
((GameState) this.handler).chosenBuildingLot = null;
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 CheckHarasserAttacked method execute.
@Override
public State execute() {
try {
Unit attacker = null;
int workers = 0;
Set<Unit> attackers = new HashSet<>();
// Thanks to @N00byEdge to the cleaner code
for (Unit u : ((GameState) this.handler).getGame().enemy().getUnits()) {
if (!u.getType().isBuilding() && u.getType().canAttack()) {
Unit target = (u.getTarget() == null ? u.getOrderTarget() : u.getTarget());
if (target != null && target.equals(((GameState) this.handler).chosenHarasser)) {
if (u.getType().isWorker()) {
workers++;
attacker = u;
}
attackers.add(u);
continue;
}
}
}
if (workers > 1) {
((GameState) this.handler).EI.defendHarass = true;
}
if (attackers.isEmpty()) {
if (!((GameState) this.handler).getGame().isVisible(((GameState) this.handler).enemyBase.getTilePosition()) && ((GameState) this.handler).chosenUnitToHarass == null) {
((GameState) this.handler).chosenHarasser.move(((GameState) this.handler).enemyBase.getPosition());
}
return State.SUCCESS;
} else {
boolean winHarass = ((GameState) this.handler).simulateHarass(((GameState) this.handler).chosenHarasser, attackers, 70);
if (winHarass) {
if (workers == 1 && !attacker.equals(((GameState) this.handler).chosenUnitToHarass)) {
((GameState) this.handler).chosenHarasser.attack(attacker);
((GameState) this.handler).chosenUnitToHarass = attacker;
return State.SUCCESS;
}
} else {
if (((GameState) this.handler).chosenHarasser.getHitPoints() <= 15) {
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
((GameState) this.handler).chosenHarasser.stop();
((GameState) this.handler).chosenHarasser = null;
((GameState) this.handler).chosenUnitToHarass = null;
} else {
Position kite = getGs().kiteAway(((GameState) this.handler).chosenHarasser, attackers);
((GameState) this.handler).chosenHarasser.move(kite);
((GameState) this.handler).chosenUnitToHarass = null;
}
return State.FAILURE;
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations