use of org.openbw.bwapi4j.unit.MineralPatch in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method execute.
@Override
public State execute() {
try {
if (gameState.walkingMinerals.isEmpty())
return State.SUCCESS;
for (Map.Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
if (u.getValue().first != UnitType.Terran_Command_Center)
continue;
SCV scv = u.getKey();
Unit movingMineral = u.getKey().getTargetUnit();
if (movingMineral == null) {
MineralPatch target = getCloserMineral(u);
if (target == null) {
if (scv.getOrderTarget() != null && scv.getOrder() != Order.Move) {
scv.move(u.getValue().second.toPosition());
}
continue;
}
if (!target.equals(scv.getTargetUnit()))
scv.rightClick(target, false);
} else if (scv.getDistance(movingMineral) < 32) {
scv.move(u.getValue().second.toPosition());
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.unit.MineralPatch in project Ecgberht by Jabbo16.
the class CheckBlockingMinerals method execute.
@Override
public State execute() {
try {
Worker scv = gameState.chosenWorkerDrop;
MineralPatch chosen = null;
if (gameState.chosenIsland == null)
return State.FAILURE;
for (Mineral p : gameState.chosenIsland.getBlockingMinerals()) {
if (!p.getUnit().exists())
continue;
chosen = (MineralPatch) p.getUnit();
break;
}
if (chosen != null) {
if (scv.getOrderTarget() != null && scv.getOrderTarget().equals(chosen))
return State.FAILURE;
scv.gather(chosen);
return State.FAILURE;
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.unit.MineralPatch in project Ecgberht by Jabbo16.
the class SendToDrop method execute.
@Override
public State execute() {
try {
if (gameState.chosenDropShip != null && gameState.chosenWorker != null) {
Worker chosen = gameState.chosenWorker;
if (gameState.workerIdle.contains(chosen)) {
gameState.workerIdle.remove(chosen);
} else if (gameState.workerMining.containsKey(chosen)) {
MineralPatch mineral = gameState.workerMining.get(chosen);
gameState.workerMining.remove(chosen);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
}
gameState.chosenDropShip.setCargo(new TreeSet<>(Collections.singletonList(gameState.chosenWorker)));
gameState.chosenDropShip.setTarget(gameState.chosenIsland.getLocation().toPosition());
gameState.chosenWorkerDrop = gameState.chosenWorker;
gameState.chosenWorker = null;
return State.SUCCESS;
}
gameState.chosenDropShip = null;
gameState.chosenWorker = null;
gameState.chosenIsland = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.unit.MineralPatch in project Ecgberht by Jabbo16.
the class CollectMineral method execute.
@Override
public State execute() {
try {
Worker chosen = gameState.chosenWorker;
if (!gameState.mineralsAssigned.isEmpty()) {
MineralPatch closestMineral = null;
int workerPerPatch = 2;
if (gameState.workerMining.size() < 7)
workerPerPatch = 1;
for (Entry<MineralPatch, Integer> m : gameState.mineralsAssigned.entrySet()) {
if ((closestMineral == null || chosen.getDistance(m.getKey()) < chosen.getDistance(closestMineral)) && m.getValue() < workerPerPatch) {
closestMineral = m.getKey();
}
}
if (closestMineral != null && chosen.gather(closestMineral, false)) {
gameState.mineralsAssigned.put(closestMineral, gameState.mineralsAssigned.get(closestMineral) + 1);
gameState.workerMining.put(chosen, closestMineral);
gameState.workerIdle.remove(chosen);
gameState.chosenWorker = null;
gameState.mining++;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.unit.MineralPatch in project Ecgberht by Jabbo16.
the class Repair method execute.
@Override
public State execute() {
try {
boolean cheesed = IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2;
boolean fastExpanding = gameState.getStrat().name.contains("GreedyFE") && Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && gameState.firstExpand;
if (cheesed || fastExpanding) {
if (gameState.chosenRepairer.move(gameState.chosenUnitRepair.getPosition())) {
if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
gameState.workerIdle.remove(gameState.chosenRepairer);
} else {
if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
gameState.workerMining.remove(gameState.chosenRepairer);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
}
}
gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.SUCCESS;
}
} else if (gameState.chosenRepairer.repair(gameState.chosenUnitRepair)) {
if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
gameState.workerIdle.remove(gameState.chosenRepairer);
} else {
if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
gameState.workerMining.remove(gameState.chosenRepairer);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
}
}
gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
if (gameState.chosenUnitRepair instanceof MobileUnit) {
((MobileUnit) gameState.chosenUnitRepair).move(gameState.chosenRepairer.getPosition());
}
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.SUCCESS;
}
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations