The Secret, Yet Simple Maths Behind Doom's Super Shotgun

A few months back, a coder with some spare time dived into Doom's random number generator and tweaked a few things, with the results not what you'd expect. The super shotgun had the strangest behaviour of all — the changes should have made it broken-strong, but instead it was much weaker. So what magical numbers powered the super shotty? Back into the code we go.

First here's the relevant bit about the shotguns from Jonathan Dowland original analysis:

The bullet-based (hitscan) weapons have no spread at all: the shotgun becomes like a sniper rifle, and the chain-gun is likewise always true. You'd think this would make the super-shotgun a pretty lethal weapon, but it seems to have been nerfed: the spread pattern is integral to its function.

Doom had some wacky things ticking over under the hood and even for the most adept programmer, it can take a long time to unwind the steps and figure out what's really going on. A Stockholm-based software dev by the name of "Chris" decided to get to the bottom of the super shotgun's odd behaviour in the face of determinism.

After running into a variety of dead ends trawling through Doom's code, he finally hit upon some functions — specialised chunks of code repeated used by the game — called "A_FirePistol", "A_FireShotgun" and "A_FireShotgun2". One guess as to which of those covers the super shotgun.

This led to the weapon's firing code, which works in a fairly straightforward manner. It fires 20 projectiles in a spread, however, each projectile does a random amount of damage. The trick of it is that the randomness wasn't drawn directly from Doom's random set of numbers, it's actually modified in such a way that each projectile will do damage in the range of 5-15.

When Dowland played with the code, he made it so Doom would always output 0 or 255 when asked for a random number. Turns out the super shotgun's special maths (really just the use of the modulo operator) would cause the damage of each projectile to always be the lowest possible — hence feeling "nerfed".

Basically, Dowland picked the worst two values to test with — 0x00 and 0xFF — at least in the case of the super shotgun.

The Mystery of the Deterministic Super Shotgun [Two Wrongs]


Comments

    man edge of your seat kind of stuff. I can finally sleep at night.

Join the discussion!

Trending Stories Right Now