Class ASDamage

java.lang.Object
megamek.common.alphaStrike.ASDamage
All Implemented Interfaces:
Serializable

public class ASDamage extends Object implements Serializable
Represents a single AlphaStrike damage value that may be minimal damage (0*). Minimal Damage is represented by isMinimal() returning true, all other values by getDamage() being their damage value and isMinimal() returning false. ASDamage is immutable.
See Also:
  • Field Details

    • damage

      public final int damage
      The value of this damage. Is 0 for both zero damage and minimal damage. When using this for damage resolution, make sure to check for minimal damage separately.
    • minimal

      public final boolean minimal
      True if this is minimal damage, i.e. 0*
    • ZERO

      public static final ASDamage ZERO
      A constant that represents zero damage. May be used as a return value instead of null.
    • MINIMAL_DAMAGE

      public static final ASDamage MINIMAL_DAMAGE
      A constant that represents minimal damage 0*.
  • Constructor Details

    • ASDamage

      public ASDamage(double damageValue)
      Creates an AlphaStrike damage value that may be minimal damage, i.e. 0*. When 0 < damageValue < 0.5, the result will be minimal damage. Otherwise, damageValue is rounded normally (a negative damageValue is set to 0).
    • ASDamage

      public ASDamage(double damageValue, boolean allowMinimal)
      Creates an AlphaStrike damage value. It may be minimal damage, i.e. 0*, only if allowMinimal is true. In that case, when 0 < damageValue < 0.5, the result will be minimal damage. When allowMinimal is false or damageValue >= 0.5, damageValue is rounded normally (a negative damageValue is set to 0).
    • ASDamage

      public ASDamage(int damageValue, boolean isMinimal)
      Creates an AlphaStrike damage value that may be minimal damage, i.e. 0*. When the given isMinimal is true, this overrides any damageValue given and the resulting ASDamage will be 0*. Otherwise, the resulting ASDamage will be equal to the damageValue (a negative damageValue is set to 0).
  • Method Details

    • createRoundedNormal

      public static ASDamage createRoundedNormal(double dmg)
      Creates an AlphaStrike damage value that may be minimal damage, i.e. 0*. When 0 < damageValue < 0.5, the result will be minimal damage. Otherwise, damageValue is rounded normally (a negative damageValue is set to 0).
    • createDualRoundedNormal

      public static ASDamage createDualRoundedNormal(double dmg)
      Creates an AlphaStrike damage value that may be minimal damage, i.e. 0*. The value is first rounded up to the nearest tenth, then assigned minimal damage if < 0.5, otherwise rounded normally (i.e. up or down depending on the tenth) to the nearest integer.
    • createDualRoundedUp

      public static ASDamage createDualRoundedUp(double dmg)
      Creates an AlphaStrike damage value from the given double value. The value is first rounded up to the nearest tenth, then assigned minimal damage if < 0.5, otherwise rounded up (i.e. up or down depending on the tenth) to the nearest integer.
    • createDualRoundedNormalNoMinimal

      public static ASDamage createDualRoundedNormalNoMinimal(double dmg)
      Creates an AlphaStrike damage value from the given double value. The value is first rounded up to the nearest tenth, then rounded normally (i.e. up or down depending on the tenth) to the nearest integer. There is no minimal damage, i.e. dmg < 0.41 becomes 0.
    • hasDamage

      public boolean hasDamage()
      Returns true if this ASDamage represents any damage, minimal or 1 or more.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringWithZero

      public String toStringWithZero()
    • asDoubleValue

      public double asDoubleValue()
    • parse

      public static ASDamage parse(String asText)
      Tries to parse the given text to the appropriate ASDamage. Acceptable values are "0", "0*", "-" (equal to "0") and all positive Integers. Other values will result in an IllegalArgumentException.
      Parameters:
      asText - The text to translate to an ASDamage value
      Returns:
      The ASDamage value represented by the given text
      Throws:
      IllegalArgumentException - When the value cannot be parsed or is less than zero
    • parse

      public static ASDamage parse(String asText, ASDamage defaultValue)
      Tries to parse the given text to the appropriate ASDamage. Acceptable values are "0", "0*", "-" (equal to "0") and all positive Integers. When the given text cannot be parsed or represents an illegal value (e.g. a negative number), the given default is returned instead.
      Parameters:
      asText - The text to translate to an ASDamage value
      defaultValue - A value to return if the given text cannot be converted
      Returns:
      The ASDamage value represented by the given text if it can be converted, the given defaultValue otherwise