protected IHex getHex(final Coords coords) { return getBoard().getHex(coords); }
/** * Copies the data of another board into given array of Hexes, offset by the * specified x and y. */ protected static void copyBoardInto(IHex[] dest, int destWidth, int x, int y, IBoard copied) { for (int i = 0; i < copied.getHeight(); i++) { for (int j = 0; j < copied.getWidth(); j++) { dest[(i + y) * destWidth + j + x] = copied.getHex(j, i); } } }
/** * Returns the highest elevation in the current path * * @return */ public int getMaxElevation() { int maxElev = 0; for (MoveStep step : steps) { maxElev = Math.max(maxElev, getGame().getBoard().getHex(step.getPosition()).getLevel()); } return maxElev; }
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; }
@Override public boolean isLocationProhibited(Coords c, int currElevation) { IHex hex = game.getBoard().getHex(c); if(hex.containsTerrain(Terrains.SPACE) && doomedInSpace()) { return true; } //gun emplacements must be placed on a building return !hex.containsTerrain(Terrains.BUILDING); }
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 double getMassOfAllInBuilding(final IGame game, final Coords coords) { double mass = 0; // Add the mass of anyone else standing in/on this building. final IHex hex = game.getBoard().getHex(coords); final int buildingElevation = hex.terrainLevel(Terrains.BLDG_ELEV); final int bridgeElevation = hex.terrainLevel(Terrains.BRIDGE_ELEV); Iterator<Entity> crowd = game.getEntities(coords); while (crowd.hasNext()) { Entity e = crowd.next(); if (buildingElevation >= e.getElevation() || bridgeElevation >= e.getElevation()) { mass += e.getWeight(); } } return mass; }
/** * In hexes with buildings, returns the elevation relative to the roof. Otherwise returns the elevation * relative to the surface. */ public int getClearance() { IHex hex = entity.getGame().getBoard().getHex(getPosition()); if (hex.containsTerrain(Terrains.BLDG_ELEV)) { return elevation - hex.terrainLevel(Terrains.BLDG_ELEV); } return elevation; }
/** * Returns the distance between the highest elevation in the jump path and * the elevation at the landing point. This gives the largest distance the * unit has fallen during the jump. */ public int getJumpMaxElevationChange() { return getMaxElevation() - getGame().getBoard().getHex(getFinalCoords()).getLevel(); }
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; }
/** * Checks to see if the entities' elevation is below the surface of a water * hex. * * @return True if the entity is underwater, else false. */ public boolean isUnderwater() { IHex occupiedHex = game.getBoard().getHex(getPosition()); if (occupiedHex.containsTerrain(Terrains.WATER) && (relHeight() < occupiedHex.surface())) { return true; } return false; }
private void findGeysers() { IBoard b = server.getGame().getBoard(); int height = b.getHeight(); int width = b.getWidth(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (b.getHex(x, y).containsTerrain(Terrains.GEYSER)) { geysers.add(new GeyserInfo(new Coords(x, y))); } } } }
@Override /** * Checks to see if a Tank is capable of going hull-down. This is true if * hull-down rules are enabled and the Tank is in a fortified hex. * * @return True if hull-down is enabled and the Tank is in a fortified hex. */ public boolean canGoHullDown() { // MoveStep line 2179 performs this same check // performing it here will allow us to disable the Hulldown button // if the movement is illegal IHex occupiedHex = game.getBoard().getHex(getPosition()); return occupiedHex.containsTerrain(Terrains.FORTIFIED) && game.getOptions().booleanOption(OptionsConstants.ADVGRNDMOV_TACOPS_HULL_DOWN); }
/** * 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); } } }
/** * Modifier to attacks due to attacker terrain */ public static ToHitData getAttackerTerrainModifier(IGame game, int entityId) { final Entity attacker = game.getEntity(entityId); final IHex hex = game.getBoard().getHex(attacker.getPosition()); ToHitData toHit = new ToHitData(); // space screens; bonus depends on number (level) if (hex.terrainLevel(Terrains.SCREEN) > 0) { toHit.addModifier(hex.terrainLevel(Terrains.SCREEN) + 1, "attacker in screen(s)"); } return toHit; }
/** * Returns this mech's jumping MP, modified for missing & underwater jets. */ @Override public int getJumpMPWithTerrain() { if (getPosition() == null) { return getJumpMP(); } int waterLevel = game.getBoard().getHex(getPosition()) .terrainLevel(Terrains.WATER); if ((waterLevel <= 0) || (getElevation() >= 0)) { return getJumpMP(); } return 0; }
/** * If the QuadVee is in vehicle mode (or converting to it) then it follows * the rules for tanks going hull-down, which requires a fortified hex. * * @return True if hull-down is enabled and the QuadVee is in a fortified hex. */ @Override public boolean canGoHullDown() { if (getConversionMode() == CONV_MODE_VEHICLE != convertingNow) { IHex occupiedHex = game.getBoard().getHex(getPosition()); return occupiedHex.containsTerrain(Terrains.FORTIFIED) && game.getOptions().booleanOption(OptionsConstants.ADVGRNDMOV_TACOPS_HULL_DOWN); } return super.canGoHullDown(); }
/** * get final elevation relative to the tops of any buildings in the hex * @return */ public int getFinalClearance() { if (getLastStep() != null) { return getLastStep().getClearance(); } IHex hex = entity.getGame().getBoard().getHex(getEntity().getPosition()); if (hex.containsTerrain(Terrains.BLDG_ELEV)) { return getEntity().getElevation() - hex.terrainLevel(Terrains.BLDG_ELEV); } return getEntity().getElevation(); }