private double calcIceHazard(Entity movingUnit, IHex hex, MoveStep step, boolean jumpLanding, StringBuilder logMsg) { logMsg.append("\n\tCalculating ice hazard: "); // Hover units are above the surface. if (EntityMovementMode.HOVER == movingUnit.getMovementMode() || EntityMovementMode.WIGE == movingUnit.getMovementMode()) { logMsg.append("Hovering above ice (0)."); return 0; } // If there is no water under the ice, don't worry about breaking // through. if (hex.depth() < 1) { logMsg.append("No water under ice (0)."); return 0; } // Hazard is based on chance to break through to the water underneath. double breakthroughMod = jumpLanding ? 0.5 : 0.1667; logMsg.append("\n\t\tChance to break through ice: ") .append(LOG_PERCENT.format(breakthroughMod)); double hazard = calcWaterHazard(movingUnit, hex, step, logMsg) * breakthroughMod; logMsg.append("\n\t\tHazard value (") .append(LOG_DECIMAL.format(hazard)).append(")."); return hazard; }
/** * Returns a Target for an Accidental Fall From above, or null if no * possible target is there * * @param c The <code>Coords</code> of the hex in which the accidental * fall from above happens * @param ignore The entity who is falling * @return The <code>Entity</code> that should be an AFFA target. */ public Entity getAffaTarget(Coords c, Entity ignore) { Vector<Entity> vector = new Vector<Entity>(); if (board.contains(c)) { IHex hex = board.getHex(c); for (Entity entity : getEntitiesVector(c)) { if (entity.isTargetable() && ((entity.getElevation() == 0) // Standing on hex surface || (entity.getElevation() == -hex.depth())) // Standing on hex floor && (entity.getAltitude() == 0) && !(entity instanceof Infantry) && (entity != ignore)) { vector.addElement(entity); } } } if (!vector.isEmpty()) { int count = vector.size(); int random = Compute.randomInt(count); return vector.elementAt(random); } return null; }
elevation = Math.max(-targetHex.depth(), targetHex .terrainLevel(Terrains.BRIDGE_ELEV)); height = targetHex.terrainLevel(Terrains.BLDG_ELEV);
int depth = hex.depth(false);
Mockito.when(mockPath.isJumping()).thenReturn(false); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[]{Terrains.ICE, Terrains.WATER}); Mockito.when(mockHexThree.depth()).thenReturn(1); Assert.assertEquals(166.7, testRanker.checkPathForHazards(mockPath, mockInfantry, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Mockito.when(mockHexThree.depth()).thenReturn(0); Mockito.when(mockHexThree.terrainLevel(Terrains.WATER)).thenReturn(1); Mockito.when(mockFinalHex.terrainLevel(Terrains.WATER)).thenReturn(2); Mockito.when(mockHexTwo.depth()).thenReturn(0); Mockito.when(mockHexThree.depth()).thenReturn(1); Mockito.when(mockFinalHex.depth()).thenReturn(2); Mockito.when(mockUnit.getArmor(Mech.LOC_CT)).thenReturn(0); Assert.assertEquals(166.7, testRanker.checkPathForHazards(mockPath, mockUnit, mockGame), TOLERANCE); Mockito.when(mockHexThree.terrainLevel(Terrains.WATER)).thenReturn(0); Mockito.when(mockFinalHex.terrainLevel(Terrains.WATER)).thenReturn(0); Mockito.when(mockHexTwo.depth()).thenReturn(0); Mockito.when(mockHexThree.depth()).thenReturn(0); Mockito.when(mockFinalHex.depth()).thenReturn(0); Mockito.when(mockFinalHex.getTerrainTypes()).thenReturn(new int[]{Terrains.ICE, Terrains.WATER}); Mockito.when(mockFinalHex.terrainLevel(Terrains.WATER)).thenReturn(2); Mockito.when(mockFinalHex.depth()).thenReturn(2); Mockito.when(mockUnit.getArmor(Mockito.eq(Mech.LOC_LLEG))).thenReturn(0); Assert.assertEquals(25.0, testRanker.checkPathForHazards(mockPath, mockUnit, mockGame), TOLERANCE); Mockito.when(mockUnit.getArmor(Mockito.eq(Mech.LOC_LLEG))).thenReturn(10); Mockito.when(mockFinalHex.terrainLevel(Terrains.WATER)).thenReturn(0); Mockito.when(mockFinalHex.depth()).thenReturn(0);
/** * 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; }
} else { attUnderWater = attHex.containsTerrain(Terrains.WATER) && (attHex.depth() > 0) && (attEl < attHex.surface()); attInWater = attHex.containsTerrain(Terrains.WATER) && (attHex.depth() > 0) && (attEl == attHex.surface()); attOnLand = !(attUnderWater || attInWater); } else { targetUnderWater = targetHex.containsTerrain(Terrains.WATER) && (targetHex.depth() > 0) && (targEl < targetHex.surface()); targetInWater = targetHex.containsTerrain(Terrains.WATER) && (targetHex.depth() > 0) && (targEl == targetHex.surface()); targetOnLand = !(targetUnderWater || targetInWater);
if((hex.terrainsPresent() == 0) || (hex.containsTerrain(Terrains.WATER) && (hex.depth() == 0))) { hex.addTerrain(tf.createTerrain(Terrains.MUD, 1)); if(hex.containsTerrain(Terrains.WATER)) { if(hex.containsTerrain(Terrains.WATER) && !hex.containsTerrain(Terrains.RAPIDS) && (hex.depth() > 0)) { hex.addTerrain(tf.createTerrain(Terrains.RAPIDS, 1)); if(hex.containsTerrain(Terrains.WATER) && !(hex.terrainLevel(Terrains.RAPIDS) > 1) && (hex.depth() > 0)) { hex.addTerrain(tf.createTerrain(Terrains.RAPIDS, 2)); && hex.containsTerrain(Terrains.WATER) && (hex.depth() > 0)) {
int bldcur = Math.max(-current.depth(true), current.terrainLevel(Terrains.BLDG_ELEV)); int bldnex = Math.max(-next.depth(true), next.terrainLevel(Terrains.BLDG_ELEV)); if (((assumedElevation == bldcur) retVal -= next.surface(); } else if (elevation == -(current.depth(true))) { if (climb || isJumpingNow) { retVal = bldnex + next.surface();
&& currentHex.depth(true) > 0) {
if (sea) { SeaMineDepthDialog smd = new SeaMineDepthDialog( clientgui.frame, hex.depth()); smd.setVisible(true);
- hex.surface(); int building = hex.terrainLevel(Terrains.BLDG_ELEV); int depth = -hex.depth(true);
&& (curHex.depth() > 0) && (step.getElevation() < curHex.surface()); if (curHex.containsTerrain(Terrains.FIRE) && !underwater
.isAirborne())); boolean isUnderwater = ((entityTarget != null) && (hex != null)) && hex.containsTerrain(Terrains.WATER) && (hex.depth() > 0) && (entityTarget.getElevation() < hex.surface()); ToHitData toHit = new ToHitData();
targEl = -game.getBoard().getHex(target.getPosition()).depth(); } else { targEl = te.relHeight();