Search in sources :

Example 11 with MineralPatch

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;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) Unit(org.openbw.bwapi4j.unit.Unit) Map(java.util.Map)

Example 12 with MineralPatch

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;
    }
}
Also used : Mineral(bwem.Mineral) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker)

Example 13 with MineralPatch

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;
    }
}
Also used : MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker)

Example 14 with MineralPatch

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;
    }
}
Also used : MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker)

Example 15 with MineralPatch

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;
    }
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch)

Aggregations

MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)16 Worker (org.openbw.bwapi4j.unit.Worker)9 Position (org.openbw.bwapi4j.Position)4 SCV (org.openbw.bwapi4j.unit.SCV)4 Area (bwem.Area)3 TilePosition (org.openbw.bwapi4j.TilePosition)3 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)3 MutablePair (ecgberht.Util.MutablePair)2 Unit (org.openbw.bwapi4j.unit.Unit)2 Base (bwem.Base)1 Mineral (bwem.Mineral)1 MapPrinterExample (bwem.example.MapPrinterExample)1 Geyser (bwem.unit.Geyser)1 Mineral (bwem.unit.Mineral)1 Squad (ecgberht.Squad)1 UnitInfo (ecgberht.UnitInfo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Player (org.openbw.bwapi4j.Player)1