GetMissileDamage
native int GetMissileDamage(int mask, int add, int ptr = AAPTR_DEFAULT)
Usage
Gets the damage of the calling actor or the pointed-to actor. This is meant to be used on projectiles, and the purpose of this function is to emulate the usual damage randomization rules utilized in GZDoom-supported games (such as using the actor's Damage value and multiplying it by 1d8 or by 1d8 with STRIFEDAMAGE). Note, however, that GetMissileDamage does NOT automatically take the rules dictated by the game or flags into account; instead, you have to provide the randomization values manually.
Note, this function retrieves information only. If you want to modify how missiles deal damage, see the DoSpecialDamage virtual or DamageFunction.
Parameters
- int mask
- Provides a mask for the randomization of the add value. If non-zero, the add value will be multiplied by
random(0,255) & mask
; otherwise add will be used directly. - For default randomization without any flags, use 7.
- int add
- A multiplier for the damage value. Normally
1
is used here, which then may or may not be randomized (depending on the mask value). Ripping projectiles, however, use 2.
- int ptr
- A DECORATE actor pointer. Default is AAPTR_DEFAULT, which refers to the calling actor. In ZScript this isn't necessary, since the caller of the function can be modified directly.
Return value
If the projectile has a DamageFunction defined:
- GetMissileDamage will call the defined damage function and return its value. The mask and add argumenst are ignored in this case. Note, for this to work, DamageFunction has to be defined properly (meaning, the actor must only have DamageFunction but not Damage defined).
If the projectile does NOT have DamageFunction defined and instead relies on its Damage property:
- If mask is 0: GetMissileDamage will return the actor's Damage value multiplied by the add argument.
- If mask is NOT 0: the add argument will be first multiplied by an equivalent of
random(0,255) & mask
, and the function will return that value multiplied by the actor's Damage.
Additionally, in DECORATE only, if the Damage property is defined with an expression, that expression will be used directly.
When projectiles deal their damage normally, only two flags may affect the internal formula: RIPPER and STRIFEDAMAGE. If you want to fully emulate the normal damage RNG accounting for both, use:
int dmg;
if (self.bRIPPER == true)
{
dmg = self.GetMissileDamage(3, 2);
}
else if (self.bSTRIFEDAMAGE == true)
{
dmg = self.GetMissileDamage(3, 1);
}
else
{
dmg = self.GetMissileDamage(7, 1);
}
or, in shorter form, using the ternary operator:
int dmg = self.bRIPPER? self.GetMissileDamage(3, 2) : self.GetMissileDamage(self.bSTRIFEDAMAGE? 3 : 7, 1);
With this calculation, dmg
will contain the damage as randomized by default.
Examples
This rocket uses its damage property for its splash damage.
class CustomRocket : Rocket { Default { Damage 10; } States { Death: MISL B 8 Bright A_Explode(GetMissileDamage(7, 1)); Goto Super::Death+1; } }
On impact, the rocket does a direct damage between 10 and 80 (random(1, 8) * 10
). For its splash damage, calling GetMissileDamage while passing 7 and 1 as mask and add, respectively, gets the same damage calculation.
// Damage is not an expression and mask is non-zero, so this formula is used: ((random(0, 255) & mask) + add) * damage // mask is 7, add is 1 and damage is 10: ((random(0, 255) & 7) + 1) * 10 // Returns a value between 0 and 7 (inclusive): random(0, 255) & 7 // Add 1 for a value between 1 and 8 (inclusive): (random(0, 7) + 1) // Multiply by 10 for the damage: random(1, 8) * 10