use of ecgberht.GameState 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.GameState in project Ecgberht by Jabbo16.
the class ChooseAttackPosition method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).squads.isEmpty()) {
return State.FAILURE;
}
for (Squad u : ((GameState) this.handler).squads.values()) {
Pair<Integer, Integer> p = ((GameState) this.handler).inMap.getPosition(((GameState) this.handler).getSquadCenter(u).toTilePosition(), true);
if (p.first != null && p.second != null) {
if (!((GameState) this.handler).firstProxyBBS && ((GameState) this.handler).strat.name == "ProxyBBS") {
((GameState) this.handler).firstProxyBBS = true;
((GameState) this.handler).getGame().sendText("Get ready for a party in your house!");
}
u.giveAttackOrder(new TilePosition(p.second, p.first).toPosition());
u.status = Status.ATTACK;
continue;
} else if (((GameState) this.handler).enemyBase != null) {
((GameState) this.handler).attackPosition = ((GameState) this.handler).enemyBase.getPosition();
continue;
} else {
u.status = Status.IDLE;
continue;
}
}
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 ChooseBlotWorker method execute.
@Override
public State execute() {
try {
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).chosenBuildingLot.getPosition();
if (!((GameState) this.handler).workerIdle.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerIdle) {
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
}
if (!((GameState) this.handler).workerTask.isEmpty()) {
for (Pair<Unit, Unit> u : ((GameState) this.handler).workerTask) {
if ((closestWorker == null || u.first.getDistance(chosen) < closestWorker.getDistance(chosen)) && u.second.getType().isMineralField() && !u.first.isCarryingMinerals()) {
closestWorker = u.first;
}
}
}
if (closestWorker != null) {
((GameState) this.handler).chosenWorker = 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 CollectMineral method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenWorker;
if (!((GameState) this.handler).mineralsAssigned.isEmpty()) {
Unit closestMineral = null;
for (Entry<Unit, Integer> m : ((GameState) this.handler).mineralsAssigned.entrySet()) {
if ((closestMineral == null || chosen.getDistance(m.getKey()) < chosen.getDistance(closestMineral)) && m.getValue() < 2) {
closestMineral = m.getKey();
}
}
if (closestMineral != null) {
((GameState) this.handler).mineralsAssigned.put(closestMineral, ((GameState) this.handler).mineralsAssigned.get(closestMineral) + 1);
((GameState) this.handler).workerIdle.remove(chosen);
((GameState) this.handler).workerMining.put(chosen, closestMineral);
chosen.gather(closestMineral, false);
((GameState) this.handler).chosenWorker = null;
((GameState) this.handler).mining++;
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 ChooseRepairer method execute.
@Override
public State execute() {
try {
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).chosenBuildingRepair.getPosition();
int frame = ((GameState) this.handler).frameCount;
for (Unit u : ((GameState) this.handler).workerIdle) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
if (closestWorker != null) {
((GameState) this.handler).chosenRepairer = closestWorker;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations