@Override public StringBuffer getTooltip() { // Tooltip info for a sensor blip if (onlyDetectedBySensors()) return new StringBuffer(Messages.getString("BoardView1.sensorReturn")); // No sensor blip... Infantry thisInfantry = null; if (entity instanceof Infantry) thisInfantry = (Infantry) entity; GunEmplacement thisGunEmp = null; if (entity instanceof GunEmplacement) thisGunEmp = (GunEmplacement) entity; Aero thisAero = null; if (entity instanceof Aero) thisAero = (Aero) entity; tooltipString = new StringBuffer(); // Unit Chassis and Player addToTT( "Unit", NOBR, Integer.toHexString(PlayerColors.getColorRGB(entity.getOwner().getColorIndex())), entity.getChassis(), entity.getOwner().getName()); // Pilot Info // Nickname > Name > "Pilot" String pnameStr = "Pilot"; if ((entity.getCrew().getName() != null) && !entity.getCrew().getName().equals("")) pnameStr = entity.getCrew().getName(); if ((entity.getCrew().getNickname() != null) && !entity.getCrew().getNickname().equals("")) pnameStr = "'" + entity.getCrew().getNickname() + "'"; addToTT("Pilot", BR, pnameStr, entity.getCrew().getGunnery(), entity.getCrew().getPiloting()); // Pilot Status if (!entity.getCrew().getStatusDesc().equals("")) addToTT("PilotStatus", NOBR, entity.getCrew().getStatusDesc()); // Pilot Advantages int numAdv = entity.getCrew().countOptions(PilotOptions.LVL3_ADVANTAGES); if (numAdv == 1) addToTT("Adv1", NOBR, numAdv); else if (numAdv > 1) addToTT("Advs", NOBR, numAdv); // Pilot Manei Domini if ((entity.getCrew().countOptions(PilotOptions.MD_ADVANTAGES) > 0)) addToTT("MD", NOBR); // Unit movement ability if (thisGunEmp == null) { addToTT("Movement", BR, entity.getWalkMP(), entity.getRunMPasString()); if (entity.getJumpMP() > 0) tooltipString.append("/" + entity.getJumpMP()); } // Armor and Internals addToTT("ArmorInternals", BR, entity.getTotalArmor(), entity.getTotalInternal()); // Heat, not shown for units with 999 heat sinks (vehicles) if (entity.getHeatCapacity() != 999) { if (entity.heat == 0) addToTT("Heat0", BR); else addToTT("Heat", BR, entity.heat); } // Actual Movement if (thisGunEmp == null) { // In the Movement Phase, unit not done if (!entity.isDone() && this.bv.game.getPhase() == Phase.PHASE_MOVEMENT) { // "Has not yet moved" only during movement phase addToTT("NotYetMoved", BR); // In the Movement Phase, unit is done - or in the Firing Phase } else if ((entity.isDone() && this.bv.game.getPhase() == Phase.PHASE_MOVEMENT) || this.bv.game.getPhase() == Phase.PHASE_FIRING) { int tmm = Compute.getTargetMovementModifier(bv.game, entity.getId()).getValue(); // Unit didn't move if (entity.moved == EntityMovementType.MOVE_NONE) { addToTT("NoMove", BR, tmm); // Unit did move } else { // Colored arrow // get the color resource String guipName = "AdvancedMoveDefaultColor"; if ((entity.moved == EntityMovementType.MOVE_RUN) || (entity.moved == EntityMovementType.MOVE_VTOL_RUN) || (entity.moved == EntityMovementType.MOVE_OVER_THRUST)) guipName = "AdvancedMoveRunColor"; else if (entity.moved == EntityMovementType.MOVE_SPRINT) guipName = "AdvancedMoveSprintColor"; else if (entity.moved == EntityMovementType.MOVE_JUMP) guipName = "AdvancedMoveJumpColor"; // HTML color String from Preferences String moveTypeColor = Integer.toHexString( GUIPreferences.getInstance().getColor(guipName).getRGB() & 0xFFFFFF); // Arrow addToTT("Arrow", BR, moveTypeColor); // Actual movement and modifier addToTT( "MovementF", NOBR, entity.getMovementString(entity.moved), entity.delta_distance, tmm); } // Special Moves if (entity.isEvading()) addToTT("Evade", NOBR); if ((thisInfantry != null) && (thisInfantry.isTakingCover())) addToTT("TakingCover", NOBR); if (entity.isCharging()) addToTT("Charging", NOBR); if (entity.isMakingDfa()) addToTT("DFA", NOBR); } } // ASF Velocity if (thisAero != null) { addToTT("AeroVelocity", BR, thisAero.getCurrentVelocity()); } // Gun Emplacement Status if (thisGunEmp != null) { if (thisGunEmp.isTurret() && thisGunEmp.isTurretLocked(thisGunEmp.getLocTurret())) addToTT("TurretLocked", BR); } // Unit Immobile if ((thisGunEmp == null) && (entity.isImmobile())) addToTT("Immobile", BR); if (entity.isHiddenActivating()) { addToTT( "HiddenActivating", BR, IGame.Phase.getDisplayableName(entity.getHiddenActivationPhase())); } else if (entity.isHidden()) { addToTT("Hidden", BR); } // Jammed by ECM if (isAffectedByECM()) { addToTT("Jammed", BR); } // If DB, add information about who sees this Entity if (bv.game.getOptions().booleanOption("double_blind")) { StringBuffer playerList = new StringBuffer(); boolean teamVision = bv.game.getOptions().booleanOption("team_vision"); for (IPlayer player : entity.getWhoCanSee()) { if (player.isEnemyOf(entity.getOwner()) || !teamVision) { playerList.append(player.getName()); playerList.append(", "); } } if (playerList.length() > 1) { playerList.delete(playerList.length() - 2, playerList.length()); addToTT("SeenBy", BR, playerList.toString()); } } // If sensors, display what sensors this unit is using if (bv.game.getOptions().booleanOption("tacops_sensors")) { addToTT("Sensors", BR, entity.getSensorDesc()); } // Weapon List if (GUIPreferences.getInstance().getBoolean(GUIPreferences.SHOW_WPS_IN_TT)) { ArrayList<Mounted> weapons = entity.getWeaponList(); HashMap<String, Integer> wpNames = new HashMap<String, Integer>(); // Gather names, counts, Clan/IS // When clan then the number will be stored as negative for (Mounted curWp : weapons) { String weapDesc = curWp.getDesc(); // Append ranges WeaponType wtype = (WeaponType) curWp.getType(); int ranges[]; if (entity instanceof Aero) { ranges = wtype.getATRanges(); } else { ranges = wtype.getRanges(curWp); } String rangeString = "("; if ((ranges[RangeType.RANGE_MINIMUM] != WeaponType.WEAPON_NA) && (ranges[RangeType.RANGE_MINIMUM] != 0)) { rangeString += ranges[RangeType.RANGE_MINIMUM] + "/"; } else { rangeString += "-/"; } int maxRange = RangeType.RANGE_LONG; if (bv.game.getOptions().booleanOption(OptionsConstants.AC_TAC_OPS_RANGE)) { maxRange = RangeType.RANGE_EXTREME; } for (int i = RangeType.RANGE_SHORT; i <= maxRange; i++) { rangeString += ranges[i]; if (i != maxRange) { rangeString += "/"; } } weapDesc += rangeString + ")"; if (wpNames.containsKey(weapDesc)) { int number = wpNames.get(weapDesc); if (number > 0) wpNames.put(weapDesc, number + 1); else wpNames.put(weapDesc, number - 1); } else { WeaponType wpT = ((WeaponType) curWp.getType()); if (entity.isClan() && TechConstants.isClan(wpT.getTechLevel(entity.getYear()))) wpNames.put(weapDesc, -1); else wpNames.put(weapDesc, 1); } } // Print to Tooltip tooltipString.append("<FONT SIZE=\"-2\">"); for (Entry<String, Integer> entry : wpNames.entrySet()) { // Check if weapon is destroyed, text gray and strikethrough if so, remove the "x "/"*" // Also remove "+", means currently selected for firing boolean wpDest = false; String nameStr = entry.getKey(); if (entry.getKey().startsWith("x ")) { nameStr = entry.getKey().substring(2, entry.getKey().length()); wpDest = true; } if (entry.getKey().startsWith("*")) { nameStr = entry.getKey().substring(1, entry.getKey().length()); wpDest = true; } if (entry.getKey().startsWith("+")) { nameStr = entry.getKey().substring(1, entry.getKey().length()); nameStr = nameStr.concat(" <I>(Firing)</I>"); } // normal coloring tooltipString.append("<FONT COLOR=#8080FF>"); // but: color gray and strikethrough when weapon destroyed if (wpDest) tooltipString.append("<FONT COLOR=#a0a0a0><S>"); String clanStr = ""; if (entry.getValue() < 0) clanStr = Messages.getString("BoardView1.Tooltip.Clan"); // when more than 5 weapons are present, they will be grouped // and listed with a multiplier if (weapons.size() > 5) { addToTT("WeaponN", BR, Math.abs(entry.getValue()), clanStr, nameStr); } else { // few weapons: list each weapon separately for (int i = 0; i < Math.abs(entry.getValue()); i++) { addToTT("Weapon", BR, Math.abs(entry.getValue()), clanStr, nameStr); } } // Weapon destroyed? End strikethrough if (wpDest) tooltipString.append("</S>"); tooltipString.append("</FONT>"); } tooltipString.append("</FONT>"); } return tooltipString; }
/** To-hit number for a death from above attack, assuming that movement has been handled */ public static ToHitData toHit(IGame game, int attackerId, Targetable target, Coords src) { final Entity ae = game.getEntity(attackerId); // arguments legal? if (ae == null) { throw new IllegalArgumentException("Attacker is null"); } // Do to pretreatment of physical attacks, the target may be null. if (target == null) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is null"); } int targetId = Entity.NONE; Entity te = null; if (target.getTargetType() == Targetable.TYPE_ENTITY) { te = (Entity) target; targetId = target.getTargetId(); } else { return new ToHitData(TargetRoll.IMPOSSIBLE, "Invalid Target"); } if (!game.getOptions().booleanOption("friendly_fire")) { // a friendly unit can never be the target of a direct attack. if ((target.getTargetType() == Targetable.TYPE_ENTITY) && ((((Entity) target).getOwnerId() == ae.getOwnerId()) || ((((Entity) target).getOwner().getTeam() != IPlayer.TEAM_NONE) && (ae.getOwner().getTeam() != IPlayer.TEAM_NONE) && (ae.getOwner().getTeam() == ((Entity) target).getOwner().getTeam())))) { return new ToHitData( TargetRoll.IMPOSSIBLE, "A friendly unit can never be the target of a direct attack."); } } final boolean targetInBuilding = Compute.isInBuilding(game, te); ToHitData toHit = null; final int attackerElevation = ae.getElevation() + game.getBoard().getHex(ae.getPosition()).getLevel(); final int targetElevation = target.getElevation() + game.getBoard().getHex(target.getPosition()).getLevel(); final int attackerHeight = attackerElevation + ae.getHeight(); // check elevation of target flying VTOL if (target.isAirborneVTOLorWIGE()) { if ((targetElevation - attackerHeight) > ae.getJumpMP()) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Elevation difference to high"); } } // can't target yourself if (ae.equals(te)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "You can't target yourself"); } // Infantry CAN'T dfa!!! if (ae instanceof Infantry) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Infantry can't dfa"); } // Can't target a transported entity. if ((Entity.NONE != te.getTransportId())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is a passenger."); } // Can't target a entity conducting a swarm attack. if ((Entity.NONE != te.getSwarmTargetId())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is swarming a Mek."); } // check range if (src.distance(target.getPosition()) > 1) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target not in range"); } // can't dfa while prone, even if you somehow did manage to jump if (ae.isProne()) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Attacker is prone"); } // can't attack mech making a different displacement attack if (te.hasDisplacementAttack()) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is already making a charge/DFA attack"); } // can't attack the target of another displacement attack if (te.isTargetOfDisplacementAttack() && (te.findTargetedDisplacement().getEntityId() != ae.getId())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is the target of another charge/DFA"); } // Can't target units in buildings (from the outside). if (targetInBuilding) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is inside building"); } // Attacks against adjacent buildings automatically hit. if ((target.getTargetType() == Targetable.TYPE_BUILDING) || (target.getTargetType() == Targetable.TYPE_FUEL_TANK) || (target instanceof GunEmplacement)) { return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS, "Targeting adjacent building."); } // Can't target woods or ignite a building with a physical. if ((target.getTargetType() == Targetable.TYPE_BLDG_IGNITE) || (target.getTargetType() == Targetable.TYPE_HEX_CLEAR) || (target.getTargetType() == Targetable.TYPE_HEX_IGNITE)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Invalid attack"); } // Set the base BTH int base = ae.getCrew().getPiloting(); toHit = new ToHitData(base, "base"); // BMR(r), page 33. +3 modifier for DFA on infantry. if (te instanceof Infantry) { toHit.addModifier(3, "Infantry target"); } // Battle Armor targets are hard for Meks and Tanks to hit. if (te instanceof BattleArmor) { toHit.addModifier(1, "battle armor target"); } if ((ae instanceof Mech) && ((Mech) ae).isSuperHeavy()) { toHit.addModifier(1, "attacker is superheavy mech"); } // attacker movement toHit.append( Compute.getAttackerMovementModifier(game, attackerId, EntityMovementType.MOVE_JUMP)); // target movement toHit.append(Compute.getTargetMovementModifier(game, targetId)); // piloting skill differential if ((ae.getCrew().getPiloting() != te.getCrew().getPiloting())) { toHit.addModifier( ae.getCrew().getPiloting() - te.getCrew().getPiloting(), "piloting skill differential"); } // attacker is spotting if (ae.isSpotting()) { toHit.addModifier(+1, "attacker is spotting"); } // target prone if (te.isProne()) { toHit.addModifier(-2, "target prone and adjacent"); } // If it has a torso-mounted cockpit and two head sensor hits or three // sensor hits... // It gets a =4 penalty for being blind! if ((ae instanceof Mech) && (((Mech) ae).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED)) { int sensorHits = ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_HEAD); int sensorHits2 = ae.getBadCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, Mech.LOC_CT); if ((sensorHits + sensorHits2) == 3) { return new ToHitData( TargetRoll.IMPOSSIBLE, "Sensors Completely Destroyed for Torso-Mounted Cockpit"); } else if (sensorHits == 2) { toHit.addModifier(4, "Head Sensors Destroyed for Torso-Mounted Cockpit"); } } // target immobile toHit.append(Compute.getImmobileMod(te)); toHit.append(AbstractAttackAction.nightModifiers(game, target, null, ae, false)); Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game); // evading bonuses ( if (te.isEvading()) { toHit.addModifier(te.getEvasionBonus(), "target is evading"); } if (te instanceof Tank) { toHit.setSideTable(ToHitData.SIDE_FRONT); toHit.setHitTable(ToHitData.HIT_NORMAL); } else if (te.isProne()) { toHit.setSideTable(ToHitData.SIDE_REAR); toHit.setHitTable(ToHitData.HIT_NORMAL); } else { toHit.setSideTable(te.sideTable(src)); toHit.setHitTable(ToHitData.HIT_PUNCH); } // Attacking Weight Class Modifier. if (game.getOptions().booleanOption(OptionsConstants.AGM_TAC_OPS_PHYSICAL_ATTACK_PSR)) { if (ae.getWeightClass() == EntityWeightClass.WEIGHT_LIGHT) { toHit.addModifier(-2, "Weight Class Attack Modifier"); } else if (ae.getWeightClass() == EntityWeightClass.WEIGHT_MEDIUM) { toHit.addModifier(-1, "Weight Class Attack Modifier"); } } if ((ae instanceof Mech) && ((Mech) ae).hasIndustrialTSM()) { toHit.addModifier(2, "industrial TSM"); } // done! return toHit; }