use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class Repair method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenRepairer.repair(((GameState) this.handler).chosenBuildingRepair)) {
if (((GameState) this.handler).workerIdle.contains(((GameState) this.handler).chosenRepairer)) {
((GameState) this.handler).workerIdle.remove(((GameState) this.handler).chosenRepairer);
} else {
if (((GameState) this.handler).workerMining.containsKey(((GameState) this.handler).chosenRepairer)) {
Unit mineral = ((GameState) this.handler).workerMining.get(((GameState) this.handler).chosenRepairer);
((GameState) this.handler).workerMining.remove(((GameState) this.handler).chosenRepairer);
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).repairerTask.add(new Pair<Unit, Unit>(((GameState) this.handler).chosenRepairer, ((GameState) this.handler).chosenBuildingRepair));
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 CheckScan method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).CSs.isEmpty()) {
return State.FAILURE;
}
if (((GameState) this.handler).getGame().elapsedTime() - ((GameState) this.handler).startCount > 1) {
for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
if ((u.isCloaked() || u.isBurrowed()) && !u.isDetected() && u.getType().canAttack()) {
((GameState) this.handler).checkScan = u.getTilePosition();
return State.SUCCESS;
}
}
}
List<BaseLocation> valid = new ArrayList<>();
for (BaseLocation b : ((GameState) this.handler).EnemyBLs) {
if (((GameState) this.handler).getGame().isVisible(b.getTilePosition()) || b.isIsland()) {
continue;
}
if (((GameState) this.handler).enemyBase != null) {
if (((GameState) this.handler).enemyBase.getTilePosition().equals(b.getTilePosition())) {
continue;
}
}
valid.add(b);
}
if (valid.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).CSs) {
if (u.getEnergy() == 200) {
Random random = new Random();
((GameState) this.handler).checkScan = valid.get(random.nextInt(valid.size())).getTilePosition();
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 ChooseBuildingToHarass method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenUnitToHarass != null) {
return State.FAILURE;
}
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (((GameState) this.handler).enemyBase != null) {
if (u.type.isBuilding()) {
if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(((GameState) this.handler).enemyBase.getPosition()).getCenter())) {
((GameState) this.handler).chosenUnitToHarass = u.unit;
return State.SUCCESS;
}
}
}
}
if (((GameState) this.handler).chosenHarasser.isIdle()) {
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
((GameState) this.handler).chosenHarasser.stop();
((GameState) this.handler).chosenHarasser = null;
((GameState) this.handler).chosenUnitToHarass = null;
}
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 ChooseWorker method execute.
@Override
public State execute() {
try {
Unit closestWorker = null;
int frame = ((GameState) this.handler).frameCount;
Position chosen = ((GameState) this.handler).chosenPosition.toPosition();
if (!((GameState) this.handler).workerIdle.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerIdle) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
}
if (!((GameState) this.handler).workerMining.isEmpty()) {
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).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 Move method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenWorker;
if (!chosen.canMove()) {
return State.FAILURE;
}
boolean success = false;
if (((GameState) this.handler).chosenToBuild == UnitType.Terran_Refinery) {
success = chosen.build(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition);
} else {
Position realEnd = ((GameState) this.handler).getCenterFromBuilding(((GameState) this.handler).chosenPosition.toPosition(), ((GameState) this.handler).chosenToBuild);
success = chosen.move(realEnd);
}
if (success) {
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).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition)));
((GameState) this.handler).deltaCash.first += ((GameState) this.handler).chosenToBuild.mineralPrice();
((GameState) this.handler).deltaCash.second += ((GameState) this.handler).chosenToBuild.gasPrice();
((GameState) this.handler).chosenWorker = null;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations