use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class Squad method microMedic.
private void microMedic(Medic u, Set<Unit> marinesToHeal) {
PlayerUnit healTarget = getHealTarget(u, marinesToHeal);
if (healTarget != null) {
UtilMicro.heal(u, healTarget);
marinesToHeal.add(healTarget);
} else if (status == Status.IDLE) {
if (getGs().defendPosition != null) {
int range = UnitType.Terran_Marine.groundWeapon().maxRange();
if (getGs().defendPosition.getDistance(u.getPosition()) <= range * ((double) (new Random().nextInt((10 + 1) - 4) + 4)) / 10.0 && Util.shouldIStop(u.getPosition())) {
UtilMicro.stop(u);
} else if (u.getDistance(getGs().defendPosition) > range)
UtilMicro.move(u, getGs().defendPosition);
}
} else if (status == Status.REGROUP) {
if (medicOnly) {
Optional<Squad> closest = getGs().sqManager.squads.values().stream().filter(s -> !s.medicOnly).min(Comparator.comparingDouble(s -> u.getDistance(s.getSquadCenter())));
closest.ifPresent(squad -> UtilMicro.move(u, squad.getSquadCenter()));
return;
}
Position pos = getGs().getNearestCC(u.getPosition(), true);
if (Util.broodWarDistance(pos, u.getPosition()) >= 400)
UtilMicro.heal(u, pos);
} else if (status == Status.ADVANCE && attack != null)
UtilMicro.heal(u, attack);
else if (center.getDistance(u.getPosition()) > 32 * 6)
UtilMicro.heal(u, center);
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class Squad method microTank.
private void microTank(UnitInfo u) {
SiegeTank st = (SiegeTank) u.unit;
if (st.isAttackFrame() || st.isStartingAttack() || st.isSieged() && u.currentOrder == Order.Unsieging)
return;
if (!st.isSieged() && u.currentOrder == Order.Sieging)
return;
if (u.currentOrder == Order.Unsieging || u.currentOrder == Order.Sieging)
return;
switch(status) {
case ATTACK:
case DEFENSE:
boolean found = false;
boolean close = false;
int threats = (int) squadSim.enemies.stream().filter(e -> e.unitType.canAttack() || e.unitType.isSpellcaster() || Util.isStaticDefense(e.unitType)).count();
for (UnitInfo e : squadSim.enemies) {
if (e.flying || e.unit instanceof Worker || e.unit instanceof Medic || (e.unitType.isBuilding() && !Util.isStaticDefense(e)))
continue;
int distance = u.getDistance(e);
if (!found && distance <= UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().maxRange() - 8 && (e.health + e.shields >= 60 || threats > 2)) {
found = true;
}
if (!close && distance < UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().minRange())
close = true;
if (found && close)
break;
}
if (found && !close) {
if (!st.isSieged()) {
st.siege();
return;
}
}
if (status == Status.DEFENSE && st.isSieged() && getGs().defendPosition != null) {
double range = u.groundRange - 8;
if (u.getDistance(getGs().defendPosition) > range)
st.unsiege();
return;
}
Set<UnitInfo> tankTargets = squadSim.enemies.stream().filter(e -> !e.flying).collect(Collectors.toSet());
if (st.isSieged()) {
tankTargets.removeIf(e -> u.getDistance(e) > UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().maxRange() - 8 || (e.unitType.isBuilding() && !Util.isStaticDefense(e)) || (!e.unitType.isBuilding() && !e.unitType.canAttack() && !e.unitType.isSpellcaster()));
if (tankTargets.isEmpty() && Math.random() * 10 <= 3) {
st.unsiege();
return;
}
}
UnitInfo target = Util.getTankTarget(u, tankTargets);
if (target != null)
UtilMicro.attack(u, target);
else if (attack != null && Math.random() * 10 <= 2.5) {
if (st.isSieged())
st.unsiege();
else
UtilMicro.move(st, attack);
}
break;
case IDLE:
Position move = null;
if (getGs().defendPosition != null) {
move = getGs().defendPosition;
} else if (!getGs().DBs.isEmpty()) {
Unit bunker = getGs().DBs.keySet().iterator().next();
if (Util.broodWarDistance(bunker.getPosition(), center) >= 180 && getGs().getArmySize() < getGs().getStrat().armyForAttack && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
if (u.currentOrder != Order.Move)
move = bunker.getPosition();
}
} else if (getGs().mainChoke != null && !getGs().learningManager.isNaughty() && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
if (Util.broodWarDistance(getGs().mainChoke.getCenter().toPosition(), center) >= 200 && getGs().getArmySize() < getGs().getStrat().armyForAttack) {
if (u.currentOrder != Order.Move)
move = getGs().mainChoke.getCenter().toPosition();
}
} else if (Util.broodWarDistance(u.position, center) >= 180 && u.currentOrder != Order.Move) {
if (getGs().getGame().getBWMap().isWalkable(center.toWalkPosition()))
move = center;
}
if (move != null) {
WeaponType weapon = Util.getWeapon(u.unitType);
int range = weapon.maxRange();
if (u.currentOrder == Order.AttackMove || u.currentOrder == Order.PlayerGuard || u.currentOrder == Order.Move) {
if (u.getDistance(move) <= range * ((double) (new Random().nextInt((10 + 1) - 4) + 4)) / 10.0 && Util.shouldIStop(u.position)) {
if (!st.isSieged() && getGs().getPlayer().hasResearched(TechType.Tank_Siege_Mode)) {
st.siege();
} else
UtilMicro.stop(st);
return;
}
} else if (u.getDistance(move) > range) {
if (st.isSieged() && !getGs().defense) {
st.unsiege();
} else
UtilMicro.attack(st, move);
return;
}
}
break;
case REGROUP:
if (st.isDefenseMatrixed() || getGs().sim.farFromFight(u, squadSim, false))
return;
Position pos = getGs().getNearestCC(u.position, true);
if (Util.broodWarDistance(pos, u.position) >= 400)
UtilMicro.move(st, pos);
break;
case ADVANCE:
if (st.isSieged() && Math.random() * 10 <= 6)
st.unsiege();
else {
double dist = Util.broodWarDistance(u.position, center);
if (dist >= 300) {
UtilMicro.attack(st, center);
return;
} else if (attack != null) {
UtilMicro.move(st, attack);
}
}
break;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class Squad method executeRangedAttackLogic.
private void executeRangedAttackLogic(UnitInfo u) {
if (u.unit.isAttackFrame() || u.unit.isStartingAttack())
return;
UnitInfo target = Util.getRangedTarget(u, squadSim.enemies, attack);
if (target == null) {
if (attack != null)
UtilMicro.attack((MobileUnit) u.unit, attack);
return;
}
double distToTarget = u.getDistance(target);
Optional<UnitInfo> bunker = squadSim.allies.stream().filter(ally -> ally.unitType == UnitType.Terran_Bunker).findFirst();
if (status == Status.DEFENSE && IntelligenceAgency.enemyIsRushing() && bunker.isPresent() && u.getDistance(bunker.get()) > distToTarget) {
UtilMicro.move((MobileUnit) u.unit, bunker.get().lastPosition);
}
double speed = u.speed;
if (getGs().frameCount - u.unit.getLastCommandFrame() <= 10)
return;
WeaponType w = Util.getWeapon(u, target);
double range = u.player.getUnitStatCalculator().weaponMaxRange(w);
int cooldown = (target.flying ? ((AirAttacker) u.unit).getAirWeaponCooldown() : ((GroundAttacker) u.unit).getGroundWeaponCooldown()) - getGs().getIH().getRemainingLatencyFrames() - 2;
int framesToFiringRange = (int) Math.ceil(Math.max(0, distToTarget - range) / speed);
if (cooldown <= framesToFiringRange) {
UtilMicro.attack(u, target);
return;
}
Position predictedPosition = null;
int targetRange = target.player.getUnitStatCalculator().weaponMaxRange(Util.getWeapon(target, u));
boolean kite = true;
boolean enemyTooClose = distToTarget <= 3 * 32 && targetRange <= 32;
boolean moveCloser = target.unitType == UnitType.Terran_Siege_Tank_Siege_Mode || (target.unit instanceof SCV && ((SCV) target.unit).isRepairing() && target.unit.getOrderTarget() != null && target.unit.getOrderTarget().getType() == UnitType.Terran_Bunker) || (target.unitType.isBuilding() && !Util.canAttack(target, u));
if (!moveCloser) {
predictedPosition = UtilMicro.predictUnitPosition(target, 2);
if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
double distPredicted = u.getDistance(predictedPosition);
double distCurrent = u.getDistance(target);
if (distPredicted > distCurrent) {
kite = false;
if (distToTarget > (range - 24))
moveCloser = true;
} else if (distCurrent == distPredicted && range >= (targetRange + 64) && distToTarget > (range - 48)) {
moveCloser = true;
}
}
}
if (moveCloser && !enemyTooClose) {
if (distToTarget > 32 && !u.unit.isStartingAttack() && !u.unit.isAttackFrame()) {
if (predictedPosition != null)
UtilMicro.move((MobileUnit) u.unit, predictedPosition);
else
UtilMicro.move((MobileUnit) u.unit, target.lastPosition);
} else
UtilMicro.attack(u, target);
return;
}
if ((kite || enemyTooClose) && target.unitType.topSpeed() > 0) {
Position kitePos = UtilMicro.kiteAwayAlt(u.position, target.lastPosition);
if (kitePos != null)
UtilMicro.move((MobileUnit) u.unit, kitePos);
else {
kitePos = UtilMicro.kiteAway(u.unit, squadSim.enemies);
if (kitePos != null)
UtilMicro.move((MobileUnit) u.unit, kitePos);
}
} else
UtilMicro.attack(u, target);
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class Squad method giveMoveOrder.
public void giveMoveOrder(Position retreat) {
int frameCount = getGs().frameCount;
for (UnitInfo u : members) {
PlayerUnit pU = u.unit;
if (u.unitType == UnitType.Terran_Siege_Tank_Siege_Mode && pU.getOrder() == Order.Unsieging)
continue;
if (u.unitType == UnitType.Terran_Siege_Tank_Tank_Mode && pU.getOrder() == Order.Sieging)
continue;
Position lastTarget = ((MobileUnit) u.unit).getTargetPosition() == null ? pU.getOrderTargetPosition() : ((MobileUnit) u.unit).getTargetPosition();
if (lastTarget != null && lastTarget.equals(retreat))
continue;
if (attack != null && frameCount != pU.getLastCommandFrame())
((MobileUnit) u.unit).move(retreat);
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class UtilMicro method kiteAwayAlt.
// Based on @Locutus micro logic, credits to him.
public static Position kiteAwayAlt(Position unitPos, Position fleePos) {
Position delta = fleePos.subtract(unitPos);
double angleToTarget = Math.atan2(delta.getY(), delta.getX());
Position bestPosition = null;
boolean shouldBreak = false;
for (int i = 0; i <= 3; i++) {
if (shouldBreak)
break;
for (int sign = -1; i == 0 ? sign == -1 : sign <= 1; sign += 2) {
double a = angleToTarget + (i * sign * Math.PI / 6);
Position position = new Position(unitPos.getX() - (int) Math.round(64.0 * Math.cos(a)), unitPos.getY() - (int) Math.round(64.0 * Math.sin(a)));
if (!verifyPosition(position) || !verifyPosition(position.add(new Position(-16, -16))) || !verifyPosition(position.add(new Position(16, -16))) || !verifyPosition(position.add(new Position(16, 16))) || !verifyPosition(position.add(new Position(-16, 16)))) {
continue;
}
bestPosition = position;
shouldBreak = true;
}
}
if (bestPosition != null && getGs().getGame().getBWMap().isValidPosition(bestPosition)) {
return bestPosition;
}
return null;
}
Aggregations