// --------------------------------------------------------------------------
//
//	Machinegun
//
// --------------------------------------------------------------------------
	
ACTOR U_Machinegun : BaseWeapon replaces Machinegun
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 30
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "Clip2"
	Weapon.AmmoType2 "MachinegunAmmo"
	Weapon.SelectionOrder 600
	-WEAPON.CHEATNOTWEAPON
	Inventory.PickupSound "CBOXPKUP"
	Inventory.PickupMessage "You got the Machine Gun!"
	Obituary "%o was mowed down by %k's Machine Gun."
	Scale 0.8
	tag "Machine gun"
	States
	{
	Spawn:
		MGN1 Z -1
		Stop

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist", 1, "PuristGun")
		TNT1 A 0 A_Giveinventory("HeavyAutomaticWeapon",1)
		TNT1 A 0 A_Giveinventory("MinigunSelected",1)
		TNT1 A 0 A_Giveinventory("GoSpecial",1)
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_TakeInventory("TossGrenade", 1)
		TNT1 A 0 A_Takeinventory("WeapSpecial",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
		TNT1 A 0 A_Takeinventory("IdleCounter",200)
		TNT1 A 0 ACS_ExecuteAlways(1044)
		TNT1 A 4
		TNT1 A 0 A_Raise
		Wait

	Deselect:
		MGNS ABCDEF 1
		TNT1 A 0 A_TakeInventory("MinigunSelected", 1)
		TNT1 A 0 A_Takeinventory("HeavyAutomaticWeapon",1)
		TNT1 A 0 A_Lower
		Wait

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality", 1, "Steady")
		TNT1 A 0 A_PlaySound("CHGNPKUP")
	Ready1:
		MGNS FEDCBA 1
	Ready2:
        TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
        TNT1 A 0 A_JumpIfInventory("Taunting",1,"TauntR")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
		TNT1 A 0 A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		MGN1 A 1 A_WeaponReady
		Goto Ready2

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

// --------------------------------------------------------------------------
//
//	Fire
//
// --------------------------------------------------------------------------

	Fire:
		TNT1 A 0 A_JumpIfInventory("MachinegunAmmo", 1, 1)
		Goto Reload
		TNT1 A 0 A_PlaySound("FARHMG", 6)
		TNT1 A 0 A_ZoomFactor(0.98)
		TNT1 A 0 A_FireCustomMissile("YellowFlareSpawn",0,0,0,0)
		TNT1 A 0 A_FireCustomMissile("GunFireSmoke",0,0,0,0,0,0)
		TNT1 A 0 A_Jump(64,3)
		TNT1 A 0 A_FireBullets(4.5, 4.5, -1, 11, "HitPuff")
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_FireBullets(4.5, 4.5, -1, 11, "MachineGunBulletPuff")
		TNT1 A 0 A_FireCustomMissile("DecorativeTracer", frandom(-2,2), 0, 0, -12, 0, frandom(-2,2))
		TNT1 A 0 A_SpawnItemEx("PlayerMuzzle2",30,5,27)
		TNT1 A 0 A_SetPitch(-1.1 + pitch)
		TNT1 A 0 A_JumpIfInventory("FireSeq", 1, 4)
		MGN1 B 1 BRIGHT A_PlaySound("HMGFIRE")
		TNT1 A 0 A_GiveInventory("FireSeq",1)
		TNT1 A 0 A_Jump(256,3)
		MGN1 K 1 BRIGHT A_PlaySound("HMGFIRE")
		TNT1 A 0 A_TakeInventory("FireSeq",1)
		TNT1 A 0 A_TakeInventory("MachinegunAmmo",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Firecustommissile("RifleCaseSpawn",5,0,5,-12)
		MGN1 DE 1 A_SetPitch(0.4 + pitch)
		TNT1 A 0 A_Refire
		goto Ready2

	AltFire:
		TNT1 A 0 A_PlaySound("weapons/firegrenade")
		TNT1 A 0 A_JumpIfInventory("FiredGrenade", 1, "ReloadGrenade")
		TNT1 A 0 A_FireCustomMissile("RedFlareSpawn",-5,0,0,0)
		TNT1 AAAAAA 0 A_FireCustomMissile("ShotgunParticles", random(-16,16), 0, -1, random(-9,9))
		MGN2 A 1 BRIGHT A_FireCustomMissile("ShortGrenade", 0, 1, 0, 0)
		TNT1 A 0 A_SetPitch(-5.0 + pitch)
		MGN2 BC 1 BRIGHT A_SetPitch(1.0 + pitch)
		MGN2 DEF 1 A_SetPitch(1.0 + pitch)
		TNT1 A 0 A_GiveInventory("FiredGrenade", 1)
		MGN1 A 10
		TNT1 A 0 A_Refire
		goto Ready2

	DryFire:
		MGN1 A 5 A_PlaySound("weapons/empty")
		goto Ready2

	DryFireAlt:
		MGN1 A 5 A_PlaySound("weapons/empty2")
		goto Ready2

// --------------------------------------------------------------------------
//
//	Reload
//
// --------------------------------------------------------------------------

	ReloadGrenade:
		TNT1 A 0 A_JumpIfInventory("AmmoRocket",1,1)
		Goto DryFireAlt
		TNT1 A 0 A_PlaySound("GRLLO1")
		MGN2 GHIJJJJJJJJKLM 1
		MGN2 M 30
		TNT1 A 0 A_PlaySound("InsertShell")
		MGN2 NOPON 1
		MGN2 M 30
		TNT1 A 0 A_PlaySound("GRLLO2")
		TNT1 A 0 A_TakeInventory("FiredGrenade", 1)
		TNT1 A 0 A_TakeInventory("AmmoRocket",1)
		MGN2 MLKJJJJJJJJIHG 1
		TNT1 A 0 A_Refire
		Goto Ready2
		
    Reload:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("MachinegunAmmo",60,"Ready2")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto DryFire
		TNT1 A 0 A_JumpIfInventory("TurboReload",1,"ReloadLoop")
		TNT1 A 0 A_JumpIfInventory("MachinegunAmmo",1,"Reload2")
		TNT1 A 0 A_PlaySound("PistolReload2")
		MGNR ABCDEFG 1
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		MGNR G 10
		TNT1 A 0 A_PlaySound("PistolReload5")
		MGNR HIJKL 1
		TNT1 A 0 A_PlaySound("PistolReload3",5,0.5)
		MGNR M 4
		MGNR NOP 1
		MGN2 KKJIHG 1
		Goto ReloadLoop
		
    Reload2:
		MGN2 GHIJKLMMMMMM 1
		TNT1 A 0 A_PlaySound("PistolReload2")
		MGNR PONMMMLKJIH 1
		MGNR G 20
		TNT1 A 0 A_PlaySound("PistolReload5")
		MGNR HIJKL 1
		TNT1 A 0 A_PlaySound("PistolReload3",5,0.5)
		MGNR M 4
		MGNR NOP 1
		MGN2 KKJIHG 1
		Goto ReloadLoop

	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("MachinegunAmmo",60,"ReloadDone")
		TNT1 A 0 A_JumpIfInventory("Clip2",1,1)
		Goto ReloadDone
		TNT1 A 0 A_Giveinventory("MachinegunAmmo",1)
		TNT1 A 0 A_Takeinventory("Clip2",1)
		Goto ReloadLoop

	ReloadDone:
		TNT1 A 0 A_Refire
		Goto Ready2

// --------------------------------------------------------------------------
//
//	End Stuff
//
// --------------------------------------------------------------------------

	KickFlash:
		MGNK ABCD 1
		MGNK E 9
		MGNK DCBA 1
		MGN1 A 1
		Stop

	AirKickFlash:
		MGNK ABCD 1
		MGNK E 11
		MGNK DCBA 1
		MGN1 A 1
		Stop

	TauntFlash:
		MGNK ABCD 1
		MGNK E 36
		MGNK DCBA 1
		MGN1 A 1
		Stop

	GrenadeFlash:
		MGNS ABCDEF 1
		Stop
	}
}

ACTOR MachinegunAmmo : Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 60
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 60
   	Inventory.Icon "MGN1Z0"
}