Search in sources :

Example 1 with Bunker

use of org.openbw.bwapi4j.unit.Bunker in project Ecgberht by Jabbo16.

the class SquadManager method updateBunkers.

void updateBunkers() {
    // TODO improve
    for (Map.Entry<Bunker, Set<UnitInfo>> bunker : getGs().DBs.entrySet()) {
        SimInfo bunkerSim = getGs().sim.getSimulation(getGs().unitStorage.getAllyUnits().get(bunker.getKey()), SimInfo.SimType.MIX);
        if (!bunkerSim.enemies.isEmpty()) {
            if (bunker.getValue().size() < 4) {
                Marine closest = null;
                double bestDist = Double.MAX_VALUE;
                for (UnitInfo u : bunkerSim.allies) {
                    if (!(u.unit instanceof Marine))
                        continue;
                    double dist = u.getDistance(bunker.getKey());
                    if (dist < bestDist) {
                        closest = (Marine) u.unit;
                        bestDist = dist;
                    }
                }
                if (closest != null) {
                    UnitInfo closestUI = getGs().unitStorage.getAllyUnits().get(closest);
                    bunker.getValue().add(closestUI);
                    bunkerSim.allies.remove(closestUI);
                    closest.rightClick(bunker.getKey(), false);
                }
            }
        } else {
            bunker.getKey().unloadAll();
            bunkerSim.allies.addAll(bunker.getValue());
            bunker.getValue().clear();
        }
    }
}
Also used : SimInfo(ecgberht.Simulation.SimInfo) Set(java.util.Set) Marine(org.openbw.bwapi4j.unit.Marine) Bunker(org.openbw.bwapi4j.unit.Bunker) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

SimInfo (ecgberht.Simulation.SimInfo)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Bunker (org.openbw.bwapi4j.unit.Bunker)1 Marine (org.openbw.bwapi4j.unit.Marine)1