Actor StartAmmoAGL : Inventory
{Inventory.MaxAmount 1}

// --------------------------------------------------------------------------
//
// Grenade launcher
//
// --------------------------------------------------------------------------

ACTOR AutoGrenadeLauncher: BrutalWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 12
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "GrenadeAmmo"
	Weapon.AmmoType2 "AGLAmmo"
	Weapon.SelectionOrder 6000
	-WEAPON.CHEATNOTWEAPON
	AttackSound "None"
	Inventory.PickupSound "ROCKPKUP"
	Inventory.Pickupmessage "You got the Automatic Grenade launcher!"
	Obituary "%o was shot down by %k's Automatic Grenade launcher"
	Scale 1.0
	tag "Automatic Grenade launcher"
	States
	{
	Spawn:
		GLRW A -1
		Stop

	Select:
		TNT1 A 0 A_JumpIfInventory("IsPlayingAsPurist",1,"PuristGun")
	//	TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(1001,7)==0,"PuristGun")

TNT1 A 0
TNT1 A 0 A_JumpIfInventory("StartAmmoAGL",1,"Selected")
TNT1 A 0 A_GiveInventory("AGLAmmo",6)
TNT1 A 0 A_GiveInventory("StartAmmoAGL",1)
Selected:


TNT1 A 0 A_Giveinventory("GrenadeLauncherSelected",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("SwitchFlashlight",1)
		TNT1 A 0 A_Takeinventory("Taunting",1)
	//	TNT1 A 0 A_Takeinventory("IdleCounter",200)
		TNT1 A 4
		TNT1 A 0 A_Raise
		Wait

	Deselect:
		TNT1 A 0 A_PlaySound("weapons/changing")
		GLRS ABCDEF 1
TNT1 A 1 A_Takeinventory("GrenadeLauncherSelected",1)
	TNT1 A 0 A_TakeInventory("TossGrenade",1)
		TNT1 A 0 A_Lower
		Wait

	Ready:
		TNT1 A 0 A_JumpIfInventory("GoFatality",1,"Steady")
		TNT1 A 0 A_PlaySound("RLANDRAW",5)
	Ready1:
		 GLRS FEDCBA 1
TNT1 A 0 A_GunFlash
	Ready2:
		//TNT1 A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Reload")
TNT1 A 0 A_JumpIfInventory("Unloading",1,"Unload")
	//	TNT1 A 0 A_JumpIfInventory("Taunting",1,"Taunt")
		TNT1 A 0 A_JumpIfInventory("Salute1",1,"Salute")
		TNT1 A 0 A_JumpIfInventory("Salute2",1,"Salute")
//TNT1 A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
TNT1 A 0 A_WeaponReady(WRF_ALLOWRELOAD) //A_JumpIfInventory("IdleCounter",200,"PlayerIsIdle")
		GLRS A 1 A_WeaponReady
		Loop

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

	Fire:
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",1,1)
		Goto Reload
		TNT1 A 0 A_FireCustomMissile("RedFlareSpawn",-5,0,0,0)
		//TNT1 A 0 A_PlaySound("DSRFIRE",1)
		TNT1 A 0 A_PlaySound("weapons/firegrenade",1,0.7)
		TNT1 A 0 A_FireCustomMissile("Alerter")
		GLRF AB 1 BRIGHT
		TNT1 A 0 A_FireCustomMissile("AGLMissile",frandom(-1,1),1,0,-5,0,frandom(4,5))
		TNT1 A 0 A_Takeinventory("AGLAmmo",1)
		TNT1 A 0 A_AlertMonsters
		GLRF C 1 BRIGHT A_SetPitch(-3.0 + pitch)
		GLRF D 1 A_SetPitch(-1.0 + pitch)
		GLRS AAAA 1 A_SetPitch(0.6 + pitch)
		GLRF EFG 1 A_SetPitch(0.3 + pitch)
		GLRS A 1
		TNT1 A 0 A_Refire
		Goto Ready2

	AltFire:
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",1,1)
		Goto Reload
		TNT1 A 0 A_FireCustomMissile("RedFlareSpawn",-5,0,0,0)
		//TNT1 A 0 A_PlaySound("DSRFIRE",1)
		TNT1 A 0 A_PlaySound("weapons/firegrenade",1,0.7)
		TNT1 A 0 A_FireCustomMissile("Alerter")
		GLRF AB 1 BRIGHT
		TNT1 A 0 A_FireCustomMissile("AGLMissileAlt",frandom(-1,1),1,0,-5,0,frandom(4,5))
		TNT1 A 0 A_Takeinventory("AGLAmmo",1)
		TNT1 A 0 A_AlertMonsters
		GLRF C 1 BRIGHT A_SetPitch(-3.0 + pitch)
		GLRF D 1 A_SetPitch(-1.0 + pitch)
		GLRS AAAA 1 A_SetPitch(0.6 + pitch)
		GLRF EFG 1 A_SetPitch(0.3 + pitch)
		GLRS A 1
		TNT1 A 0 A_Refire
		Goto Ready2

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

    Reload:
		GLRS A 1 A_WeaponReady
		GLRS A 6
		TNT1 A 0 A_Takeinventory("Reloading",1)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",6,"Ready2")
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,"Reloadin")
goto Ready2
		Reloadin:
		TNT1 A 0 A_PlaySound("Reload",5)
		GLRR ABCDE 1
		
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",5,10)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",4,8)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",3,6)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",2,4)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",1,2)
		TNT1 AAAAAA 0 A_FireCustomMissile("AGLCasing",random(-80,-120),0,-4,-4,0,random(-10,-20))
		GLRR E 8
		
	ReloadLoop:
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",6,"FinishReload")
		TNT1 A 0 A_JumpIfInventory("GrenadeAmmo",1,1)
		Goto FinishReload
		GLRR E 2
		GLRR E 2 A_PlaySound("insertshell",1)
		GLRR FGE 1
		GLRR HIJ 1
		GLRR E 2
		TNT1 A 0 A_Giveinventory("AGLAmmo",1)
		TNT1 A 0 A_Takeinventory("GrenadeAmmo",1)
		Goto ReloadLoop
		
	FinishReload:
		GLRR E 4
		GLRR EDCBA 1
		Goto Ready2



Unload:
		GLRS A 1 A_WeaponReady
		GLRS A 6
		TNT1 A 0 A_Takeinventory("Unloading",1)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",1,"Unloadin")
		goto Ready2
		Unloadin:
		TNT1 A 0 A_PlaySound("Reload",5)
		GLRR ABCDE 1
		
		TNT1 AAAAAA 0 A_FireCustomMissile("AGLCasing",random(-80,-120),0,-4,-4,0,random(-10,-20))
		GLRR E 8
		

	UnloadLoop:
		GLRR E 2
		GLRR E 2 A_PlaySound("insertshell",1)
		GLRR FGE 1
		GLRR HIJ 1
		GLRR E 2
		TNT1 A 0 A_Giveinventory("GrenadeAmmo",1)
		TNT1 A 0 A_Takeinventory("AGLAmmo",1)
		TNT1 A 0 A_JumpIfInventory("AGLAmmo",1,"UnloadLoop")
		Goto FinishUnload
		
	FinishUnload:
		GLRR E 4
		GLRR EDCBA 1
		Goto Ready2


		
//	NoNeedToReload:
//		GLRS A 1 A_Refire
//		Goto Ready2

// --------------------------------------------------------------------------
//
//	Misc.
//
// --------------------------------------------------------------------------

	DryFire:
		TNT1 A 0 A_PlaySound("weapons/empty2",2)
		Goto Ready2

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

// --------------------------------------------------------------------------
//
//	End stuff
//
// --------------------------------------------------------------------------

	TauntFlash:
		GLRK ABCD 1
		GLRK E 35
		GLRK DCBA 1
		GLRK A 1
		Stop

	KickFlash:
		GLRK BCD 1
		GLRK E 10
		GLRK DCB 1
		GLRK A 1
		Stop

	AirKickFlash:
		GLRK BCD 1
		GLRK E 12
		GLRK DCB 1
		GLRK A 1
		Stop

	SlideKickStartFlash:
		GLRK BCD 1
		GLRK E 18
		Stop
	
	SlideKickEndFlash:
		GLRK EDCBA 2
		GLRK A 1
		Stop

//	GrenadeFlash:
//		GLRS ABCDEF 1	
//		Stop
	}
}




ACTOR AGLMissile
{
	Radius 4
	Height 4
	Speed 50
	Damage 30
	+MISSILE
	+BLOODSPLATTER
	+SKYEXPLODE
	//+DOOMBOUNCE
	+EXPLODEONWATER
	+NOTELEPORT
	-BOUNCEONACTORS
	DamageType ExplosiveImpact
	Gravity 0.7
	Scale 0.6
	SeeSound "Weapons/GrenadeBounce"
	DeathSound "none"
	Obituary "%o was exploded by %k's grenade."
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(waterlevel > 1,"SpawnUnderwater")
		GRNP AAAAAAAA 1 A_CustomMissile("AGLTrail",2,0,random(160,210),2,random(-30,30))
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",6,"Death")
		Loop
	SpawnUnderwater:
		GRNP AAAA 2
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",6,"Death")
		Loop
	Death:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItem("AGLMissileExplosion")
		Stop
	}
}

