Search in sources :

Example 16 with WalkPosition

use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.

the class MapPrinter method line.

public void line(WalkPosition a, WalkPosition b, Color col, dashed_t dashedMode) {
    int n = Math.max(1, BwemExt.roundedDist(a, b));
    if ((dashedMode == dashed_t.dashed) && (n >= 4))
        n /= 2;
    for (int i = 0; i <= n; ++i) {
        int x = (a.getX() * i + b.getX() * (n - i)) / n;
        int y = (a.getY() * i + b.getY() * (n - i)) / n;
        point(new WalkPosition(x, y), col);
    }
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition)

Example 17 with WalkPosition

use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.

the class MapPrinterExample method printNeutral.

private void printNeutral(Map theMap, Neutral n, Color col) {
    final WalkPosition delta = new WalkPosition(n.getCenter().getX() < theMap.getData().getMapData().getCenter().getX() ? +1 : -1, n.getCenter().getY() < theMap.getData().getMapData().getCenter().getY() ? +1 : -1);
    final int stackSize = mapPrinter.showStackedNeutrals ? theMap.getData().getTile(n.getTopLeft()).getStackedNeutralCount() : 1;
    for (int i = 0; i < stackSize; ++i) {
        WalkPosition origin = n.getTopLeft().toWalkPosition().add(delta.multiply(new WalkPosition(i, i)));
        WalkPosition size = n.getSize().toWalkPosition();
        if (!theMap.getData().getMapData().isValid(origin) || !theMap.getData().getMapData().isValid(origin.add(size).subtract(new WalkPosition(1, 1))))
            break;
        mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), col, MapPrinter.fill_t.fill);
        if (mapPrinter.showBlockingBuildings && n.isBlocking())
            if (i < stackSize - 1) {
                mapPrinter.point(origin, MapPrinter.CustomColor.BLOCKING_NEUTRALS.color());
                mapPrinter.point(origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BLOCKING_NEUTRALS.color());
                mapPrinter.point(new WalkPosition(origin.getX(), (origin.add(size).subtract(new WalkPosition(1, 1))).getY()), MapPrinter.CustomColor.BLOCKING_NEUTRALS.color());
                mapPrinter.point(new WalkPosition((origin.add(size).subtract(new WalkPosition(1, 1))).getX(), origin.getY()), MapPrinter.CustomColor.BLOCKING_NEUTRALS.color());
            } else {
                mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BLOCKING_NEUTRALS.color());
            }
    }
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition) ChokePoint(bwem.ChokePoint)

Example 18 with WalkPosition

use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.

the class MapPrinterExample method printMap.

