use of ecgberht.Simulation.SimInfo in project Ecgberht by Jabbo16.
the class VesselAgent method getNewStatus.
private void getNewStatus() {
SimInfo mySimAir = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.AIR);
SimInfo mySimMix = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.MIX);
boolean chasenByScourge = false;
boolean sporeColony = false;
double maxScore = 0;
PlayerUnit chosen = null;
if (getGs().enemyRace == Race.Zerg && !mySimAir.enemies.isEmpty()) {
for (UnitInfo u : mySimAir.enemies) {
if (u.unit instanceof Scourge && u.target.equals(unit))
chasenByScourge = true;
else if (u.unit instanceof SporeColony && unitInfo.getDistance(u) < u.airRange * 1.2)
sporeColony = true;
if (chasenByScourge && sporeColony)
break;
}
}
if (!mySimMix.enemies.isEmpty()) {
// Irradiate
Set<UnitInfo> irradiateTargets = new TreeSet<>(mySimMix.enemies);
for (UnitInfo t : mySimMix.allies) {
if (t.unit instanceof SiegeTank)
irradiateTargets.add(t);
}
if (follow != null && !irradiateTargets.isEmpty() && getGs().getPlayer().hasResearched(TechType.Irradiate) && unit.getEnergy() >= TechType.Irradiate.energyCost() && follow.status != Squad.Status.IDLE) {
for (UnitInfo u : irradiateTargets) {
if (!u.visible)
continue;
if (u.unit instanceof Building || u.unit instanceof Egg || (!(u.unit instanceof Organic) && !(u.unit instanceof SiegeTank)))
continue;
if (u.unit instanceof MobileUnit && (u.unit.isIrradiated() || ((MobileUnit) u.unit).isStasised()))
continue;
if (getGs().wizard.isUnitIrradiated(u.unit))
continue;
double score = 1;
int closeUnits = 0;
for (UnitInfo close : irradiateTargets) {
if (u.equals(close) || !(close.unit instanceof Organic) || close.burrowed)
continue;
if (u.getDistance(close) <= 32)
closeUnits++;
}
if (// Kill it with fire!!
u.unitType == UnitType.Zerg_Lurker)
// Kill it with fire!!
score = u.burrowed ? 20 : 18;
else if (u.unitType == UnitType.Zerg_Mutalisk)
score = 8;
else if (u.unitType == UnitType.Zerg_Hydralisk)
score = 5;
else if (u.unitType == UnitType.Zerg_Zergling)
score = 2;
// Prefer healthy units
score *= u.percentHealth;
double multiplier = u.unit instanceof SiegeTank ? 3.75 : u.unitType == UnitType.Zerg_Lurker ? 2.5 : u.unitType == UnitType.Zerg_Mutalisk ? 2 : 1;
score += multiplier * closeUnits;
if (chosen == null || score > maxScore) {
chosen = u.unit;
maxScore = score;
}
}
if (maxScore >= 5) {
status = Status.IRRADIATE;
target = chosen;
return;
}
}
chosen = null;
maxScore = 0;
// EMP
Set<UnitInfo> empTargets = new TreeSet<>(mySimMix.enemies);
if (follow != null && !empTargets.isEmpty() && getGs().getPlayer().hasResearched(TechType.EMP_Shockwave) && unit.getEnergy() >= TechType.EMP_Shockwave.energyCost() && follow.status != Squad.Status.IDLE) {
for (UnitInfo u : empTargets) {
// TODO Change to rectangle to choose best Position and track emped positions
if (!u.visible || u.unit instanceof Building || u.unit instanceof Worker || u.unit instanceof MobileUnit && (u.unit.isIrradiated() || ((MobileUnit) u.unit).isStasised()))
continue;
if (getGs().wizard.isUnitEMPed(u.unit))
continue;
double score = 1;
double closeUnits = 0;
for (UnitInfo close : empTargets) {
if (u.equals(close))
continue;
if (close.lastPosition.getDistance(u.lastPosition) <= WeaponType.EMP_Shockwave.innerSplashRadius())
closeUnits += close.shields * 0.6;
}
if (u.unitType == UnitType.Protoss_High_Templar)
score = 10;
else if (u.unitType == UnitType.Protoss_Arbiter)
score = 7;
else if (u.unitType == UnitType.Protoss_Archon || u.unitType == UnitType.Protoss_Dark_Archon)
score = 5;
// Prefer healthy units(shield)
score *= u.percentShield;
double multiplier = u.unitType == UnitType.Protoss_High_Templar ? 6 : 1;
score += multiplier * closeUnits;
if (chosen == null || score > maxScore) {
chosen = u.unit;
maxScore = score;
}
}
if (maxScore >= 6) {
status = Status.EMP;
target = chosen;
return;
}
}
chosen = null;
maxScore = 0;
}
if (!mySimMix.allies.isEmpty()) {
// Defense Matrix
Set<UnitInfo> matrixTargets = new TreeSet<>(mySimMix.allies);
if (follow != null && !matrixTargets.isEmpty() && unit.getEnergy() >= TechType.Defensive_Matrix.energyCost() && follow.status != Squad.Status.IDLE) {
for (UnitInfo u : matrixTargets) {
if (!(u.unit instanceof MobileUnit))
continue;
if (getGs().wizard.isDefenseMatrixed((MobileUnit) u.unit))
continue;
double score = 1;
if (!u.unit.isUnderAttack() || ((MobileUnit) u.unit).isDefenseMatrixed())
continue;
if (u.unitType.isMechanical())
score = 8;
if (u.unitType == UnitType.Terran_Marine || u.unitType == UnitType.Terran_Firebat)
score = 3;
if (u.unitType == UnitType.Terran_SCV || u.unitType == UnitType.Terran_Medic)
score = 1;
score *= (double) u.unitType.maxHitPoints() / (double) u.health;
if (chosen == null || score > maxScore) {
chosen = u.unit;
maxScore = score;
}
}
if (maxScore >= 2) {
status = Status.DMATRIX;
target = chosen;
return;
}
}
}
if ((status == Status.IRRADIATE || status == Status.DMATRIX || status == Status.EMP) && target != null)
return;
if (!mySimAir.enemies.isEmpty()) {
if (unit.isUnderAttack() || chasenByScourge || sporeColony)
status = Status.KITE;
else if (Util.broodWarDistance(unit.getPosition(), center) >= 100)
status = Status.FOLLOW;
else if (mySimAir.lose)
status = Status.KITE;
} else if (mySimMix.lose)
status = Status.RETREAT;
else if (Util.broodWarDistance(unit.getPosition(), center) >= 200)
status = Status.FOLLOW;
else
status = Status.HOVER;
}
use of ecgberht.Simulation.SimInfo in project Ecgberht by Jabbo16.
the class WraithAgent method runAgent.
@Override
public boolean runAgent() {
// TODO improve
try {
if (!unit.exists() || unitInfo == null)
return true;
actualFrame = getGs().frameCount;
frameLastOrder = unit.getLastCommandFrame();
airAttackers.clear();
if (frameLastOrder == actualFrame)
return false;
Position attack = getBestBaseToHarass();
UnitInfo closestThreat = null;
double bestDist = Double.MAX_VALUE;
SimInfo airSim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.AIR);
airAttackers = airSim.enemies;
for (UnitInfo u : airAttackers) {
double predictedDist = unitInfo.getPredictedDistance(u);
if (predictedDist < bestDist) {
closestThreat = u;
bestDist = predictedDist;
}
}
Set<UnitInfo> mainTargets = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.MIX).enemies;
UnitInfo harassed = chooseHarassTarget(mainTargets);
if (closestThreat != null) {
Weapon myWeapon = closestThreat.flying ? unit.getAirWeapon() : unit.getGroundWeapon();
double hisAirWeaponRange = closestThreat.airRange;
Position kitePos = UtilMicro.kiteAway(unit, new TreeSet<>(Collections.singleton(closestThreat)));
if (myWeapon.maxRange() > hisAirWeaponRange && bestDist > hisAirWeaponRange) {
if (myWeapon.cooldown() != 0) {
if (kitePos != null) {
UtilMicro.move(unit, kitePos);
return false;
}
} else if (harassed != null && unitInfo.getDistance(harassed) <= myWeapon.maxRange()) {
UtilMicro.attack(unitInfo, harassed);
} else
UtilMicro.attack(unitInfo, closestThreat);
return false;
}
if (kitePos != null) {
UtilMicro.move(unit, kitePos);
return false;
}
}
if (harassed != null) {
UtilMicro.attack(unitInfo, harassed);
return false;
}
UnitInfo target = Util.getRangedTarget(unitInfo, mainTargets);
if (target != null) {
UtilMicro.attack(unitInfo, target);
return false;
}
if (attack != null) {
if (attack.getDistance(myUnit.getPosition()) >= 32 * 5)
UtilMicro.move(unit, attack);
else
UtilMicro.attack(unit, attack);
return false;
}
return false;
} catch (Exception e) {
System.err.println("Exception WraithAgent");
e.printStackTrace();
}
return false;
}
use of ecgberht.Simulation.SimInfo 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();
}
}
}
Aggregations