ACTOR AGLMissileAlt
{
	Radius 4
	Height 4
	Speed 50
	Damage(random(1,2))
	+MISSILE
	+BLOODSPLATTER
	+SKYEXPLODE
	+DOOMBOUNCE
	+EXPLODEONWATER
	+NOTELEPORT
	-BOUNCEONACTORS
	DamageType Kick
	BounceFactor 0.6
	WallBounceFactor 0.4
	Gravity 0.7
	Scale 0.6
	SeeSound "Weapons/GrenadeBounce"
	DeathSound "none"
	Obituary "%o was exploded by %k's grenade."
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(waterlevel > 1,"SpawnUnderwater")
		GRNP AAAAAAAA 1 A_CustomMissile("AGLTrail",2,0,random(160,210),2,random(-30,30))
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",6,"Explode")
		Loop
	SpawnUnderwater:
		GRNP AAAA 2
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",6,"Explode")
		Loop
	Death:
		GRNP AAAA 2
		TNT1 A 0 A_GiveInventory("GrenadeTime",1)
		TNT1 A 0 A_JumpIfInventory("GrenadeTime",6,"Explode")
		Loop
	Explode:
		TNT1 A 0 A_NoBlocking
		TNT1 A 0 A_SpawnItem("AGLMissileExplosion",0,2)
		Stop
	}
}

ACTOR AGLMissileExplosion
{
	Game Doom
	Speed 1
	Gravity 0.0
	BounceFactor 0.1
	WallBounceFactor 0.1
	Radius 1
	Height 1
	Damage 0
	+MISSILE
	+NOTELEPORT
	+NOBLOCKMAP
	+BLOODLESSIMPACT 
	+FORCEXYBILLBOARD
	+MOVEWITHSECTOR
	+DOOMBOUNCE
	+DONTSPLASH
	+THRUACTORS
	+THRUGHOST
	+GHOST
	//+NOBLOCKMAP
	//+NOGRAVITY
	//+MISSILE
	//+DoomBounce
	//BounceFactor 0.1
	//WallBounceFactor 0.1
	Damagetype ExplosiveImpact
	//DeathSound "Explosion"
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 Radius_Quake(3,8,0,15,0)
		TNT1 A 1
		TNT1 A 0 A_CustomMissile("ExplosionSplashSpawner")
		TNT1 A 0 A_SpawnItemEx("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_Scream
		TNT1 A 0 A_SpawnItem("ExplosionLight")
		TNT1 A 0 A_CustomMissile("MetalShardz1",5,0,random(0,360),2,random(0,360))
		TNT1 A 0 A_CustomMissile("MetalShardz2",5,0,random(0,360),2,random(0,360))
		TNT1 A 0 A_CustomMissile("MetalShardz3",5,0,random(0,360),2,random(0,360))
		//TNT1 A 0 A_Explode(50,200)

		TNT1 A 0 A_Explode(57, 160)
		TNT1 A 0 A_Explode(29, 320)
		TNT1 A 0 A_Explode(14, 480)


		TNT1 AAAAAAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random(0,360),2,random(0,180))
		TNT1 AAAAAAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAAAAAA 0 A_CustomMissile("ExplosionParticleVeryFast",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAA 0 A_CustomMissile("SmallExplosionFlames",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAA 0 A_CustomMissile("ExplosionSmokeFast22",0,0,random(0,360),2,random(0,360))
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_SpawnItemEx("LiquidExplosionEffectSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_PlaySound("FAREXPL",3)
		TNT1 AAAAA 4 A_CustomMissile("AGLMissileCluster",2,0,random(0,360),2,random(0,60))
		TNT1 AAAAA 35
		Stop
	}
}

ACTOR AGLMissileCluster
{
	Game Doom
	Speed 20
	Gravity 0.0
	BounceFactor 0.1
	WallBounceFactor 0.1
	Radius 1
	Height 1
	Damage 0
	+MISSILE
	+NOTELEPORT
	+NOBLOCKMAP
	+BLOODLESSIMPACT 
	+FORCEXYBILLBOARD
	+MOVEWITHSECTOR
	+DOOMBOUNCE
	+DONTSPLASH
	+THRUACTORS
	+THRUGHOST
	+GHOST
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_ScaleVelocity(frandom(0.1,1.0))
		TNT1 A 2
		//TNT1 A 0 A_CustomMissile("DummyParticle",0,0,0,0,0)
		TNT1 A 0 A_Scream
		TNT1 AAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random(0,360),2,random(0,180))
		TNT1 AAAAA 0 A_CustomMissile("ExplosionParticleHeavy",0,0,random(0,360),2,random(0,360))
		TNT1 AAAAA 0 A_CustomMissile("ExplosionParticleVeryFast",0,0,random(0,360),2,random(0,360))
		TNT1 AA 0 A_CustomMissile("TinyExplosionFlames",0,0,random(0,360),2,random(0,360))
		TNT1 AA 0 A_CustomMissile("ExplosionSmokeFast22",0,0,random(0,360),2,random(0,360))
		TNT1 A 7
		Stop
	}
}

ACTOR AGLTrail : OldschoolRocketSmokeTrail2
{
	Scale 0.2
	Alpha 0.5
}

ACTOR AGLAmmo : Ammo
{
	+INVENTORY.IGNORESKILL
	Inventory.Amount 0
	Inventory.MaxAmount 6
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 6
	Inventory.Icon "GLRWA0"
}