ACTOR PDCMP150 : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "CMP-150"
        Weapon.Ammotype1 "CMP150Clip"
  Weapon.Ammotype2 "PDPistolAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 32
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a CMP-150."
  Obituary  "%k picked off %o with his CMP-150."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKA4 I -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TK37 A 2 
    TK37 B 2
    TK37 C 2
    TK37 D 2
    TK37 EF 2
    TK37 G -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TK37 G 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("CMP150Clip",32,2)
	 KLBG A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+7

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/CMP150Reload")
     TK37 YZ 2
	 TK38 ABCDEFG 2
	 TK38 HIJKLMNOPQRSTUVXYZ 1
	 TK39 ABCDEFGHIJKLMNOPQRSTU 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDPistolAmmo",1)
	 TNT1 A 0 A_GiveInventory("CMP150Clip",1)
	 TNT1 A 0 A_JumpIfInventory("CMP150Clip",32,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TK39 VXYZ 1
	 TK40 ABCDEFGHIJK 1
	 Goto Ready+7
	
  Deselect:
    TK37 TUVX 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/CMP150","Weapon")
    TK37 H 1 BRIGHT A_FireBullets(2, 2, 1, 6, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 25,cos(pitch)*4,sin(-pitch)*0+30, frandom(0.5,1.2),frandom(-2.5,1.2),frandom(1.5,2.5))
    TK37 I 2 
	TK37 J 2 A_REFIRE
	TK37 KLMNOPQRS 2 
    Goto Ready+7
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

ACTOR CMP150Clip : Ammo
{
Inventory.MaxAmount 32 // size of the clip
Ammo.BackpackAmount 0
Ammo.BackpackMaxAmount 32 //MUST be the same as Inventory.MaxAmmount
+INVENTORY.IGNORESKILL
}

ACTOR PDCMP150Pickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a CMP-150."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKA4 I -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDCMP150")
	  TNT1 A 0 A_JumpIfInventory("PlayingasPerfectKirby",1,"PickupPerfectKirby")
	  TNT1 A 0 A_JumpIfInventory("PlayingasRED",1,"PickupRED")
	  stop
	  PickupPerfectKirby:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/PerfectKirby/PerfectKirbyWeaponPickup")
		Stop
	  PickupRED:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/RED/REDWeaponPickup")
		Stop
   }
}
