コード例 #1
0
ファイル: TestTank.java プロジェクト: rhubarbselleven/megamek
  public boolean correctCriticals(StringBuffer buff) {
    Vector<Mounted> unallocated = new Vector<Mounted>();
    boolean correct = true;

    for (Mounted mount : tank.getMisc()) {
      if (mount.getLocation() == Entity.LOC_NONE && !(mount.getType().getCriticals(tank) == 0)) {
        unallocated.add(mount);
      }
    }
    for (Mounted mount : tank.getWeaponList()) {
      if (mount.getLocation() == Entity.LOC_NONE) {
        unallocated.add(mount);
      }
    }
    for (Mounted mount : tank.getAmmo()) {
      int ammoType = ((AmmoType) mount.getType()).getAmmoType();
      if ((mount.getLocation() == Entity.LOC_NONE)
          && (mount.getUsableShotsLeft() > 1 || ammoType == AmmoType.T_CRUISE_MISSILE)) {
        unallocated.add(mount);
      }
    }

    if (!unallocated.isEmpty()) {
      buff.append("Unallocated Equipment:\n");
      for (Mounted mount : unallocated) {
        buff.append(mount.getType().getInternalName()).append("\n");
      }
      correct = false;
    }

    return correct;
  }
コード例 #2
0
ファイル: TestTank.java プロジェクト: rhubarbselleven/megamek
  public float getTankWeightTurret() {
    float weight = 0f;

    // For omni vees, the base chassis sets a turret weight
    if (tank.isOmni() && tank.getBaseChassisTurretWeight() >= 0) {
      weight = tank.getBaseChassisTurretWeight();
    } else {
      // For non-omnis, count up the weight of eq in the turret
      for (Mounted m : tank.getEquipment()) {
        if ((m.getLocation() == tank.getLocTurret()) && !(m.getType() instanceof AmmoType)) {
          weight += m.getType().getTonnage(tank);
        }
      }
      // Turrets weight 10% of the weight of weapons in them
      weight = weight / 10.0f;
    }

    if (tank.isSupportVehicle()) {
      if (getEntity().getWeight() < 5) {
        return TestEntity.ceil(weight, CEIL_KILO);
      } else {
        return TestEntity.ceil(weight, CEIL_HALFTON);
      }
    } else {
      return TestEntity.ceilMaxHalf(weight, getWeightCeilingTurret());
    }
  }
コード例 #3
0
 @Override
 public String checkFixable() {
   if (null == unit) {
     return null;
   }
   if (isSalvaging()) {
     // check for armor
     if (unit.getEntity().getArmorForReal(loc, false) > 0
         || (unit.getEntity().hasRearArmor(loc)
             && unit.getEntity().getArmorForReal(loc, true) > 0)) {
       return "must salvage armor in this location first";
     }
     // you can only salvage a location that has nothing left on it
     int systemRepairable = 0;
     for (int i = 0; i < unit.getEntity().getNumberOfCriticals(loc); i++) {
       CriticalSlot slot = unit.getEntity().getCritical(loc, i);
       // ignore empty & non-hittable slots
       if ((slot == null) || !slot.isEverHittable()) {
         continue;
       }
       // we don't care about the final critical hit to the system
       // in locations because that just represents the location destruction
       if (slot.getType() == CriticalSlot.TYPE_SYSTEM) {
         if (slot.isRepairable()) {
           if (systemRepairable > 0) {
             return "Repairable parts in "
                 + unit.getEntity().getLocationName(loc)
                 + " must be salvaged or scrapped first.";
           } else {
             systemRepairable++;
           }
         }
       } else if (slot.isRepairable()) {
         return "Repairable parts in "
             + unit.getEntity().getLocationName(loc)
             + " must be salvaged or scrapped first.";
       }
     }
     // protomechs only have system stuff in the crits, so we need to also
     // check for mounted equipment separately
     for (Mounted m : unit.getEntity().getEquipment()) {
       if (m.isRepairable() && (m.getLocation() == loc || m.getSecondLocation() == loc)) {
         return "Repairable parts in "
             + unit.getEntity().getLocationName(loc)
             + " must be salvaged or scrapped first."
             + m.getName();
       }
     }
   }
   return null;
 }
コード例 #4
0
 @Override
 public void remove(boolean salvage) {
   blownOff = false;
   if (null != unit) {
     unit.getEntity().setInternal(IArmorState.ARMOR_DESTROYED, loc);
     unit.getEntity().setLocationBlownOff(loc, false);
     Part spare = campaign.checkForExistingSparePart(this);
     if (!salvage) {
       campaign.removePart(this);
     } else if (null != spare) {
       spare.incrementQuantity();
       campaign.removePart(this);
     }
     unit.removePart(this);
     if (loc != Protomech.LOC_TORSO) {
       Part missing = getMissingPart();
       unit.addPart(missing);
       campaign.addPart(missing, 0);
     }
     // According to StratOps, this always destroys all equipment in that location as well
     for (int i = 0; i < unit.getEntity().getNumberOfCriticals(loc); i++) {
       final CriticalSlot cs = unit.getEntity().getCritical(loc, i);
       if (null == cs || !cs.isEverHittable()) {
         continue;
       }
       cs.setHit(true);
       cs.setDestroyed(true);
       cs.setRepairable(false);
       Mounted m = cs.getMount();
       if (null != m) {
         m.setHit(true);
         m.setDestroyed(true);
         m.setRepairable(false);
       }
     }
     for (Mounted m : unit.getEntity().getEquipment()) {
       if (m.getLocation() == loc || m.getSecondLocation() == loc) {
         m.setHit(true);
         m.setDestroyed(true);
         m.setRepairable(false);
       }
     }
   }
   setUnit(null);
   updateConditionFromEntity(false);
 }
コード例 #5
0
ファイル: TestTank.java プロジェクト: rhubarbselleven/megamek
  @Override
  public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
    boolean correct = true;
    if (skip()) {
      return true;
    }
    if (!correctWeight(buff)) {
      buff.insert(0, printTechLevel() + printShortMovement());
      buff.append(printWeightCalculation()).append("\n");
      correct = false;
    }
    if (!engine.engineValid) {
      buff.append(engine.problem.toString()).append("\n\n");
      correct = false;
    }
    if (tank.hasWorkingMisc(MiscType.F_ARMORED_MOTIVE_SYSTEM)
        && !((tank.getMovementMode() == EntityMovementMode.WHEELED)
            || (tank.getMovementMode() == EntityMovementMode.TRACKED)
            || (tank.getMovementMode() == EntityMovementMode.HOVER)
            || (tank.getMovementMode() == EntityMovementMode.HYDROFOIL)
            || (tank.getMovementMode() == EntityMovementMode.NAVAL)
            || (tank.getMovementMode() == EntityMovementMode.SUBMARINE)
            || (tank.getMovementMode() == EntityMovementMode.WIGE))) {
      buff.append("Armored Motive system and incompatible movemement mode!\n\n");
      correct = false;
    }
    if (tank.getFreeSlots() < 0) {
      buff.append("Not enough item slots available! Using ");
      buff.append(Math.abs(tank.getFreeSlots()));
      buff.append(" slot(s) too many.\n\n");
      correct = false;
    }
    int armorLimit = (int) (((tank.getWeight() * 7) / 2) + 40);
    if (tank.getTotalOArmor() > armorLimit) {
      buff.append("Armor exceeds point limit for ");
      buff.append(tank.getWeight());
      buff.append("-ton vehicle: ");
      buff.append(tank.getTotalOArmor());
      buff.append(" points > ");
      buff.append(armorLimit);
      buff.append(".\n\n");
      correct = false;
    }
    if (tank instanceof VTOL) {
      if (!tank.hasWorkingMisc(MiscType.F_MAST_MOUNT)) {
        for (Mounted m : tank.getEquipment()) {
          if (m.getLocation() == VTOL.LOC_ROTOR) {
            buff.append("rotor equipment must be placed in mast mount");
            correct = false;
          }
        }
      }
      if (tank.getOArmor(VTOL.LOC_ROTOR) > VTOL_MAX_ROTOR_ARMOR) {
        buff.append(tank.getOArmor(VTOL.LOC_ROTOR));
        buff.append(
            " points of VTOL rotor armor exceed " + VTOL_MAX_ROTOR_ARMOR + "-point limit.\n\n");
        correct = false;
      }
    }
    for (Mounted m : tank.getMisc()) {
      if (m.getType().hasFlag(MiscType.F_COMBAT_VEHICLE_ESCAPE_POD)) {
        if (m.getLocation()
            != (tank instanceof SuperHeavyTank ? SuperHeavyTank.LOC_REAR : Tank.LOC_REAR)) {
          buff.append("combat vehicle escape pod must be placed in rear");
          correct = false;
        }
      }
    }
    for (int loc = 0; loc < tank.locations(); loc++) {
      int count = 0;
      for (Mounted misc : tank.getMisc()) {
        if ((misc.getLocation() == loc) && misc.getType().hasFlag(MiscType.F_MANIPULATOR)) {
          count++;
        }
      }
      if (count > 2) {
        buff.append("max of 2 manipulators per location");
        correct = false;
        break;
      }
    }

    if (showFailedEquip() && hasFailedEquipment(buff)) {
      correct = false;
    }
    if (hasIllegalTechLevels(buff, ammoTechLvl)) {
      correct = false;
    }
    if (hasIllegalEquipmentCombinations(buff)) {
      correct = false;
    }
    // only tanks with fusion engine can be vacuum protected
    if (!(tank.getEngine().isFusion()
            || (tank.getEngine().getEngineType() == Engine.FUEL_CELL)
            || (tank.getEngine().getEngineType() == Engine.SOLAR)
            || (tank.getEngine().getEngineType() == Engine.BATTERY)
            || (tank.getEngine().getEngineType() == Engine.FISSION)
            || (tank.getEngine().getEngineType() == Engine.NONE))
        && !tank.doomedInVacuum()) {
      buff.append("Vacuum protection requires fusion engine.\n");
      correct = false;
    }

    if (!correctCriticals(buff)) {
      correct = false;
    }
    return correct;
  }