use of org.openbw.bwapi4j.unit.Marine 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();
}
}
}