Package megamek.common.alphaStrike
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final ASDamageVectorA constant that represents zero damage, written as 0/0/0/0 in toString().static final ASDamageVectorA constant that represents zero damage as special damage, written as -/-/-/- in toString(). -
Constructor Summary
ConstructorsConstructorDescriptionASDamageVector(ASDamage S, ASDamage M, ASDamage L, ASDamage E, int rangeBands, boolean isStandard) Construct an ASDamageVector from ASDamage values. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic ASDamageVectorcreate(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.static ASDamageVectorcreateNormRndDmg(double s) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmg(double s, double m) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmg(double s, double m, double l) Creates an ASDamageVector for special damage (e.g.static ASDamageVectorcreateNormRndDmg(double s, double m, double l, double e) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmg(List<Double> values, int ranges) Creates an ASDamageVector for special damage from the given double values and the number of ranges to be used.static ASDamageVectorcreateNormRndDmgNoMin(double s) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmgNoMin(double s, double m) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmgNoMin(double s, double m, double l) Creates an ASDamageVector for special damage from the given double values.static ASDamageVectorcreateNormRndDmgNoMin(double s, double m, double l, double e) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateNormRndDmgNoMin(List<Double> values, int ranges) Creates an ASDamageVector for special damage from the given double values and the number of ranges to be used.static ASDamageVectorcreateUpRndDmg(double s, double m, double l) Creates an ASDamageVector for S/M/L standard damage from the given double values.static ASDamageVectorcreateUpRndDmg(double s, double m, double l, double e) Creates an ASDamageVector for S/M/L/E standard damage from the given double values.static ASDamageVectorcreateUpRndDmg(List<Double> values, int ranges) Deprecated, for removal: This API element is subject to removal in a future version.static ASDamageVectorcreateUpRndDmgMinus(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).E()Returns the value of theErecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the ASDamage of this ASDamageVector for the given range, so the S, M, L, or E damage.booleanReturns true if this ASDamageVector represents any damage at any range, minimal or 1 or more.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theisStandardrecord component.L()Returns the value of theLrecord component.M()Returns the value of theMrecord component.static ASDamageVectorTries to parse the given text to the appropriate ASDamageVector.intReturns the value of therangeBandsrecord component.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.S()Returns the value of theSrecord component.toString()Returns a string representation of this record class.booleanusesDamage(ASRange range) Deprecated, for removal: This API element is subject to removal in a future version.
-
Field Details
-
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
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, 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
Returns the ASDamage of this ASDamageVector for the given range, so the S, M, L, or E damage. -
create
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
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
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
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
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
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
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
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
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. -
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
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
-
reducedBy
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
S
Returns the value of theSrecord component.- Returns:
- the value of the
Srecord component
-
M
Returns the value of theMrecord component.- Returns:
- the value of the
Mrecord component
-
L
Returns the value of theLrecord component.- Returns:
- the value of the
Lrecord component
-
E
Returns the value of theErecord component.- Returns:
- the value of the
Erecord component
-
rangeBands
public int rangeBands()Returns the value of therangeBandsrecord component.- Returns:
- the value of the
rangeBandsrecord component
-
isStandard
public boolean isStandard()Returns the value of theisStandardrecord component.- Returns:
- the value of the
isStandardrecord component
-