// --------------------------------------------------------------------------
//
// HKP2000 (Weapon)
//
// --------------------------------------------------------------------------

ACTOR "HKP2000" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon hkp2000_rat

+AMMO_OPTIONAL

	Weapon.SelectionOrder 600
  weapon.ammotype "HKP2000Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "357sigAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //20
	obituary "%k killed %o with P2000."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a P2000."
	Tag "P2000"
	Weapon.UpSound "HKP2000/Ready"
	//AttackSound "HKP2000/Fire" 
	Scale 0.2
	+NOAUTOFIRE

	States
	{
	Ready:
		W17E P 1 A_WeaponReady
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotReady")
		Loop
		


	Deselect:
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
	Goto DeselectLoop
		
	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 240, 0, 0)//Weapon Weight
	TNT1 A 1 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelect")

		W17A BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W17B ABCDEFGHI 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		W17A BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W17B ABCDEFGHI 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready

	Fire:

	W17D U 0 A_JumpIfNoAmmo("AltFire")
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
	
		W17D A 1 A_GunFlash
		W17D B 1 A_WEAPONREADY(WRF_NOFIRE)
		W17D C 1 A_WEAPONREADY(WRF_NOFIRE)
		//W17D D 1

		//TNT1 A 0 A_Refire
		W17D DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W17E ABCDEFGHIJKLMNOP 1 A_WeaponReady
		Goto Ready








//Bot compatibility

	BotReady:
		
		W17E P 1 A_WeaponReady
		TNT1 A 0 A_REFIRE
		Loop


	BotFire:
		W17D A 1 A_GunFlash
		W17D B 1 A_WEAPONREADY(WRF_NOFIRE)
		W17D CDE 1 A_WEAPONREADY(WRF_NOFIRE)
		W17D DEFGHIJKLMNOPQRSTUVWXYZ 1 A_Refire
		W17E ABCDEFGHIJKLMNOP 1 A_Refire

		Goto Ready




  Altfire:
    TNT1 A 0 A_JumpIfInventory("HKP2000Clip",13,"Ready")
    TNT1 A 0 A_JumpIfInventory("357sigAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W17F ABCDEFGHIJKLM 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("HKP2000/Reload", 6)
		W17F NOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W17G ABCDEFGH 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmo
	
	
  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("HKP2000Clip",1)
    TNT1 A 0 A_TakeInventory("357sigAmmo",1)
    TNT1 A 0 A_JumpIfInventory("HKP2000Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("357sigAmmo",1,"ReloadAmmo")
    goto ReloadEnd		

	ReloadEnd:
		W17G IJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W17H ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W17I AB 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_JumpIfInventory("Fire_Holdkey",1,"Fire")//A_Refire
		Goto Ready




	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
	TNT1 A 0 A_GiveInventory("CrosshairGrow", 7)
	    TNT1 A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,10,5)
TNT1 A 0 A_PlaySound ("HKP2000/FIRE")
		TNT1 A 0 A_PlaySound("HKP2000/Distant", 7)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-1.5,1.5), 0, 11, 0, 0, frandom(-1.5,1.5))
		TNT1 A 2 A_FireBullets(0.3, 0.3, -1, 35.0, "hkp2000Bullet")//6.55
		Goto LightDone
 	Spawn:
		W17Z A -1
		Stop
	}
}