actor HDPistol : HDWeapon replaces Pistol
{
	obituary "%o got capped by %k's pea shooter."
	weapon.selectionorder 800
	weapon.ammotype1 HDPistolMag
	weapon.ammotype2 HDPistolMags//Ammo
	weapon.kickback 30
	+WEAPON.WIMPY_WEAPON
	decal "BulletScratch"
	states
	{
	Select:
		PISG A 0 A_TakeInventory ("Reloading", 999)
		PISG A 1 A_Raise
		PISG AA 0 A_Raise
		loop
	Deselect:
		TNT1 A 0 A_TakeInventory ("IsKicking", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		PISG A 0 A_Lower
		PISG A 1 A_Lower
		loop
	Ready:
		TNT1 A 0 A_JumpIfInventory ("Reloading", 1, "Reload")
		TNT1 A 0 A_JumpIfInventory("HDPistolMag",1,2)
		PISG C 1 A_WeaponReady(16)
		goto MagCheck
		PISG A 1 A_WeaponReady(16)
		goto MagCheck
	MagCheck:
		RIFG A 0 A_GiveInventory("NotShot",1)
		RIFG A 0 A_JumpIfInventory("HDPistolMags",0,"Ready")
		RIFG A 0 A_JumpIfInventory("NotShot",210,"FillMag")
		goto Ready
	FillMag:
		PISG A 0 A_TakeInventory("NotShot",9999)
		PISG A 0 A_JumpIfInventory("HDPistolAmmo",12,1)
		goto Ready
		PISG A 0 A_GiveInventory("HDPistolMags",1)
		PISG A 0 A_TakeInventory("HDPistolAmmo",12)
		goto Ready
	HoldEmpty:
		PISG C 1 A_WeaponReady(12)
		PISG C 0 A_Refire
		goto Ready
	AltFire:
		TNT1 A 0 A_JumpIfInventory("HDPistolMag",1,1)
		goto HoldEmpty
		PISG A 3
		goto Fire
	Fire:
		TNT1 A 0 A_JumpIfInventory("HDPistolMag",1,1)
		goto HoldEmpty
		PISG A 2
		goto Hold
	AltHold:
		TNT1 A 0 A_JumpIfInventory("HDPistolMag",1,1)
		goto HoldEmpty
		PISG A 3
		PISG B 2
		goto Hold
	Hold:
		TNT1 A 0 A_JumpIfInventory("HDPistolMag",1,1)
		goto HoldEmpty
		PISG B 0 A_ZoomFactor(0.99,ZOOM_INSTANT|ZOOM_NOSCALETURNING)
		PISG B 3 A_GunFlash
		PISG C 2 ACS_ExecuteAlways (553, 0, random(12,16), random(8, 10), 0)
		PISG C 0 A_FireCustomMissile("HDSpent9mmEjector")
	Followthrough:
		PISG D 2
		PISG B 3 A_ReFire
		goto Ready
	Flash:
		PISF A 1 BRIGHT A_Light1
		PISF A 0 ACS_ExecuteAlways (553, 0, random(4,16), random(4, 12), 0)
		PISF A 0 A_FireBullets (1.7, 1.7, -1, 12, "BulletPuffSmall", 0, 48*40+random(-128,128))
		goto EndFlash
	AltFlash:
		PISF A 1 BRIGHT A_Light1
		PISF A 0 A_FireBullets (0.6, 0.6, -1, 12, "BulletPuffSmall", 0, 48*40+random(-128,128))
		goto EndFlash
	EndFlash:
		PISF A 1 BRIGHT A_PlaySound ("weapons/pistol")
		PISF A 0 A_Jump (96,2)
		PISF A 0 A_AlertMonsters
		PISF A 0 A_ZoomFactor(1.0,ZOOM_INSTANT|ZOOM_NOSCALETURNING)
		PISF A 0 A_Light0
		PISF A 0 A_TakeInventory("HDPistolMag",1)
		stop
	Reload:
		PISG A 0 A_JumpIfInventory("HDPistolMag",0,"ReloadNone")
		PISG A 0 A_JumpIfInventory("HDPistolMags",1,"Reload1")
		PISG A 0 A_JumpIfInventory("HDPistolAmmo",1,"Reload1")
		goto ReloadNone
	ReloadNone:
		PISG BCBA 3
		PISG A 0 A_TakeInventory("Reloading",999)
		goto Ready
	Reload1:
		PISG A 5 offset (0,32)
		PISG B 5 offset (0,34)
		PISG D 5 offset (0,36) A_PlaySoundEx("weapons/pocket","Body")
		PISG E 10 offset (0,38)
//		PISG E 4 offset (0,39) ACS_ExecuteAlways (554, 0, 8, 12)
		TNT1 A 0 A_JumpIfInventory("HDPistolMags",1,"Reload2")
		goto Reload2Shitty
	Reload2:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
			Reload2EmptyFirst:
			TNT1 A 0 A_JumpIfInventory("HDPistolMag",2,1)
			goto Reload2EmptyFirstEnd
			TNT1 A 0 A_TakeInventory("HDPistolMag",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			loop
			Reload2EmptyFirstEnd:
		TNT1 A 0 A_TakeInventory("HDPistolMags",1)
		TNT1 A 0 A_GiveInventory("HDPistolMag",12)
		goto Reload2ReturnToPool
	Reload2Shitty:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
			Reload2EmptyFirst2:
			TNT1 A 0 A_JumpIfInventory("HDPistolMag",2,1)
			goto Reload2EmptyFirstEnd2
			TNT1 A 0 A_TakeInventory("HDPistolMag",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			loop
			Reload2EmptyFirstEnd2:
		PISG E 1 offset(0,39) ACS_ExecuteAlways (554, 0, 8, random(1,11))
			Reload2ReturnToPool:
			TNT1 A 0 A_JumpIfInventory("ShittyReloadDummy",1,1)
			goto Reload3
			TNT1 A 0 A_TakeInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_GiveInventory("HDPistolAmmo",1)
			loop
	Reload3:
		PISG E 4 offset (0,42) A_PlaySoundEx("weapons/rifleclick","Body")
		PISG D 5 offset (0,36)
		PISG B 5 offset (0,34) A_TakeInventory("Reloading",999)
		goto Ready
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("HDPistolPickup", 0,0,0,velx,vely,velz,0,32,0)
		stop
	}
}
ACTOR HDPistolAmmo : Ammo
{
	+inventory.ignoreskill
	+inventory.undroppable
	inventory.maxamount 24
	ammo.backpackmaxamount 48
	ammo.backpackamount 6
}
ACTOR HDPistolMags : Ammo
{
	+inventory.ignoreskill
	+inventory.undroppable
	inventory.maxamount 6
	ammo.backpackmaxamount 12
	ammo.backpackamount 2
}
ACTOR HDPistolMag : Ammo
{
	+inventory.ignoreskill
	+inventory.undroppable
	inventory.maxamount 13
	ammo.backpackmaxamount 13
	ammo.backpackamount 0
}
ACTOR HDPistolPickup : HDWeaponPickup replaces HDPistol
{
	scale 0.65
	inventory.pickupmessage "You got the pistol!"
	inventory.pickupsound "misc/w_pkup"
	states
	{
	spawn:
		PIST A -1
		stop
	Pickup:
		TNT1 A 0 A_JumpIfInventory ("CanPickUpItems", 1, 1)
		fail
		TNT1 A 0 A_JumpIfInventory ("HDPistol", 1, 1)
		goto Pickup0
		TNT1 A 0 A_JumpIfInventory ("HDPistolAmmo", 0, "FullAmmo")
		goto Pickup0
	FullAmmo:
		TNT1 A 0
		fail
	Pickup0:
		TNT1 A 0 A_GiveInventory ("PistolPickupRounds", (28+random(0,1)*2+random(0,1)))
	Pickup0a:
		TNT1 A 0 A_JumpIfInventory ("HDPistol", 1, "Pickup2")
		TNT1 A 0 A_GiveInventory ("HDPistol", 1)
		goto Pickup2
		//if the mag is full, add a full mag
		TNT1 A 0 A_JumpIfInventory ("PistolPickupRounds", 12, "PickupMagOnly")
	PickupMagOnly:
		TNT1 A 0 A_GiveInventory("HDPistolMags",1)
		stop
	Pickup1:
		TNT1 A 0 A_GiveInventory ("HDPistolMag", 1)
		TNT1 A 0 A_TakeInventory ("PistolPickupRounds", 1)
		TNT1 A 0 A_JumpIfInventory ("PistolPickupRounds", 1, 1)
		stop
		TNT1 A 0
		loop
	Pickup2:
		TNT1 A 0 A_GiveInventory ("HDPistolAmmo", 1)
		TNT1 A 0 A_TakeInventory ("PistolPickupRounds", 1)
		TNT1 A 0 A_JumpIfInventory ("PistolPickupRounds", 1, 1)
		stop
		TNT1 A 0
		loop
	}
}
actor PistolPickupRounds : Ammo
{
	+inventory.undroppable
	inventory.maxamount 13
	ammo.backpackmaxamount 13
	ammo.backpackamount 0
}

actor HDSpent9mm
{
	+missile
	+doombounce
	+bounceonactors
	+noteleport
	+forcexybillboard
	scale 0.6
	height 1
	radius 1
	states
	{
	spawn:
		PBRS ABCDEFGH 2
		loop
	death:
		TNT1 A 0 A_ChangeFlag("missile",0)
		TNT1 A 0 A_ChangeFlag("doombounce",0)
		TNT1 A 0 A_Jump (256, 1,1,1,1,2,2,2,2,3,3,4)
		PBRS C 500
		stop
		PBRS G 500
		stop
		PBRS A 500
		stop
		PBRS E 500
		stop
	}
}
actor HDSpent9mmEjector : IdleDummy
{
	+missile
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("HDSpent9mm", 12,1,-1, random(-1,-3),random(4,8),random(-3,2), 0,160)
		stop
	}
}