@Override
  public int getBVMod(Entity unit) {
    if (CampaignMain.cm.getBooleanConfig("USEFLATGUNNERYLASERMODIFIER")) {
      CampaignData.mwlog.debugLog("Using Flat GL Mod");
      return getBVModFlat(unit);
    }
    double laserBV = 0;
    double gunneryLaserBVBaseMod =
        megamek.common.Crew.getBVSkillMultiplier(
            unit.getCrew().getGunnery() - 1, unit.getCrew().getPiloting());
    double originalLaserBV = 0;
    for (Mounted weapon : unit.getWeaponList()) {
      if (weapon.getType().hasFlag(WeaponType.F_ENERGY)) {
        laserBV += weapon.getType().getBV(unit);
        originalLaserBV += weapon.getType().getBV(unit);
      }
    }
    // This is adding the base BV of the weapon twice - once originally, and once here.
    // Need to back out the original cost so that it only gets added once.
    CampaignData.mwlog.debugLog("Laser BV: " + laserBV);
    CampaignData.mwlog.debugLog("Original Laser BV: " + originalLaserBV);
    CampaignData.mwlog.debugLog(
        "Mod: " + (int) ((laserBV * gunneryLaserBVBaseMod) - originalLaserBV));

    return (int) ((laserBV * gunneryLaserBVBaseMod) - originalLaserBV);
  }
Exemple #2
0
 @Override
 public void updateConditionFromEntity(boolean checkForDestruction) {
   int priorHits = hits;
   if (null != unit) {
     Entity entity = unit.getEntity();
     for (int i = 0; i < entity.locations(); i++) {
       if (entity.getNumberOfCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT, i) > 0) {
         // check for missing equipment as well
         if (!unit.isSystemMissing(Mech.SYSTEM_COCKPIT, i)) {
           hits = entity.getDamagedCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT, i);
           break;
         } else {
           remove(false);
           return;
         }
       }
     }
     if (checkForDestruction
         && hits > priorHits
         && Compute.d6(2) < campaign.getCampaignOptions().getDestroyPartTarget()) {
       remove(false);
       return;
     }
   }
 }
Exemple #3
0
  @Override
  public Rectangle getBounds() {
    // Start with the hex and add the label
    bounds = new Rectangle(0, 0, bv.hex_size.width, bv.hex_size.height);
    updateLabel();
    bounds.add(labelRect);
    // Add space for 4 little status boxes
    if (labelPos == Positioning.RIGHT) {
      bounds.add(-4 * (labelRect.height + 2) + labelRect.x, labelRect.y);
    } else {
      bounds.add(4 * (labelRect.height + 2) + labelRect.x + labelRect.width, labelRect.y);
    }

    // Move to board position, save this origin for correct drawing
    hexOrigin = bounds.getLocation();
    Point ePos;
    if (secondaryPos == -1) {
      ePos = bv.getHexLocation(entity.getPosition());
    } else {
      ePos = bv.getHexLocation(entity.getSecondaryPositions().get(secondaryPos));
    }
    bounds.setLocation(hexOrigin.x + ePos.x, hexOrigin.y + ePos.y);

    entityRect =
        new Rectangle(
            bounds.x + (int) (20 * bv.scale),
            bounds.y + (int) (14 * bv.scale),
            (int) (44 * bv.scale),
            (int) (44 * bv.scale));

    return bounds;
  }
Exemple #4
0
 /**
  * We only want to show double-blind visibility indicators on our own mechs and teammates mechs
  * (assuming team vision option).
  */
 private boolean trackThisEntitiesVisibilityInfo(Entity e) {
   IPlayer localPlayer = bv.getLocalPlayer();
   if (localPlayer == null) {
     return false;
   }
   if (bv.game.getOptions().booleanOption("double_blind") // $NON-NLS-1$
       && ((e.getOwner().getId() == localPlayer.getId())
           || (bv.game.getOptions().booleanOption("team_vision") // $NON-NLS-1$
               && (e.getOwner().getTeam() == localPlayer.getTeam())))) {
     return true;
   }
   return false;
 }
Exemple #5
0
 public String getPlayerColor() {
   if (onlyDetectedBySensors()) {
     return "C0C0C0";
   } else {
     return Integer.toHexString(PlayerColors.getColorRGB(entity.getOwner().getColorIndex()));
   }
 }
