Search in sources :

Example 6 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class MoveIsland method execute.

@Override
public State execute() {
    try {
        Worker chosen = gameState.chosenWorkerDrop;
        UnitType chosenType = UnitType.Terran_Command_Center;
        TilePosition chosenTile = gameState.chosenIsland.getLocation();
        Position realEnd = Util.getUnitCenterPosition(chosenTile.toPosition(), chosenType);
        if (chosen.move(realEnd)) {
            gameState.workerBuild.put((SCV) chosen, new MutablePair<>(chosenType, chosenTile));
            gameState.deltaCash.first += chosenType.mineralPrice();
            gameState.deltaCash.second += chosenType.gasPrice();
            gameState.chosenWorkerDrop = null;
            gameState.chosenIsland = null;
            gameState.islandExpand = false;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition) Worker(org.openbw.bwapi4j.unit.Worker)

Example 7 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class BwemExt method centerOfBuilding.

public static Position centerOfBuilding(final TilePosition tilePosition, final TilePosition buildingSize) {
    final Position pixelSize = buildingSize.toPosition();
    final Position pixelOffset = pixelSize.divide(new Position(2, 2));
    return tilePosition.toPosition().add(pixelOffset);
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 8 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class Build method execute.

@Override
public State execute() {
    try {
        List<SCV> toRemove = new ArrayList<>();
        for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            if (u.getKey().getOrder() != Order.PlaceBuilding && gameState.getGame().getBWMap().isVisible(u.getValue().second) && gameState.canAfford(u.getValue().first)) {
                SCV chosen = u.getKey();
                if (u.getValue().first == UnitType.Terran_Bunker) {
                    if (!chosen.build(u.getValue().second, u.getValue().first)) {
                        gameState.deltaCash.first -= u.getValue().first.mineralPrice();
                        gameState.deltaCash.second -= u.getValue().first.gasPrice();
                        toRemove.add(chosen);
                        chosen.stop(false);
                        gameState.workerIdle.add(chosen);
                    }
                } else if (u.getKey().getOrder() == Order.PlayerGuard) {
                    if (Math.random() < 0.8)
                        chosen.build(u.getValue().second, u.getValue().first);
                    else
                        chosen.move(u.getKey().getPosition().add(new Position(32, 0)));
                } else
                    chosen.build(u.getValue().second, u.getValue().first);
            }
        }
        for (SCV s : toRemove) gameState.workerBuild.remove(s);
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV) ArrayList(java.util.ArrayList)

Example 9 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class VultureAgent method patrol.

private void patrol() {
    if (unit.getOrder() == Order.Patrol)
        return;
    if (attackUnit != null && unit.getOrder() != Order.Patrol) {
        Position pos = Util.choosePatrolPositionVulture(unit, attackUnit);
        if (pos != null && getGs().getGame().getBWMap().isValidPosition(pos)) {
            unit.patrol(pos);
            attackUnit = null;
            lastPatrolFrame = actualFrame;
            return;
        }
    }
    attackUnit = null;
}
Also used : Position(org.openbw.bwapi4j.Position)

Example 10 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class CameraModule method updateCameraPosition.

private void updateCameraPosition() {
    double moveFactor = 0.1;
    if (followUnit && game.getBWMap().isValidPosition(cameraFocusUnit.getPosition())) {
        cameraFocusPosition = cameraFocusUnit.getPosition();
    }
    currentCameraPosition = currentCameraPosition.add(new Position((int) (moveFactor * (cameraFocusPosition.getX() - currentCameraPosition.getX())), (int) (moveFactor * (cameraFocusPosition.getY() - currentCameraPosition.getY()))));
    Position currentMovedPosition = currentCameraPosition.subtract(new Position(scrWidth / 2, scrHeight / 2 - 40));
    // Position currentMovedPosition = new Position(currentCameraPosition.getX() - scrWidth / 2, currentCameraPosition.getY() - scrHeight / 2 - 40); // -40 to account for HUD
    if (game.getBWMap().isValidPosition(currentCameraPosition))
        game.getInteractionHandler().setScreenPosition(currentMovedPosition);
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Aggregations

Position (org.openbw.bwapi4j.Position)55 TilePosition (org.openbw.bwapi4j.TilePosition)19 UnitInfo (ecgberht.UnitInfo)10 Worker (org.openbw.bwapi4j.unit.Worker)10 UnitType (org.openbw.bwapi4j.type.UnitType)9 SimInfo (ecgberht.Simulation.SimInfo)8 Util (ecgberht.Util.Util)8 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Ecgberht.getGs (ecgberht.Ecgberht.getGs)7 UtilMicro (ecgberht.Util.UtilMicro)7 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)7 Area (bwem.Area)6 Base (bwem.Base)6 Collectors (java.util.stream.Collectors)6 Order (org.openbw.bwapi4j.type.Order)6 java.util (java.util)5 WeaponType (org.openbw.bwapi4j.type.WeaponType)5 ArrayList (java.util.ArrayList)4 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 Squad (ecgberht.Squad)3