public void printMap(Map theMap) {
    java.util.Map<Integer, Color> mapZoneColor = new HashMap<>();
    for (int y = 0; y < theMap.getData().getMapData().getWalkSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getWalkSize().getX(); ++x) {
        WalkPosition p = new WalkPosition(x, y);
        MiniTile miniTile = theMap.getData().getMiniTile(p, CheckMode.NO_CHECK);
        Color col;
        if (miniTile.isSea()) {
            if (mapPrinter.showSeaSide && theMap.getData().isSeaWithNonSeaNeighbors(p))
                col = MapPrinter.CustomColor.SEA_SIDE.color();
            else
                col = MapPrinter.CustomColor.SEA.color();
        } else {
            if (mapPrinter.showLakes && miniTile.isLake()) {
                col = MapPrinter.CustomColor.LAKE.color();
            } else {
                if (mapPrinter.showAltitude) {
                    int c = 255 - ((miniTile.getAltitude().intValue() * 255) / theMap.getHighestAltitude().intValue());
                    col = new Color(c, c, c);
                } else {
                    col = MapPrinter.CustomColor.TERRAIN.color();
                }
                if (mapPrinter.showAreas || mapPrinter.showContinents)
                    if (miniTile.getAreaId().intValue() > 0) {
                        Area area = theMap.getArea(miniTile.getAreaId());
                        Color zoneColor = getZoneColor(area, mapZoneColor);
                        int red = zoneColor.getRed() * col.getRed() / 255;
                        int green = zoneColor.getGreen() * col.getGreen() / 255;
                        col = new Color(red, green, 0);
                    } else {
                        col = MapPrinter.CustomColor.TINY_AREA.color();
                    }
            }
        }
        mapPrinter.point(p, col);
    }
    if (mapPrinter.showData)
        for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) {
            int data = ((TileImpl) theMap.getData().getTile(new TilePosition(x, y))).getInternalData();
            int c = (((data / 1) * 1) % 256);
            Color col = new Color(c, c, c);
            WalkPosition origin = (new TilePosition(x, y)).toWalkPosition();
            mapPrinter.rectangle(origin, origin.add(new WalkPosition(3, 3)), col, MapPrinter.fill_t.fill);
        }
    if (mapPrinter.showUnbuildable)
        for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) if (!theMap.getData().getTile(new TilePosition(x, y)).isBuildable()) {
            WalkPosition origin = (new TilePosition(x, y)).toWalkPosition();
            mapPrinter.rectangle(origin.add(new WalkPosition(1, 1)), origin.add(new WalkPosition(2, 2)), MapPrinter.CustomColor.UNBUILDABLE.color());
        }
    if (mapPrinter.showGroundHeight)
        for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) {
            Tile.GroundHeight groundHeight = theMap.getData().getTile(new TilePosition(x, y)).getGroundHeight();
            if (groundHeight.intValue() >= Tile.GroundHeight.HIGH_GROUND.intValue())
                for (int dy = 0; dy < 4; ++dy) for (int dx = 0; dx < 4; ++dx) {
                    WalkPosition p = (new TilePosition(x, y).toWalkPosition()).add(new WalkPosition(dx, dy));
                    if (// groundHeight is usefull only for walkable miniTiles
                    theMap.getData().getMiniTile(p, CheckMode.NO_CHECK).isWalkable())
                        if (((dx + dy) & (groundHeight == Tile.GroundHeight.HIGH_GROUND ? 1 : 3)) != 0)
                            mapPrinter.point(p, MapPrinter.CustomColor.HIGHER_GROUND.color());
                }
        }
    if (mapPrinter.showAssignedResources)
        for (Area area : theMap.getAreas()) for (Base base : area.getBases()) {
            for (Mineral m : base.getMinerals()) mapPrinter.line(base.getCenter().toWalkPosition(), m.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color());
            for (Geyser g : base.getGeysers()) mapPrinter.line(base.getCenter().toWalkPosition(), g.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color());
        }
    if (mapPrinter.showGeysers)
        for (Geyser g : theMap.getNeutralData().getGeysers()) printNeutral(theMap, g, MapPrinter.CustomColor.GEYSERS.color());
    if (mapPrinter.showMinerals)
        for (Mineral m : theMap.getNeutralData().getMinerals()) printNeutral(theMap, m, MapPrinter.CustomColor.MINERALS.color());
    if (mapPrinter.showStaticBuildings)
        for (StaticBuilding s : theMap.getNeutralData().getStaticBuildings()) printNeutral(theMap, s, MapPrinter.CustomColor.STATIC_BUILDINGS.color());
    if (mapPrinter.showStartingLocations)
        for (TilePosition t : theMap.getData().getMapData().getStartingLocations()) {
            WalkPosition origin = t.toWalkPosition();
            // same size for other races
            WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition();
            mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.STARTING_LOCATIONS.color(), MapPrinter.fill_t.fill);
        }
    if (mapPrinter.showBases)
        for (Area area : theMap.getAreas()) {
            for (Base base : area.getBases()) {
                WalkPosition origin = base.getLocation().toWalkPosition();
                // same size for other races
                WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition();
                MapPrinter.dashed_t dashMode = base.getBlockingMinerals().isEmpty() ? MapPrinter.dashed_t.not_dashed : MapPrinter.dashed_t.dashed;
                mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BASES.color(), MapPrinter.fill_t.do_not_fill, dashMode);
            }
        }
    if (mapPrinter.showChokePoints) {
        for (MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> f : theMap.getRawFrontier()) mapPrinter.point(f.getRight(), mapPrinter.showAreas ? MapPrinter.CustomColor.CHOKE_POINTS_SHOW_AREAS.color() : MapPrinter.CustomColor.CHOKE_POINTS_SHOW_CONTINENTS.color());
        for (Area area : theMap.getAreas()) for (ChokePoint cp : area.getChokePoints()) {
            ChokePoint.Node[] nodes = { ChokePoint.Node.END1, ChokePoint.Node.END2 };
            for (ChokePoint.Node n : nodes) mapPrinter.square(cp.getNodePosition(n), 1, new Color(255, 0, 255), MapPrinter.fill_t.fill);
            mapPrinter.square(cp.getCenter(), 1, new Color(0, 0, 255), MapPrinter.fill_t.fill);
        }
    }
    try {
        mapPrinter.writeImageToFile(Paths.get("map.png"), "png");
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : TileImpl(bwem.tile.TileImpl) Mineral(bwem.unit.Mineral) StaticBuilding(bwem.unit.StaticBuilding) HashMap(java.util.HashMap) MiniTile(bwem.tile.MiniTile) Tile(bwem.tile.Tile) MiniTile(bwem.tile.MiniTile) IOException(java.io.IOException) ChokePoint(bwem.ChokePoint) Base(bwem.Base) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Area(bwem.area.Area) Geyser(bwem.unit.Geyser) TilePosition(org.openbw.bwapi4j.TilePosition) WalkPosition(org.openbw.bwapi4j.WalkPosition) ChokePoint(bwem.ChokePoint)

Example 19 with WalkPosition

use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.

the class MapTest method assertEquals_MiniTileAltitudes.

/**
 * Tests that each MiniTile's Altitude for all WalkPositions match between
 * the original BWAPI/BWEM in C++ and this Java port.
 */
private void assertEquals_MiniTileAltitudes(AdvancedData data, BWEM_DummyData dummyBwemData) {
    final List<ImmutableTriple<WalkPosition, Integer, Integer>> wrongAltitudes = new ArrayList<>();
    for (int y = 0; y < data.getMapData().getWalkSize().getY(); ++y) {
        for (int x = 0; x < data.getMapData().getWalkSize().getX(); ++x) {
            final WalkPosition w = new WalkPosition(x, y);
            final int expected = dummyBwemData.getMiniTileAltitudes()[data.getMapData().getWalkSize().getX() * y + x];
            final int actual = data.getMiniTile(w).getAltitude().intValue();
            // Assert.assertEquals(w + ": mini tile altitude is wrong.", expected, actual);
            if (expected != actual) {
                wrongAltitudes.add(new ImmutableTriple<>(w, expected, actual));
            }
        }
    }
    for (final ImmutableTriple<WalkPosition, Integer, Integer> triple : wrongAltitudes) {
        logger.warn("Wrong MiniTile altitude for WalkPosition: " + triple.getLeft().toString() + ", expected=" + triple.getMiddle() + ", actual=" + triple.getRight());
    }
}
Also used : ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) ArrayList(java.util.ArrayList) WalkPosition(org.openbw.bwapi4j.WalkPosition) ChokePoint(bwem.ChokePoint)

