/** * by default, entities can move as far down as they can move up */ public int getMaxElevationDown() { return getMaxElevationDown(getElevation()); }
/** * Returns the elevation of the entity's highest point relative to * the surface of the hex the entity is in , i.e. * relHeight() == getElevation() + getHeight() */ @Override public int relHeight() { return getElevation() + height(); }
/** * Returns the absolute elevation above ground level 0 that this entity * would be on if it were placed into the specified hex. * Hovercraft, naval vessels, and hydrofoils move on the * surface of the water */ public int elevationOccupied(IHex hex) { return elevationOccupied(hex, getElevation()); }
/** * is this a naval vessel on the surface of the water? */ public boolean isSurfaceNaval() { // TODO: assuming submarines on the surface act like surface naval // vessels until rules clarified // http://www.classicbattletech.com/forums/index.php/topic,48987.0.html return (getElevation() == 0) && isNaval(); }
/** * When compiling an unloading step, both the transporter and the unloaded * unit probably occupy some other position on the board. * * The position, and elevation for the stacking violation are derived from * the passed Entity. * * @param transport * Represents the unit transporing entering, which may affect * stacking, can be null */ public static Entity stackingViolation(IGame game, Entity entering, Coords dest, Entity transport) { return stackingViolation(game, entering, entering.getElevation(), dest, transport); }
/** * Apply PSR modifier for difficult terrain in the current position * * @param roll the PSR to modify */ public void addPilotingModifierForTerrain(PilotingRollData roll) { if (getElevation() > 0) { return; } addPilotingModifierForTerrain(roll, getPosition()); }
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; }
@Override public int getElevation() { if ((game != null) && game.getBoard().inSpace()) { return 0; } // Altitude is not the same as elevation. If an aero is at 0 altitude, // then it is // grounded and uses elevation normally. Otherwise, just set elevation // to a very // large number so that a flying aero won't interact with the ground // maps in any way if (isAirborne()) { return 999; } return super.getElevation(); }
/** * get final elevation relative to the hex. */ public int getFinalElevation() { if (getLastStep() != null) { return getLastStep().getElevation(); } return getEntity().getElevation(); }
/** * cycle through entities on team and collect all the airborne VTOL/WIGE * * @return a vector of relevant entity ids */ @Override public Vector<Integer> getAirborneVTOL() { //a vector of unit ids Vector<Integer> units = new Vector<Integer>(); for (Entity entity : game.getEntitiesVector()) { if (entity.getOwner().equals(this)) { if (((entity instanceof VTOL) || (entity.getMovementMode() == EntityMovementMode.WIGE)) && (!entity.isDestroyed()) && (entity.getElevation() > 0)) { units.add(entity.getId()); } } } return units; }
/** * 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; }
/** * Returns the elevation of this entity, relative to the current Hex's * surface */ @Override public int getElevation() { if (Entity.NONE != getTransportId()) { return game.getEntity(getTransportId()).getElevation(); } if ((null == getPosition()) && (isDeployed())) { throw new IllegalStateException("Entity #" + getId() + " does not know its position."); } if (isOffBoard()) { return 0; } return elevation; }
/** * Returns true if there is any unit that is an enemy of the specified unit * in the specified hex. This is only called for stacking purposes, and so * does not return true if the enemy unit is currenly making a DFA. */ public static boolean isEnemyIn(IGame game, Entity entity, Coords coords, boolean onlyMechs, boolean ignoreInfantry, int enLowEl) { int enHighEl = enLowEl + entity.getHeight(); for (Entity inHex : game.getEntitiesVector(coords)) { int inHexEnLowEl = inHex.getElevation(); int inHexEnHighEl = inHexEnLowEl + inHex.getHeight(); if ((!onlyMechs || (inHex instanceof Mech)) && !(ignoreInfantry && (inHex instanceof Infantry)) && inHex.isEnemyOf(entity) && !inHex.isMakingDfa() && (enLowEl <= inHexEnHighEl) && (enHighEl >= inHexEnLowEl)) { return true; } } return false; }
/** * 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(); }
@Override public boolean isAirborneVTOLorWIGE() { // stuff that moves like a VTOL is flying unless at elevation 0 or on // top of/in a building, if ((getMovementMode() == EntityMovementMode.VTOL) || (getMovementMode() == EntityMovementMode.WIGE)) { if ((game != null) && (game.getBoard() != null) && (getPosition() != null) && (game.getBoard().getHex(getPosition()) != null) && ((game.getBoard().getHex(getPosition()) .terrainLevel(Terrains.BLDG_ELEV) >= getElevation()) || (game .getBoard().getHex(getPosition()) .terrainLevel(Terrains.BRIDGE_ELEV) >= getElevation()))) { return false; } return getElevation() > 0; } return false; }
/** * To-hit number for a ram, assuming that movement has been handled */ public ToHitData toHit(IGame game) { final Entity entity = game.getEntity(getEntityId()); return toHit(game, game.getTarget(getTargetType(), getTargetId()), entity.getPosition(), entity.getElevation(), entity.moved); }
public ToHitData toHit(IGame game, boolean skid) { final Entity entity = game.getEntity(getEntityId()); return toHit(game, game.getTarget(getTargetType(), getTargetId()), entity.getPosition(), entity.getElevation(), entity.moved, skid, false); }
/** * To-hit number for a ram, assuming that movement has been handled */ public ToHitData toHit(IGame game) { final Entity entity = game.getEntity(getEntityId()); return toHit(game, game.getTarget(getTargetType(), getTargetId()), entity.getPosition(), entity.getElevation(), entity.getPriorPosition(), entity.moved); }
/** * Determine if the given set of coordinates has a gun emplacement on the roof of a building. * @param c The coordinates to check */ public boolean hasRooftopGunEmplacement(Coords c) { Building building = getBoard().getBuildingAt(c); if(building == null) { return false; } IHex hex = getBoard().getHex(c); for (Entity entity : getEntitiesVector(c, true)) { if (entity.hasETypeFlag(Entity.ETYPE_GUN_EMPLACEMENT) && entity.getElevation() == hex.ceiling()) { return true; } } return false; }
@Override public void load(Entity unit, boolean checkElev, int bayNumber) { if (unit.hasETypeFlag(Entity.ETYPE_PROTOMECH)) { boolean rear = bayNumber > 0; for (Transporter t : getTransports()) { if ((t instanceof ProtomechClampMount) && t.canLoad(unit) && (!checkElev || (unit.getElevation() == getElevation())) && (((ProtomechClampMount) t).isRear() == rear)) { t.load(unit); unit.setTargetBay(-1); return; } } } super.load(unit, checkElev, bayNumber); }