Search in sources :

Example 16 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Scan method execute.

@Override
public State execute() {
    try {
        for (Unit u : ((GameState) this.handler).CSs) {
            if (u.getEnergy() >= 50 && u.getOrder() != Order.CastScannerSweep) {
                if (u.useTech(TechType.Scanner_Sweep, ((GameState) this.handler).checkScan.toPosition())) {
                    ((GameState) this.handler).startCount = ((GameState) this.handler).getGame().elapsedTime();
                    ((GameState) this.handler).playSound("uav.mp3");
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 17 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class CheckEnemyBaseVisible method execute.

@Override
public State execute() {
    try {
        if (!((GameState) this.handler).getGame().enemy().getUnits().isEmpty()) {
            for (Unit u : ((GameState) this.handler).getGame().enemy().getUnits()) {
                if (u.getType().isBuilding()) {
                    if (((GameState) this.handler).getGame().getUnitsInRadius(((GameState) this.handler).chosenScout.getPosition(), 500).contains(u)) {
                        ((GameState) this.handler).enemyBase = BWTA.getNearestBaseLocation(u.getTilePosition());
                        ((GameState) this.handler).ScoutSLs = new HashSet<BaseLocation>();
                        // ((GameState)this.handler).choosenScout.stop();
                        // ((GameState)this.handler).workerIdle.add(((GameState)this.handler).choosenScout);
                        ((GameState) this.handler).chosenHarasser = ((GameState) this.handler).chosenScout;
                        ((GameState) this.handler).chosenScout = null;
                        ((GameState) this.handler).getGame().sendText(Utils.formatText("!", Utils.Yellow));
                        ((GameState) this.handler).playSound("gear.mp3");
                        ((GameState) this.handler).EnemyBLs.clear();
                        ((GameState) this.handler).EnemyBLs.addAll(((GameState) this.handler).BLs);
                        // ((GameState)this.handler).EnemyBLs.sort(new BaseLocationComparator(true));
                        return State.SUCCESS;
                    }
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit) BaseLocation(bwta.BaseLocation)

Example 18 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChooseMedic method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).UBs.isEmpty()) {
            return State.FAILURE;
        } else {
            for (Unit u : ((GameState) this.handler).UBs) {
                if (u.getType() == UnitType.Terran_Academy) {
                    int marine_count = 0;
                    if (!((GameState) this.handler).DBs.isEmpty()) {
                        for (Set<Unit> p : ((GameState) this.handler).DBs.values()) {
                            marine_count += p.size();
                        }
                    }
                    if (!((GameState) this.handler).MBs.isEmpty() && ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Medic) * 4 < ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Marine) - marine_count) {
                        for (Unit b : ((GameState) this.handler).MBs) {
                            if (!b.isTraining()) {
                                ((GameState) this.handler).chosenUnit = UnitType.Terran_Medic;
                                ((GameState) this.handler).chosenBuilding = b;
                                return State.SUCCESS;
                            }
                        }
                    }
                    break;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 19 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChooseTank method execute.

@Override
public State execute() {
    try {
        if (!((GameState) this.handler).Fs.isEmpty()) {
            if (((GameState) this.handler).siegeResearched) {
                if (((GameState) this.handler).strat.name != "FullMech") {
                    if (((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Vulture) == 0) {
                        return State.FAILURE;
                    }
                    if (((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Siege_Tank_Siege_Mode) + ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Siege_Tank_Tank_Mode) * 5 < ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Marine) + ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Medic) + ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Vulture)) {
                        for (Unit b : ((GameState) this.handler).Fs) {
                            if (!b.isTraining() && b.canTrain()) {
                                ((GameState) this.handler).chosenUnit = UnitType.Terran_Siege_Tank_Tank_Mode;
                                ((GameState) this.handler).chosenBuilding = b;
                                return State.SUCCESS;
                            }
                        }
                    }
                } else {
                    if (((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Siege_Tank_Siege_Mode) + ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Siege_Tank_Tank_Mode) < ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Marine) * 2 + ((GameState) this.handler).getPlayer().allUnitCount(UnitType.Terran_Vulture)) {
                        Pair<Integer, Integer> cash = ((GameState) this.handler).getCash();
                        if (cash.second < (UnitType.Terran_Siege_Tank_Tank_Mode.gasPrice())) {
                            return State.FAILURE;
                        }
                        for (Unit b : ((GameState) this.handler).Fs) {
                            if (!b.isTraining() && b.canTrain()) {
                                ((GameState) this.handler).chosenUnit = UnitType.Terran_Siege_Tank_Tank_Mode;
                                ((GameState) this.handler).chosenBuilding = b;
                                return State.SUCCESS;
                            }
                        }
                    }
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 20 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChooseArmorInfUp method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).UBs.isEmpty()) {
            return State.FAILURE;
        }
        for (Unit u : ((GameState) this.handler).UBs) {
            if (u.canUpgrade(UpgradeType.Terran_Infantry_Armor) && !u.isResearching() && !u.isUpgrading()) {
                ((GameState) this.handler).chosenUnitUpgrader = u;
                ((GameState) this.handler).chosenUpgrade = UpgradeType.Terran_Infantry_Armor;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit)

Aggregations

Unit (bwapi.Unit)73 GameState (ecgberht.GameState)36 Test (org.junit.Test)21 Position (bwapi.Position)14 TilePosition (bwapi.TilePosition)10 BaseLocation (bwta.BaseLocation)7 Pair (bwapi.Pair)6 UnitType (bwapi.UnitType)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Player (bwapi.Player)3 EnemyBuilding (ecgberht.EnemyBuilding)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 Squad (ecgberht.Squad)2 Game (bwapi.Game)1 UnitCommand (bwapi.UnitCommand)1 Region (bwta.Region)1 Random (java.util.Random)1