Example 20 with WalkPosition

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

the class BWMapInitializer method onBlockingNeutralDestroyed.

void onBlockingNeutralDestroyed(Neutral pBlocking) {
    if (pBlocking == null) {
        throw new IllegalStateException();
    }
    if (!pBlocking.isBlocking()) {
        asserter.throwIllegalStateException("");
    }
    for (Area pArea : pBlocking.getBlockedAreas()) {
        for (ChokePoint cp : pArea.getChokePoints()) {
            cp.onBlockingNeutralDestroyed(pBlocking);
        }
    }
    // there remains some blocking Neutrals at the same location
    if (getData().getTile(pBlocking.getTopLeft()).getNeutral() != null) {
        return;
    }
    // Unblock the miniTiles of pBlocking:
    AreaId newId = pBlocking.getBlockedAreas().iterator().next().getId();
    WalkPosition pBlockingW = pBlocking.getSize().toWalkPosition();
    for (int dy = 0; dy < pBlockingW.getY(); ++dy) {
        for (int dx = 0; dx < pBlockingW.getX(); ++dx) {
            MiniTile miniTile = getData().getMiniTile(pBlocking.getTopLeft().toWalkPosition().add(new WalkPosition(dx, dy)));
            if (miniTile.isWalkable()) {
                miniTile.replaceBlockedAreaId(newId);
            }
        }
    }
    // Unblock the Tiles of pBlocking:
    for (int dy = 0; dy < pBlocking.getSize().getY(); ++dy) {
        for (int dx = 0; dx < pBlocking.getSize().getX(); ++dx) {
            getData().getTile(pBlocking.getTopLeft().add(new TilePosition(dx, dy))).resetAreaId();
            setAreaIdInTile(pBlocking.getTopLeft().add(new TilePosition(dx, dy)));
        }
    }
    if (automaticPathUpdate()) {
        getGraph().computeChokePointDistanceMatrix();
    }
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) WalkPosition(org.openbw.bwapi4j.WalkPosition)

Aggregations

WalkPosition (org.openbw.bwapi4j.WalkPosition)24 ArrayList (java.util.ArrayList)10 TilePosition (org.openbw.bwapi4j.TilePosition)7 ChokePoint (bwem.ChokePoint)5 MiniTile (bwem.tile.MiniTile)5 Area (bwem.area.Area)4 AreaId (bwem.area.typedef.AreaId)4 Pair (bwem.util.Pair)4 MutablePair (org.apache.commons.lang3.tuple.MutablePair)4 AreaInitializerImpl (bwem.area.AreaInitializerImpl)3 Tile (bwem.tile.Tile)3 TileImpl (bwem.tile.TileImpl)3 Altitude (bwem.typedef.Altitude)3 CPPath (bwem.typedef.CPPath)3 Geyser (bwem.unit.Geyser)3 Mineral (bwem.unit.Mineral)3 StaticBuilding (bwem.unit.StaticBuilding)3 BwemExt (bwem.util.BwemExt)3 Utils (bwem.util.Utils)3 HashMap (java.util.HashMap)3