use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class UtilMicro method move.
public static void move(MobileUnit u, Position pos) {
if (pos == null || u == null || !u.exists())
return;
if (getGs().frameCount == u.getLastCommandFrame())
return;
Position targetPos = u.getTargetPosition();
if (pos.equals(targetPos) || (targetPos != null && pos.toTilePosition().equals(targetPos.toTilePosition())))
return;
if (!getGs().getGame().getBWMap().isValidPosition(pos))
return;
if (!u.isFlying() && !getGs().getGame().getBWMap().isWalkable(pos.toWalkPosition()))
return;
u.move(pos);
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class Squad method microRanged.
// Based on @Locutus micro logic
private void microRanged(UnitInfo u) {
switch(status) {
case ATTACK:
case DEFENSE:
executeRangedAttackLogic(u);
break;
case IDLE:
if (getGs().getStrat().proxy)
return;
Position move = null;
if (getGs().defendPosition != null) {
if (u.currentOrder != Order.Stop)
move = getGs().defendPosition;
} else if (!getGs().DBs.isEmpty()) {
Unit bunker = getGs().DBs.keySet().iterator().next();
if (u.currentOrder != Order.Stop)
move = bunker.getPosition();
} else if (getGs().mainChoke != null && !getGs().learningManager.isNaughty() && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
if (u.currentOrder != Order.Stop)
move = getGs().mainChoke.getCenter().toPosition();
} else if (Util.broodWarDistance(u.position, center) >= 190 && u.currentOrder != Order.Move) {
if (getGs().getGame().getBWMap().isWalkable(center.toWalkPosition()))
move = center;
}
if (move != null) {
WeaponType weapon = Util.getWeapon(u.unitType);
int range2 = weapon == WeaponType.None ? UnitType.Terran_Marine.groundWeapon().maxRange() : weapon.maxRange();
if (u.currentOrder == Order.AttackMove) {
if (u.getDistance(move) <= range2 * ((double) (new Random().nextInt((10 + 1) - 4) + 4)) / 10.0 && Util.shouldIStop(u.position)) {
UtilMicro.stop((MobileUnit) u.unit);
return;
}
} else if (u.getDistance(move) > range2) {
UtilMicro.attack((MobileUnit) u.unit, move);
return;
}
}
break;
case REGROUP:
if (((MobileUnit) u.unit).isDefenseMatrixed() || getGs().sim.farFromFight(u, squadSim, false) || squadSim.enemies.stream().noneMatch(e -> Util.getWeapon(e, u).maxRange() > 32)) {
executeRangedAttackLogic(u);
return;
}
Position pos = getGs().getNearestCC(u.position, true);
if (Util.broodWarDistance(pos, u.position) >= 400) {
UtilMicro.move((MobileUnit) u.unit, pos);
}
break;
case ADVANCE:
double dist = Util.broodWarDistance(u.position, center);
if (dist >= 240) {
UtilMicro.move((MobileUnit) u.unit, center);
return;
} else if (attack != null)
UtilMicro.move((MobileUnit) u.unit, attack);
break;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class SquadManager method createSquads.
public void createSquads(List<Cluster> friendly) {
squads.clear();
int counter = 0;
for (Cluster c : friendly) {
Squad s = new Squad(counter, new Position((int) c.modeX, (int) c.modeY), getGs().sim.getSimulation(c));
squads.put(counter, s);
counter++;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method getCloserMineral.
private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
double bestDist = Double.MAX_VALUE;
MineralPatch closerMineral = null;
SCV scv = entry.getKey();
Position buildTarget = entry.getValue().second.toPosition();
for (MineralPatch mineralPatch : gameState.walkingMinerals) {
if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
continue;
double dist = mineralPatch.getDistance(buildTarget) * 1.2;
if (dist > scv.getDistance(buildTarget))
continue;
Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
continue;
if (dist < bestDist) {
bestDist = dist;
closerMineral = mineralPatch;
}
}
return closerMineral;
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class CheckHarasserAttacked method execute.
@Override
public State execute() {
try {
if (gameState.enemyMainBase == null) {
gameState.chosenUnitToHarass = null;
gameState.chosenHarasser = null;
return State.FAILURE;
}
if (gameState.chosenUnitToHarass != null) {
if (!gameState.bw.getBWMap().isValidPosition(gameState.chosenUnitToHarass.getPosition())) {
gameState.chosenUnitToHarass = null;
}
}
UnitInfo attacker = null;
int workers = 0;
Set<UnitInfo> attackers = new TreeSet<>();
// Thanks to @N00byEdge for cleaner code
for (UnitInfo u : gameState.unitStorage.getAllyUnits().get(gameState.chosenHarasser).attackers) {
if (!(u.unit instanceof Building) && u.unit instanceof Attacker && u.unit.exists()) {
if (u.unit instanceof Worker) {
workers++;
attacker = u;
}
attackers.add(u);
}
}
if (workers > 1) {
gameState.learningManager.setHarass(true);
gameState.chosenUnitToHarass = null;
return State.FAILURE;
}
if (attackers.isEmpty()) {
if (!gameState.getGame().getBWMap().isVisible(gameState.enemyMainBase.getLocation()) && gameState.chosenUnitToHarass == null) {
gameState.chosenHarasser.move(gameState.enemyMainBase.getLocation().toPosition());
}
return State.SUCCESS;
} else {
boolean winHarass = gameState.sim.simulateHarass(gameState.chosenHarasser, attackers, 70);
if (winHarass) {
if (workers == 1 && !attacker.unit.equals(gameState.chosenUnitToHarass)) {
UtilMicro.attack(gameState.chosenHarasser, attacker);
gameState.chosenUnitToHarass = attacker.unit;
return State.SUCCESS;
}
} else {
if (IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.Unknown) {
gameState.explore = true;
gameState.chosenUnitToHarass = null;
gameState.chosenHarasser.stop(false);
return State.FAILURE;
} else if (gameState.chosenHarasser.getHitPoints() <= 15) {
gameState.workerIdle.add(gameState.chosenHarasser);
gameState.chosenHarasser.stop(false);
gameState.chosenHarasser = null;
gameState.chosenUnitToHarass = null;
} else {
// Position kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
Optional<UnitInfo> closestUnit = attackers.stream().min(Comparator.comparing(u -> u.getDistance(gameState.chosenHarasser)));
Position kite = closestUnit.map(unit1 -> UtilMicro.kiteAwayAlt(gameState.chosenHarasser.getPosition(), unit1.position)).orElse(null);
if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
UtilMicro.move(gameState.chosenHarasser, kite);
gameState.chosenUnitToHarass = null;
} else {
kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
UtilMicro.move(gameState.chosenHarasser, kite);
gameState.chosenUnitToHarass = null;
}
}
}
return State.FAILURE;
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations