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

ACTOR MP40Secondary : Ammo
{
  Inventory.PickupMessage "You picked up a mag of MP40 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 "MP40" : Weapon 11453
{
  Weapon.AmmoUse 0
  Weapon.AmmoGive2 70
  Weapon.AmmoType "MP40Primary"
  Weapon.AmmoType2 "MP40Secondary"
  Obituary "\cJ%k \cG> \cKMP40 \cG> \cJ%o"
  Inventory.Pickupmessage "You picked up the Maschinenpistole 40."
  Inventory.PickupSound "ppsh/pickup"
	//$Category ZT2 - Weapons
	//$Title PPSH-41
	//$Sprite PPSHF0
  Tag "Maschinenpistole 40"
  +WEAPON.NOAUTOFIRE
  Scale 0.75
  States
  {
  Ready:
	PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
	PPSS A 0 //A_JumpIfInventory("QuickGrenading",1,"ToGrenade")
	PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
    MP40 A 1 A_WeaponReady
    Goto Ready
  ToGrenade:
	PPSS A 0 A_SelectWeapon("Type-97 Grenade")
	Goto Deselect
  QuickMelee:
	PPBL A 1
	PPBL B 0 A_PlaySoundEx("fist/swing","Weapon")
	PPBL BC 1
	PPBL D 0 A_CustomPunch (random(4,5),1,0,"BlockPuff")
	PPBL D 2
	PPBL E 4
	PPBL DCBA 2
	PPBL A 0 A_TakeInventory("DoBlocking",1)
	Goto Ready
  ToReady:
	NULL A 0
	Goto Ready
	NULL AAA 0
	NULL A 0 A_PlaySoundEx("dryfire/smg","SoundSlot6")
	Goto Ready
  Deselect:
	 MPSL DCBA 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+4
  Select:
	 TNT1 A 0 A_SetCrosshair(17)
	 TNT1 AA 0 A_Raise
	 TNT1 A 1 A_WeaponReady
	 TNT1 A 0 A_PlaySoundEx("cloth/melee","SoundSlot6")
	 Goto SelectAnim
  SelectAnim:
	 MPSL ABCD 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto Ready
  //=================================================================================
  // AMMO CHECKING
  //=================================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",32,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",40,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",48,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,"BoltCheck")
	 Goto ToReady
  //=================================================================================
  
  BoltCheck:
	 TNT1 A 0 A_TakeInventory("PullBolt",1)
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",1,"ReloadAnim")
	 TNT1 A 0 A_GiveInventory("PullBolt",1)
	 Goto ReloadAnim
  
  ReloadAnim:
     9MRL A 0 ACS_ExecuteAlways(820,0,0,0,0)
	 40RL ABCD 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL E 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL FG 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL H 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL I 0 A_PlaySoundEx("mp40/magout","SoundSlot6")
	 40RL IJK 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL L 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL M 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL N 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL O 4 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL P 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL QRST 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL I 0 A_PlaySoundEx("mp40/magin","SoundSlot6")
	 40RL U 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL V 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL W 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL X 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL YZ 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM A 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM A 0 A_JumpIfInventory("PullBolt",1,"BoltPull")
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 Goto CalculateAmmo
  BoltPull:
	 40RM BCDE 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM F 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM G 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL I 0 A_PlaySoundEx("mp40/boltback","SoundSlot6")
	 40RM G 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM HIJ 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM K 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RM L 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 40RL I 0 A_PlaySoundEx("mp40/boltfwd","SoundSlot6")
	 40RM MNO 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 Goto CalculateAmmo
  //=================================================================================
  // AMMO CALCULATION
  //=================================================================================
  CalculateAmmo:
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"CalculateAmmoPerk")
     TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",32,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP40Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP40Primary",1)
	 Loop
  CalculateAmmoPerk:
     TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CalculateAmmoPerk10")
     TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",40,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP40Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP40Primary",1)
	 Loop
  CalculateAmmoPerk10:
     TNT1 A 0 A_JumpIfInventory("MP40Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP40Primary",48,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP40Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP40Primary",1)
	 Loop
  //=================================================================================
  Fire:
	 PPFI A 0 A_JumpIfInventory("MP40Primary",1,1)
	 Goto ToReady+2
	 PPFI A 0 A_TakeInventory("MP40Primary",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,3,0,0), ACS_ExecuteWithResult(566,3,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("mp40/fire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch-0.5)
	 PPFI A 0 A_Jump(255,"Flash1","Flash2","Flash3")
	 Goto Flash1
  Flash1:
	 MP40 B 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  Flash2:
	 MP40 D 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  Flash3:
	 MP40 E 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  FireEnd:
	 PPFI A 0 A_SetPitch(pitch+0.4)
	 MP40 C 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"Ready")
	 PPFI A 0 A_ReFire
	 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
  Spawn:
    PPSH F -1
    Stop
  }
}