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 SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionASDamage(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 SummaryModifier and TypeMethodDescriptiondoublestatic ASDamagecreateDualRoundedNormal(double dmg) Creates an AlphaStrike damage value that may be minimal damage, i.e.static ASDamagecreateDualRoundedNormalNoMinimal(double dmg) Creates an AlphaStrike damage value from the given double value.static ASDamagecreateDualRoundedUp(double dmg) Creates an AlphaStrike damage value from the given double value.static ASDamagecreateRoundedNormal(double dmg) Creates an AlphaStrike damage value that may be minimal damage, i.e.booleanReturns true if this ASDamage represents any damage, minimal or 1 or more.static ASDamageTries to parse the given text to the appropriate ASDamage.static ASDamageTries to parse the given text to the appropriate ASDamage.toString()
- 
Field Details- 
damagepublic 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.
- 
minimalpublic final boolean minimalTrue if this is minimal damage, i.e. 0*
- 
ZEROA constant that represents zero damage. May be used as a return value instead of null.
- 
MINIMAL_DAMAGEA constant that represents minimal damage 0*.
 
- 
- 
Constructor Details- 
ASDamagepublic 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).
- 
ASDamagepublic 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).
- 
ASDamagepublic 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- 
createRoundedNormalCreates 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).
- 
createDualRoundedNormalCreates 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.
- 
createDualRoundedUpCreates 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.
- 
createDualRoundedNormalNoMinimalCreates 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.
- 
hasDamagepublic boolean hasDamage()Returns true if this ASDamage represents any damage, minimal or 1 or more.
- 
toString
- 
toStringWithZero
- 
asDoubleValuepublic double asDoubleValue()
- 
parseTries 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
 
- 
parseTries 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
 
 
-