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 JMenu touchOffExplosivesMenu() { JMenu menu = new JMenu("Touch off explosives"); Building bldg = client.getBoard().getBuildingAt(coords); if ((bldg != null)) { for (final DemolitionCharge charge : bldg.getDemolitionCharges()) { if (charge.playerId == client.getLocalPlayer().getId() && coords.equals(charge.pos)) { JMenuItem item = new JMenuItem(charge.damage + " Damage"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { client.sendExplodeBuilding(charge); } }); menu.add(item); } } } return menu; }
/** * Determines whether the attacker and the target are in the same building. * * @return true if the target can and does occupy the same building, false * otherwise. */ public static boolean isInSameBuilding(IGame game, Entity attacker, Targetable target) { if (!(target instanceof Entity)) { return false; } Entity targetEntity = (Entity) target; if (!Compute.isInBuilding(game, attacker) || !Compute.isInBuilding(game, targetEntity)) { return false; } Building attkBldg = game.getBoard().getBuildingAt( attacker.getPosition()); Building targBldg = game.getBoard().getBuildingAt(target.getPosition()); return attkBldg.equals(targBldg); }
/** * 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; }
private double potentialBuildingDamage(int x, int y, Entity entity) { Coords coords = new Coords(x, y); Building building = game.getBoard().getBuildingAt(coords); if (building == null) { return 0; } int potentialDmg = (int) Math.ceil((double) building.getCurrentCF(coords) / 10); boolean aptGunnery = entity.hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY); double oddsTakeDmg = 1 - (Compute.oddsAbove(entity.getCrew().getPiloting(), aptGunnery) / 100); return potentialDmg * oddsTakeDmg; }
final Building building = game.getBoard().getBuildingAt(coords); final IHex hex = game.getBoard().getHex(coords);
/** * Gets valid & empty starting coords around the specified point. This * method iterates through the list of Coords and returns the first Coords * that does not have a stacking violation. */ protected Coords getFirstValidCoords(Entity deployedUnit, List<Coords> possibleDeployCoords) { // Check all of the hexes in order. for (Coords dest : possibleDeployCoords) { Entity violation = Compute.stackingViolation(game, deployedUnit, dest, deployedUnit.getElevation(), dest, null); // Ignore coords that could cause a stacking violation if (violation != null) { continue; } // Make sure we don't overload any buildings in this hex. Building building = game.getBoard().getBuildingAt(dest); if (null != building) { double mass = getMassOfAllInBuilding(game, dest) + deployedUnit.getWeight(); if (mass > building.getCurrentCF(dest)) { continue; } } return dest; } System.out.println("Returning no deployment position; THIS IS BAD!"); // If NONE of them are acceptable, then just return null. return null; }
.getBuildingAt(pos); if (bldg != null) { targets.add(new BuildingTarget(pos, clientgui.getClient().getGame()
/** * 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; }
Building parentBuilding = game.getBoard().getBuildingAt(position); //the building the targeted hex belongs to. We have to get this and then get values for the specific hex internally to it. int targetCF = parentBuilding.getCurrentCF(position); int targetArmor = parentBuilding.getArmor(position); Building parentBuilding = game.getBoard().getBuildingAt(position); int targetCF = parentBuilding.getCurrentCF(position); int targetArmor = parentBuilding.getArmor(position);
Building bldg = game.getBoard().getBuildingAt(c); if (bldg != null) { Targetable t = new BuildingTarget(c, game.getBoard(), false);
final Building building = game.getBoard().getBuildingAt(finalCoords); if (building == null) { return false; while (steps.hasMoreElements()) { final MoveStep step = steps.nextElement(); final Building building = game.getBoard().getBuildingAt(step.getPosition()); if (building == null) { continue;
pos = pos.translated(facing); if (((Entity) this).getGame().getBoard().getBuildingAt(pos) != null) { return "Buildings in the way" + lenString;
- game.getBoard().getHex(ai.attackPos).surface(), ai.attackPos)) { los.setThruBldg(game.getBoard().getBuildingAt(in.get(0)));
pos = pos.translated(facing); if (((Entity) this).getGame().getBoard().getBuildingAt(pos) != null) { return "Buildings in the way" + lenString;
/** * Run this command with the arguments supplied */ @Override public void run(int connId, String[] args) { int countbad = 0; for (Entity entity : server.getGame().getEntitiesVector()) { if (entity.fixElevation()) { Building bldg = server.getGame().getBoard().getBuildingAt(entity.getPosition()); if (bldg != null) { server.checkForCollapse(bldg, server.getGame().getPositionMap(), entity.getPosition(), true, server.getvPhaseReport()); } server.sendServerChat(entity.getDisplayName() + " elevation fixed, see megameklog.txt for details & report a bug if you know how this happened"); countbad++; } } server.sendServerChat(connId, "" + countbad + " unit(s) had elevation problems"); }
default String hasRoomForVerticalLanding() { Coords pos = ((Entity) this).getPosition(); IHex hex = ((Entity) this).getGame().getBoard().getHex(((Entity) this).getPosition()); if (((Entity) this).getGame().getBoard().getBuildingAt(pos) != null) { return "Buildings in the way"; } // no units in the way for (Entity en : ((Entity) this).getGame().getEntitiesVector(pos)) { if (!en.isAirborne()) { return "Ground units in the way"; } } hex = ((Entity) this).getGame().getBoard().getHex(pos); // if the hex is null, then we are offboard. Don't let units // land offboard. if (null == hex) { return "landing area not on the map"; } // landing must contain only acceptable terrain if (!hex.isClearForLanding()) { return "Unacceptable terrain for landing"; } return null; }
private void adjustPathForBridge(MovePath path) { boolean needsAdjust = false; for (Coords c : path.getCoordsSet()) { IHex hex = getGame().getBoard().getHex(c); if ((hex != null) && hex.containsTerrain(Terrains.BRIDGE)) { if (getGame().getBoard().getBuildingAt(c).getCurrentCF(c) >= path.getEntity().getWeight()) { needsAdjust = true; break; } else { needsAdjust = false; break; } } } if (!needsAdjust) { return; } MovePath adjusted = new MovePath(getGame(), path.getEntity()); adjusted.addStep(MoveStepType.CLIMB_MODE_ON); adjusted.addSteps(path.getStepVector(), true); adjusted.addStep(MoveStepType.CLIMB_MODE_OFF); path.replaceSteps(adjusted.getStepVector()); }
@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); }
@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); }