A_FireShotgun2

From ZDoom Wiki
Jump to navigation Jump to search
DoomWiki.org
For more information on this article, visit the A_FireShotgun2 page on the Doom Wiki.

A_FireShotgun2

(no parameters)

Performs Doom's super shotgun attack, firing 20 pellets dealing 5 * 1d3 damage each. This function can be very roughly described as a shortcut to A_FireBullets, A_PlaySound and A_GunFlash with certain predetermined hardcoded parameters:

    SHT2 A 0 A_FireBullets (11.2, 7.1, 20, 5, "BulletPuff")
    SHT2 A 0 A_PlaySound ("weapons/sshotf", CHAN_WEAPON)
    SHT2 A 7 A_GunFlash

However, in practice A_FireShotgun2 uses a special pitch calculation that results in a spread pattern that, while covering roughly the same area as A_FireBullets, looks nothing like it. This is how the function is defined in GZDoom in ZScript:

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found here.
action void A_FireShotgun2()
{
	if (player == null)
	{
		return;
	}

	A_StartSound ("weapons/sshotf", CHAN_WEAPON);
	Weapon weap = player.ReadyWeapon;
	if (weap != null && invoker == weap && stateinfo != null && stateinfo.mStateType == STATE_Psprite)
	{
		if (!weap.DepleteAmmo (weap.bAltFire, true, 2))
			return;
		
		player.SetPsprite(PSP_FLASH, weap.FindState('Flash'), true);
	}
	player.mo.PlayAttacking2 ();

	double pitch = BulletSlope ();
		
	for (int i = 0 ; i < 20 ; i++)
	{
		int damage = 5 * random[FireSG2](1, 3);
		double ang = angle + Random2[FireSG2]() * (11.25 / 256);

		// Doom adjusts the bullet slope by shifting a random number [-255,255]
		// left 5 places. At 2048 units away, this means the vertical position
		// of the shot can deviate as much as 255 units from nominal. So using
		// some simple trigonometry, that means the vertical angle of the shot
		// can deviate by as many as ~7.097 degrees.

		LineAttack (ang, PLAYERMISSILERANGE, pitch + Random2[FireSG2]() * (7.097 / 256), damage, 'Hitscan', "BulletPuff");
	}
}