use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class VultureAgent method getNewStatus.
private void getNewStatus() {
if (mySim.enemies.isEmpty()) {
status = Status.ATTACK;
} else {
boolean meleeOnly = checkOnlyMelees();
if (!meleeOnly && getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND).lose) {
status = Util.isInOurBases(unitInfo) ? Status.KITE : Status.RETREAT;
return;
}
if (status == Status.PATROL && actualFrame - lastPatrolFrame > 5) {
status = Status.COMBAT;
return;
}
int cd = unit.getGroundWeapon().cooldown();
UnitInfo closestAttacker = Util.getClosestUnit(unitInfo, mySim.enemies, true);
if (closestAttacker != null && (cd != 0 || unitInfo.getDistance(closestAttacker) < unitInfo.groundRange * 0.6)) {
status = Status.KITE;
return;
}
if (status == Status.COMBAT || status == Status.ATTACK) {
/*if (attackUnit != null) {
int weaponRange = attackUnit instanceof GroundAttacker ? ((GroundAttacker) attackUnit).getGroundWeaponMaxRange() : 0;
if (weaponRange > type.groundWeapon().maxRange()) return;
}*/
if (cd > 0) {
if (attackUnit != null) {
Position predictedPosition = UtilMicro.predictUnitPosition(attackUnit, 2);
if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
double distPredicted = unit.getDistance(predictedPosition);
double distCurrent = unitInfo.getDistance(attackUnit);
if (distPredicted > distCurrent) {
status = Status.COMBAT;
return;
} else {
attackUnit = null;
attackPos = null;
status = Status.KITE;
return;
}
}
}
if (mySim.enemies.isEmpty()) {
status = Status.ATTACK;
return;
}
status = Status.COMBAT;
return;
}
}
if (status == Status.KITE) {
UnitInfo closest = getUnitToAttack(mySim.enemies);
if (closest != null) {
double dist = unitInfo.getDistance(closest);
double speed = type.topSpeed();
double timeToEnter = 0.0;
if (speed > .00001)
timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
if (timeToEnter >= cd) {
// status = Status.COMBAT;
status = Status.PATROL;
attackUnit = closest;
return;
}
} else {
status = Status.ATTACK;
return;
}
if (cd == 0)
status = Status.COMBAT;
}
}
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class CheckScan method execute.
@Override
public State execute() {
try {
if (gameState.CSs.isEmpty())
return State.FAILURE;
if (gameState.frameCount - gameState.startCount > 40 + gameState.getIH().getLatency()) {
for (ComsatStation u : gameState.CSs) {
if (u.getEnergy() < 50)
continue;
for (UnitInfo e : gameState.unitStorage.getEnemyUnits().values()) {
if ((e.unit.isCloaked() || e.burrowed) && !e.unit.isDetected() && e.unit instanceof Attacker) {
if (gameState.sim.getSimulation(e, true).allies.stream().noneMatch(a -> a.unitType.canAttack()))
continue;
gameState.checkScan = new MutablePair<>(u, e.lastPosition);
return State.SUCCESS;
}
}
}
}
List<Base> valid = new ArrayList<>();
for (Base b : gameState.enemyBLs) {
if (gameState.getGame().getBWMap().isVisible(b.getLocation()) || b.getArea().getAccessibleNeighbors().isEmpty()) {
continue;
}
if (gameState.enemyMainBase != null && gameState.enemyMainBase.getLocation().equals(b.getLocation())) {
continue;
}
valid.add(b);
}
if (valid.isEmpty())
return State.FAILURE;
for (ComsatStation u : gameState.CSs) {
if (u.getEnergy() == 200) {
Random random = new Random();
gameState.checkScan = new MutablePair<>(u, Util.getUnitCenterPosition(valid.get(random.nextInt(valid.size())).getLocation().toPosition(), gameState.enemyRace.getCenter()));
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations