public boolean isOffScreen() { return !bv.game.getBoard().contains(hexLoc); }
/** * Return a Vector of gun emplacements at Coords <code>c</code> * * @param c The coordinates to check * @return <code>Vector<Entity></code> */ public Vector<GunEmplacement> getGunEmplacements(Coords c) { Vector<GunEmplacement> vector = new Vector<GunEmplacement>(); // Only build the list if the coords are on the board. if (board.contains(c)) { for (Entity entity : getEntitiesVector(c, true)) { if (entity.hasETypeFlag(Entity.ETYPE_GUN_EMPLACEMENT)) { vector.addElement((GunEmplacement) entity); } } } return vector; }
/** * Moves the position one hex in the direction indicated. Does not change * facing. * * @param dir */ public void moveInDir(int dir) { position = position.translated(dir); if (!getGame().getBoard().contains(position)) { throw new RuntimeException("Coordinate off the board."); } }
public void addStrategicBuildingTarget(final Coords coords) { if (null == coords) { throw new NullPointerException("Coords is null."); } if (!getGame().getBoard().contains(coords)) { log(getClass(), "addStrategicBuildingTarget(Coords)", LogLevel.WARNING, "Board does not contain " + coords.toFriendlyString()); return; } getStrategicBuildingTargets().add(coords); }
void addCoordFacingCombos(Iterator<CoordFacingCombo> cfit) { final String METHOD_NAME = "addCoordFacingCombos(Iterator<CoordFacingCombo>)"; owner.methodBegin(getClass(), METHOD_NAME); try { while (cfit.hasNext()) { CoordFacingCombo cf = cfit.next(); if(cf != null && owner.getGame().getBoard().contains(cf.coords)) { expandToInclude(cf.getCoords()); } } } finally { owner.methodEnd(getClass(), METHOD_NAME); } }
private IBoard generateMockBoard() { // we'll be on a nice, empty, 20x20 board, not in space. final IBoard mockBoard = Mockito.mock(Board.class); final IHex mockHex = new Hex(); Mockito.when(mockBoard.getHex(Mockito.any(Coords.class))).thenReturn(mockHex); Mockito.when(mockBoard.contains(Mockito.any(Coords.class))).thenReturn(true); Mockito.when(mockBoard.inSpace()).thenReturn(false); return mockBoard; }
/** * Convenience function encapsulating logic for whether, if we continue forward * along the current path in the current direction, we will run off the board * @return */ public boolean nextForwardStepOffBoard() { return !game.getBoard().contains(getFinalCoords().translated(getFinalFacing())); } }
private static void findCliffNeighbours(IBoard board, Coords c, ArrayList<Coords> candidate, HashSet<Coords> ignore) { candidate.add(c); ignore.add(c); int elevation = board.getHex(c).getLevel(); for (int dir = 0; dir < 6; dir++) { Coords t = c.translated(dir); if (board.contains(t) && !ignore.contains(t)) { if (hexCouldBeCliff(board, t)) { IHex hex = board.getHex(t); int el = hex.getLevel(); if (el == elevation) { findCliffNeighbours(board, t, candidate, ignore); } } else { ignore.add(t); } } } }
/** * Adds on-board HexTargets within the MAX_ARTILLERY_BLAST_RADIUS of the given coordinates * to the given HexTarget set. * @param coords Center coordinates * @param targetList List of target hexes * @param game game pointer */ private void addHexDonuts(Coords coords, Set<Targetable> targetList, IGame game) { // while we're here, consider shooting at hexes within "MAX_BLAST_RADIUS" // of the designated coordinates for(int radius = 1; radius <= MAX_ARTILLERY_BLAST_RADIUS; radius++) { for(Coords donutHex : BotGeometry.getHexDonut(coords, radius)) { // don't bother adding off-board donuts. if(game.getBoard().contains(donutHex)) { targetList.add(new HexTarget(donutHex, game.getBoard(), Targetable.TYPE_HEX_ARTILLERY)); } } } }
private Coords resumeAfterObstacle(Coords coords, int nextDirection) { Coords next = selectNextGrid(nextDirection, coords); while (board.contains(next) && !isHexBuildable(board.getHex(next))) { next = selectNextGrid(nextDirection, next); } return next; }
public static boolean hasFireBetween(Coords start, Coords end, IGame game) { ArrayList<Coords> in = Coords.intervening(start, end); for ( Coords hex : in ) { // ignore off-board hexes if (!game.getBoard().contains(hex)) { continue; } if ( game.getBoard().getHex(hex).containsTerrain(Terrains.FIRE) ) { return true; } } return false; }
/** * Apply the current Hex to the Board at the specified location. */ public void resurfaceHex(Coords c) { if (board.contains(c)) { IHex newHex = curHex.duplicate(); newHex.setLevel(board.getHex(c).getLevel()); board.resetStoredElevation(); board.setHex(c, newHex); } }
private Coords extendRoad(Coords coords, int nextDirection, int roadStyle) { Coords next = selectNextGrid(nextDirection, coords); if (board.contains(next) && hexNeedsBridge(board.getHex(next))) { if (nextDirection == E || nextDirection == W) { nextDirection = coords.direction(next); } Coords end = tryToBuildBridge(coords, nextDirection); return end; } connectHexes(coords, next, roadStyle); connectHexes(next, coords, roadStyle); return next; }
private void connectHexes(Coords src, Coords dest, int roadStyle) { if (board.contains(src)) { IHex hex = board.getHex(src); ITerrain t = hex.getTerrain(Terrains.ROAD); if (t == null) { t = hex.getTerrain(Terrains.BRIDGE); } if (t == null) { addRoad(hex, src.direction(dest), roadStyle); } else { t.setExit(src.direction(dest), true); } } }
/** * Determines if this Board contains the Coords, and if so, highlights that * Coords. * * @param coords the Coords. */ public void highlight(Coords coords) { if ((coords == null) || game.getBoard().contains(coords)) { setHighlighted(coords); moveCursor(highlightSprite, coords); moveCursor(firstLOSSprite, null); moveCursor(secondLOSSprite, null); processBoardViewEvent(new BoardViewEvent(this, coords, null, BoardViewEvent.BOARD_HEX_HIGHLIGHTED, 0)); } }
/** * Determines if this Board contains the Coords, and if so, "selects" that * Coords. * * @param coords the Coords. */ public void select(Coords coords) { if ((coords == null) || game.getBoard().contains(coords)) { setSelected(coords); moveCursor(selectedSprite, coords); moveCursor(firstLOSSprite, null); moveCursor(secondLOSSprite, null); processBoardViewEvent(new BoardViewEvent(this, coords, null, BoardViewEvent.BOARD_HEX_SELECTED, 0)); } }
/** * Updates the supplied Game's list of hexes illuminated. * * @param game The game to update * @return True if new hexes were added, else false. */ public boolean setHexesIlluminated(IGame game) { boolean hexesAdded = false; final Entity attacker = getEntity(game); final Coords apos = attacker.getPosition(); final Targetable target = getTarget(game); final Coords tpos = target.getPosition(); ArrayList<Coords> intervening = Coords.intervening(apos, tpos); for (Coords c : intervening) { if (game.getBoard().contains(c)){ hexesAdded |= game.addIlluminatedPosition(c); } } return hexesAdded; }
public void checkLOS(Coords c) { if ((c == null) || game.getBoard().contains(c)) { if (getFirstLOS() == null) { setFirstLOS(c); firstLOSHex(c); processBoardViewEvent(new BoardViewEvent(this, c, null, BoardViewEvent.BOARD_FIRST_LOS_HEX, 0)); } else { secondLOSHex(c, getFirstLOS()); processBoardViewEvent(new BoardViewEvent(this, c, null, BoardViewEvent.BOARD_SECOND_LOS_HEX, 0)); setFirstLOS(null); } } }
/** * defensively check and correct elevation */ public boolean fixElevation() { if (!isDeployed() || isOffBoard() || !game.getBoard().contains(getPosition())) { return false; } if (!isElevationValid(getElevation(), game.getBoard().getHex(getPosition()))) { System.err.println(getDisplayName() + " in hex " + HexTarget.coordsToId(getPosition()) + " is at invalid elevation: " + getElevation()); setElevation(0 - game.getBoard() .getHex(getPosition()).depth()); System.err.println(" moved to elevation " + getElevation()); return true; } return false; }
/** * Apply the current Hex to the Board at the specified location. */ public void addToHex(Coords c) { if (board.contains(c)) { IHex newHex = curHex.duplicate(); IHex oldHex = board.getHex(c); newHex.setLevel(oldHex.getLevel()); int terrainTypes[] = oldHex.getTerrainTypes(); for (int i = 0; i < terrainTypes.length; i++) { int terrainID = terrainTypes[i]; if (!newHex.containsTerrain(terrainID) && oldHex.containsTerrain(terrainID)) { newHex.addTerrain(oldHex.getTerrain(terrainID)); } } board.resetStoredElevation(); board.setHex(c, newHex); } }