use of org.openbw.bwapi4j.type.Color in project BWAPI4J by OpenBW.
the class TestListenerBwem method onFrame.
@Override
public void onFrame() {
try {
// Send idle workers to mine at the closest mineral patch.
for (final Worker worker : workers) {
if (worker.isIdle()) {
MineralPatch closestMineralPatch = null;
for (final MineralPatch mineralPatch : bw.getMineralPatches()) {
if (closestMineralPatch == null) {
closestMineralPatch = mineralPatch;
} else {
if (mineralPatch.getPosition().getDistance(self.getStartLocation().toPosition()) < closestMineralPatch.getPosition().getDistance(self.getStartLocation().toPosition())) {
closestMineralPatch = mineralPatch;
}
}
}
worker.gather(closestMineralPatch);
}
}
/* Train an SCV at every Command Center. */
{
if (self.getRace() == Race.Terran) {
for (final PlayerUnit u : bw.getUnits(self)) {
if (u instanceof CommandCenter) {
final CommandCenter commandCenter = (CommandCenter) u;
if (!commandCenter.isTraining()) {
commandCenter.trainWorker();
}
}
}
}
}
/* Highlight starting locations and possible base locations. */
{
for (final Base base : bwem.getMap().getBases()) {
final boolean isStartingLocation = base.isStartingLocation();
final Color highlightColor = isStartingLocation ? Color.GREEN : Color.YELLOW;
final Position baseLocation = base.getLocation().toPosition();
final Position resourceDepotSize = UnitType.Terran_Command_Center.tileSize().toPosition();
if (isOnScreen(baseLocation)) {
bw.getMapDrawer().drawBoxMap(baseLocation, baseLocation.add(resourceDepotSize), highlightColor);
}
/* Display minerals. */
for (final Mineral mineral : base.getMinerals()) {
if (isOnScreen(mineral.getCenter())) {
bw.getMapDrawer().drawLineMap(mineral.getCenter(), base.getCenter(), Color.CYAN);
}
}
/* Display geysers. */
for (final Geyser geyser : base.getGeysers()) {
if (isOnScreen(geyser.getCenter())) {
bw.getMapDrawer().drawLineMap(geyser.getCenter(), base.getCenter(), Color.GREEN);
}
}
}
}
/* Highlight choke points. */
{
final int chokePointRadius = 8;
final Color chokePointColor = Color.RED;
for (final ChokePoint chokePoint : bwem.getMap().getChokePoints()) {
final Position center = chokePoint.getCenter().toPosition();
if (isOnScreen(center)) {
bw.getMapDrawer().drawCircleMap(center, chokePointRadius, chokePointColor);
bw.getMapDrawer().drawLineMap(center.getX() - chokePointRadius, center.getY(), center.getX() + chokePointRadius, center.getY(), chokePointColor);
bw.getMapDrawer().drawLineMap(center.getX(), center.getY() - chokePointRadius, center.getX(), center.getY() + chokePointRadius, chokePointColor);
}
}
}
/* Highlight workers. */
{
for (final Worker worker : workers) {
final Position tileSize = new TilePosition(worker.tileWidth(), worker.tileHeight()).toPosition();
final Position topLeft = worker.getPosition().subtract(tileSize.divide(new Position(2, 2)));
final Position bottomRight = topLeft.add(tileSize);
if (isOnScreen(topLeft)) {
bw.getMapDrawer().drawBoxMap(topLeft, bottomRight, Color.BROWN);
}
}
}
/* Draw mouse position debug info. */
{
final Position screenPosition = bw.getInteractionHandler().getScreenPosition();
final Position mousePosition = screenPosition.add(bw.getInteractionHandler().getMousePosition());
final String mouseText = "T:" + mousePosition.toTilePosition().toString() + "\nW:" + mousePosition.toWalkPosition().toString() + "\nP:" + mousePosition.toString();
bw.getMapDrawer().drawBoxMap(mousePosition.toTilePosition().toPosition(), mousePosition.toTilePosition().toPosition().add(new TilePosition(1, 1).toPosition()), Color.WHITE);
bw.getMapDrawer().drawTextMap(mousePosition.add(new Position(20, -10)), mouseText);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
Aggregations