Now that I've reviewed the mod, I would like to ask about Quakes stagger system. How does it work? Is it the same as DOOMs? I figure that I'd ask here, since the Nightmare difficulty apparently alters the stagger chances for enemies, and I've always been quite curious about how it works since it seems inconsistent. I do apologise if this is not the right place to ask.
Each enemy monster has it's own logic to determine when the pain animation gets triggered and how often it can be triggered. The monster code is in the "src" folder and each monster's file is prefixed by m_, such as m_ogre.qc. Each time a monster takes damage, it's pain function is called and it will check to see if the monster should become staggered. For the Ogre in QBJ3 the function is called
ogre_pain and looks like this:
Code:
void(entity attacker, float damage) ogre_pain =
{
local float r;
// don't make multiple pain sounds right after each other
if (self.pain_finished > time)
return;
ogre_pain_sound();
r = random();
if (skill == 3)
r *= random(); // nightmare: make the long stuns rare
if (r > 0.12) //since we removed the other pain anims, i recalculated the base chance of the pain anims. longest is 12% #funfact
ogre_pain1 ();
else
ogre_paind1 ();
}
First of all, it checks to see if it was already staggered too recently. This is the
self.pain_finished > time line.
pain_finished specifies at what time in the future the monster can be staggered again,
time is the current time. If the monster was staggered too recently then the function stops there and then and won't be triggered again until the Ogre takes more damage, at which point it'll check again. For this example we'll assume enough time has passed for the monster to be staggered again, or that the monster has yet to be staggered at all.
Next line
ogre_pain_sound(); triggers the pain sound effect.
After that, it generates a random number. Quake's random numbers are between 0.0 and 1.0.
Next line, it checks to see if the skill is set to nightmare (
skill == 3 means nightmare). If so then it makes the random number smaller by multiplying it by another random number. On average it will halve the value of the random number.
Finally, it picks between two different pain animations based on the final result of the random number. If the random number is above 0.12 (88% chance usually) then it triggers the short stagger animation which is started by
ogre_pain1(). Otherwise if the random number is equal to or below 0.12 (12% chance usually) then it triggers the much longer stagger animation through
ogre_paind1(). Usually monsters have multiple pain animations but the Ogre in QBJ3 only has 2: a short and long stagger. On nightmare, the extra modification to the random number ends up meaning that the chance for a long stagger fluctuates between 0% and 12% each time the monster takes damage, or 6% on average.
Those two stagger animation functions also determine how much time has to pass until the monster can be staggered again by calling the
PainFinished function (code for this not shown). The short stagger prevents the Ogre from being staggered again until 1.0 seconds have passed, and the long stagger prevents the Ogre from being staggered until 2.0 seconds have passed.
TLDR: On non-nightmare, the Ogre has a 88% chance of suffering a short stagger when taking damage, and a 12% chance of suffering a long stagger. If a short stagger occurs then it can't be staggered again until 1 second has passed, and for long staggers it's until 2 seconds have passed. On nightmare the long stagger chance fluctuates between 0% and 12% (average at 6%).
And that's just the Ogre. For the Hell Knight in QBJ3, on non-nightmare it will be staggered if 44 damage was taken in one go or if 8 seconds have passed since it was last staggered. On nightmare, the auto-stagger after 8 seconds is disabled and you have to do 44 damage in one hit to stagger. Regardless of difficulty, it can't be staggered again until 1 second has passed.
Shambers have different logic as well, etc. It's all custom per monster type.
Finally, if you're wondering why they chose to multiply two random numbers for the Ogre instead of just changing the nightmare long stagger threshold to 6%... your guess is as good as mine!