ACTOR PDRCP45 : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "RC-P45"
        Weapon.Ammotype1 "RCP45Clip"
  Weapon.Ammotype2 "PDPistolAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 80
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a RC-P45."
  Obituary  "%k's RC-P45 cleared the room %o was hiding in."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKB4 O -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TL47 A 2 
    TL47 B 2
    TL47 C 2
    TL47 D 2
    TL47 EFGHIJKLMN 1
    TL47 O -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TL47 O 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("RCP45Clip",80,2)
	 KLBG A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+14

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/GoldenEyeReload")
     TL48 IJKL 2
	 TNT1 A 10
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDPistolAmmo",1)
	 TNT1 A 0 A_GiveInventory("RCP45Clip",1)
	 TNT1 A 0 A_JumpIfInventory("RCP45Clip",80,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TL48 MNOPQRST 2
	 Goto Ready+14
	
  Deselect:
    TL48 EFGH 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/RCP45","Weapon")
    TL47 P 1 BRIGHT A_FireBullets(1, 1, 1, 11, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TL47 Q 1 
	TL47 R 1 A_REFIRE
	TL47 STUVXYZ 2  
	TL48 ABCD 2
    Goto Ready+14
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDRCP45Pickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a RC-P45."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKB4 O -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDRCP45")
	  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
   }
}