Exemple #6
0
  /**
   * Used to determine if this EntitySprite is only detected by an enemies sensors and hence should
   * only be a sensor return.
   *
   * @return
   */
  private boolean onlyDetectedBySensors() {
    boolean sensors = bv.game.getOptions().booleanOption("tacops_sensors");
    boolean sensorsDetectAll = bv.game.getOptions().booleanOption("sensors_detect_all");
    boolean doubleBlind = bv.game.getOptions().booleanOption("double_blind");
    boolean hasVisual = entity.hasSeenEntity(bv.getLocalPlayer());
    boolean hasDetected = entity.hasDetectedEntity(bv.getLocalPlayer());

    if (sensors
        && doubleBlind
        && !sensorsDetectAll
        && !trackThisEntitiesVisibilityInfo(entity)
        && hasDetected
        && !hasVisual) {
      return true;
    } else {
      return false;
    }
  }
 @Override
 protected int calcnClusterAero(Entity entityTarget) {
   if (usesClusterTable()
       && !ae.isCapitalFighter()
       && (entityTarget != null)
       && !entityTarget.isCapitalScale()) {
     return (int) Math.ceil(attackValue / 2.0);
   } else {
     return 1;
   }
 }
  public int getBVModFlat(Entity unit) {
    int numberOfLasers = 0;
    int gunneryLaserBVBaseMod = CampaignMain.cm.getIntegerConfig("GunneryLaserBaseBVMod");

    for (Mounted weapon : unit.getWeaponList()) {
      if (weapon.getType().hasFlag(WeaponType.F_ENERGY)) {
        numberOfLasers++;
      }
    }
    return numberOfLasers * gunneryLaserBVBaseMod;
  }
  public ToHitData toHit(IGame game, Targetable target) {
    final Entity ae = getEntity(game);

    // arguments legal?
    if (ae == null) {
      throw new IllegalStateException("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");
    }

    if (!game.getOptions().booleanOption(OptionsConstants.BASE_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.");
    }

    // set the to-hit
    ToHitData toHit = new ToHitData(2, "base");

    TeleMissile tm = (TeleMissile) ae;

    // thrust used
    if (ae.mpUsed > 0) toHit.addModifier(ae.mpUsed, "thrust used");

    // out of fuel
    if (tm.getFuel() <= 0) toHit.addModifier(+6, "out of fuel");

    // modifiers for the originating unit need to be added later, because
    // they may change as a result of damage

    // done!
    return toHit;
  }
Exemple #10
0
  /** Damage that a mech does with a successful DFA. */
  public static int getDamageFor(Entity entity, boolean targetInfantry) {
    int toReturn = (int) Math.ceil((entity.getWeight() / 10.0) * 3.0);

    if (DfaAttackAction.hasTalons(entity)) {
      toReturn *= 1.5;
    }

    if (targetInfantry) {
      toReturn = Math.max(1, toReturn / 10);
    }
    return toReturn;
  }
Exemple #11
0
  private void updateLabel() {
    int face = (entity.isCommander() && !onlyDetectedBySensors()) ? Font.ITALIC : Font.PLAIN;
    labelFont = new Font("SansSerif", face, (int) (10 * Math.max(bv.scale, 0.9))); // $NON-NLS-1$

    // Check the hexes in directions 2,5,1,4 if they are free of entities
    // and place the label in the direction of the first free hex
    // if none are free, the label will be centered in the current hex
    labelRect =
        new Rectangle(
            bv.getFontMetrics(labelFont).stringWidth(getAdjShortName()) + 4,
            bv.getFontMetrics(labelFont).getAscent() + 2);

    Coords position = entity.getPosition();
    if (bv.game.getEntitiesVector(position.translated("SE"), true).isEmpty()) {
      labelRect.setLocation((int) (bv.hex_size.width * 0.55), (int) (0.75 * bv.hex_size.height));
      labelPos = Positioning.RIGHT;
    } else if (bv.game.getEntitiesVector(position.translated("NW"), true).isEmpty()) {
      labelRect.setLocation(
          (int) (bv.hex_size.width * 0.45) - labelRect.width,
          (int) (0.25 * bv.hex_size.height) - labelRect.height);
      labelPos = Positioning.LEFT;
    } else if (bv.game.getEntitiesVector(position.translated("NE"), true).isEmpty()) {
      labelRect.setLocation(
          (int) (bv.hex_size.width * 0.55), (int) (0.25 * bv.hex_size.height) - labelRect.height);
      labelPos = Positioning.RIGHT;
    } else if (bv.game.getEntitiesVector(position.translated("SW"), true).isEmpty()) {
      labelRect.setLocation(
          (int) (bv.hex_size.width * 0.45) - labelRect.width, (int) (0.75 * bv.hex_size.height));
      labelPos = Positioning.LEFT;
    } else {
      labelRect.setLocation(
          bv.hex_size.width / 2 - labelRect.width / 2, (int) (0.75 * bv.hex_size.height));
      labelPos = Positioning.RIGHT;
    }

    // If multiple units are present in a hex, fan out the labels
    labelRect.y +=
        (bv.getFontMetrics(labelFont).getAscent() + 4)
            * bv.game.getEntitiesVector(position).indexOf(entity);
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * megamek.common.weapons.WeaponHandler#handleEntityDamage(megamek.common
  * .Entity, java.util.Vector, megamek.common.Building, int, int, int, int)
  */
 @Override
 protected void handleEntityDamage(
     Entity entityTarget,
     Vector<Report> vPhaseReport,
     Building bldg,
     int hits,
     int nCluster,
     int bldgAbsorbs) {
   super.handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs);
   if (!missed && ((entityTarget instanceof Mech) || (entityTarget instanceof Aero))) {
     Report r = new Report(3400);
     r.subject = subjectId;
     r.indent(2);
     int extraHeat = 0;
     // if this is a fighter squadron, we need to account for number of
     // weapons
     // should default to one for non squadrons
     for (int i = 0; i < nweaponsHit; i++) {
       extraHeat += Compute.d6();
     }
     if (entityTarget.getArmor(hit) > 0
         && (entityTarget.getArmorType(hit.getLocation()) == EquipmentType.T_ARMOR_REFLECTIVE)) {
       entityTarget.heatFromExternal += Math.max(1, extraHeat / 2);
       r.add(Math.max(1, extraHeat / 2));
       r.choose(true);
       r.messageId = 3406;
       r.add(extraHeat);
       r.add(EquipmentType.armorNames[entityTarget.getArmorType(hit.getLocation())]);
     } else if (entityTarget.getArmor(hit) > 0
         && (entityTarget.getArmorType(hit.getLocation())
             == EquipmentType.T_ARMOR_HEAT_DISSIPATING)) {
       entityTarget.heatFromExternal += extraHeat / 2;
       r.add(extraHeat / 2);
       r.choose(true);
       r.messageId = 3406;
       r.add(extraHeat);
       r.add(EquipmentType.armorNames[entityTarget.getArmorType(hit.getLocation())]);
     } else {
       entityTarget.heatFromExternal += extraHeat;
       r.add(extraHeat);
       r.choose(true);
     }
     vPhaseReport.addElement(r);
   }
 }
Exemple #13
0
 private Color getDamageColor() {
   switch (entity.getDamageLevel()) {
     case Entity.DMG_CRIPPLED:
       return Color.black;
     case Entity.DMG_HEAVY:
       return Color.red;
     case Entity.DMG_MODERATE:
       return Color.yellow;
     case Entity.DMG_LIGHT:
       return Color.green;
   }
   return null;
 }
Exemple #14
0
 private String getAdjShortName() {
   if (onlyDetectedBySensors()) {
     return Messages.getString("BoardView1.sensorReturn"); // $NON-NLS-1$
   } else {
     String name = entity.getShortName();
     int firstApo = name.indexOf('\'');
     int secondApo = name.indexOf('\'', name.indexOf('\'') + 1);
     if ((firstApo >= 0) && (secondApo >= 0)) {
       name = name.substring(firstApo + 1, secondApo).toUpperCase();
     }
     return name;
   }
 }
 private boolean isSameEquipment(Object equipment, Object newEquipment) {
   if (newEquipment instanceof Part && equipment instanceof Part) {
     if (((Part) equipment).isSamePartType((Part) newEquipment)) {
       return true;
     }
   }
   if (newEquipment instanceof Entity && equipment instanceof Entity) {
     Entity entityA = (Entity) newEquipment;
     Entity entityB = (Entity) equipment;
     if (entityA.getChassis().equals(entityB.getChassis())
         && entityA.getModel().equals(entityB.getModel())) {
       return true;
     }
   }
   return false;
 }
  @Test
  public void testInitDamage() {
    Princess mockPrincess = Mockito.mock(Princess.class);

    FireControl mockFireControl = Mockito.mock(FireControl.class);
    Mockito.when(mockPrincess.getFireControl()).thenReturn(mockFireControl);

    ToHitData mockToHit = Mockito.mock(ToHitData.class);
    Mockito.when(
            mockFireControl.guessToHitModifierPhysical(
                Mockito.any(Entity.class),
                Mockito.any(EntityState.class),
                Mockito.any(Targetable.class),
                Mockito.any(EntityState.class),
                Mockito.any(PhysicalAttackType.class),
                Mockito.any(IGame.class)))
        .thenReturn(mockToHit);
    Mockito.when(mockToHit.getValue()).thenReturn(7);

    Entity mockShooter = Mockito.mock(BipedMech.class);
    Mockito.when(mockShooter.getId()).thenReturn(1);
    Mockito.when(mockShooter.getWeight()).thenReturn(50.0);

    EntityState mockShooterState = Mockito.mock(EntityState.class);

    Mech mockTarget = Mockito.mock(BipedMech.class);
    Mockito.when(mockTarget.isLocationBad(Mockito.anyInt())).thenReturn(false);
    Mockito.when(mockTarget.getArmor(Mockito.anyInt(), Mockito.eq(false))).thenReturn(10);
    Mockito.when(mockTarget.getArmor(Mockito.anyInt(), Mockito.eq(true))).thenReturn(5);
    Mockito.when(mockTarget.getInternal(Mockito.anyInt())).thenReturn(6);

    EntityState mockTargetState = Mockito.mock(EntityState.class);

    IGame mockGame = Mockito.mock(IGame.class);

    PhysicalInfo testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess));
    testPhysicalInfo.setShooter(mockShooter);
    testPhysicalInfo.setTarget(mockTarget);
    Mockito.doNothing()
        .when(testPhysicalInfo)
        .setDamageDirection(Mockito.any(EntityState.class), Mockito.any(Coords.class));
    Mockito.doReturn(1).when(testPhysicalInfo).getDamageDirection();

    PhysicalAttackType punch = PhysicalAttackType.LEFT_PUNCH;
    PhysicalAttackType kick = PhysicalAttackType.LEFT_KICK;

    PunchAttackAction punchAction = Mockito.mock(PunchAttackAction.class);
    Mockito.doReturn(punchAction)
        .when(testPhysicalInfo)
        .buildAction(Mockito.eq(punch), Mockito.anyInt(), Mockito.any(Targetable.class));
    Mockito.when(punchAction.toHit(Mockito.any(IGame.class))).thenReturn(mockToHit);

    KickAttackAction kickAction = Mockito.mock(KickAttackAction.class);
    Mockito.doReturn(kickAction)
        .when(testPhysicalInfo)
        .buildAction(Mockito.eq(kick), Mockito.anyInt(), Mockito.any(Targetable.class));
    Mockito.when(kickAction.toHit(Mockito.any(IGame.class))).thenReturn(mockToHit);

    // Test a vanilla punch.
    testPhysicalInfo.setShooter(mockShooter);
    testPhysicalInfo.setAttackType(punch);
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(5.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0099, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(5.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Test a vanilla kick.
    testPhysicalInfo.setShooter(mockShooter);
    testPhysicalInfo.setAttackType(kick);
    testPhysicalInfo.initDamage(kick, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0099, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Make the puncher heavier.
    Mockito.when(mockShooter.getWeight()).thenReturn(100.0);
    testPhysicalInfo.setShooter(mockShooter);
    testPhysicalInfo.setAttackType(punch);
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0099, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Give the target less armor and internals
    Mockito.when(mockTarget.isLocationBad(Mockito.anyInt())).thenReturn(false);
    Mockito.when(mockTarget.getArmor(Mockito.anyInt(), Mockito.eq(false))).thenReturn(6);
    Mockito.when(mockTarget.getArmor(Mockito.anyInt(), Mockito.eq(true))).thenReturn(3);
    Mockito.when(mockTarget.getInternal(Mockito.anyInt())).thenReturn(3);
    Mockito.when(mockShooter.getWeight()).thenReturn(100.0);
    testPhysicalInfo.setShooter(mockShooter);
    testPhysicalInfo.setAttackType(punch);
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.5929, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.1943, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(10.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Test a non-biped trying to punch.
    testPhysicalInfo.setShooter(Mockito.mock(QuadMech.class));
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.0, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Test not being able to hit.
    Mockito.when(mockToHit.getValue()).thenReturn(13);
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.0, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);

    // Test a non-mech.
    testPhysicalInfo.setShooter(Mockito.mock(Tank.class));
    testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame);
    Assert.assertEquals(0.0, testPhysicalInfo.getProbabilityToHit(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedCriticals(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE);
    Assert.assertEquals(0.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE);
  }
Exemple #17
0
  /** 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;
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector,
  * megamek.common.Entity, boolean)
  */
 @Override
 protected boolean specialResolution(Vector<Report> vPhaseReport, Entity entityTarget) {
   boolean done = false;
   if (bMissed) {
     return done;
   }
   Report r = new Report(3700);
   int taserRoll = Compute.d6(2);
   r.add(taserRoll);
   r.newlines = 0;
   vPhaseReport.add(r);
   if (entityTarget.getWeight() > 100) {
     return done;
   }
   if (entityTarget instanceof BattleArmor) {
     r = new Report(3706);
     r.addDesc(entityTarget);
     // shut down for rest of scenario, so we actually kill it
     // TODO: fix for salvage purposes
     r.add(entityTarget.getLocationAbbr(hit));
     vPhaseReport.add(r);
     entityTarget.destroyLocation(hit.getLocation());
     // Check to see if the squad has been eliminated
     if (entityTarget.getTransferLocation(hit).getLocation() == Entity.LOC_DESTROYED) {
       vPhaseReport.addAll(server.destroyEntity(entityTarget, "all troopers eliminated", false));
     }
     done = true;
   } else if (entityTarget instanceof Mech) {
     if (((Mech) entityTarget).isIndustrial()) {
       if (taserRoll >= 8) {
         r = new Report(3705);
         r.addDesc(entityTarget);
         r.add(4);
         entityTarget.taserShutdown(4, false);
       } else {
         // suffer +2 to piloting and gunnery for 4 rounds
         r = new Report(3710);
         r.addDesc(entityTarget);
         r.add(2);
         r.add(4);
         entityTarget.setTaserInterference(2, 4, true);
       }
     } else {
       if (taserRoll >= 11) {
         r = new Report(3705);
         r.addDesc(entityTarget);
         r.add(3);
         vPhaseReport.add(r);
         entityTarget.taserShutdown(3, false);
       } else {
         r = new Report(3710);
         r.addDesc(entityTarget);
         r.add(2);
         r.add(3);
         vPhaseReport.add(r);
         entityTarget.setTaserInterference(2, 3, true);
       }
     }
   } else if ((entityTarget instanceof Protomech)
       || (entityTarget instanceof Tank)
       || (entityTarget instanceof Aero)) {
     if (taserRoll >= 8) {
       r = new Report(3705);
       r.addDesc(entityTarget);
       r.add(4);
       vPhaseReport.add(r);
       entityTarget.taserShutdown(4, false);
     } else {
       r = new Report(3710);
       r.addDesc(entityTarget);
       r.add(2);
       r.add(4);
       vPhaseReport.add(r);
       entityTarget.setTaserInterference(2, 4, false);
     }
   }
   return done;
 }
Exemple #19
0
  @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;
  }
Exemple #20
0
  public static boolean hasTalons(Entity entity) {

    if (entity instanceof Mech) {

      if (entity instanceof BipedMech) {

        return (entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_RLEG)
                && entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_RLEG))
            || (entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_LLEG)
                && entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_LLEG));
      }
      return (entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_RLEG)
              && entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_RLEG))
          || (entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_LLEG)
              && entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_LLEG))
          || ((entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_RARM))
              && (entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_RARM)
                  || (entity.hasWorkingMisc(MiscType.F_TALON, -1, Mech.LOC_LARM)
                      && entity.hasWorkingSystem(Mech.ACTUATOR_FOOT, Mech.LOC_LARM))));
    }

    return false;
  }
