use of ecgberht.Agents.DropShipAgent 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.DropShipAgent in project Ecgberht by Jabbo16.
the class ChooseDropShip method execute.
@Override
public State execute() {
try {
for (Agent u : gameState.agents.values()) {
if (u instanceof DropShipAgent && u.statusToString().equals("IDLE")) {
gameState.chosenDropShip = (DropShipAgent) u;
return State.SUCCESS;
}
}
gameState.chosenDropShip = null;
gameState.chosenWorker = null;
gameState.chosenIsland = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of ecgberht.Agents.DropShipAgent in project Ecgberht by Jabbo16.
the class ChoosePosition method execute.
@Override
public State execute() {
try {
if (gameState.chosenToBuild == UnitType.None)
return State.FAILURE;
Player self = gameState.getPlayer();
TilePosition origin;
if (gameState.chosenToBuild.isRefinery()) {
if (!gameState.vespeneGeysers.isEmpty()) {
for (Entry<VespeneGeyser, Boolean> g : gameState.vespeneGeysers.entrySet()) {
if (!g.getValue()) {
gameState.chosenPosition = g.getKey().getTilePosition();
return State.SUCCESS;
}
}
}
} else if (gameState.chosenToBuild == UnitType.Terran_Command_Center) {
if (!gameState.islandBases.isEmpty() && gameState.islandCCs.size() < gameState.islandBases.size()) {
if (gameState.islandExpand)
return State.FAILURE;
for (Agent u : gameState.agents.values()) {
if (u instanceof DropShipAgent && u.statusToString().equals("IDLE")) {
gameState.islandExpand = true;
return State.FAILURE;
}
}
}
TilePosition main;
if (gameState.mainCC != null)
main = gameState.mainCC.second.getTilePosition();
else
main = gameState.getPlayer().getStartLocation();
List<Base> valid = new ArrayList<>();
if (gameState.getStrat().name.equals("PlasmaWraithHell")) {
for (Base b : gameState.specialBLs) {
if (!gameState.CCs.containsKey(b)) {
gameState.chosenPosition = b.getLocation();
return State.SUCCESS;
}
}
}
for (Base b : gameState.BLs) {
if (!gameState.CCs.containsKey(b) && Util.isConnected(b.getLocation(), main))
valid.add(b);
}
List<Base> remove = new ArrayList<>();
for (Base b : valid) {
if (gameState.getGame().getBWMap().isVisible(b.getLocation()) && !gameState.getGame().getBWMap().isBuildable(b.getLocation(), true)) {
remove.add(b);
continue;
}
if (b.getArea() != gameState.naturalArea) {
for (Unit u : gameState.enemyCombatUnitMemory) {
if (gameState.bwem.getMap().getArea(u.getTilePosition()) == null || !(u instanceof Attacker) || u instanceof Worker) {
continue;
}
if (gameState.bwem.getMap().getArea(u.getTilePosition()).equals(b.getArea())) {
remove.add(b);
break;
}
}
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (gameState.bwem.getMap().getArea(u.tileposition) == null)
continue;
if (gameState.bwem.getMap().getArea(u.tileposition).equals(b.getArea())) {
remove.add(b);
break;
}
}
}
}
valid.removeAll(remove);
if (valid.isEmpty())
return State.FAILURE;
gameState.chosenPosition = valid.get(0).getLocation();
return State.SUCCESS;
} else {
if (!gameState.workerBuild.isEmpty()) {
for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
gameState.testMap.updateMap(w.second, w.first, false);
}
}
if (!gameState.chosenToBuild.equals(UnitType.Terran_Bunker) && !gameState.chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (gameState.getStrat().proxy && gameState.chosenToBuild == UnitType.Terran_Barracks) {
origin = gameState.mapCenter.toTilePosition();
} else if (gameState.mainCC != null && gameState.mainCC.first != null) {
origin = gameState.mainCC.first.getLocation();
} else
origin = self.getStartLocation();
} else if (gameState.chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (gameState.defendPosition != null)
origin = gameState.defendPosition.toTilePosition();
else if (gameState.DBs.isEmpty()) {
origin = Util.getClosestChokepoint(self.getStartLocation().toPosition()).getCenter().toTilePosition();
} else {
origin = gameState.DBs.keySet().stream().findFirst().map(UnitImpl::getTilePosition).orElse(null);
}
} else if (gameState.learningManager.isNaughty() && gameState.enemyRace == Race.Zerg) {
origin = gameState.getBunkerPositionAntiPool();
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
} else {
origin = gameState.testMap.findBunkerPositionAntiPool();
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
} else if (gameState.mainCC != null)
origin = gameState.mainCC.second.getTilePosition();
else
origin = gameState.getPlayer().getStartLocation();
}
} else if (gameState.Ts.isEmpty()) {
if (gameState.defendPosition != null && gameState.naturalChoke != null && gameState.defendPosition.equals(gameState.naturalChoke.getCenter().toPosition())) {
origin = gameState.testMap.findBunkerPosition(gameState.naturalChoke);
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
}
}
if (gameState.mainChoke != null && !gameState.getStrat().name.equals("MechGreedyFE") && !gameState.getStrat().name.equals("BioGreedyFE") && !gameState.getStrat().name.equals("14CC") && !gameState.getStrat().name.equals("BioMechGreedyFE")) {
origin = gameState.testMap.findBunkerPosition(gameState.mainChoke);
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
} else
origin = gameState.mainChoke.getCenter().toTilePosition();
} else if (gameState.naturalChoke != null) {
origin = gameState.testMap.findBunkerPosition(gameState.naturalChoke);
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
} else
origin = gameState.mainChoke.getCenter().toTilePosition();
} else {
origin = gameState.testMap.findBunkerPosition(gameState.mainChoke);
if (origin != null) {
gameState.testMap = gameState.map.clone();
gameState.chosenPosition = origin;
return State.SUCCESS;
} else
origin = gameState.mainChoke.getCenter().toTilePosition();
}
} else
origin = gameState.Ts.stream().findFirst().map(UnitImpl::getTilePosition).orElse(null);
TilePosition position = gameState.testMap.findPositionNew(gameState.chosenToBuild, origin);
gameState.testMap = gameState.map.clone();
if (position != null) {
gameState.chosenPosition = position;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of ecgberht.Agents.DropShipAgent in project Ecgberht by Jabbo16.
the class CheckDropped method execute.
@Override
public State execute() {
try {
Worker scv = gameState.chosenWorkerDrop;
DropShipAgent ship = gameState.chosenDropShip;
if (ship == null)
return State.SUCCESS;
if (scv != null && ship.statusToString().equals("RETREAT")) {
Unit transport = scv.getTransport();
if (transport == null) {
gameState.chosenDropShip = null;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations