ACTOR PistolCasingSmoke
{
	Radius 1
	Height 1
	PROJECTILE
	+NOCLIP
	Scale 0.125
	Speed 1
	RENDERSTYLE TRANSLUCENT
	ALPHA 0.05
	States
	{
	Spawn:
		SMKE ABCDEFG 1 
		Stop
	Death:
		SMKE H 1
		Stop
	}
}

ACTOR PistolSmokeSpawner
{
    Radius 1
    Height 1
    Speed 12//25
    PROJECTILE
    States
    {
    Spawn:
        NULL A 1
        NULL A 0 A_Die
        Goto Death
    Death:
        NULL A 0 A_CustomMissile("PistolSmoke",0,0,0)
        Stop
    }
}

ACTOR PistolSmoke
{
	Radius		1
	Height		1
	RenderStyle ADD
	Alpha		0.3//.6
	Scale		0.1
	+NOGRAVITY
	+NOBLOCKMAP
	+FLOORCLIP
	+FORCEXYBILLBOARD
	States
	{
	Spawn:
		SMOK ABCDEFGHIJKLMNOPQ 1 
		Stop
	}
}

ACTOR PistolCasing
{
	Height 1.69
	Radius 1.56
	Speed 12
	Scale .13
	BounceCount 5
	BounceFactor 0.5
	PROJECTILE
	+DOOMBOUNCE
	- NOGRAVITY
	- NOBLOCKMAP
	SeeSound "weapons/pistolcasings" 
	States
	{
	Spawn:
		CAS1 A 0 A_PlaySound("NULL")
		CAS1 A 0 A_Jump(128,6)
		CAS1 T 1 A_CustomMissile("PistolCasingSmoke",0,0,0,2,0)
		CAS1 BKHN 4 A_CustomMissile("PistolCasingSmoke",0,0,0,2,0)
		Goto Spawn+1
		CAS1 L 1 A_CustomMissile("PistolCasingSmoke",0,0,0,2,0)
		CAS1 GMHJ 4 A_CustomMissile("PistolCasingSmoke",0,0,0,2,0)
		Goto Spawn+1
	Death:
		//CAS1 LGMHJC 3 A_CustomMissile("PistolCasingSmoke",0,0,0,2,0)
		CAS1 A 0 A_Jump(128,12)
		CAS1 A 0 A_Jump(128,10)
		CAS1 A 0 A_Jump(128,8)
		CAS1 A 0 A_Jump(128,6)
		CAS1 A 0 A_Jump(128,4)
		CAS1 A 0 A_Jump(128,2)
		CAS1 Q -1
		Stop
		CAS1 S -1
		Stop
		CAS1 O -1
		Stop
		CAS1 M -1
		Stop
		CAS1 G -1
		Stop
		CAS1 C -1
		Stop      
		CAS1 A -1
		Stop
	}
}

/*
ACTOR RandomPistolAmmoSpawner : PistolAmmo replaces Clip
{
	States
	{
	Spawn:
		9MAG A 1
		9MAG A 0 A_Jump(12,2)
		9MAG A 0 A_SpawnItem("PistolMag")
		stop
		9MAG A 0 A_SpawnItem("PistolBandolier")
		stop
	}
}

ACTOR PistolMag : PistolAmmo
{
	+INVENTORY.IGNORESKILL
	Height 4.6
	Radius 13.2
	Scale 0.1
	Inventory.Amount 17
	Inventory.PickupMessage "Picked up a 9mm pistol Magazine."
	States
	{
	Spawn:
		P45M A 0 A_Jump(128,2)
		P45M A -1 A_Countdown
		Stop
		P45M B -1 A_Countdown
		Stop
	}
}	

ACTOR PistolBandolier : PistolAmmo
{
	+INVENTORY.IGNORESKILL
	Scale 0.45
	Inventory.Amount 102
	Inventory.PickupMessage "Picked up a bandolier of 9mm magazines."
	States
	{
	Spawn:
		BNDO B -1
		Stop
	}
}
*/

