GetMissileDamage

From ZDoom Wiki
Jump to: navigation, search

int GetMissileDamage (int mask, int add [, int pointer])

Usage

Gets the damage of the calling or pointed to actor. This function replaces the use of the damage variable in expressions.


If the damage passed to the damage property is not an expression, such as Damage 5, the damage is calculated like the following if mask is 0:

add * damage

However, if mask is non-zero, the damage is calculated like this:

((random(0, 255) & mask) + add) * damage

If the damage passed to the damage property is an expression, however, such as Damage (random(1, 3) * 12), mask and add are ignored, and the damage is calculated using that expression.

pointer is the actor to get its damage. This is an actor pointer, defaulting to AAPTR_DEFAULT (the calling actor).

Return value

The function returns the actor's damage after calculation.

Examples

This rocket uses its damage property for its splash damage.

ACTOR CustomRocket : Rocket
{
    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