use of ecgberht.Agents.WraithAgent in project Ecgberht by Jabbo16.
the class Ecgberht method onUnitComplete.
@Override
public void onUnitComplete(Unit arg0) {
try {
if (arg0 instanceof MineralPatch || arg0 instanceof VespeneGeyser || arg0 instanceof SpecialBuilding || arg0 instanceof Critter || arg0 instanceof ScannerSweep) {
return;
}
skycladObserver.moveCameraUnitCompleted(arg0);
PlayerUnit pU = (PlayerUnit) arg0;
UnitType type = arg0.getType();
if (!type.isNeutral() && pU.getPlayer().getId() == self.getId()) {
gs.unitStorage.onUnitComplete(arg0);
if (gs.ih.getFrameCount() > 0)
gs.supplyMan.onComplete(arg0);
if (type.isBuilding()) {
gs.builtBuildings++;
if (type.isRefinery()) {
for (Entry<VespeneGeyser, Boolean> r : gs.vespeneGeysers.entrySet()) {
if (r.getKey().getTilePosition().equals(arg0.getTilePosition())) {
gs.vespeneGeysers.put(r.getKey(), true);
break;
}
}
for (Entry<SCV, Building> u : gs.workerTask.entrySet()) {
if (u.getValue().equals(arg0)) {
gs.workerGas.put(u.getKey(), (GasMiningFacility) arg0);
gs.workerTask.remove(u.getKey());
break;
}
}
gs.refineriesAssigned.put((GasMiningFacility) arg0, 1);
gs.builtRefinery++;
} else {
if (type == UnitType.Terran_Command_Center) {
Base ccBase = Util.getClosestBaseLocation(arg0.getPosition());
if (!gs.islandBases.isEmpty() && gs.islandBases.contains(ccBase))
gs.islandCCs.put(ccBase, (CommandCenter) arg0);
else
gs.CCs.put(ccBase, (CommandCenter) arg0);
if (gs.getStrat().name.equals("BioMechGreedyFE") && Util.getNumberCCs() > 2)
gs.getStrat().raxPerCC = 3;
else if (gs.getStrat().name.equals("BioMechGreedyFE") && Util.getNumberCCs() < 3)
gs.getStrat().raxPerCC = 2;
gs.addNewResources(ccBase);
if (gs.frameCount != 0 && gs.firstExpand && ccBase.getArea().equals(gs.naturalArea) && !gs.defense)
gs.workerTransfer();
if (gs.frameCount != 0 && gs.firstExpand) {
gs.firstExpand = false;
if (gs.getStrat().name.equals("14CC")) {
gs.scipio.choose14CCTransition();
transition();
}
if (gs.naturalChoke != null)
gs.defendPosition = gs.naturalChoke.getCenter().toPosition();
}
if (((CommandCenter) arg0).getAddon() != null && !gs.CSs.contains(((CommandCenter) arg0).getAddon())) {
gs.CSs.add((ComsatStation) ((CommandCenter) arg0).getAddon());
}
if (gs.frameCount == 0)
gs.mainCC = new MutablePair<>(ccBase, arg0);
}
if (type == UnitType.Terran_Comsat_Station)
gs.CSs.add((ComsatStation) arg0);
if (type == UnitType.Terran_Bunker)
gs.DBs.put((Bunker) arg0, new TreeSet<>());
if (type == UnitType.Terran_Engineering_Bay || type == UnitType.Terran_Academy) {
gs.UBs.add((ResearchingFacility) arg0);
}
if (type == UnitType.Terran_Barracks)
gs.MBs.add((Barracks) arg0);
if (type == UnitType.Terran_Factory)
gs.Fs.add((Factory) arg0);
if (type == UnitType.Terran_Starport)
gs.Ps.add((Starport) arg0);
if (type == UnitType.Terran_Science_Facility)
gs.UBs.add((ResearchingFacility) arg0);
if (type == UnitType.Terran_Control_Tower)
gs.UBs.add((ResearchingFacility) arg0);
if (type == UnitType.Terran_Armory)
gs.UBs.add((ResearchingFacility) arg0);
if (type == UnitType.Terran_Supply_Depot)
gs.SBs.add((SupplyDepot) arg0);
if (type == UnitType.Terran_Machine_Shop)
gs.UBs.add((ResearchingFacility) arg0);
if (type == UnitType.Terran_Missile_Turret)
gs.Ts.add((MissileTurret) arg0);
for (Entry<SCV, Building> u : gs.workerTask.entrySet()) {
if (u.getValue().equals(arg0)) {
gs.workerIdle.add(u.getKey());
gs.workerTask.remove(u.getKey());
break;
}
}
}
} else if (type.isWorker())
gs.workerIdle.add((Worker) arg0);
else if (type == UnitType.Terran_Vulture && !gs.getStrat().name.equals("TheNitekat") && !bw.getBWMap().mapHash().equals("666dd28cd3c85223ebc749a481fc281e58221e4a"))
gs.agents.put(arg0, new VultureAgent(arg0));
else if (type == UnitType.Terran_Dropship) {
DropShipAgent d = new DropShipAgent(arg0);
gs.agents.put(arg0, d);
} else if (type == UnitType.Terran_Science_Vessel) {
VesselAgent v = new VesselAgent(arg0);
gs.agents.put(arg0, v);
} else if (type == UnitType.Terran_Wraith) {
if (!gs.getStrat().name.equals("PlasmaWraithHell")) {
String name = gs.pickShipName();
gs.agents.put(arg0, new WraithAgent(arg0, name));
}
} else {
gs.myArmy.add(gs.unitStorage.getAllyUnits().get(arg0));
if (gs.enemyMainBase != null && gs.silentCartographer.mapCenter.getDistance(gs.enemyMainBase.getLocation()) < arg0.getTilePosition().getDistance(gs.enemyMainBase.getLocation())) {
((MobileUnit) arg0).move(gs.silentCartographer.mapCenter.toPosition());
}
}
}
} catch (Exception e) {
System.err.println("onUnitComplete exception");
e.printStackTrace();
}
}
use of ecgberht.Agents.WraithAgent in project Ecgberht by Jabbo16.
the class Ecgberht method onUnitDestroy.
@Override
public void onUnitDestroy(Unit arg0) {
try {
UnitType type = arg0.getType();
if (type.isMineralField()) {
if (gs.mineralsAssigned.containsKey(arg0)) {
gs.map.updateMap(arg0.getTilePosition(), type, true);
gs.testMap = gs.map.clone();
List<Unit> aux = new ArrayList<>();
for (Entry<Worker, MineralPatch> w : gs.workerMining.entrySet()) {
if (arg0.equals(w.getValue())) {
w.getKey().stop(false);
gs.workerIdle.add(w.getKey());
aux.add(w.getKey());
}
}
for (Unit u : aux) gs.workerMining.remove(u);
gs.mineralsAssigned.remove(arg0);
}
}
if (!type.isBuilding() && !type.isRefinery() && type != UnitType.Resource_Vespene_Geyser && type != UnitType.Spell_Scanner_Sweep && !first) {
gs.playSound("first.mp3");
first = true;
}
if (!type.isNeutral() && (!type.isSpecialBuilding() || type.isRefinery())) {
if (arg0 instanceof ResourceDepot)
gs.baseManager.onDestroy((ResourceDepot) arg0);
if (arg0 instanceof PlayerUnit && ((PlayerUnit) arg0).getPlayer().isEnemy()) {
IntelligenceAgency.onDestroy(arg0, type);
if (arg0.equals(gs.chosenUnitToHarass))
gs.chosenUnitToHarass = null;
if (type.isBuilding()) {
if (!type.isResourceDepot())
gs.map.updateMap(arg0.getTilePosition(), type, true);
} else
gs.initDefensePosition = arg0.getTilePosition();
} else if (arg0 instanceof PlayerUnit && ((PlayerUnit) arg0).getPlayer().getId() == self.getId()) {
if (gs.ih.getFrameCount() > 0)
gs.supplyMan.onDestroy(arg0);
if (arg0 instanceof Worker) {
if (gs.getStrat().name.equals("ProxyBBS") || gs.getStrat().name.equals("ProxyEightRax")) {
UnitInfo ally = gs.unitStorage.getAllyUnits().get(arg0);
if (ally != null)
gs.myArmy.remove(ally);
}
for (SCV r : gs.repairerTask.keySet()) {
if (r.equals(arg0)) {
gs.workerIdle.add((Worker) arg0);
gs.repairerTask.remove(r);
break;
}
}
gs.workerIdle.remove(arg0);
if (arg0.equals(gs.naughtySCV))
gs.naughtySCV = null;
if (arg0.equals(gs.chosenScout))
gs.chosenScout = null;
if (arg0.equals(gs.chosenHarasser)) {
gs.chosenHarasser = null;
gs.chosenUnitToHarass = null;
getGs().firstScout = false;
}
if (arg0.equals(gs.chosenWorker))
gs.chosenWorker = null;
if (arg0.equals(gs.chosenRepairer))
gs.chosenRepairer = null;
for (Worker u : gs.workerDefenders.keySet()) {
if (arg0.equals(u)) {
gs.workerDefenders.remove(u);
break;
}
}
if (gs.workerMining.containsKey(arg0)) {
MineralPatch mineral = gs.workerMining.get(arg0);
gs.workerMining.remove(arg0);
if (gs.mineralsAssigned.containsKey(mineral)) {
gs.mining--;
gs.mineralsAssigned.put(mineral, gs.mineralsAssigned.get(mineral) - 1);
}
}
if (gs.workerGas.containsKey(arg0)) {
GasMiningFacility aux = gs.workerGas.get(arg0);
Integer auxInt = gs.refineriesAssigned.get(aux);
gs.refineriesAssigned.put(aux, auxInt - 1);
gs.workerGas.remove(arg0);
}
if (gs.workerTask.containsKey(arg0)) {
if (!gs.islandBases.isEmpty() && gs.workerTask.get(arg0) instanceof CommandCenter) {
Base ccBase = Util.getClosestBaseLocation(gs.workerTask.get(arg0).getPosition());
if (gs.islandBases.contains(ccBase))
gs.islandExpand = false;
}
gs.buildingLot.add(gs.workerTask.get(arg0));
gs.workerTask.remove(arg0);
}
if (gs.workerBuild.containsKey(arg0)) {
if (gs.workerBuild.get(arg0).first == UnitType.Terran_Command_Center) {
if (bwem.getMap().getArea(gs.workerBuild.get(arg0).second).equals(gs.naturalArea)) {
Bunker b = !gs.DBs.isEmpty() ? gs.DBs.keySet().iterator().next() : null;
if (b != null)
gs.defendPosition = b.getPosition();
else
gs.defendPosition = gs.mainChoke.getCenter().toPosition();
}
if (!gs.islandBases.isEmpty()) {
Base ccBase = Util.getClosestBaseLocation(arg0.getPosition());
if (gs.islandBases.contains(ccBase))
gs.islandExpand = false;
}
gs.deltaCash.first -= gs.workerBuild.get(arg0).first.mineralPrice();
gs.deltaCash.second -= gs.workerBuild.get(arg0).first.gasPrice();
gs.workerBuild.remove(arg0);
}
}
} else if (type.isBuilding()) {
if (type != UnitType.Terran_Command_Center) {
gs.map.updateMap(arg0.getTilePosition(), type, true);
}
for (Entry<SCV, Mechanical> r : gs.repairerTask.entrySet()) {
if (r.getValue().equals(arg0)) {
gs.workerIdle.add(r.getKey());
gs.repairerTask.remove(r.getKey());
break;
}
}
if (arg0.equals(gs.proxyBuilding))
gs.proxyBuilding = null;
for (Entry<SCV, Building> w : gs.workerTask.entrySet()) {
if (w.getValue().equals(arg0)) {
if (w.getValue() instanceof CommandCenter) {
if (bwem.getMap().getArea(w.getValue().getTilePosition()).equals(gs.naturalArea)) {
Bunker b = gs.DBs.keySet().iterator().next();
if (b != null)
gs.defendPosition = b.getPosition();
else
gs.defendPosition = gs.mainChoke.getCenter().toPosition();
}
if (!gs.islandBases.isEmpty()) {
Base ccBase = Util.getClosestBaseLocation(arg0.getPosition());
if (gs.islandBases.contains(ccBase))
gs.islandExpand = false;
}
}
gs.workerTask.remove(w.getKey());
gs.workerIdle.add(w.getKey());
break;
}
}
for (Unit w : gs.buildingLot) {
if (w.equals(arg0)) {
if (w instanceof CommandCenter && bwem.getMap().getArea(w.getTilePosition()).equals(gs.naturalArea)) {
Bunker b = !gs.DBs.isEmpty() ? gs.DBs.keySet().iterator().next() : null;
if (b != null)
gs.defendPosition = b.getPosition();
else
gs.defendPosition = gs.mainChoke.getCenter().toPosition();
}
gs.buildingLot.remove(w);
break;
}
}
for (CommandCenter u : gs.CCs.values()) {
if (u.equals(arg0)) {
gs.removeResources(arg0);
if (u.getAddon() != null)
gs.CSs.remove(u.getAddon());
if (bwem.getMap().getArea(arg0.getTilePosition()).equals(gs.naturalArea)) {
gs.defendPosition = gs.mainChoke.getCenter().toPosition();
}
gs.CCs.remove(Util.getClosestBaseLocation(arg0.getPosition()));
if (arg0.equals(gs.mainCC.second)) {
if (gs.CCs.size() > 0) {
for (Unit c : gs.CCs.values()) {
if (!c.equals(arg0)) {
gs.mainCC = new MutablePair<>(Util.getClosestBaseLocation(u.getPosition()), u);
break;
}
}
} else {
gs.mainCC = null;
break;
}
}
break;
}
}
for (CommandCenter u : gs.islandCCs.values()) {
if (u.equals(arg0)) {
gs.removeResources(arg0);
if (u.getAddon() != null)
gs.CSs.remove(u.getAddon());
gs.islandCCs.remove(Util.getClosestBaseLocation(arg0.getPosition()));
break;
}
}
gs.CSs.remove(arg0);
gs.Fs.remove(arg0);
gs.MBs.remove(arg0);
if (arg0.equals(gs.proxyBuilding)) {
gs.proxyBuilding = null;
gs.getStrat().trainUnits.remove(UnitType.Terran_Vulture);
}
if (arg0 instanceof ResearchingFacility)
gs.UBs.remove(arg0);
gs.SBs.remove(arg0);
gs.Ts.remove(arg0);
gs.Ps.remove(arg0);
if (type == UnitType.Terran_Bunker && gs.DBs.containsKey(arg0)) {
gs.myArmy.addAll(gs.DBs.get(arg0));
gs.DBs.remove(arg0);
}
if (type.isRefinery() && gs.refineriesAssigned.containsKey(arg0)) {
List<Unit> aux = new ArrayList<>();
for (Entry<Worker, GasMiningFacility> w : gs.workerGas.entrySet()) {
if (arg0.equals(w.getValue())) {
gs.workerIdle.add(w.getKey());
aux.add(w.getKey());
}
}
for (Unit u : aux) gs.workerGas.remove(u);
gs.refineriesAssigned.remove(arg0);
for (VespeneGeyser g : gs.vespeneGeysers.keySet()) {
if (g.getTilePosition().equals(arg0.getTilePosition()))
gs.vespeneGeysers.put(g, false);
}
}
gs.testMap = gs.map.clone();
} else if (type == UnitType.Terran_Vulture)
gs.agents.remove(arg0);
else if (type == UnitType.Terran_Dropship)
gs.agents.remove(arg0);
else if (type == UnitType.Terran_Science_Vessel)
gs.agents.remove(arg0);
else if (type == UnitType.Terran_Wraith && !gs.getStrat().name.equals("PlasmaWraithHell") && gs.agents.containsKey(arg0)) {
String wraith = ((WraithAgent) gs.agents.get(arg0)).name;
gs.shipNames.add(wraith);
gs.agents.remove(arg0);
}
UnitInfo ally = gs.unitStorage.getAllyUnits().get(arg0);
if (ally != null)
gs.myArmy.remove(ally);
}
gs.unitStorage.onUnitDestroy(arg0);
}
} catch (Exception e) {
System.err.println("OnUnitDestroy Exception");
e.printStackTrace();
}
}
use of ecgberht.Agents.WraithAgent in project Ecgberht by Jabbo16.
the class GameState method runAgents.
void runAgents() {
List<Agent> rem = new ArrayList<>();
for (Agent ag : agents.values()) {
if (ag.runAgent())
rem.add(ag);
}
for (Agent ag : rem) {
if (ag instanceof WraithAgent) {
String wraith = ((WraithAgent) ag).name;
shipNames.add(wraith);
} else if (ag instanceof VesselAgent)
((VesselAgent) ag).follow = null;
agents.remove(ag.myUnit);
}
}
Aggregations