Exemple #21
0
 /** Damage done to a mech after a successful DFA. */
 public static int getDamageTakenBy(Entity entity) {
   return (int) Math.ceil(entity.getWeight() / 5.0);
 }
Exemple #22
0
 public Coords getPosition() {
   return entity.getPosition();
 }
Exemple #23
0
  /** 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);
  }
 public TeleMissileAttackAction(Entity attacker, Targetable target) {
   super(attacker.getId(), target.getTargetType(), target.getTargetId());
 }
Exemple #25
0
  /**
   * 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();
  }
  /** To-hit number for the mech to push another mech */
  public static ToHitData toHit(IGame game, int attackerId, Targetable target) {
    final Entity ae = game.getEntity(attackerId);
    int targetId = Entity.NONE;
    Entity te = null;
    if (target.getTargetType() == Targetable.TYPE_ENTITY) {
      te = (Entity) target;
      targetId = target.getTargetId();
    }
    if (ae == null)
      return new ToHitData(ToHitData.IMPOSSIBLE, "You can't attack from a null entity!");
    if (te == null) return new ToHitData(ToHitData.IMPOSSIBLE, "You can't target a null entity!");
    IHex attHex = game.getBoard().getHex(ae.getPosition());
    IHex targHex = game.getBoard().getHex(te.getPosition());
    final int attackerElevation = ae.getElevation() + attHex.getElevation();
    final int targetElevation = target.getElevation() + targHex.getElevation();
    final boolean targetInBuilding = Compute.isInBuilding(game, te);
    Building bldg = null;
    if (targetInBuilding) {
      bldg = game.getBoard().getBuildingAt(te.getPosition());
    }
    ToHitData toHit = null;

    // arguments legal?
    if (ae == null || target == null) {
      throw new IllegalArgumentException("Attacker or target not valid");
    }

    // can't target yourself
    if (ae.equals(te)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "You can't target yourself");
    }

    // non-mechs can't push
    if (!(ae instanceof Mech)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Non-mechs can't push");
    }

    // Quads can't push
    if (ae.entityIsQuad()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is a quad");
    }

    // can't make physical attacks while spotting
    if (ae.isSpotting()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is spotting this turn");
    }

    // Can only push mechs
    if (te != null && !(te instanceof Mech)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is not a mech");
    }

    // Can't push with flipped arms
    if (ae.getArmsFlipped()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Arms are flipped to the rear. Can not push.");
    }

    // Can't target a transported entity.
    if (te != null && Entity.NONE != te.getTransportId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is a passenger.");
    }

    // Can't target a entity conducting a swarm attack.
    if (te != null && Entity.NONE != te.getSwarmTargetId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is swarming a Mek.");
    }

    // check if both arms are present
    if (ae.isLocationBad(Mech.LOC_RARM) || ae.isLocationBad(Mech.LOC_LARM)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing");
    }

    // check if attacker has fired arm-mounted weapons
    if (ae.weaponFiredFrom(Mech.LOC_RARM) || ae.weaponFiredFrom(Mech.LOC_LARM)) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Weapons fired from arm this turn");
    }

    // check range
    if (ae.getPosition().distance(target.getPosition()) > 1) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not in range");
    }

    // target must be at same elevation
    if (attackerElevation != targetElevation) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not at same elevation");
    }

    // can't push mech making non-pushing displacement attack
    if (te != null && te.hasDisplacementAttack() && !te.isPushing()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is making a charge/DFA attack");
    }

    // can't push mech pushing another, different mech
    if (te != null && te.isPushing() && te.getDisplacementAttack().getTargetId() != ae.getId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is pushing another mech");
    }

    // can't do anything but counter-push if the target of another attack
    if (ae.isTargetOfDisplacementAttack()
        && ae.findTargetedDisplacement().getEntityId() != target.getTargetId()) {
      return new ToHitData(
          ToHitData.IMPOSSIBLE, "Attacker is the target of another push/charge/DFA");
    }

    // can't attack the target of another displacement attack
    if (te != null
        && te.isTargetOfDisplacementAttack()
        && te.findTargetedDisplacement().getEntityId() != ae.getId()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is the target of another push/charge/DFA");
    }

    // check facing
    if (!target.getPosition().equals(ae.getPosition().translated(ae.getFacing()))) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target not directly ahead of feet");
    }

    // can't push while prone
    if (ae.isProne()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone");
    }

    // can't push prone mechs
    if (te != null && te.isProne()) {
      return new ToHitData(ToHitData.IMPOSSIBLE, "Target is prone");
    }

    // Can't target units in buildings (from the outside).
    if (targetInBuilding) {
      if (!Compute.isInBuilding(game, ae)) {
        return new ToHitData(ToHitData.IMPOSSIBLE, "Target is inside building");
      } else if (!game.getBoard().getBuildingAt(ae.getPosition()).equals(bldg)) {
        return new ToHitData(ToHitData.IMPOSSIBLE, "Target is inside differnt building");
      }
    }

    // Attacks against adjacent buildings automatically hit.
    if ((target.getTargetType() == Targetable.TYPE_BUILDING)
        || (target.getTargetType() == Targetable.TYPE_FUEL_TANK)) {
      return new ToHitData(
          ToHitData.IMPOSSIBLE,
          "You can not push a building (well, you can, but it won't do anything).");
    }

    // 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(ToHitData.IMPOSSIBLE, "Invalid attack");
    }

    // Set the base BTH
    int base = 4;

    if (game.getOptions().booleanOption("maxtech_physical_BTH")) {
      base = ae.getCrew().getPiloting() - 1;
    }

    toHit = new ToHitData(base, "base");

    // attacker movement
    toHit.append(Compute.getAttackerMovementModifier(game, attackerId));

    // target movement
    toHit.append(Compute.getTargetMovementModifier(game, targetId));

    // attacker terrain
    toHit.append(Compute.getAttackerTerrainModifier(game, attackerId));

    // target terrain
    toHit.append(Compute.getTargetTerrainModifier(game, te));

    // damaged or missing actuators
    if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_RARM)) {
      toHit.addModifier(2, "Right Shoulder destroyed");
    }
    if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_LARM)) {
      toHit.addModifier(2, "Left Shoulder destroyed");
    }

    // water partial cover?
    if (te.height() > 0
        && te.getElevation() == -1
        && targHex.terrainLevel(Terrains.WATER) == te.height()) {
      toHit.addModifier(3, "target has partial cover");
    }

    // target immobile
    toHit.append(Compute.getImmobileMod(te));

    Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game);

    toHit.append(nightModifiers(game, target, null, ae));
    // side and elevation shouldn't matter

    // 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 (((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(
            ToHitData.IMPOSSIBLE, "Sensors Completely Destroyed for Torso-Mounted Cockpit");
      } else if (sensorHits == 2) {
        toHit.addModifier(4, "Head Sensors Destroyed for Torso-Mounted Cockpit");
      }
    }

    // done!
    return toHit;
  }
Exemple #27
0
 public ToHitData toHit(IGame game) {
   final Entity entity = game.getEntity(getEntityId());
   return DfaAttackAction.toHit(
       game, getEntityId(), game.getTarget(getTargetType(), getTargetId()), entity.getPosition());
 }
  /**
   * handle this weapons firing
   *
   * @return a <code>boolean</code> value indicating wether this should be kept or not
   */
  @Override
  public boolean handle(IGame.Phase phase, Vector<Report> vPhaseReport) {
    if (!this.cares(phase)) {
      return true;
    }

    // Report weapon attack and its to-hit value.
    Report r = new Report(3115);
    r.indent();
    r.newlines = 0;
    r.subject = subjectId;
    r.add(wtype.getName());
    r.messageId = 3120;
    r.add(target.getDisplayName(), true);
    vPhaseReport.addElement(r);
    if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
      r = new Report(3135);
      r.subject = subjectId;
      r.add(toHit.getDesc());
      vPhaseReport.addElement(r);
      return false;
    } else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
      r = new Report(3140);
      r.newlines = 0;
      r.subject = subjectId;
      r.add(toHit.getDesc());
      vPhaseReport.addElement(r);
    } else if (toHit.getValue() == TargetRoll.AUTOMATIC_SUCCESS) {
      r = new Report(3145);
      r.newlines = 0;
      r.subject = subjectId;
      r.add(toHit.getDesc());
      vPhaseReport.addElement(r);
    }

    addHeat();

    // deliver screen
    Coords coords = target.getPosition();
    server.deliverScreen(coords, vPhaseReport);

    // damage any entities in the hex
    for (Entity entity : game.getEntitiesVector(coords)) {
      // if fighter squadron all fighters are damaged
      if (entity instanceof FighterSquadron) {
        for (Entity fighter : ((FighterSquadron) entity).getFighters()) {
          ToHitData squadronToHit = new ToHitData();
          squadronToHit.setHitTable(ToHitData.HIT_NORMAL);
          HitData hit = fighter.rollHitLocation(squadronToHit.getHitTable(), ToHitData.SIDE_FRONT);
          hit.setCapital(false);
          vPhaseReport.addAll(server.damageEntity(fighter, hit, attackValue));
          server.creditKill(fighter, ae);
        }
      } else {
        ToHitData hexToHit = new ToHitData();
        hexToHit.setHitTable(ToHitData.HIT_NORMAL);
        HitData hit = entity.rollHitLocation(hexToHit.getHitTable(), ToHitData.SIDE_FRONT);
        hit.setCapital(false);
        vPhaseReport.addAll(server.damageEntity(entity, hit, attackValue));
        server.creditKill(entity, ae);
      }
    }
    return false;
  }
  /** updates fields for the unit */
  public void setEntity(Entity en) {

    if (en instanceof Infantry) {
      pilotL.setString(Messages.getString("PilotMapSet.pilotLAntiMech"));
    } else {
      pilotL.setString(Messages.getString("PilotMapSet.pilotL"));
    }
    nameL.setString(en.getCrew().getName());
    nickL.setString(en.getCrew().getNickname());
    pilotR.setString(Integer.toString(en.getCrew().getPiloting()));
    gunneryR.setString(Integer.toString(en.getCrew().getGunnery()));

    if (null != getPortrait(en.getCrew())) {
      portraitArea.setIdleImage(getPortrait(en.getCrew()));
    }

    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("rpg_gunnery")) {
      gunneryLR.setString(Integer.toString(en.getCrew().getGunneryL()));
      gunneryMR.setString(Integer.toString(en.getCrew().getGunneryM()));
      gunneryBR.setString(Integer.toString(en.getCrew().getGunneryB()));
      gunneryL.setVisible(false);
      gunneryR.setVisible(false);
      gunneryLL.setVisible(true);
      gunneryLR.setVisible(true);
      gunneryML.setVisible(true);
      gunneryMR.setVisible(true);
      gunneryBL.setVisible(true);
      gunneryBR.setVisible(true);
    } else {
      gunneryLL.setVisible(false);
      gunneryLR.setVisible(false);
      gunneryML.setVisible(false);
      gunneryMR.setVisible(false);
      gunneryBL.setVisible(false);
      gunneryBR.setVisible(false);
      gunneryL.setVisible(true);
      gunneryR.setVisible(true);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("toughness")) {
      toughBR.setString(Integer.toString(en.getCrew().getToughness()));
    } else {
      toughBL.setVisible(false);
      toughBR.setVisible(false);
    }
    if ((en.getGame() != null)
        && en.getGame().getOptions().booleanOption("individual_initiative")) {
      initBR.setString(Integer.toString(en.getCrew().getInitBonus()));
    } else {
      initBL.setVisible(false);
      initBR.setVisible(false);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("command_init")) {
      commandBR.setString(Integer.toString(en.getCrew().getCommandBonus()));
    } else {
      commandBL.setVisible(false);
      commandBR.setVisible(false);
    }
    hitsR.setString(en.getCrew().getStatusDesc());
    for (int i = 0; i < advantagesR.length; i++) {
      advantagesR[i].setString(""); // $NON-NLS-1$
    }
    int i = 0;
    for (Enumeration<IOptionGroup> advGroups = en.getCrew().getOptions().getGroups();
        advGroups.hasMoreElements(); ) {
      if (i >= (N_ADV - 1)) {
        advantagesR[i++].setString(Messages.getString("PilotMapSet.more"));
        break;
      }
      IOptionGroup advGroup = advGroups.nextElement();
      if (en.getCrew().countOptions(advGroup.getKey()) > 0) {
        advantagesR[i++].setString(advGroup.getDisplayableName());
        for (Enumeration<IOption> advs = advGroup.getOptions(); advs.hasMoreElements(); ) {
          if (i >= (N_ADV - 1)) {
            advantagesR[i++].setString("  " + Messages.getString("PilotMapSet.more"));
            break;
          }
          IOption adv = advs.nextElement();
          if (adv.booleanValue()) {
            advantagesR[i++].setString("  " + adv.getDisplayableNameWithValue());
          }
        }
      }
    }
  }