/** * @param hex * @return true if the hex needs a bridge to cross */ private boolean hexNeedsBridge(IHex hex) { if (hex.containsTerrain(Terrains.ROAD) || hex.containsTerrain(Terrains.BRIDGE)) return false; return (hex.containsTerrain(Terrains.WATER) || hex .containsTerrain(Terrains.MAGMA)); }
/** * @param hex * @return true if it is reasonable to build on this hex */ private boolean isHexBuildable(IHex hex) { if (hex.containsTerrain(Terrains.WATER) || hex.containsTerrain(Terrains.IMPASSABLE) || hex.containsTerrain(Terrains.MAGMA) || hex.containsTerrain(Terrains.SWAMP)) { return false; // uneconomic to build here } if (hex.getLevel() >= 4) { return false; // don't build on mountaintops (aesthetics) } return true; }
@Override public boolean containsBridges() { for (Coords c : bldgByCoords.keySet()) { IHex hex = getHex(c); if (hex.containsTerrain(Terrains.BRIDGE)) { return true; } } return false; }
@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); }
public int elevationOccupied(IHex hex, int elevation) { if (hex == null) { return 0; } if ((movementMode == EntityMovementMode.VTOL) || (movementMode == EntityMovementMode.WIGE)) { return hex.surface() + elevation; } else if (((movementMode == EntityMovementMode.HOVER) || (movementMode == EntityMovementMode.NAVAL) || (movementMode == EntityMovementMode.HYDROFOIL) || hex.containsTerrain(Terrains.ICE)) && hex.containsTerrain(Terrains.WATER)) { return hex.surface(); } else { return hex.floor(); } }
public void setBridgeCF(int value) { for (Building bldg : buildings) { for (Enumeration<Coords> coords = bldg.getCoords(); coords.hasMoreElements();) { Coords c = coords.nextElement(); IHex h = getHex(c); if (h.containsTerrain(Terrains.BRIDGE)) { bldg.setCurrentCF(value, c); } } } }
/** * Helper function that calculates the effective elevation for a unit standing there. * @param hex The hex to check * @param entity The entity to check * @return The effective elevation */ private int calculateUnitElevationInHex(IHex hex, Entity entity) { // we calculate the height of a hex as "on the ground" by default // Special exceptions: // We are a mech, which can hopping on top of some buildings // We are naval unit going under a bridge, in which case the height is the water level (naval units go on the surface, mostly) // We are non-naval going into water but not onto a bridge, in which case the height is the floor (mechs sink to the bottom) int hexElevation = hex.getLevel(); if(entity.hasETypeFlag(Entity.ETYPE_MECH) && hex.containsTerrain(Terrains.BLDG_CF)) { hexElevation = hex.ceiling(); } else if(entity.isNaval() && hex.containsTerrain(Terrains.BRIDGE)) { hexElevation = hex.getLevel(); } else if(!entity.isSurfaceNaval() && hex.containsTerrain(Terrains.WATER) && !hex.containsTerrain(Terrains.BRIDGE)) { hexElevation = hex.floor(); } return hexElevation; }
/** * 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; }
/** * Spreads the fire, and reports the spread, to the specified hex, if * possible, if the hex isn't already on fire, and the fire roll is made. */ public void spreadFire(Coords coords, TargetRoll roll, int height) { IHex hex = game.getBoard().getHex(coords); if (hex == null) { // Don't attempt to spread fire off the board. return; } if(Math.abs(hex.ceiling() - height) > 4) { return; } if (!(hex.containsTerrain(Terrains.FIRE)) && server.checkIgnition(coords, roll)) { Report r = new Report(5150, Report.PUBLIC); r.add(coords.getBoardNum()); vPhaseReport.addElement(r); } }
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; }
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))); } } } }
/** * 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; }
@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); }
private void addRoad(IHex hex, int exitDirection, int type) { ITerrainFactory tf = Terrains.getTerrainFactory(); if (hex.containsTerrain(Terrains.WATER)) { hex.removeTerrain(Terrains.WATER); hex.addTerrain(tf.createTerrain(Terrains.WATER, 0)); type = 1; } hex.addTerrain(tf.createTerrain(Terrains.ROAD, type, true, (1 << exitDirection) & 63)); }
/** * 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); } }
/** * Checks if an entity is landing (from a jump) in heavy woods. */ public PilotingRollData checkLandingInHeavyWoods( EntityMovementType overallMoveType, IHex curHex) { PilotingRollData roll = getBasePilotingRoll(overallMoveType); if (curHex.containsTerrain(Terrains.WOODS, 2)) { roll.append(new PilotingRollData(getId(), 0, "landing in heavy woods")); addPilotingModifierForTerrain(roll); } else if (curHex.containsTerrain(Terrains.WOODS, 3)) { roll.append(new PilotingRollData(getId(), 0, "landing in ultra woods")); addPilotingModifierForTerrain(roll); } else { roll.addModifier(TargetRoll.CHECK_FALSE, "hex does not contain heavy or ultra woods"); } return roll; }
/** * 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(); }
/** * Checks if the entity is landing (from a jump) on ice-covered water. */ public PilotingRollData checkLandingOnIce( EntityMovementType overallMoveType, IHex curHex) { PilotingRollData roll = getBasePilotingRoll(overallMoveType); if (curHex.containsTerrain(Terrains.ICE) && (curHex.terrainLevel(Terrains.WATER) > 0)) { roll.append(new PilotingRollData(getId(), 0, "landing on ice-covered water")); addPilotingModifierForTerrain(roll); adjustDifficultTerrainPSRModifier(roll); } else { roll.addModifier(TargetRoll.CHECK_FALSE, "hex is not covered by ice"); } return roll; }
/** * Apply PSR modifier for difficult terrain at the specified coordinates * * @param roll the PSR to modify * @param c the coordinates where the PSR happens * @param enteringRubble True if entering rubble, else false */ public void addPilotingModifierForTerrain(PilotingRollData roll, Coords c, boolean enteringRubble) { if ((c == null) || (roll == null)) { return; } if (isOffBoard() || !(isDeployed())) { return; } IHex hex = game.getBoard().getHex(c); hex.terrainPilotingModifier(getMovementMode(), roll, enteringRubble); if (hex.containsTerrain(Terrains.JUNGLE) && hasAbility(OptionsConstants.PILOT_TM_FOREST_RANGER)) { roll.addModifier(-1, "Forest Ranger"); } }
/** * 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(); }