A_FireShotgun2

From ZDoom Wiki
Jump to navigation Jump to search
Ktip.png This page describes a function made for one of the natively supported games. These functions are made with very specific purpose and provide no flexibility, so using them in custom projects is not recommended. Authors are encouraged to use one of the more generalized functions in custom projects. For example: A_FireBullets.
DoomWiki.org
For more information on this article, visit the A_FireShotgun2 page on the Doom Wiki.


StateProvider

action void A_FireShotgun2()

Usage

Performs Doom's super shotgun attack, firing 20 pellets dealing 5 * 1d3 damage each. This function is roughly equivalent to A_FireBullets, A_StartSound and A_GunFlash with certain predetermined hardcoded parameters:

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

A_FireShotgun2 internally uses a somewhat different pitch calculation from A_FireBullets, which results in a different, more oval spread pattern.

ZScript definition

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 on GZDoom GitHub.
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");
	}
}

See Also