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;
}
}
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);
}
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;
}
}
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;
}
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);
}
Aggregations