ACTOR PistolMagEmpty
{
	Height 4.5
	Radius 9.5
	Speed 1
	Scale .5
	Reactiontime 16
	BounceCount 1
	//BounceFactor
	PROJECTILE
	+DOOMBOUNCE
	- NOGRAVITY
	- NOBLOCKMAP
	SeeSound "weapons/emptymag/drop" 
	States
	{
	Spawn:
		EMAG A 0 A_Jump(128,8)
		EMAG A 0 A_PlaySound("NULL")
		EMAG ABCDEF 1 A_Countdown
		Goto Spawn+1
		EMAG I 0 A_PlaySound("NULL")
		EMAG IJKLMN 1 A_Countdown
		Goto Spawn+8
	Death:
		EMAG A 0 A_Jump(128,2)
		EMAG G -1
		Stop
		EMAG O -1
		Stop
	}
}
ACTOR PistolStackCheck : Inventory
{
	Inventory.MaxAmount 1
}

ACTOR PistolMagCheck : Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 18
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 18
}

ACTOR PistolChamberCheck : Inventory
{
	Inventory.MaxAmount 1 
}

actor PistolPickup : CustomInventory
{
	Inventory.PickupMessage "Picked up a 9mm Pistol."
	Inventory.PickupSound "misc/w_pkup"
	states
	{
    Spawn:
		P45W A -1
		stop
	Pickup:
		P45W A 0 A_JumpIfInventory("GZDA_Pistol",1,5)
		P45W A 0 A_GiveInventory("GZDA_Pistol",1)
		P45W A 0 A_GiveInventory("PistolMagCheck",12)
		P45W A 0 A_GiveInventory("PistolHudCheck1",6)
		P45W A 0 A_GiveInventory("PistolHudCheck2",6)	  
		stop
		P45W A 0 A_JumpIf(ACS_ExecuteWithResult(291,0,0,0)==1,2)
		P45W A 0 A_GiveInventory("PistolAmmo",1)
		stop
		P45W A 0
	}
}

