Record Class ASDamageVector

java.lang.Object
java.lang.Record
megamek.common.alphaStrike.ASDamageVector
Record Components:
rangeBands - The number of damage values used by this damage vector. 2 indicates that only the S and M damage values are used, as with SRM. 4 indicates all S/M/L/E damage values are used such as with Aero.
isStandard - True for standard damage that uses 0 (e.g. 2/2/0), false for specials that use a dash (AC2/2/-)
All Implemented Interfaces:
Serializable

public record ASDamageVector(ASDamage S, ASDamage M, ASDamage L, ASDamage E, int rangeBands, boolean isStandard) extends Record implements Serializable
Represents an AlphaStrike damage value combination of between 1 and 4 damage values which typically correspond to S/M/L/E ranges. Each damage value is an ASDamage field, and they can be directly accessed as S, M, L and E. The ASDamage fields store integer damage values with the option of being minimal damage. The ASDamageVector remembers how many damage values are used and if it is special damage (using - for no damage) or standard damage (using 0 for no damage) and toString() writes the damage values accordingly. ASDamageVector is immutable.
See Also:
  • Field Details

    • ZERO

      public static final ASDamageVector ZERO
      A constant that represents zero damage, written as 0/0/0/0 in toString(). May be used as a return value instead of null.
    • ZERO_SPECIAL

      public static final ASDamageVector ZERO_SPECIAL
      A constant that represents zero damage as special damage, written as -/-/-/- in toString(). May be used as a return value instead of null.
  • Constructor Details

    • ASDamageVector

      public ASDamageVector(ASDamage S, ASDamage M, ASDamage L, ASDamage E, int rangeBands, boolean isStandard)
      Construct an ASDamageVector from ASDamage values. Damage is set to 0 for unused ranges. When std is true, creates a standard damage type vector that uses "0" for zero damage, otherwise prints "-" for zero damage.
  • Method Details

    • hasDamage

      public boolean hasDamage()
      Returns true if this ASDamageVector represents any damage at any range, minimal or 1 or more.
    • usesDamage

      @Deprecated(since="0.51.0", forRemoval=true) public boolean usesDamage(ASRange range)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns true when this ASDamageVector uses the given range; e.g. Aero standard damage will return true for all ranges while SRM damage will return true only for SHORT and MEDIUM. Note that this does not check if unused ranges happen to contain damage values of more than null, only if this ASDamageVector was constructed to include the given range.
    • getDamage

      public ASDamage getDamage(ASRange range)
      Returns the ASDamage of this ASDamageVector for the given range, so the S, M, L, or E damage.
    • create

      public static ASDamageVector create(int s, int m, int l, int e, int ranges)
      Creates an ASDamageVector using the given integer values as damage and the number of ranges. Negative damage values are set to 0; ranges is kept between 1 and 4. The values actually used depend on the given ranges value; when ranges is 2, only the s and m values are used.
    • createNormRndDmg

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmg(double s)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage (e.g. IF2) from the given double value. The value is rounded first up to the nearest tenth, then normally to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage.
    • createNormRndDmg

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmg(double s, double m)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. 0 values are printed as - (dash)
    • createNormRndDmg

      public static ASDamageVector createNormRndDmg(double s, double m, double l)
      Creates an ASDamageVector for special damage (e.g. LRM1/1/2) from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. 0 values are printed as - (dash)
    • createNormRndDmg

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmg(double s, double m, double l, double e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage (e.g. REAR1/1/-/-) from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. 0 values are printed as - (dash)
    • createNormRndDmgNoMin

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmgNoMin(double s)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage from the given double value. The value is rounded first up to the nearest tenth, then normally to the nearest integer. Minimal damage is not used. 0 values are printed as - (dash)
    • createNormRndDmgNoMin

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmgNoMin(double s, double m)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer. Minimal damage is not used. 0 values are printed as - (dash)
    • createNormRndDmgNoMin

      public static ASDamageVector createNormRndDmgNoMin(double s, double m, double l)
      Creates an ASDamageVector for special damage from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer. Minimal damage is not used. 0 values are printed as - (dash)
    • createNormRndDmgNoMin

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createNormRndDmgNoMin(double s, double m, double l, double e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for special damage from the given double values. The values are rounded first up to the nearest tenth, then normally to the nearest integer. Minimal damage is not used. 0 values are printed as - (dash)
    • createNormRndDmg

      public static ASDamageVector createNormRndDmg(@Nullable List<Double> values, int ranges)
      Creates an ASDamageVector for special damage from the given double values and the number of ranges to be used. The values are rounded first up to the nearest tenth, then normally (i.e. up or down depending on the tenth) the nearest integer. Minimal damage will be used. When printed, the ASDamageVector will use - for zero values.
    • createNormRndDmgNoMin

      public static ASDamageVector createNormRndDmgNoMin(@Nullable List<Double> values, int ranges)
      Creates an ASDamageVector for special damage from the given double values and the number of ranges to be used. The values are rounded first up to the nearest tenth, then normally (i.e. up or down depending on the tenth) the nearest integer. Minimal damage is not used. When printed, the ASDamageVector will use - for zero values.
    • createUpRndDmg

      @Deprecated(since="0.51.0", forRemoval=true) public static ASDamageVector createUpRndDmg(@Nullable List<Double> values, int ranges)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an ASDamageVector for standard damage from the given double values and the number of ranges to be used (usually 3 or 4). The values are rounded first up to the nearest tenth, then up to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. When printed, the ASDamageVector will use 0 (not a dash) for zero values.
    • createUpRndDmgMinus

      public static ASDamageVector createUpRndDmgMinus(@Nullable List<Double> values, int ranges)
      Creates an ASDamageVector for special damage from the given double values and the number of ranges to be used (usually 3 or 4). The values are rounded first up to the nearest tenth, then up to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. When printed, the ASDamageVector will use "-" for zero values.
    • createUpRndDmg

      public static ASDamageVector createUpRndDmg(double s, double m, double l)
      Creates an ASDamageVector for S/M/L standard damage from the given double values. The values are rounded first up to the nearest tenth, then up to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. When printed, the ASDamageVector will use 0 (not a dash) for zero values.
    • createUpRndDmg

      public static ASDamageVector createUpRndDmg(double s, double m, double l, double e)
      Creates an ASDamageVector for S/M/L/E standard damage from the given double values. The values are rounded first up to the nearest tenth, then up to the nearest integer and values between 0 and 0.5 excl. end up as minimal damage. When printed, the ASDamageVector will use 0 (not a dash) for zero values.
    • toString

      @Nonnull public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • toStringForSerialization

      public String toStringForSerialization()
      Returns:
      A string representation of this ASDamageVector for serialization. This should not be used for display or other purposes and not be changed unless the rules change.
    • parse

      public static ASDamageVector parse(String asText)
      Tries to parse the given text to the appropriate ASDamageVector. Acceptable values are combinations of four or fewer "0", "0*", "-" (equal to "0") and positive Integers separated by slashes, e.g. "2/0* /0/0" (without the space) or "11/-". Other values will result in an IllegalArgumentException.
      Parameters:
      asText - The text to translate to an ASDamageVector value
      Returns:
      The ASDamageVector represented by the given text
      Throws:
      IllegalArgumentException - When the text cannot be parsed
    • canParse

      public static boolean canParse(String asText)
    • reducedBy

      public ASDamageVector reducedBy(int damageReduction)
      Returns a new damage vector where the damage value of all ranges are reduced by the given reduction, down to a minimum of 0. A 5/2/1 reduced by 1 becomes 4/1/0. A 5/2/1 reduced by 3 becomes 2/0/0. Note that negative reduction can be used but will also increase 0 values.
      Parameters:
      damageReduction - The amount of damage to deduct.
      Returns:
      A new ASDamageVector with reduced damage
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • S

      public ASDamage S()
      Returns the value of the S record component.
      Returns:
      the value of the S record component
    • M

      public ASDamage M()
      Returns the value of the M record component.
      Returns:
      the value of the M record component
    • L

      public ASDamage L()
      Returns the value of the L record component.
      Returns:
      the value of the L record component
    • E

      public ASDamage E()
      Returns the value of the E record component.
      Returns:
      the value of the E record component
    • rangeBands

      public int rangeBands()
      Returns the value of the rangeBands record component.
      Returns:
      the value of the rangeBands record component
    • isStandard

      public boolean isStandard()
      Returns the value of the isStandard record component.
      Returns:
      the value of the isStandard record component