(int)(relSize[0]* (hexSide[zoom] + hexSideBySin30[zoom])*m_board.getWidth())+leftMargin, (int)(relSize[1]*2*hexSideByCos30[zoom]*m_board.getHeight())+topMargin, (int)((relSize[2]-relSize[0])*(hexSide[zoom] + hexSideBySin30[zoom])*m_board.getWidth()), (int)((relSize[3]-relSize[1])*2*hexSideByCos30[zoom]*m_board.getHeight())); (int)(relSize[0]*(hexSide[zoom] + hexSideBySin30[zoom])*m_board.getWidth())+leftMargin, (int)(relSize[1]*2*hexSideByCos30[zoom]*m_board.getHeight())+topMargin, (int)((relSize[2]-relSize[0])*(hexSide[zoom] + hexSideBySin30[zoom])*m_board.getWidth()), (int)((relSize[3]-relSize[1])*2*hexSideByCos30[zoom]*m_board.getHeight()));
/** * 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); } } }
/** * Updates the boardSize variable with the proper values for this board. */ private void updateBoardSize() { int width = (game.getBoard().getWidth() * (int) (HEX_WC * scale)) + (int) ((HEX_W / 4) * scale); int height = (game.getBoard().getHeight() * (int) (HEX_H * scale)) + (int) ((HEX_H / 2) * scale); boardSize = new Dimension(width, height); }
/** * Returns a list of Coords of all hexes on the board. * Returns ONLY hexes where board.getHex != null. */ private ArrayList<Coords> allBoardHexes() { IBoard board = game.getBoard(); if (board == null) return null; ArrayList<Coords> CoordList = new ArrayList<Coords>(); for (int i = 0; i < board.getWidth(); i++) { for (int j = 0; j < board.getHeight(); j++) { IHex hex = board.getHex(i, j); if (hex != null) { CoordList.add(new Coords(i, j)); } } } return CoordList; }
private void buildStraightRoad(Coords start, int direction, int roadStyle) { Coords coords = start; while (coords != null && coords.getX() <= board.getWidth() && coords.getX() >= -1 && coords.getY() <= board.getHeight() && coords.getY() >= -1) { cityPlan.add(coords); Coords next = extendRoad(coords, direction, roadStyle); if (next == null) { coords = resumeAfterObstacle(coords, direction); } else coords = next; } }
public boolean isOnBoardEdge(IBoard board) { return (getX() == 0) || (getY() == 0) || (getX() == (board.getWidth() - 1)) || (getY() == (board.getHeight() - 1)); }
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))); } } } }
Coords edgeCoords; int boardHeight = game.getBoard().getHeight(); int boardWidth = game.getBoard().getWidth(); StringBuilder msg = new StringBuilder("Getting distance to home edge: "); if (CardinalEdge.NORTH.equals(homeEdge)) {
private void findElevators() { IBoard b = server.getGame().getBoard(); int height = b.getHeight(); int width = b.getWidth(); int exits = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (b.getHex(x, y).containsTerrain(Terrains.ELEVATOR)) { exits = b.getHex(x, y).getTerrain(Terrains.ELEVATOR) .getExits(); // add the elevator to each list it belongs in. // exits are abused to hold which d6 roll(s) move this // elevator for (int z = 0; z < 6; z++) { if ((exits & 1) == 1) { elevators[z].positions.add(new Coords(x, y)); } exits >>= 1; } } } } }
/** * Figures out the "opposite" edge for the given entity on the entity's game board * @param entity Entity to evaluate * @return the Board.START_ constant representing the "opposite" edge */ public static CardinalEdge getClosestEdge(Entity entity) { int distanceToWest = entity.getPosition().getX(); int distanceToEast = entity.getGame().getBoard().getWidth() - entity.getPosition().getX(); int distanceToNorth = entity.getPosition().getY(); int distanceToSouth = entity.getGame().getBoard().getHeight() - entity.getPosition().getY(); boolean closerWestThanEast = distanceToWest < distanceToEast; boolean closerNorthThanSouth = distanceToNorth < distanceToSouth; int horizontalDistance = Math.min(distanceToWest, distanceToEast); int verticalDistance = Math.min(distanceToNorth, distanceToSouth); if(horizontalDistance < verticalDistance) { return closerWestThanEast ? CardinalEdge.WEST : CardinalEdge.EAST; } else { return closerNorthThanSouth ? CardinalEdge.NORTH : CardinalEdge.SOUTH; } }
/** * Adds an Road to the map. Goes from one border to another, and has one * turn in it. Map must be at least 3x3. */ private void addGenericRoad() { Coords c = new Coords(Compute.randomInt(board.getWidth()), Compute .randomInt(board.getHeight())); int side0 = Compute.randomInt(6); int side1 = Compute.randomInt(5); if (side1 >= side0) { side1++; } buildStraightRoad(c, side0, 1); buildStraightRoad(c, side1, 1); } }
/** * Check to see if screen clears */ private void resolveScreen() { IBoard board = game.getBoard(); int width = board.getWidth(); int height = board.getHeight(); // Cycle through all hexes, checking for screens debugTime("resolve screen 1", true); for (int currentXCoord = 0; currentXCoord < width; currentXCoord++ ) { for (int currentYCoord = 0; currentYCoord < height; currentYCoord++) { Coords currentCoords = new Coords(currentXCoord, currentYCoord); IHex currentHex = board.getHex(currentXCoord, currentYCoord); // check for existence of screen if (currentHex.containsTerrain(Terrains.SCREEN)){ if(Compute.d6(2)>6) { Report r = new Report(9075, Report.PUBLIC); r.add(currentCoords.getBoardNum()); vPhaseReport.addElement(r); currentHex.removeTerrain(Terrains.SCREEN); server.getHexUpdateSet().add(currentCoords); } } } } debugTime("resolve screen 1 end", true); }
/** * Enables relevant buttons and sets up for your turn. */ private void beginMyTurn() { // Make sure we've got the correct local player p = clientgui.getClient().getLocalPlayer(); // By default, we should get 5 hexes per 4 mapsheets (4 mapsheets is // 16*17*4 hexes, so 1088) IGame game = clientgui.getClient().getGame(); IBoard board = game.getBoard(); int preDesignateArea = game.getOptions().intOption(OptionsConstants.ADVCOMBAT_MAP_AREA_PREDESIGNATE); int hexesPer = game.getOptions().intOption(OptionsConstants.ADVCOMBAT_NUM_HEXES_PREDESIGNATE); double mapArea = board.getWidth() * board.getHeight(); startingHexes = (int) Math.ceil((mapArea) / preDesignateArea) * hexesPer; artyAutoHitHexes.clear(); setArtyEnabled(startingHexes); butDone.setEnabled(true); }
/** * Worker function that determines the direction in which the given entity will go off board * if it starts at the given coordinates with the given vectors. * @param entity Entity to examine * @param startingCoords Starting coordinates * @param vectors Starting velocity vector * @return Flight direction. OffBoardDirection.NONE if the given entity will be able to remain on board. */ private static OffBoardDirection calculateOffBoardDirection(Entity entity, Coords startingCoords, int[] vectors) { Coords nextCoords = Compute.getFinalPosition(startingCoords, vectors); int availableThrust = entity.getRunMP(); IBoard board = entity.getGame().getBoard(); OffBoardDirection offBoardDirection = OffBoardDirection.NONE; // step one: check if the position is out of bounds by more than the unit has available thrust if(nextCoords.getX() < -availableThrust) { offBoardDirection = OffBoardDirection.WEST; } else if (nextCoords.getX() > board.getWidth() + availableThrust) { offBoardDirection = OffBoardDirection.EAST; } else if (nextCoords.getY() < -availableThrust) { offBoardDirection = OffBoardDirection.NORTH; } else if(nextCoords.getY() > board.getHeight() + availableThrust) { offBoardDirection = OffBoardDirection.SOUTH; } return offBoardDirection; }
/** * Determines if the given move path ends on the given board edge * @param movePath The move path to check. * @param edge The edge to check for. * @return True or false. */ private boolean isOnBoardEdge(MovePath movePath, int destinationRegion) { Coords coords = movePath.getFinalCoords(); switch(destinationRegion) { case Board.START_N: return coords.getY() == 0; case Board.START_S: return coords.getY() == movePath.getGame().getBoard().getHeight() - 1; case Board.START_E: return coords.getX() == movePath.getGame().getBoard().getWidth() - 1; case Board.START_W: return coords.getX() == 0; default: return false; } }
protected void deployMinefields(Vector<Minefield> deployedMinefields, int number, int type) { for (int i = 0; i < number; i++) { Coords coords = new Coords(Compute.randomInt(game.getBoard() .getWidth()), Compute.randomInt(game.getBoard().getHeight()) ); if (game.containsMinefield(coords)) { Minefield mf = game.getMinefields(coords).get(0); if (mf.getPlayerId() == getLocalPlayer().getId()) { i--; continue; } } else { Minefield mf = null; if (type == 0) { mf = Minefield.createMinefield(coords, getLocalPlayer() .getId(), Minefield.TYPE_CONVENTIONAL, 10); } else if (type == 1) { mf = Minefield.createMinefield(coords, getLocalPlayer() .getId(), Minefield.TYPE_COMMAND_DETONATED, 10); } else if (type == 2) { mf = Minefield.createMinefield(coords, getLocalPlayer() .getId(), Minefield.TYPE_VIBRABOMB, 20); } deployedMinefields.add(mf); } } }
/** * Returns whether an entity can flee from its current position. Currently * returns true if the entity is on the edge of the board. */ public boolean canFlee() { Coords pos = getPosition(); return (pos != null) && ((getWalkMP() > 0) || (this instanceof Infantry)) && !isProne() && !isStuck() && !isShutDown() && !getCrew().isUnconscious() && ((pos.getX() == 0) || (pos.getX() == (game.getBoard().getWidth() - 1)) || (pos.getY() == 0) || (pos.getY() == (game.getBoard() .getHeight() - 1))); }
int width = board.getWidth(); int height = board.getHeight();
/** * Gives the distance to the closest edge */ int distanceToClosestEdge(Coords position, IGame game) { final String METHOD_NAME = "distanceToClosestEdge(Coords, IGame)"; getOwner().methodBegin(BasicPathRanker.class, METHOD_NAME); try { int width = game.getBoard().getWidth(); int height = game.getBoard().getHeight(); int minimum = position.getX(); if ((width - position.getX()) < minimum) { minimum = position.getX(); } if (position.getY() < minimum) { minimum = position.getY(); } if ((height - position.getY()) < minimum) { minimum = height - position.getY(); } return minimum; } finally { getOwner().methodEnd(BasicPathRanker.class, METHOD_NAME); } }
public IBoard implantOldBoard(IGame game, int west, int north, int east, int south) { IBoard oldBoard = game.getBoard(); for (int x = 0; x < oldBoard.getWidth(); x++) { for (int y = 0; y < oldBoard.getHeight(); y++) { int newX = x+west; int newY = y+north; if (oldBoard.contains(x, y) && board.contains(newX, newY)) { IHex oldHex = oldBoard.getHex(x, y); IHex hex = board.getHex(newX, newY); hex.removeAllTerrains(); hex.setLevel(oldHex.getLevel()); int terrainTypes[] = oldHex.getTerrainTypes(); for (int i = 0; i < terrainTypes.length; i++) { int terrainID = terrainTypes[i]; if (!hex.containsTerrain(terrainID) && oldHex.containsTerrain(terrainID)) { hex.addTerrain(oldHex.getTerrain(terrainID)); } } hex.setTheme(oldHex.getTheme()); board.setHex(newX, newY, hex); board.resetStoredElevation(); } } } return board; }