use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.
the class CheckEnemyBaseVisible method execute.
@Override
public State execute() {
try {
List<PlayerUnit> enemies = gameState.getGame().getUnits(gameState.getIH().enemy());
if (!enemies.isEmpty()) {
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (Util.broodWarDistance(gameState.chosenScout.getPosition(), u.lastPosition) <= 500) {
gameState.enemyMainBase = Util.getClosestBaseLocation(u.lastPosition);
gameState.scoutSLs = new HashSet<>();
if (!gameState.getStrat().name.equals("PlasmaWraithHell")) {
gameState.chosenHarasser = (Worker) gameState.chosenScout;
}
gameState.chosenScout = null;
Util.sendText("!");
gameState.playSound("gearthere.mp3");
if (gameState.enemyStartBase == null) {
gameState.enemyBLs.clear();
gameState.enemyBLs.addAll(gameState.BLs);
gameState.enemyBLs.sort(new BaseLocationComparator(gameState.enemyMainBase));
if (gameState.firstScout) {
gameState.enemyStartBase = gameState.enemyMainBase;
gameState.enemyMainArea = gameState.enemyStartBase.getArea();
gameState.enemyNaturalBase = gameState.enemyBLs.get(1);
gameState.enemyNaturalArea = gameState.enemyNaturalBase.getArea();
}
}
return State.SUCCESS;
}
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.
the class CheckPerimeter method execute.
@Override
public State execute() {
try {
gameState.enemyInBase.clear();
gameState.defense = false;
Set<Unit> enemyInvaders = new TreeSet<>(gameState.enemyCombatUnitMemory);
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (u.unitType.canAttack() || u.unitType == UnitType.Protoss_Pylon || u.unitType.canProduce() || u.unitType.isRefinery()) {
enemyInvaders.add(u.unit);
}
}
for (Unit u : enemyInvaders) {
UnitType uType = u.getType();
if (u instanceof Building || ((uType.canAttack() || uType.isSpellcaster() || u instanceof Loadable) && uType != UnitType.Zerg_Scourge && uType != UnitType.Terran_Valkyrie && uType != UnitType.Protoss_Corsair && !(u instanceof Overlord))) {
Area enemyArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (enemyArea != null) {
Area myMainArea = gameState.mainCC != null ? gameState.mainCC.first.getArea() : null;
Area myNatArea = gameState.naturalArea;
for (Base b : gameState.CCs.keySet()) {
if (!b.getArea().equals(enemyArea))
continue;
if ((myMainArea != null && !b.getArea().equals(myMainArea) && (myNatArea != null && !b.getArea().equals(myNatArea))))
continue;
gameState.enemyInBase.add(u);
break;
}
}
for (Map.Entry<SCV, Building> c : gameState.workerTask.entrySet()) {
int dist = c.getValue() instanceof CommandCenter ? 500 : 200;
if (Util.broodWarDistance(u.getPosition(), c.getValue().getPosition()) <= dist) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.CCs.values()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 500) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.DBs.keySet()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.SBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (ResearchingFacility c : gameState.UBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
if (!gameState.getStrat().name.equals("ProxyBBS") && !gameState.getStrat().name.equals("ProxyEightRax")) {
for (Unit c : gameState.MBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
}
}
}
if (!gameState.enemyInBase.isEmpty()) {
/*if ((((GameState) gameState).getArmySize() >= 50 && ((GameState) gameState).getArmySize() / ((GameState) gameState).enemyInBase.size() > 10)) {
return State.FAILURE;
}*/
gameState.defense = true;
return State.SUCCESS;
}
int cFrame = gameState.frameCount;
List<Worker> toDelete = new ArrayList<>();
for (Worker u : gameState.workerDefenders.keySet()) {
if (u.getLastCommandFrame() == cFrame)
continue;
Position closestDefense;
if (gameState.learningManager.isNaughty()) {
if (!gameState.DBs.isEmpty()) {
closestDefense = gameState.DBs.keySet().iterator().next().getPosition();
u.move(closestDefense);
toDelete.add(u);
continue;
}
}
closestDefense = gameState.getNearestCC(u.getPosition(), false);
if (closestDefense != null) {
u.move(closestDefense);
toDelete.add(u);
}
}
for (Worker u : toDelete) {
u.stop(false);
gameState.workerDefenders.remove(u);
gameState.workerIdle.add(u);
}
for (Squad u : gameState.sqManager.squads.values()) {
if (u.status == Status.DEFENSE) {
Position closestCC = gameState.getNearestCC(u.getSquadCenter(), false);
if (closestCC != null) {
Area squad = gameState.bwem.getMap().getArea(u.getSquadCenter().toTilePosition());
Area regCC = gameState.bwem.getMap().getArea(closestCC.toTilePosition());
if (squad != null && regCC != null) {
if (!squad.equals(regCC)) {
if (!gameState.DBs.isEmpty() && gameState.CCs.size() == 1) {
u.giveMoveOrder(gameState.DBs.keySet().iterator().next().getPosition());
} else {
u.giveMoveOrder(Util.getClosestChokepoint(u.getSquadCenter()).getCenter().toPosition());
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
u.status = Status.IDLE;
u.attack = null;
}
}
gameState.defense = false;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.
the class ChooseMachineShop method execute.
@Override
public State execute() {
try {
if (gameState.getStrat().name.equals("VultureRush") && (gameState.Fs.size() < 2 || gameState.UBs.stream().anyMatch(u -> u instanceof MachineShop)))
return State.FAILURE;
if (gameState.getStrat().name.equals("TheNitekat") && (gameState.Fs.size() > 1 || gameState.UBs.stream().anyMatch(u -> u instanceof MachineShop)))
return State.FAILURE;
if (!gameState.Fs.isEmpty()) {
for (Factory c : gameState.Fs) {
if (!c.isTraining() && c.getAddon() == null) {
gameState.chosenBuildingAddon = c;
gameState.chosenAddon = UnitType.Terran_Machine_Shop;
return State.SUCCESS;
}
}
}
gameState.chosenBuildingAddon = null;
gameState.chosenAddon = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.
the class ChooseBuildingToHarass method execute.
@Override
public State execute() {
try {
if (gameState.chosenUnitToHarass != null)
return State.FAILURE;
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (gameState.enemyMainBase != null && gameState.bwem.getMap().getArea(u.tileposition).equals(gameState.bwem.getMap().getArea(gameState.enemyMainBase.getLocation()))) {
gameState.chosenUnitToHarass = u.unit;
return State.SUCCESS;
}
}
if (gameState.chosenHarasser.isIdle()) {
gameState.workerIdle.add(gameState.chosenHarasser);
gameState.chosenHarasser.stop(false);
gameState.chosenHarasser = null;
gameState.chosenUnitToHarass = null;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations