예제 #1
0
  public int rollPilotingSkill() {
    if (getOptions().booleanOption(OptionsConstants.PILOT_APTITUDE_PILOTING)) {
      return Compute.d6(3, 2);
    }

    return Compute.d6(2);
  }
예제 #2
0
  public int rollGunnerySkill() {
    if (getOptions().booleanOption(OptionsConstants.PILOT_APTITUDE_GUNNERY)) {
      return Compute.d6(3, 2);
    }

    return Compute.d6(2);
  }
예제 #3
0
 /**
  * Get the side being targeted. If the targeted side is determined randomly, the calculation
  * occurs each time the side is requested.
  *
  * @return an <code>int</code> that represents the side being targeted; the value will be one of
  *     SIDE_FRONT, SIDE_REAR, SIDE_LEFT, or SIDE_RIGHT, and *never* SIDE_RANDOM.
  */
 public int getSideTable() {
   int side = sideTable;
   if (side == SIDE_RANDOM) {
     side = Compute.randomInt(4);
   }
   return side;
 }
예제 #4
0
  @Override
  public int sideTable(Coords src, boolean usePrior, int face) {
    Coords effectivePos = getPosition();
    if (usePrior) {
      effectivePos = getPriorPosition();
    }
    if (src.equals(effectivePos)) {
      // most places handle 0 range explicitly,
      // this is a safe default (calculation gives SIDE_RIGHT)
      return ToHitData.SIDE_FRONT;
    }
    // calculate firing angle
    int fa = (effectivePos.degree(src) + ((6 - face) * 60)) % 360;

    int leftBetter = 2;
    // if we're right on the line, we need to special case this
    // defender would choose along which hex the LOS gets drawn, and that
    // side also determines the side we hit in
    if ((fa % 30) == 0) {
      IHex srcHex = game.getBoard().getHex(src);
      IHex curHex = game.getBoard().getHex(getPosition());
      if ((srcHex != null) && (curHex != null)) {
        LosEffects.AttackInfo ai =
            LosEffects.buildAttackInfo(
                src, getPosition(), 1, getElevation(), srcHex.floor(), curHex.floor());
        ArrayList<Coords> in = Coords.intervening(ai.attackPos, ai.targetPos, true);
        leftBetter =
            LosEffects.dividedLeftBetter(
                in, game, ai, Compute.isInBuilding(game, this), new LosEffects());
      }
    }

    if ((fa == 330) && (leftBetter == 0)) {
      return ToHitData.SIDE_FRONTLEFT;
    } else if ((fa == 270) && (leftBetter == 0)) {
      return ToHitData.SIDE_REARLEFT;
    } else if ((fa == 210) && (leftBetter == 0)) {
      return ToHitData.SIDE_REAR;
    } else if ((fa == 150) && (leftBetter == 0)) {
      return ToHitData.SIDE_REARRIGHT;
    } else if ((fa == 90) && (leftBetter == 1)) {
      return ToHitData.SIDE_REARRIGHT;
    } else if ((fa == 30) && (leftBetter == 1)) {
      return ToHitData.SIDE_FRONTRIGHT;
    } else if ((fa > 30) && (fa <= 90)) {
      return ToHitData.SIDE_FRONTRIGHT;
    } else if ((fa > 90) && (fa < 150)) {
      return ToHitData.SIDE_REARRIGHT;
    } else if ((fa >= 150) && (fa < 210)) {
      return ToHitData.SIDE_REAR;
    } else if ((fa >= 210) && (fa < 270)) {
      return ToHitData.SIDE_REARLEFT;
    } else if ((fa >= 270) && (fa < 330)) {
      return ToHitData.SIDE_FRONTLEFT;
    } else {
      return ToHitData.SIDE_FRONT;
    }
  }
예제 #5
0
  public void drawPlot() throws ScriptException {

    double x1, y1, x2, y2;

    String functionName = getFunctionName();

    for (int i = -width; i < width; i++) {

      x1 = i / zoom;
      x2 = (i + 1) / zoom;

      y1 = compute.getFunctionValue(x1, functionName);
      y2 = compute.getFunctionValue(x2, functionName);

      g2.draw(new Line2D.Double((x1 * zoom), (-y1 * zoom), (x2 * zoom), (-y2 * zoom)));
    }
  }
 @Test
 public final void testToString() {
   assertTrue("Didn't get string", compute.toString() instanceof java.lang.String);
 }
 @Test
 public void testTemplate() {
   assertEquals("template", compute.template());
 }
 @Test
 public void testState() {
   assertEquals("state", compute.state());
 }
 @Test
 public void testMemory() {
   assertEquals(Integer.MAX_VALUE, compute.memory());
 }
예제 #10
0
 @Test
 public void testCpu() {
   // Delta=1?
   assertEquals((float) 0.0, compute.cpu(), 1);
 }
예제 #11
0
 @Test
 public void testCores() {
   assertEquals(Integer.MAX_VALUE, compute.cores());
 }
예제 #12
0
 @Test
 public void testArch() {
   assertEquals("arch", compute.arch());
 }
예제 #13
0
 /*
 @Test
 public void testAssignItem() {
 	//Fails and that's good
 	assertFalse(compute.assign(null));
 	Compute compute2 = new Compute();
 	assertTrue(compute.assign(compute2));
 }
 */
 @Test
 public void testToJSON() {
   JSONObject jsonObject = new JSONObject();
   assertFalse(jsonObject.toString().equals(compute.toJSON()));
 }
예제 #14
0
  /** Rolls up a hit location */
  @Override
  public HitData rollHitLocation(
      int table, int side, int aimedLocation, int aimingMode, int cover) {
    int nArmorLoc = LOC_FRONT;
    boolean bSide = false;
    boolean bRearSide = false;
    boolean bRear = false;
    int motiveMod = getMotiveSideMod(side);
    if ((side == ToHitData.SIDE_FRONT) && isHullDown() && !m_bHasNoTurret) {
      // on a hull down vee, all front hits go to turret if one exists.
      nArmorLoc = LOC_TURRET;
    }
    if (side == ToHitData.SIDE_FRONTLEFT) {
      nArmorLoc = LOC_FRONTLEFT;
      bSide = true;
    } else if (side == ToHitData.SIDE_FRONTRIGHT) {
      nArmorLoc = LOC_FRONTRIGHT;
      bSide = true;
    } else if (side == ToHitData.SIDE_REARRIGHT) {
      nArmorLoc = LOC_REARRIGHT;
      bRearSide = true;
    } else if (side == ToHitData.SIDE_REARLEFT) {
      nArmorLoc = LOC_REARLEFT;
      bRearSide = true;
    } else if (side == ToHitData.SIDE_REAR) {
      nArmorLoc = LOC_REAR;
      bRear = true;
    }
    HitData rv = new HitData(nArmorLoc);
    boolean bHitAimed = false;
    if ((aimedLocation != LOC_NONE) && (aimingMode != IAimingModes.AIM_MODE_NONE)) {

      int roll = Compute.d6(2);

      if ((5 < roll) && (roll < 9)) {
        rv = new HitData(aimedLocation, side == ToHitData.SIDE_REAR, true);
        bHitAimed = true;
      }
    }
    if (!bHitAimed) {
      switch (Compute.d6(2)) {
        case 2:
          rv.setEffect(HitData.EFFECT_CRITICAL);
          break;
        case 3:
          if (bSide) {
            rv = new HitData(LOC_FRONT, false, HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
          } else if (bRear) {
            rv = new HitData(LOC_REARLEFT, false, HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
          } else if (bRearSide) {
            rv.setEffect(HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
          } else {
            rv = new HitData(LOC_FRONTRIGHT, false, HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
          }
          rv.setMotiveMod(motiveMod);
          break;
        case 4:
          rv.setEffect(HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
          rv.setMotiveMod(motiveMod);
          break;
        case 5:
          if (bRear || !(bSide || bRearSide)) {
            rv.setEffect(HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
            rv.setMotiveMod(motiveMod);
          }
          break;
        case 6:
        case 7:
          break;
        case 8:
          if ((bSide || bRearSide)
              && !game.getOptions().booleanOption("tacops_vehicle_effective")) {
            rv.setEffect(HitData.EFFECT_CRITICAL);
          }
          break;
        case 9:
          if (!game.getOptions().booleanOption("tacops_vehicle_effective")) {
            rv.setEffect(HitData.EFFECT_VEHICLE_MOVE_DAMAGED);
            rv.setMotiveMod(motiveMod);
          }
          break;
        case 10:
          if (!m_bHasNoTurret) {
            rv = new HitData(LOC_TURRET);
          }
          break;
        case 11:
          if (!m_bHasNoTurret) {
            rv = new HitData(LOC_TURRET);
          }
          break;
        case 12:
          if (m_bHasNoTurret) {
            rv.setEffect(HitData.EFFECT_CRITICAL);
          } else {
            rv = new HitData(LOC_TURRET, false, HitData.EFFECT_CRITICAL);
          }
      }
    }
    if (table == ToHitData.HIT_SWARM) {
      rv.setEffect(rv.getEffect() | HitData.EFFECT_CRITICAL);
    }
    return rv;
  }
예제 #15
0
  /** 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;
  }
예제 #16
0
 /**
  * The name of the compute type for the bundle.
  *
  * @param name The name of the compute type for the bundle.
  * @see Compute
  */
 public void setName(Compute name) {
   this.name = name.toString();
 }