ACTOR PPSHPrimary : Ammo
{
  Inventory.Amount 1
  Inventory.MaxAmount 100
  Ammo.BackpackAmount 1
  Ammo.BackpackMaxAmount 100
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
}

ACTOR PPSHSecondary : Ammo
{
  Inventory.PickupMessage "You picked up a drum of PPSH-41 ammunition." // "Picked up a clip."
  Inventory.PickupSound "bullpup/magin"
  Inventory.Amount 70
  Inventory.MaxAmount 420
  Ammo.BackpackAmount 140
  Ammo.BackpackMaxAmount 420
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

ACTOR PPSHBolt : Inventory { Inventory.MaxAmount 1 }

ACTOR "PPSH-41" : Weapon 11500
{
   Weapon.SelectionOrder 700
   Weapon.AmmoUse 0
   Weapon.AmmoUse2 0
   Weapon.AmmoGive2 70
   Weapon.AmmoType "PPSHPrimary"
   Weapon.AmmoType2 "PPSHSecondary"
   +WEAPON.NOAUTOFIRE
   +WEAPON.AMMO_OPTIONAL
   Inventory.PickupMessage "You picked up the PPSH-41." // "You got the chaingun"
   Obituary "%k \cG> \cKPPSH-41 \cG> \cJo" // "%o was mowed down by %k's chaingun."
   Tag "PPSH-41"
   States
   {
   Ready:
	 PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
	 PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
     PPSI A 1 A_WeaponReady
     Loop
   QuickMelee:
	 PPSM A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM B 0 A_PlaySoundEx("fist/swing","Weapon")
	 PPSM B 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM D 0 A_CustomPunch (random(4,5),1,0,"BlockPuff")
	 PPSM C 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM D 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM E 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM FGHI 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSM A 0 A_TakeInventory("DoBlocking",1)
	 Goto Ready
   Deselect:
	 PPSS CBA 1
	 PPFI A 0 A_TakeInventory("HasFiringModes",1)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 TNT1 AAAAAAAAAA 0 A_Lower
     TNT1 A 1 A_Lower
     Goto Deselect+5
   Select:
	 TNT1 A 0 A_Raise
	 TNT1 A 1 A_WeaponReady
     Goto SelectAnim
   SelectAnim:
	 TNT1 A 0 A_SetCrosshair(17)
	 TNT1 A 0 A_GiveInventory("HasFiringModes",1)
	 PPSS A 0 A_PlaySoundEx("ppsh/select","SoundSlot6")
	 PPSS ABC 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto Ready
   AltFire:
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToFull")
	 Goto ToSemi
   ToFull:
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 TNT1 A 0 A_SetCrosshair(17)
	 PPFI A 0 A_Print("Switched to Fully Automatic mode.")
	 Goto Ready
   ToSemi:
	 TNT1 A 0 A_SetCrosshair(18)
	 PPFI A 0 A_GiveInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Semi Automatic mode.")
	 Goto Ready
   DryFire:
	 NULL A 0 A_PlaySoundEx("orderpistol/dryfire","SoundSlot6")
	 Goto Ready
   Fire:
	 PPFI A 0 A_JumpIfInventory("PPSHPrimary",1,1)
	 Goto DryFire
	 PPFI A 0 A_TakeInventory("PPSHPrimary",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,2,0,0), ACS_ExecuteWithResult(566,2,0,0), 1, 5, "BulletPuff2")
	 PPFI A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("ppsh/fire", CHAN_WEAPON)
	 PPFI A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_FireCustomMissile("MuzzleSmokeFX",0,0,4,0)
	 PPFI A 0 A_SetPitch(Pitch-1.5)
	 PPFI A 0 A_Jump(255,"MF1","MF2","MF3","MF4")
	 Goto MF1
   MF1:
	 PPSI B 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto PostFire
   MF2:
	 PPSI C 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto PostFire
   MF3:
	 PPSI D 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto PostFire
   MF4:
	 PPSI E 1 bright A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto PostFire
	 
   PostFire:
	 PPFI A 0 A_SetPitch(Pitch+1.0)
	 PPSI F 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSI A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"Ready")
	 PPFI A 0 A_ReFire
     Goto Ready
	 
	 
   //=================================================================================
  // AMMO CHECKING
  //=================================================================================
  ReloadCheck:
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",1,"ActualCheck")
	 TNT1 A 0 A_GiveInventory("PPSHBolt",1)
	 Goto ActualCheck
  ActualCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",70,"Ready")
	 TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,"ReloadAnim")
	 Goto Ready
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",85,"Ready")
	 TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,"ReloadAnim")
	 Goto Ready
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",100,"Ready")
	 TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,"ReloadAnim")
	 Goto Ready
  //=================================================================================
  
  
  ReloadAnim:
	 PPRL ABCDEF 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL G 0 A_PlaySoundEx("ppsh/magout","SoundSlot6")
	 PPRL GHI 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL J 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL K 5 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL L 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL MNO 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 Goto CalculateAmmo
	 
  //=================================================================================
  // AMMO CALCULATION
  //=================================================================================
  CalculateAmmo:
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"CalculateAmmoPerk")
     TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,2)
	 Goto ReloadEnd
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",70,"ReloadEnd")
	 TNT1 A 0 A_TakeInventory("PPSHSecondary",1)
	 TNT1 A 0 A_GiveInventory("PPSHPrimary",1)
	 Loop
  CalculateAmmoPerk:
     TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CalculateAmmoPerk10")
     TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,2)
	 Goto ReloadEnd
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",85,"ReloadEnd")
	 TNT1 A 0 A_TakeInventory("PPSHSecondary",1)
	 TNT1 A 0 A_GiveInventory("PPSHPrimary",1)
	 Loop
  CalculateAmmoPerk10:
     TNT1 A 0 A_JumpIfInventory("PPSHSecondary",1,2)
	 Goto ReloadEnd
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("PPSHPrimary",100,"ReloadEnd")
	 TNT1 A 0 A_TakeInventory("PPSHSecondary",1)
	 TNT1 A 0 A_GiveInventory("PPSHPrimary",1)
	 Loop
  //=================================================================================
	 
   ReloadEnd:
	 PPRL G 0 A_PlaySoundEx("ppsh/magin","SoundSlot6")
	 PPRL P 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL Q 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL RSTU 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL A 0 A_JumpIfInventory("PPSHBolt",1,"BoltPull")
	 PPRL A 0 A_TakeInventory("IsReloading",1)
	 Goto Ready
	
   BoltPull:
     PPSI A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB AB 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB C 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB D 3 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB E 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRM E 0 A_PlaySoundEx("ppsh/boltback","SoundSlot6")
	 PPSB E 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB FG 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB H 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB I 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRM E 0 A_PlaySoundEx("ppsh/boltfwd","SoundSlot6")
	 PPSB I 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPSB JKLMN 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	 PPRL A 0 A_TakeInventory("IsReloading",1)
	 PPRL A 0 A_TakeInventory("PPSHBolt",1)
	 Goto Ready
	 
   Flash:
     CHGF A 5 Bright A_Light1
     Goto LightDone
     CHGF B 5 Bright A_Light1
     Goto LightDone
   Spawn:
     MGUN A -1
     Stop
   }
}