/** * Helper function that calculates the "utility" of placing a turret at the given coords * @param coords The location of the building being considered. * @return An "arbitrary" utility number */ private int calculateTurretDeploymentValue(final Coords coords) { // algorithm: a building is valued by the following formula: // (CF + height * 2) / # turrets placed on the roof // This way, we will generally favor unpopulated higher CF buildings, // but have some wiggle room in case of a really tall high CF building final Building building = game.getBoard().getBuildingAt(coords); final IHex hex = game.getBoard().getHex(coords); final int turretCount = 1 + game.getGunEmplacements(coords).size(); return (building.getCurrentCF(coords) + hex.terrainLevel(Terrains.BLDG_ELEV) * 2) / turretCount; }
game); Coords toFace = closest == null ? game.getBoard().getCenter() : closest.getPosition(); int desiredFacing = (toFace.direction(movingUnit.getPosition()) + 3) % 6;
/** * 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); } } }
/** * 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); } }
for (int j = 0; j < sheetWidth; j++) { IBoard b = boards[i * sheetWidth + j]; if ((b.getWidth() != width) || (b.getHeight() != height)) { throw new IllegalArgumentException( "board is the wrong size, expected " + width + "x" + height + ", got " + b.getWidth() + "x" + b.getHeight()); if (boards[i * sheetWidth + j].getRoadsAutoExit() == false) { roadsAutoExit = false; boardListContainsBackground |= b.hasBoardBackground(); result.setRoadsAutoExit(roadsAutoExit); result.newData(resultWidth, resultHeight, resultData, null); if (boardListContainsBackground) { result.setNumBoardsHeight(sheetHeight); result.setNumBoardsWidth(sheetWidth); result.setSubBoardHeight(height); result.setSubBoardWidth(width); ListIterator<Boolean> flipIt = isRotated.listIterator(); for (IBoard b : boards) { boolean flip = flipIt.next(); result.addBackgroundPath(b.getBackgroundPath(), flip, flip); result.setType(medium);
@Override public boolean handle(IGame.Phase phase, Vector<Report> vPhaseReport) { if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_START_FIRE) && (game.getPlanetaryConditions().getAtmosphere() >= PlanetaryConditions.ATMO_TRACE)) { int rear = (ae.getFacing() + 3 + (weapon.isMechTurretMounted() ? weapon .getFacing() : 0)) % 6; Coords src = ae.getPosition(); Coords rearCoords = src.translated(rear); IBoard board = game.getBoard(); IHex currentHex = board.getHex(src); if (!board.contains(rearCoords)) { rearCoords = src; } else if (board.getHex(rearCoords).getLevel() > currentHex .getLevel()) { rearCoords = src; } else if ((board.getBuildingAt(rearCoords) != null) && ((board.getHex(rearCoords).terrainLevel( Terrains.BLDG_ELEV) + board.getHex(rearCoords) .getLevel()) > currentHex.getLevel())) { rearCoords = src; } server.createSmoke(rearCoords, SmokeCloud.SMOKE_HEAVY, 2); } return super.handle(phase, vPhaseReport); }
public boolean isSpaceborne() { // for now if you are in space, you are spaceborne, but this will become // more complicated when // we start adding multiple maps to the same game and so I should try to // replace most calls to // game.getBoard().inSpace() with this one return game != null && game.getBoard().inSpace(); }
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; }
public boolean isOffScreen() { return !bv.game.getBoard().contains(hexLoc); }
protected IHex getHex(final Coords coords) { return getBoard().getHex(coords); }
private double calcBuildingHazard(MoveStep step, Entity movingUnit, boolean jumpLanding, IBoard board, StringBuilder logMsg) { logMsg.append("\n\tCalculating building hazard: "); // Protos, BA and Infantry move through buildings freely. if (movingUnit instanceof Protomech || movingUnit instanceof Infantry) { logMsg.append("Safe for infantry and protos."); return 0; } // Jumping onto a building is handled in PathRanker validatePaths. if (jumpLanding) { return 0; } // Get the odds of failing the piloting roll while moving through the building. double odds = (1.0 - (Compute.oddsAbove(movingUnit.getCrew() .getPiloting()) / 100)); logMsg.append("\n\t\tChance to fail piloting roll: ") .append(LOG_PERCENT.format(odds)); // Hazard is based on potential damage taken. double dmg = board.getBuildingAt(step.getPosition()) .getCurrentCF(step.getPosition()) / 10D; logMsg.append("\n\t\tPotential building damage: ") .append(LOG_DECIMAL.format(dmg)); double hazard = dmg * odds; logMsg.append("\n\t\tHazard value (") .append(LOG_DECIMAL.format(hazard)).append(")."); return hazard; }
private void addArtyAutoHitHex(Coords coords) { if (!clientgui.getClient().getGame().getBoard().contains(coords)) { return; .getGame() .getBoard() .addSpecialHexDisplay( coords, new SpecialHexDisplay(
/** * is the unit flying Nape of the Earth? (i.e. one elevation above ground) */ public boolean isNOE() { if (!isAirborne()) { return false; } if (game.getBoard().inAtmosphere()) { return (1 == (getAltitude() - game.getBoard().getHex(getPosition()) .ceiling(true))); } if (game.getBoard().onGround()) { return 1 == getAltitude(); } return false; }
@Override public void gameBoardNew(GameBoardNewEvent e) { IBoard b = e.getOldBoard(); if (b != null) { b.removeBoardListener(boardListener); } b = e.getNewBoard(); if (b != null) { b.addBoardListener(boardListener); } m_board = b; initializeMap(); }
@SuppressWarnings("unchecked") protected void receiveBuildingCollapse(Packet packet) { game.getBoard().collapseBuilding((Vector<Coords>) packet.getObject(0)); }
/** * Creates and lays out a new mech display. */ public MiniMap(Container d, IGame g, IBoardView bview) throws IOException { m_game = g; m_bview = bview; m_dialog = d; m_board = m_game.getBoard(); m_bview.addBoardViewListener(boardViewListener); m_game.addGameListener(gameListener); m_board.addBoardListener(boardListener); initialize(); }
private boolean worryAboutBridges() { if (mapHasBridges != null) { return mapHasBridges.get(); } synchronized (BRIDGE_LOCK) { if (mapHasBridges != null) { return mapHasBridges.get(); } mapHasBridges = new AtomicBoolean(getGame().getBoard() .containsBridges()); } return mapHasBridges.get(); } }
@Override public boolean handle(IGame.Phase phase, Vector<Report> vPhaseReport) { if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_START_FIRE) && (game.getPlanetaryConditions().getAtmosphere() >= PlanetaryConditions.ATMO_TRACE)) { int rear = (ae.getFacing() + 3 + (weapon.isMechTurretMounted() ? weapon .getFacing() : 0)) % 6; Coords src = ae.getPosition(); Coords rearCoords = src.translated(rear); IBoard board = game.getBoard(); IHex currentHex = board.getHex(src); if (!board.contains(rearCoords)) { rearCoords = src; } else if (board.getHex(rearCoords).getLevel() > currentHex .getLevel() + 4) { rearCoords = src; } else if ((board.getBuildingAt(rearCoords) != null) && (board.getHex(rearCoords).terrainLevel( Terrains.BLDG_ELEV) + board.getHex(rearCoords).getLevel() > currentHex .getLevel() + 4)) { rearCoords = src; } server.createSmoke(rearCoords, SmokeCloud.SMOKE_HEAVY, 2); } return super.handle(phase, vPhaseReport); }