use of bwem.Area in project Ecgberht by Jabbo16.
the class BuildingMap method initMap.
// Generates an initial building map
void initMap() {
// Find valid and no valid positions for building
for (int jj = 0; jj < height; jj++) {
for (int ii = 0; ii < width; ii++) {
TilePosition x = new TilePosition(ii, jj);
// if (bw.getBWMap().isBuildable(x, false)) map[jj][ii] = "6";
if (bw.getBWMap().isBuildable(x, true))
map[jj][ii] = "6";
else
map[jj][ii] = "0";
}
}
// Finds minerals
for (MineralPatch resource : bw.getMineralPatches()) {
TilePosition resourceTile = resource.getTilePosition();
TilePosition resourceSize = resource.getType().tileSize();
for (int i = resourceTile.getY(); i < resourceTile.getY() + resourceSize.getY(); i++) {
for (int j = resourceTile.getX(); j < resourceTile.getX() + resourceSize.getX(); j++) {
if (i < 0 || i >= height || j < 0 || j >= width)
continue;
if (!map[i][j].equals("V"))
map[i][j] = "M";
}
}
}
// Finds geysers
for (VespeneGeyser resource : bw.getVespeneGeysers()) {
TilePosition resourceTile = resource.getTilePosition();
TilePosition resourceSize = resource.getType().tileSize();
for (int i = resourceTile.getY(); i < resourceTile.getY() + resourceSize.getY(); i++) {
for (int j = resourceTile.getX(); j < resourceTile.getX() + resourceSize.getX(); j++) {
if (i < 0 || i >= height || j < 0 || j >= width)
continue;
map[i][j] = "V";
}
}
}
// Finds weird neutral buildings
for (Unit resource : bw.getAllUnits()) {
if (!(resource instanceof SpecialBuilding))
continue;
TilePosition resourceTile = resource.getTilePosition();
TilePosition resourceSize = resource.getType().tileSize();
for (int i = resourceTile.getY(); i < resourceTile.getY() + resourceSize.getY(); i++) {
for (int j = resourceTile.getX(); j < resourceTile.getX() + resourceSize.getX(); j++) {
if (i < 0 || i >= height || j < 0 || j >= width)
continue;
map[i][j] = "E";
}
}
}
for (Area a : bwem.getMap().getAreas()) {
for (Base b : a.getBases()) {
TilePosition starting = b.getLocation();
for (int i = starting.getY(); i < starting.getY() + UnitType.Terran_Command_Center.tileHeight(); i++) {
for (int j = starting.getX(); j < starting.getX() + UnitType.Terran_Command_Center.tileWidth(); j++) {
if (i < 0 || i >= height || j < 0 || j >= width)
continue;
map[i][j] = "E";
}
}
map[starting.getY() + 1][starting.getX() + UnitType.Terran_Command_Center.tileWidth()] = "E";
map[starting.getY() + 2][starting.getX() + UnitType.Terran_Command_Center.tileWidth()] = "E";
map[starting.getY() + 1][starting.getX() + UnitType.Terran_Command_Center.tileWidth() + 1] = "E";
map[starting.getY() + 2][starting.getX() + UnitType.Terran_Command_Center.tileWidth() + 1] = "E";
}
}
map = fillMap(map);
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class BuildingMap method findPositionNew.
// Finds a valid position in the map for a specific building type starting with a given tileposition, searches owned areas
public TilePosition findPositionNew(UnitType buildingType, TilePosition starting) {
if (buildingType == UnitType.Terran_Bunker || buildingType == UnitType.Terran_Missile_Turret)
return findPosition(buildingType, starting);
Area find = bwem.getMap().getArea(starting);
if (find == null)
return findPosition(buildingType, starting);
TilePosition tile = findPositionArea(buildingType, find);
if (tile != null)
return tile;
for (Base b : getGs().CCs.keySet()) {
if (find.equals(b.getArea()) || (getGs().fortressSpecialBLs.containsKey(b) && buildingType != UnitType.Terran_Starport))
continue;
tile = findPositionArea(buildingType, b.getArea());
if (tile != null)
return tile;
}
return findPosition(buildingType, starting);
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class BuildingMap method findPosition.
// Finds a valid position in the map for a specific building type starting with a given tileposition
private TilePosition findPosition(UnitType buildingType, TilePosition starting) {
TilePosition buildingSize = buildingType.tileSize();
int size = Math.max(buildingSize.getY(), buildingSize.getX());
if (buildingType.canBuildAddon())
size = Math.max(buildingSize.getY(), buildingSize.getX() + 2);
if (starting == null)
starting = getGs().getPlayer().getStartLocation();
int x = starting.getY();
int y = starting.getX();
int[] coord = new int[2];
int i = 2;
int j = 2;
boolean control = false;
// Finds the first valid tileposition starting around the given tileposition
while (!control) {
for (int ii = (x - i); ii <= (x + i); ii++) {
for (int jj = (y - j); jj <= (y + j); jj++) {
if ((ii >= 0 && ii < height) && (jj >= 0 && jj < width) && (!map[ii][jj].equals("M") && !map[ii][jj].equals("V") && !map[ii][jj].equals("E") && !map[ii][jj].equals("B")) && Integer.parseInt(map[ii][jj]) >= size) {
if (buildingType == UnitType.Terran_Bunker) {
Area bunk = bwem.getMap().getArea(new TilePosition(jj, ii));
if (bunk != null && !bunk.equals(bwem.getMap().getArea(self.getStartLocation())))
continue;
}
if (checkUnitsChosenBuildingGrid(new TilePosition(jj, ii), buildingType)) {
coord[0] = ii;
coord[1] = jj;
control = true;
break;
}
}
}
if (control)
break;
}
i++;
j++;
}
return new TilePosition(coord[1], coord[0]);
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class BuildingMap method initTilesArea.
private void initTilesArea() {
boolean startOrdered = false;
boolean naturalOrdered = false;
TilePosition startTile = self.getStartLocation();
for (Area a : bwem.getMap().getAreas()) {
if (!startOrdered && bwem.getMap().getArea(startTile).equals(a)) {
tilesArea.put(a, new TreeSet<>(new tilesAreaComparator(startTile)));
startOrdered = true;
} else if (!naturalOrdered && getGs().naturalArea.equals(a)) {
tilesArea.put(a, new TreeSet<>(new tilesAreaComparator(getGs().BLs.get(1).getLocation())));
naturalOrdered = true;
} else if (a.getBases().size() == 1)
tilesArea.put(a, new TreeSet<>(new tilesAreaComparator(a.getBases().get(0).getLocation())));
else
tilesArea.put(a, new TreeSet<>(new tilesAreaComparator(a.getTop().toTilePosition())));
}
for (int jj = 0; jj < height; jj++) {
for (int ii = 0; ii < width; ii++) {
TilePosition x = new TilePosition(ii, jj);
Area a = bwem.getMap().getArea(x);
if (a != null)
tilesArea.get(a).add(x);
}
}
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class CheckBuildingFlames method execute.
@Override
public State execute() {
try {
List<SCV> toRemove = new ArrayList<>();
for (Entry<SCV, Mechanical> u : gameState.repairerTask.entrySet()) {
if (u.getValue().maxHitPoints() != u.getValue().getHitPoints()) {
if (u.getKey().getOrder() != Order.Follow && u.getKey().getOrder() != Order.Repair) {
u.getKey().rightClick(u.getValue(), false);
}
} else if (Util.countBuildingAll(UnitType.Terran_Command_Center) < 2 && u.getValue() instanceof Bunker && IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2) {
if (u.getKey().getDistance(u.getValue()) > 3 * 32)
u.getKey().move(u.getValue().getPosition());
} else if (Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && u.getValue() instanceof Bunker) {
if (u.getKey().getDistance(u.getValue()) > 3 * 32)
u.getKey().move(u.getValue().getPosition());
} else {
u.getKey().stop(false);
gameState.workerIdle.add(u.getKey());
toRemove.add(u.getKey());
}
}
for (SCV s : toRemove) gameState.repairerTask.remove(s);
boolean isBeingRepaired;
boolean cheesed = IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2;
boolean fastExpanding = gameState.getStrat().name.contains("GreedyFE") && Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && gameState.firstExpand;
for (Bunker w : gameState.DBs.keySet()) {
int count = 0;
if (UnitType.Terran_Bunker.maxHitPoints() != w.getHitPoints() || (cheesed && Util.countBuildingAll(UnitType.Terran_Command_Center) < 2) || fastExpanding) {
for (Mechanical r : gameState.repairerTask.values()) {
if (w.equals(r))
count++;
}
if (count < 2 && (gameState.defense || cheesed || fastExpanding)) {
gameState.chosenUnitRepair = w;
return State.SUCCESS;
}
if (count == 0) {
gameState.chosenUnitRepair = w;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (MissileTurret b : gameState.Ts) {
if (UnitType.Terran_Missile_Turret.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
// TODO check to add break?
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Squad s : gameState.sqManager.squads.values()) {
if (s.status != Squad.Status.IDLE)
continue;
for (UnitInfo u : s.members) {
if (u.unit instanceof Mechanical && u.health != u.unitType.maxHitPoints()) {
Area unitArea = gameState.bwem.getMap().getArea(u.tileposition);
for (Base b : gameState.CCs.keySet()) {
if (unitArea != null && b.getArea().equals(unitArea)) {
for (Mechanical r : gameState.repairerTask.values()) {
if (u.unit.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = (Mechanical) u.unit;
return State.SUCCESS;
}
}
}
}
}
}
if (!gameState.getStrat().proxy) {
isBeingRepaired = false;
for (Barracks b : gameState.MBs) {
if (UnitType.Terran_Barracks.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
}
isBeingRepaired = false;
for (Factory b : gameState.Fs) {
if (b.equals(gameState.proxyBuilding))
continue;
if (UnitType.Terran_Factory.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (ResearchingFacility b : gameState.UBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = (Mechanical) b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (SupplyDepot b : gameState.SBs) {
if (UnitType.Terran_Supply_Depot.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (CommandCenter b : gameState.CCs.values()) {
if (UnitType.Terran_Command_Center.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (ComsatStation b : gameState.CSs) {
if (UnitType.Terran_Comsat_Station.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Starport b : gameState.Ps) {
if (UnitType.Terran_Starport.maxHitPoints() != b.getHitPoints()) {
for (Mechanical r : gameState.repairerTask.values()) {
if (b.equals(r)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
gameState.chosenUnitRepair = b;
return State.SUCCESS;
}
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations