Search in sources :

Example 21 with TilePosition

use of org.openbw.bwapi4j.TilePosition 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);
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint) Base(bwem.Base)

Example 22 with TilePosition

use of org.openbw.bwapi4j.TilePosition 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);
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) Base(bwem.Base)

Example 23 with TilePosition

use of org.openbw.bwapi4j.TilePosition 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]);
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint)

Example 24 with TilePosition

use of org.openbw.bwapi4j.TilePosition 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);
        }
    }
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint)

Example 25 with TilePosition

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

the class BuildingMap method findPositionArea.

private TilePosition findPositionArea(UnitType buildingType, Area a) {
    TilePosition buildingSize = buildingType.tileSize();
    int size = Math.max(buildingSize.getY(), buildingSize.getX());
    if (buildingType.canBuildAddon())
        size = Math.max(buildingSize.getY(), buildingSize.getX() + 2);
    Set<TilePosition> tilesToCheck = tilesArea.get(a);
    for (TilePosition t : tilesToCheck) {
        int ii = t.getY();
        int jj = t.getX();
        if (!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 && checkUnitsChosenBuildingGrid(t, buildingType)) {
            return t;
        }
    }
    return null;
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint)

Aggregations

TilePosition (org.openbw.bwapi4j.TilePosition)46 ChokePoint (bwem.ChokePoint)13 Position (org.openbw.bwapi4j.Position)13 Area (bwem.Area)9 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Base (bwem.Base)7 MiniTile (bwem.tile.MiniTile)7 Tile (bwem.tile.Tile)7 ArrayList (java.util.ArrayList)7 UnitType (org.openbw.bwapi4j.type.UnitType)6 TileImpl (bwem.tile.TileImpl)4 Geyser (bwem.unit.Geyser)4 Mineral (bwem.unit.Mineral)4 Worker (org.openbw.bwapi4j.unit.Worker)4 MutablePair (ecgberht.Util.MutablePair)3 Building (org.openbw.bwapi4j.unit.Building)3 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)3 SCV (org.openbw.bwapi4j.unit.SCV)3 Area (bwem.area.Area)2 StaticBuilding (bwem.unit.StaticBuilding)2