/** * Creates the sprite for this entity. Fortunately it is no longer an extra pain to create * transparent images in AWT. */ @Override public void prepare() { final IBoard board = bv.game.getBoard(); // recalculate bounds & label getBounds(); // create image for buffer GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); image = config.createCompatibleImage(bounds.width, bounds.height, Transparency.TRANSLUCENT); Graphics2D graph = (Graphics2D) image.getGraphics(); GUIPreferences.AntiAliasifSet(graph); // translate everything (=correction for label placement) graph.translate(-hexOrigin.x, -hexOrigin.y); if (!bv.useIsometric()) { // The entity sprite is drawn when the hexes are rendered. // So do not include the sprite info here. if (onlyDetectedBySensors()) { graph.drawImage(bv.getScaledImage(radarBlipImage, true), 0, 0, this); } else { // draw the unit icon translucent if: // hidden from the enemy (and activated graphics setting); or // submerged boolean translucentHiddenUnits = GUIPreferences.getInstance() .getBoolean(GUIPreferences.ADVANCED_TRANSLUCENT_HIDDEN_UNITS); boolean shouldBeTranslucent = (trackThisEntitiesVisibilityInfo(entity) && !entity.isVisibleToEnemy()) || entity.isHidden(); if ((shouldBeTranslucent && translucentHiddenUnits) || (entity.relHeight() < 0)) { graph.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); } graph.drawImage( bv.getScaledImage(bv.tileManager.imageFor(entity, secondaryPos), true), 0, 0, this); graph.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); } } // scale the following draws according to board zoom graph.scale(bv.scale, bv.scale); boolean isInfantry = (entity instanceof Infantry); boolean isAero = (entity instanceof Aero); if ((isAero && ((Aero) entity).isSpheroid() && !board.inSpace()) && (secondaryPos == 1)) { graph.setColor(Color.WHITE); graph.draw(bv.facingPolys[entity.getFacing()]); } if ((secondaryPos == -1) || (secondaryPos == 6)) { // Gather unit conditions ArrayList<Status> stStr = new ArrayList<Status>(); criticalStatus = false; // Determine if the entity has a locked turret, // and if it is a gun emplacement boolean turretLocked = false; int crewStunned = 0; boolean ge = false; if (entity instanceof Tank) { turretLocked = !((Tank) entity).hasNoTurret() && !entity.canChangeSecondaryFacing(); crewStunned = ((Tank) entity).getStunnedTurns(); ge = entity instanceof GunEmplacement; } // draw elevation/altitude if non-zero if (entity.isAirborne()) { if (!board.inSpace()) { stStr.add(new Status(Color.CYAN, "A", SMALL)); stStr.add(new Status(Color.CYAN, Integer.toString(entity.getAltitude()), SMALL)); } } else if (entity.getElevation() != 0) { stStr.add(new Status(Color.CYAN, Integer.toString(entity.getElevation()), SMALL)); } // Shutdown if (entity.isManualShutdown()) { stStr.add(new Status(Color.YELLOW, "SHUTDOWN")); } else if (entity.isShutDown()) { stStr.add(new Status(Color.RED, "SHUTDOWN")); } // Prone, Hulldown, Stuck, Immobile, Jammed if (entity.isProne()) stStr.add(new Status(Color.RED, "PRONE")); if (entity.isHiddenActivating()) stStr.add(new Status(Color.RED, "ACTIVATING")); if (entity.isHidden()) stStr.add(new Status(Color.RED, "HIDDEN")); if (entity.isHullDown()) stStr.add(new Status(Color.ORANGE, "HULLDOWN")); if ((entity.isStuck())) stStr.add(new Status(Color.ORANGE, "STUCK")); if (!ge && entity.isImmobile()) stStr.add(new Status(Color.RED, "IMMOBILE")); if (isAffectedByECM()) stStr.add(new Status(Color.YELLOW, "Jammed")); // Turret Lock if (turretLocked) stStr.add(new Status(Color.YELLOW, "LOCKED")); // Grappling & Swarming if (entity.getGrappled() != Entity.NONE) { if (entity.isGrappleAttacker()) { stStr.add(new Status(Color.YELLOW, "GRAPPLER")); } else { stStr.add(new Status(Color.RED, "GRAPPLED")); } } if (entity.getSwarmAttackerId() != Entity.NONE) { stStr.add(new Status(Color.RED, "SWARMED")); } // Transporting if ((entity.getLoadedUnits()).size() > 0) { stStr.add(new Status(Color.YELLOW, "T", SMALL)); } // Hidden, Unseen Unit if (trackThisEntitiesVisibilityInfo(entity)) { if (!entity.isEverSeenByEnemy()) { stStr.add(new Status(Color.GREEN, "U", SMALL)); } else if (!entity.isVisibleToEnemy()) { stStr.add(new Status(Color.GREEN, "H", SMALL)); } } // Crew if (entity.getCrew().isDead()) stStr.add(new Status(Color.RED, "CrewDead")); if (crewStunned > 0) { stStr.add(new Status(Color.YELLOW, "STUNNED", new Object[] {crewStunned})); } // Infantry if (isInfantry) { int dig = ((Infantry) entity).getDugIn(); if (dig == Infantry.DUG_IN_COMPLETE) { stStr.add(new Status(Color.PINK, "D", SMALL)); } else if (dig != Infantry.DUG_IN_NONE) { stStr.add(new Status(Color.YELLOW, "Working", DIRECT)); stStr.add(new Status(Color.PINK, "D", SMALL)); } else if (((Infantry) entity).isTakingCover()) { stStr.add(new Status(Color.YELLOW, "TakingCover")); } } // Aero if (isAero) { Aero a = (Aero) entity; if (a.isRolled()) stStr.add(new Status(Color.YELLOW, "ROLLED")); if (a.getFuel() <= 0) stStr.add(new Status(Color.RED, "FUEL")); if (a.isEvading()) stStr.add(new Status(Color.GREEN, "EVADE")); if (a.isOutControlTotal() & a.isRandomMove()) { stStr.add(new Status(Color.RED, "RANDOM")); } else if (a.isOutControlTotal()) { stStr.add(new Status(Color.RED, "CONTROL")); } } if (GUIPreferences.getInstance().getShowDamageLevel()) { Color damageColor = getDamageColor(); if (damageColor != null) { stStr.add(new Status(damageColor, 0, SMALL)); } } // Unit Label // no scaling for the label, its size is changed by varying // the font size directly => better control graph.scale(1 / bv.scale, 1 / bv.scale); // Label background if (criticalStatus) { graph.setColor(LABEL_CRITICAL_BACK); } else { graph.setColor(LABEL_BACK); } graph.fillRoundRect(labelRect.x, labelRect.y, labelRect.width, labelRect.height, 5, 10); // Label text graph.setFont(labelFont); Color textColor = LABEL_TEXT_COLOR; if (!entity.isDone() && !onlyDetectedBySensors()) { textColor = GUIPreferences.getInstance().getColor(GUIPreferences.ADVANCED_UNITOVERVIEW_VALID_COLOR); } if (isSelected) { textColor = GUIPreferences.getInstance() .getColor(GUIPreferences.ADVANCED_UNITOVERVIEW_SELECTED_COLOR); } bv.drawCenteredText( graph, getAdjShortName(), labelRect.x + labelRect.width / 2, labelRect.y + labelRect.height / 2 - 1, textColor, (entity.isDone() && !onlyDetectedBySensors())); // Past here, everything is drawing status that shouldn't be seen // on a sensor return, so we'll just quit here if (onlyDetectedBySensors()) { graph.dispose(); return; } // Draw all the status information now drawStatusStrings(graph, stStr); // from here, scale the following draws according to board zoom graph.scale(bv.scale, bv.scale); // draw facing graph.setColor(Color.white); if ((entity.getFacing() != -1) && !(isInfantry && !((Infantry) entity).hasFieldGun() && !((Infantry) entity).isTakingCover()) && !(isAero && ((Aero) entity).isSpheroid() && !board.inSpace())) { graph.draw(bv.facingPolys[entity.getFacing()]); } // determine secondary facing for non-mechs & flipped arms int secFacing = entity.getFacing(); if (!((entity instanceof Mech) || (entity instanceof Protomech))) { secFacing = entity.getSecondaryFacing(); } else if (entity.getArmsFlipped()) { secFacing = (entity.getFacing() + 3) % 6; } // draw red secondary facing arrow if necessary if ((secFacing != -1) && (secFacing != entity.getFacing())) { graph.setColor(Color.red); graph.draw(bv.facingPolys[secFacing]); } if ((entity instanceof Aero) && this.bv.game.useVectorMove()) { for (int head : entity.getHeading()) { graph.setColor(Color.red); graph.draw(bv.facingPolys[head]); } } // armor and internal status bars int baseBarLength = 23; int barLength = 0; double percentRemaining = 0.00; percentRemaining = entity.getArmorRemainingPercent(); barLength = (int) (baseBarLength * percentRemaining); graph.setColor(Color.darkGray); graph.fillRect(56, 7, 23, 3); graph.setColor(Color.lightGray); graph.fillRect(55, 6, 23, 3); graph.setColor(getStatusBarColor(percentRemaining)); graph.fillRect(55, 6, barLength, 3); if (!ge) { // Gun emplacements don't have internal structure percentRemaining = entity.getInternalRemainingPercent(); barLength = (int) (baseBarLength * percentRemaining); graph.setColor(Color.darkGray); graph.fillRect(56, 11, 23, 3); graph.setColor(Color.lightGray); graph.fillRect(55, 10, 23, 3); graph.setColor(getStatusBarColor(percentRemaining)); graph.fillRect(55, 10, barLength, 3); } } graph.dispose(); }
@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; }
/** Checks if a death from above attack can hit the target, including movement */ public static ToHitData toHit(IGame game, int attackerId, Targetable target, MovePath md) { final Entity ae = game.getEntity(attackerId); // Do to pretreatment of physical attacks, the target may be null. if (target == null) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is null"); } Entity te = null; if (target.getTargetType() == Targetable.TYPE_ENTITY) { te = (Entity) target; } Coords chargeSrc = ae.getPosition(); MoveStep chargeStep = null; // Infantry CAN'T dfa!!! if (ae instanceof Infantry) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Infantry can't D.F.A."); } if (ae.getJumpType() == Mech.JUMP_BOOSTER) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Can't D.F.A. using mechanical jump boosters."); } // let's just check this if (!md.contains(MoveStepType.DFA)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "D.F.A. action not found in movement path"); } // have to jump if (!md.contains(MoveStepType.START_JUMP)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "D.F.A. must involve jumping"); } // can't target airborne units if ((te != null) && te.isAirborne()) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Cannot D.F.A. an airborne target."); } // can't target dropships if ((te != null) && (te instanceof Dropship)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Cannot D.F.A. a dropship."); } // Can't target a transported entity. if ((te != null) && (Entity.NONE != te.getTransportId())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is a passenger."); } // no evading if (md.contains(MoveStepType.EVADE)) { return new ToHitData(TargetRoll.IMPOSSIBLE, "No evading while charging"); } // Can't target a entity conducting a swarm attack. if ((te != null) && (Entity.NONE != te.getSwarmTargetId())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is swarming a Mek."); } // determine last valid step md.compile(game, ae); for (final Enumeration<MoveStep> i = md.getSteps(); i.hasMoreElements(); ) { final MoveStep step = i.nextElement(); if (!step.isLegal()) { break; } if (step.getType() == MoveStepType.DFA) { chargeStep = step; } else { chargeSrc = step.getPosition(); } } // need to reach target if ((chargeStep == null) || !target.getPosition().equals(chargeStep.getPosition())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Could not reach target with movement"); } // target must have moved already, unless it's immobile if ((te != null) && (!te.isDone() && !te.isImmobile())) { return new ToHitData(TargetRoll.IMPOSSIBLE, "Target must be done with movement"); } return DfaAttackAction.toHit(game, attackerId, target, chargeSrc); }