ACTOR EliPistol : DoomWeapon replaces Pistol
{
	Game Doom
	Weapon.SelectionOrder 1900
	Weapon.AmmoType1 "PistolMagCheck"
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 0
	Weapon.AmmoType2 "PistolAmmo"
	Weapon.AmmoGive2 0
	Obituary "$OB_MPPISTOL" // "%o was tickled by %k's pea shooter."
	+WEAPON.WIMPY_WEAPON
	+WEAPON.NOAUTOFIRE	
	Inventory.Pickupmessage "$PICKUP_PISTOL_DROPPED" // "Picked up a pistol."
	
	// Additional Flags
	+AMMO_OPTIONAL
	+NOEXTREMEDEATH
	+NOALERT	
	
	// Soon to be deprecated...
	AttackSound "Pistol/fire"	
	
	States
	{
	Spawn:
		P45W A 1
		stop
	Select:
		P45K A 0 A_PlaySound("weapons/up")
		P45K A 0 A_JumpIfNoAmmo("SelectEmpty") 
		P45K A 1 A_Raise
		Goto Select+2
	SelectEmpty:
		P45K C 1 A_Raise
		Loop
	Deselect: 
		P45K A 0 A_PlaySound("weapons/down")
		P45K A 0 A_JumpIfNoAmmo("DeselectEmpty") 
		P45K A 1 A_Lower
		Goto Deselect+2
	DeselectEmpty:
		P45K C 1 A_Lower
		Loop
	Ready: 
		P45K A 0 A_JumpIfNoAmmo("ReadyEmpty")
		P45K A 0 A_JumpIfInventory("Reload",1,"Reload")
		P45K A 1 A_WeaponReady
		LOOP
	ReadyEmpty:
		P45K C 0 A_JumpIfInventory("PistolMagCheck",1,"Ready")
		P45K C 0 A_JumpIfInventory("Reload",1,"ReloadEmpty")
		P45K C 1 A_WeaponReady
		LOOP
	Reload:
		P45R A 0 A_JumpIfInventory("PistolMagCheck",18,2)
		P45R A 0 A_JumpIfInventory("PistolAmmo",1,"EjectMagazine")
		P45R A 0 A_WeaponReady
		Goto Ready+2
		
	EjectMagazine:
		P45R A 4
		P45R B 4 A_PlaySound("Pistol/out")
		P45R C 4
		P45R D 40
		Goto InsertMagazine
	
	InsertMagazine:
		P45R E 4
		P45R F 4 A_PlaySound("Pistol/in")
		P45R G 4
		P45R I 4
		P45R H 0 A_JumpIfInventory("PistolMagCheck",18,2)
		P45R H 0 A_JumpIfInventory("PistolAmmo",1,2)
		P45R H 0 A_WeaponReady
		Goto Ready+2			
		P45R H 0 A_GiveInventory("PistolMagCheck",1)	
		P45R H 0 A_TakeInventory("PistolAmmo",1)	
		Goto InsertMagazine+4
		
	ReloadEmpty:
		P45R A 0 A_JumpIfInventory("PistolMagCheck",18,2)
		P45R A 0 A_JumpIfInventory("PistolAmmo",1,"EjectMagazineEmpty")
		P45R A 0 A_WeaponReady
		Goto ReadyEmpty+2
		
	EjectMagazineEmpty:
		P45R A 4
		P45R B 4 A_PlaySound("Pistol/out")	
		P45R C 4
		P45R D 40 A_FireCustomMissile("PistolMagEmpty",0,0,0,0)
		Goto InsertMagazineEmpty
		
	InsertMagazineEmpty:
		P45R E 4
		P45R F 4 A_PlaySound("Pistol/in")
		P45R G 4
		P45R H 0 A_JumpIfInventory("PistolMagCheck",17,2)
		P45R H 0 A_JumpIfInventory("PistolAmmo",1,2)
		P45R H 0 A_WeaponReady
		Goto ReleaseSlide
		P45R H 0 A_GiveInventory("PistolMagCheck",1)
		P45R H 0 A_TakeInventory("PistolAmmo",1)
		Goto InsertMagazineEmpty+3
		
	ReleaseSlide:
		P45R H 4 
		P45R I 4 A_PlaySound("Pistol/slide")
		P45K A 4
		P45K A 0 A_Refire
		Goto Ready+2
	Fire:
		P45K A 0 A_JumpIfNoAmmo("ReloadEmpty")
		P45K A 0 A_JumpIfInventory("PistolMagCheck",2,2)
		P45K A 0 A_JumpIfInventory("PistolMagCheck",1,"FireLast")
		
		P45F A 1 Bright A_FireBullets(2, 2, -1, random(1,3)*5, "PistolPuff", FBF_USEAMMO | FBF_NORANDOM)
		P45K A 0 A_FireCustomMissile("PistolSmokeSpawner",0,0,-7.5,10) //-15
		
		P45K A 0 A_AlertMonsters
		P45K C 1 A_SpawnItemEx("PistolCasing",25,0,38,-3+random(-1,1),3+random(-1,1),4+random(-1,1),0,0,0)
		P45K B 1
		P45K A 5
		P45K A 0 A_Refire
		Goto Ready
	FireLast:			
		P45F A 1 Bright A_FireBullets(3, 3, -1, random(1,3)*5, "PistolPuff", FBF_USEAMMO | FBF_NORANDOM)	
		P45K A 0 A_FireCustomMissile("PistolSmokeSpawner",0,0,-7.5,10) //-15
		
		P45K A 0 A_AlertMonsters
		P45K C 3 A_SpawnItemEx("PistolCasing",25,0,38,-3+random(-1,1),3+random(-1,1),4+random(-1,1),0,0,0)
		P45K F 0 A_Refire
		Goto ReadyEmpty
	} 
}