// --------------------------------------------------------------------------
//
//	MP40
//
// --------------------------------------------------------------------------

ACTOR U_MP40 : BaseWeapon replaces MP40
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 20
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "9mmMagazine"
	Weapon.AmmoType2 "MP40Ammo"
	Weapon.SelectionOrder 5500
	Obituary "%o was shot down by %k's MP40."
    Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "You got the MP40!"
    Scale 0.5
	tag "MP40"
	States
	{
 	Spawn:
		MP40 J -1
		Stop

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
        TNT1 A 0 A_PlaySound("CLIPIN")
	Ready1:
        MP4Z ABCDEFG 1
		Goto Ready2

	Ready2:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ReadyZoomed")
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"TauntL")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,2)
		MP40 A 1 A_WeaponReady
		Goto Ready2
		MP40 F 1 A_WeaponReady
		Loop

	ReadyZoomed:
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"ZoomOut")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"ZoomOut")
        TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("Unloading",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"ZoomOut")
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,2)
		MP41 A 1 A_WeaponReady
		Goto ReadyZoomed
		MP41 F 1 A_WeaponReady
		Loop

	Deselect:
		TNT1 A 0 A_PlaySound("weapons/changing")
		TNT1 A 0 A_Takeinventory("Zoomed",1)
		TNT1 A 0 A_Takeinventory("HasUnloaded",1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		MP4Z GFEDCBA 1
		TNT1 A 0 A_Lower
		Wait

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
	    TNT1 A 0 A_Takeinventory("FistsSelected",1)
		TNT1 A 0 A_Takeinventory("SawSelected",1)
		TNT1 A 0 A_Takeinventory("ShotgunSelected",1)
		TNT1 A 0 A_Takeinventory("SSGSelected",1)
		TNT1 A 0 A_Takeinventory("MinigunSelected",1)
		TNT1 A 0 A_Takeinventory("PlasmaGunSelected",1)
		TNT1 A 0 A_Takeinventory("RocketLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("GrenadeLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("BFGSelected",1)
		TNT1 A 0 A_Takeinventory("BFG10kSelected",1)
		TNT1 A 0 A_Takeinventory("RailGunSelected",1)
		TNT1 A 0 A_Giveinventory("SubMachineGunSelected",1)
		TNT1 A 0 A_Takeinventory("RevenantLauncherSelected",1)
		TNT1 A 0 A_Takeinventory("LostSoulSelected",1)
		TNT1 A 0 A_Takeinventory("FlameCannonSelected",1)
		TNT1 A 0 A_Takeinventory("HasBarrel",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 3
		TNT1 A 0 A_Raise
		Wait

	PuristGun:
		TNT1 A 0 A_TakeInventory("MP40", 1)
		Goto Deselect

	DryFire:
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,"Reload")
		TNT1 A 0 A_PlaySound("weapons/empty", 5)
		TNT1 A 0 A_Giveinventory("BoltInFront",1)
		TNT1 A 0 A_Refire
		Goto Ready2

    Fire:
        TNT1 A 0 A_JumpIfInventory("MP40Ammo",1,1)
        Goto DryFire
	    TNT1 A 0 A_JumpIfInventory("Zoomed",1,"FireZoomed")
        TNT1 A 0 A_PlaySound("MP40")
		TNT1 A 0 A_Takeinventory("MP40Ammo",1)
        TNT1 A 0 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,0,0)
		MP40 B 1 BRIGHT A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssMinor", 0, 0, 0, 0)
		TNT1 A 0 A_SetPitch(-1.0 + pitch)
		MP40 C 1 A_FireBullets (3, 3, -1, 13, "HitPuff")
		TNT1 A 0 A_SetPitch(+0.4 + pitch)
		MP40 D 1 A_FireCustomMissile("9mmCaseSpawn",5,0,6,-10)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
        MP40 E 1
		TNT1 A 0 A_SetPitch(+0.2 + pitch)
        TNT1 A 0 A_Refire
		Goto Ready2

	FireZoomed:
        TNT1 A 0 A_PlaySound("MP40")
		TNT1 A 0 A_Takeinventory("MP40Ammo",1)
        TNT1 A 0 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",-5,0,0,0)
		MP41 B 1 BRIGHT A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile("ShakeYourAssMinor", 0, 0, 0, 0)
		TNT1 A 0 A_SetPitch(-0.9 + pitch)
		MP41 C 1 A_FireBullets (1.5, 1.5, -1, 13, "HitPuff")
		TNT1 A 0 A_SetPitch(+0.4 + pitch)
		MP41 D 1 A_FireCustomMissile("9mmCaseSpawn",5,0,4,-2)
		TNT1 A 0 A_SetPitch(+0.3 + pitch)
        MP41 E 1
		TNT1 A 0 A_SetPitch(+0.25 + pitch)
        TNT1 A 0 A_Refire
		Goto ReadyZoomed

	AltFire:
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,"ZoomOut")
		TNT1 A 0 A_Giveinventory("Zoomed",1)
        TNT1 A 0 A_ZoomFactor(1.5)
		TNT1 A 0 A_Giveinventory("ADSmode",1)
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,4)
        MP4D CBA 1
        Goto ReadyZoomed
        MP4D FED 1
        Goto ReadyZoomed

	ZoomOut:
        TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,5)
        MP4D ABC 1
		TNT1 A 0 A_Jump(256,4)
        MP4D DEF 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
        Goto Ready2

	Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("MP40Ammo",32,"Ready2") //Check if weapon is full already.
        TNT1 A 0 A_JumpIfInventory("9mmMagazine",1,1) //Check if we have spare ammo.
        Goto Ready2
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("Zoomed",1,2) //Check if zoomed
		TNT1 A 0 A_Jump(256, 7)
		MP4D DEF 1
		TNT1 A 0 A_Takeinventory("Zoomed",1)
        TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,2) //Check bolt
		TNT1 A 0 A_PlaySound("weapons/empty", 5)
		MP40 F 1 A_WeaponReady
        TNT1 A 0 A_PlaySound("Reload")
		TNT1 A 0 A_GiveInventory ("Pumping", 1)
		TNT1 A 0 A_JumpIfInventory("MP40Ammo",1, "Reload2") //Check if there is any bullet left in the magazine.
		TNT1 A 0 A_JumpIfInventory("HasUnloaded", 1, "Reload3") //Check if weapon has a magazine.
		MP4R ABJCDEF 1 //no bullet in magazine
		TNT1 A 0 A_FireCustomMissile("EmptyMag9mm",-5,0,8,-4)
		MP4R GGGGFHICC 1
		Goto InsertBullets
	Reload2:
		MP4R ABJCIHF 1 //bullet in magazine
		TNT1 A 0 A_FireCustomMissile("EmptyMag9mm",-5,0,8,-4)
		MP4R GGGGFHICC 1
		Goto InsertBullets
	Reload3:
		MP4U CBA 2 //reload when unloaded
		TNT1 A 0 A_Takeinventory("HasUnloaded",1)
		MP4R GGGGFHICC 1
		Goto InsertBullets

	InsertBullets:
		TNT1 A 0 A_JumpIfInventory("MP40Ammo",32,5)
		TNT1 A 0 A_JumpIfInventory("9mmMagazine",1,2)
		TNT1 A 0 A_Jump(255, 3)
		TNT1 A 0 A_Giveinventory("MP40Ammo",1)
		TNT1 A 0 A_Takeinventory("9mmMagazine",1)
		Goto InsertBullets
		MP4R CKLLM 2
		TNT1 A 0 A_PlaySound("SLAPBABY")
		MP4R NOOPQRL 2
		MP4R LKCJBA 1
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_Takeinventory("BoltInFront",1)
        Goto Ready2

	Unload:
		TNT1 A 0 A_Takeinventory("Unloading",1)
        TNT1 A 0 A_JumpIfInventory("MP40Ammo",1,1)
        Goto Ready2
		//TNT1 A 0 A_JumpIfInventory("Zoomed",1,2)
		//TNT1 A 0 A_Jump(256, 7)
		//MP4D ABC 1
		//TNT1 A 0 A_Takeinventory("Zoomed",1)
        //TNT1 A 0 A_ZoomFactor(1.0)
		//TNT1 A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_JumpIfInventory("BoltInFront",1,2)
		TNT1 A 0 A_PlaySound("weapons/empty", 5)
		MP40 F 1 A_WeaponReady
		TNT1 A 0 A_PlaySound("Reload")
		MP4R ABJCHIIFFFGGGG 1
		TNT1 A 0 A_GiveInventory("Pumping", 1)
		TNT1 A 0 A_Takeinventory("Unloading",1)

	RemoveBullets:
		TNT1 A 0 A_JumpIfInventory("MP40Ammo",1,1)
		Goto FinishUnload
		TNT1 A 0 A_Takeinventory("MP40Ammo",1)
		TNT1 A 0 A_Giveinventory("9mmMagazine",1)
		Goto RemoveBullets

	FinishUnload:
		MP4U ABC 2
		TNT1 A 0 A_PlaySound("DryFire")
		TNT1 A 0 A_GiveInventory("HasUnloaded", 1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		Goto Ready2

	KickFlash:
		MP4K ABCDE 1
		MP4K F 6
		MP4K EDCBA 1
		Stop

	AirKickFlash:
		MP40 A 1
		MP4Z GFE 1
		MP4Z D 10
		MP4Z EFG 1
		MP40 A 1
		Stop

	TauntFlash:
		MP4R ABJCK 1
		MP4R L 31
		MP4R KCJBA 1
		MP40 A 2
		Stop

	GrenadeFlash:
		MP4Z GFEDCBA 1
		Stop
	}
}

Actor BoltInFront : Inventory
{
	inventory.maxamount 1
}