Class AmmoType

java.lang.Object
megamek.common.equipment.EquipmentType
megamek.common.equipment.AmmoType
All Implemented Interfaces:
ITechnology
Direct Known Subclasses:
BombType, SmallWeaponAmmoType

public class AmmoType extends EquipmentType
  • Field Details

  • Constructor Details

    • AmmoType

      public AmmoType()
  • Method Details

    • getMutatorName

      public String getMutatorName()
      Get the name of the mutator of this ammo type. If this is the "standard" ammo type for the weapon, returns null.
      Returns:
      A string like "Inferno", or null
    • getMunitionsFor

      public static Vector<AmmoType> getMunitionsFor(AmmoType.AmmoTypeEnum ammoType)
    • getBaseAmmo

      public AmmoType getBaseAmmo()
      Returns the base ammo type, if any.
    • equalsAmmoTypeOnly

      public boolean equalsAmmoTypeOnly(Object other)
      When comparing AmmoTypes, look at the ammoType only.
      Parameters:
      other - the Object to compare to this one.
      Returns:
      true if the other is an AmmoType object of the same ammoType as this object. N.B. different munition types are still equal.
    • isCompatibleWith

      public boolean isCompatibleWith(AmmoType other)
      Gets a value indicating whether this AmmoType is compatible with another AmmoType.

      this roughly means the same ammo type and munition type, but not rack size.

      Parameters:
      other - The other AmmoType to determine compatibility with.
    • getAmmoType

      public AmmoType.AmmoTypeEnum getAmmoType()
    • getToHitModifier

      public int getToHitModifier()
    • hasFlag

      public boolean hasFlag(EquipmentFlag flag)
      Description copied from class: EquipmentType
      Returns true when this EquipmentType has the given flag. NOTE: Even though EquipmentFlags are enums, checking e.g. a WeaponType if it has a MiscTypeFlag may return an incorrect true result, as the actual test is made using EquipmentBitSet, i.e. a number comparison.

      Example: EquipmentType.get("BAArmoredGlove").hasFlag(WeaponType.F_VGL) returns true, as WeaponType.F_VGL has the same ordinal as MiscType.F_ARMORED_GLOVE. Therefore, always make sure to test only MiscTypes against MiscTypeFlags, WeaponTypes against WeaponTypeFlags and AmmoTypes against AmmoTypeFlags. This method will log a warning if the rule is not followed.

      Overrides:
      hasFlag in class EquipmentType
      Parameters:
      flag - The EquipmentFlag to check
      Returns:
      True when this EquipmentType has the given flag
      See Also:
    • getFireTN

      public int getFireTN()
      Analog to WeaponType.getFireTNRoll(), but based on munitions. See TO:AR pg 42
      Returns:
      TN Roll
    • is

      public boolean is(AmmoType.AmmoTypeEnum ammoType)
      Gets a value indicating whether this is a certain ammo type.
      Parameters:
      ammoType - The ammo type to compare against.
    • canBeInterceptedBy

      @Deprecated(since="0.51.0", forRemoval=true) public boolean canBeInterceptedBy(@Nullable WeaponMounted amsWeapon, @Nullable GameOptions gameOptions)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Checks if this ammo can be intercepted by AMS (or PD). TODO: rules need to be checked
      Parameters:
      amsWeapon - The AMS weapon to check against, if null an AMS is assumed to be available.
      gameOptions - The game options, used to check for special rules. If null, standard rules are assumed.
      Returns:
      true if this ammo is affected by AMS, false otherwise
    • countsAsFlak

      public boolean countsAsFlak()
      We need a way to quickly determine if a given ammo type / munition counts as "Flak"

      Note, not _is_ Flak (as in the case of M_FLAK) but can be considered Flak by TW/TO/IO rules.

      Arrow IV missiles with M_CLUSTER, M_ADA, or M_STANDARD (not M_HOMING) count as Flak (TO:AU&E pp166-167, 224)

      Returns:
      counts true if this ammo can be considered Flak in some situations
    • getMunitionType

      public EnumSet<AmmoType.Munitions> getMunitionType()
    • notAllowedByClanRules

      @Deprecated(since="0.50.06") public boolean notAllowedByClanRules()
      Deprecated.
      since 0.50.06, the rules that don't allow some ammo for clan units should be based on tech access/availability, not a hardcoded list of ammo types. As soon as the tech rules for munition variations are working completely then this will be removed.
      Returns:
      true if this munition type is not allowed by clan rules
    • getDamagePerShot

      public int getDamagePerShot()
    • getRackSize

      public int getRackSize()
    • getShots

      public int getShots()
    • getAmmoRatio

      public double getAmmoRatio()
    • isCapital

      public boolean isCapital()
    • hasCustomKgPerShot

      public boolean hasCustomKgPerShot()
    • getKgPerShot

      public double getKgPerShot()
      Used by units that are constructed using per-shot weights (BA and ProtoMeks). Some ammo is defined in the rules rounded to a set number of decimal places.
      Returns:
      KG per Shot
    • canAeroUse

      public boolean canAeroUse()
      Aerospace units cannot use specialty munitions except Artemis and LBX cluster (but not standard). ATM ER and HE rounds are considered standard munitions. AR10 missiles are designed for aerospace units and all munition types are available.
      Returns:
      true if the munition can be used by aerospace units
    • canAeroUse

      public boolean canAeroUse(boolean option)
      Aerospace units cannot use specialty munitions except Artemis and LBX cluster (but not standard). ATM ER and HE rounds are considered standard munitions. AR10 missiles are designed for aerospace units and all munition types are available.
      Parameters:
      option - True if unofficial game option allowing alternate munitions for artillery bays is enabled
      Returns:
      true if the munition can be used by aerospace units
    • getOneshotAmmo

      @Nullable public static AmmoType getOneshotAmmo(Mounted<?> mounted)
      Parameters:
      mounted - Mounted Weapon/Item
      Returns:
      the first usable ammo type for the given one shot launcher
    • initializeTypes

      public static void initializeTypes()
    • toString

      public String toString()
      Overrides:
      toString in class EquipmentType
    • canClearMinefield

      public static boolean canClearMinefield(AmmoType at)
    • canDeliverMinefield

      public static boolean canDeliverMinefield(AmmoType at)
    • getKgPerShotBV

      public double getKgPerShotBV(int shots)
      Returns:
      The battle value for ProtoMek or BA ammo loads.
    • getBaseName

      public String getBaseName()
    • getSubMunitionName

      public String getSubMunitionName()
    • isAmmoValid

      public static boolean isAmmoValid(Mounted<?> ammo, WeaponType weaponType)
      Checks to ensure that the given ammo can be used with the given weapon type. Performs the following tests:
      ammo != null
      Mounted.getType() instanceof AmmoType
      Mounted.isAmmoUsable()
      isAmmoValid(AmmoType, WeaponType).
      Parameters:
      ammo - The ammunition to be tested.
      weaponType - The weapon the ammo is to be used with.
      Returns:
      TRUE if the ammo and weapon are compatible.
    • isAmmoValid

      public static boolean isAmmoValid(AmmoType ammoType, WeaponType weaponType)
      Checks to ensure that the given ammunition type is compatible with the given weapon type. Performs the following tests:
      ammoType != null
      getAmmoType() == WeaponType.getAmmoType()
      getRackSize() == WeaponType.getRackSize()
      Parameters:
      ammoType - The type of ammo to be tested.
      weaponType - The type of weapon the ammo is to be used with.
      Returns:
      TRUE if the ammo type and weapon type are compatible.
    • canSwitchToAmmo

      public static boolean canSwitchToAmmo(WeaponMounted weapon, AmmoType otherAmmo)
      Whether the given weapon can switch to the given ammo type
      Parameters:
      weapon - The weapon being considered
      otherAmmo - The other ammo type being considered
      Returns:
      true/false - null arguments or linked ammo bin for the weapon result in false
    • isEligibleForBeingArmored

      public boolean isEligibleForBeingArmored()
      Overrides:
      isEligibleForBeingArmored in class EquipmentType
      Returns:
      True if this equipment type is eligible for being an armored component, TO:AUE p.95
    • getYamlTypeName

      protected String getYamlTypeName()
      Description copied from class: EquipmentType
      Returns the YAML type name for this equipment type. Subclasses should override this to return their specific type name.
      Overrides:
      getYamlTypeName in class EquipmentType
      Returns:
      The YAML type name (e.g., "weapon", "ammo", "misc", "armor")
    • addFlags

      protected void addFlags(Map<String,Object> data)
      Description copied from class: EquipmentType
      Adds equipment flags to the YAML data map. Subclasses should override this to add type-specific flags.
      Overrides:
      addFlags in class EquipmentType
      Parameters:
      data - The YAML data map to add flags to
    • getYamlData

      public Map<String,Object> getYamlData()
      Description copied from class: EquipmentType
      Constructs a map containing the YAML-serializable data for this equipment type. Subclasses should override this method to add type-specific data.
      Overrides:
      getYamlData in class EquipmentType
      Returns:
      A map containing the YAML-serializable data for this equipment type.