Package megamek.common.alphaStrike
Class ASDamage
java.lang.Object
megamek.common.alphaStrike.ASDamage
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionASDamage
(double damageValue) Creates an AlphaStrike damage value that may be minimal damage, i.e.ASDamage
(double damageValue, boolean allowMinimal) Creates an AlphaStrike damage value.ASDamage
(int damageValue, boolean isMinimal) Creates an AlphaStrike damage value that may be minimal damage, i.e. -
Method Summary
Modifier and TypeMethodDescriptiondouble
static ASDamage
createDualRoundedNormal
(double dmg) Creates an AlphaStrike damage value that may be minimal damage, i.e.static ASDamage
createDualRoundedNormalNoMinimal
(double dmg) Creates an AlphaStrike damage value from the given double value.static ASDamage
createDualRoundedUp
(double dmg) Creates an AlphaStrike damage value from the given double value.static ASDamage
createRoundedNormal
(double dmg) Creates an AlphaStrike damage value that may be minimal damage, i.e.boolean
Returns true if this ASDamage represents any damage, minimal or 1 or more.static ASDamage
Tries to parse the given text to the appropriate ASDamage.static ASDamage
Tries to parse the given text to the appropriate ASDamage.toString()
-
Field Details
-
damage
public final int damageThe 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 minimalTrue if this is minimal damage, i.e. 0* -
ZERO
A constant that represents zero damage. May be used as a return value instead of null. -
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
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
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
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
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
-
toStringWithZero
-
asDoubleValue
public double asDoubleValue() -
parse
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
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 valuedefaultValue
- 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
-