/*

==RANGER GRENADE GUN==
A self loading grenade launcher, the Ranger's rocket
propelled grenades ignite into flames as the weapon 
builds heat, increasing velocity and the strength of 
the grenadee's explosions. At max heat, the contained
energy erupts out of the grenades on impact, leaving
charged flames that gravitate towards targets.
*/

actor BMgrenader : weapon
{
	weapon.slotnumber 4
	Weapon.AmmoUse 1
	weapon.bobstyle alpha
	weapon.bobrangex 0.2
	weapon.bobrangey 0.2
	weapon.bobspeed 2
	+noalert
	+NOAUTOAIM
	Weapon.AmmoType "Rocketammo"
	Inventory.RestrictedTo "Blastmaster"
	Inventory.PickupMessage "You got the Ranger Grenade Gun!"
	Tag "Ranger Grenade gun"
	states
	{
	Select:
		TNT1 A 0
        TNT1 AAAAAAAAAAAAAAAAAAAA 0 A_Raise
        TNT1 A 1 A_Raise
		goto ready
	Ready:
		BMST A 2
		TNT1 A 0 a_playsound ("BMGGun/raise",0)
		BGGI ABCDEFGH 1
		BGGI IJKLMN 2 a_weaponready (WRF_NOBOB)
		goto realready
	Deselect:
		TNT1 A 0
		TNT1 A 0 a_jumpifhealthlower (1, "deadlower")
		TNT1 A 0 a_takeinventory ("secretaction", 99)
		TNT1 A 0
		TNT1 A 0 a_playsound ("BMGGun/lower",0)
		BGGI MLFDCBA 1
		BMST A 5
	holster:
        TNT1 AAAAAAAAAAAAAAAAAAAA 0 A_lower
        TNT1 A 1 A_lower
		loop
	deadlower:
		TNT1 A 0
		TNT1 A 0
		TNT1 AAAAAAAAAAAAA 0 a_lower
		TNT1 A 1 a_lower
		wait	
	Realready:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		BMGG A 1 a_weaponready
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		loop
	lockdown:
		TNT1 A 0
		BMGG A 3 a_weaponready (WRF_NOPRIMARY)
		TNT1 A 0 a_firecustommissile ("smashersmokespawner",0,0,0,0,0,0)
		BMGG A 3 a_weaponready (WRF_NOPRIMARY)
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		goto realready
	Fire:
		TNT1 A 0
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		TNT1 A 0 a_jumpifinventory ("BMheat",156,"FlameShot")
		TNT1 A 0 a_jumpifinventory ("BMheat",91,"RocketShot")
		BMGG A 2
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 a_playsound ("BMGGun/fire1",CHAN_WEAPON)
		TNT1 A 0 a_firecustommissile ("GEPGrenade",0,1,0,3)
		TNT1 A 0 A_Quake(2, 5, 0, 32)
		BMGG BCDD 1 A_giveinventory ("BMheat",4)
		BMGG E 1
		BMGG E 2
		BMGG FGA 2
		TNT1 A 0 a_playsound ("BMGGun/load",0)
		BMGG IJKL 2
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		BMGG NOP 2 a_weaponready (WRF_NOBOB)
		BMGG A 2 a_weaponready
		goto realready
	Rocketshot:
		BMGG A 2
		TNT1 A 0 a_firecustommissile ("GEPMissile",0,1)
		TNT1 A 0 A_Quake(2, 5, 0, 32)
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 a_playsound ("Blastmaster/highheat",0)
		TNT1 A 0 a_playsound ("BMGGun/fire2",CHAN_WEAPON)
		TNT1 A 0 a_firecustommissile ("smashersmokespawner",0,0,0,0,0,0)
		BMG2 BCDD 1 A_giveinventory ("BMheat",3)
		BMGG E 1
		BMGG E 2
		BMGG FGA 2
		TNT1 A 0 a_playsound ("BMGGun/load",0)
		BMGG IJKL 2
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		BMGG NOP 2 a_weaponready (WRF_NOBOB)
		BMGG A 2 a_weaponready
		goto realready
	FlameShot:
		BMGG A 2
		TNT1 A 0 a_firecustommissile ("ClusterGEPMissile",0,1)
		TNT1 A 0 A_Quake(2, 5, 0, 32)
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 a_playsound ("Blastmaster/highheat",0)
		TNT1 A 0 a_playsound ("BMGGun/fire3",CHAN_WEAPON)
		TNT1 A 0 a_firecustommissile ("smashersmokespawner",0,0,0,0,0,0)
		BMG3 BCDD 1 A_giveinventory ("BMheat",2)
		BMGG E 1
		BMGG E 2
		BMGG FGA 2
		TNT1 A 0 a_playsound ("BMGGun/load",0)
		BMGG IJKL 2
		TNT1 A 0 a_jumpifinventory ("BMoverheat",1,"lockdown")
		BMGG NOP 2 a_weaponready (WRF_NOBOB)
		BMGG A 2 a_weaponready
		goto realready


	//VENT ATTACKS------------------------------------------------------------------
	Altfire:
		TNT1 A 0
		BMGG A 2 A_weaponready (WRF_NOFIRE)
		TNT1 A 0 A_jumpifinventory ("BMoverheat",1,"OverHeatFire")
		TNT1 A 0 A_jumpifinventory ("BMheat",156,"RedGrenade")
		TNT1 A 0 A_jumpifinventory ("BMheat",91,"YellowMachineGun")
		TNT1 A 0 A_jumpifinventory ("BMheat",1,"BlueFire")
		goto realready

	//Blue Fire (Tier one)----------------------------------------------------------
	BlueFire:
		TNT1 A 0 A_playsound ("BlastMaster/BlueFireStart",0)
		TNT1 A 0 A_playsound ("BlastMaster/BlueFireLoop",6,1,1)
	BlueFireLoop:
		TNT1 A 0 A_gunflash
		TNT1 A 0 A_takeinventory ("BMheat",2)
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 A_giveinventory ("BlastMasterVented",1)
		TNT1 A 0 A_recoil (0.10)
		TNT1 A 0 Bright A_FireCustomMissile ("BlueVentFire",Frandom(-5, 5), 0, random(-1,1), random(-2,-1), 0, Frandom(-2, 2))
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"SuperBlueFire")
		BMV6 AB 1 bright
		TNT1 A 0 A_jumpifinventory ("BMHeat",1,"BlueFireLoop")
		TNT1 A 0 A_playsound ("BlastMaster/BlueFireEnd",6)
		goto VentFinish
	SuperBlueFire:
		TNT1 A 0
		TNT1 A 0 A_FireCustomMissile ("BlueVentEmber1",Frandom(-5, 5), 0, random(-4,4), random(1,4), 0, Frandom(-5, 5))
		TNT1 A 0 A_FireCustomMissile ("BlueVentEmber2",Frandom(-5, 5), 0, random(-4,4), random(1,4), 0, Frandom(-5, 5))
		TNT1 A 0 Bright A_FireCustomMissile ("BlueVentFire",Frandom(-9, 9), 0, random(-3,3), random(-2,-1), 0, Frandom(-4, 4))
		TNT1 A 0 A_playsound ("BlastMaster/PowerFire",0)
		BMV6 AB 1 bright
		TNT1 A 0 A_jumpifinventory ("BMHeat",1,"BlueFireLoop")
		TNT1 A 0 A_playsound ("BlastMaster/BlueFireEnd",6)
		goto VentFinish

	//Yellow Machine Gun (Tier two)--------------------------------------------------
	YellowMachineGun:
		TNT1 A 0 A_gunflash
		TNT1 A 0 A_takeinventory ("BMheat",4)
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 A_giveinventory ("BlastMasterVented",1)
		TNT1 A 0 A_playsound ("BlastMaster/YellowShot",6)
		TNT1 A 0 A_Quake(1, 2, 0, 32)
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"YellowHitScan")
		ESHG B 0 Bright A_FireCustomMissile("YellowVentBullet",Frandom(-2, 2), 0, 0, random(-1,1), 0, Frandom(-2, 2))
		BMV6 CD 1 bright
		BMGG A 1
		TNT1 A 0 A_jumpifinventory ("BMHeat",1,"YellowMachineGun")
		goto VentFinish
	YellowHitScan:
		ESHG B 0 Bright A_FireBullets (3.5, 2.0, -1, 9, "YellowCAPuff",FBF_NORANDOM) 
		BMV6 C 1 bright
		TNT1 A 0 A_playsound ("BlastMaster/PowerGun",6)
		BMV6 D 1 bright
		BMGG A 1
		TNT1 A 0 A_jumpifinventory ("BMHeat",1,"YellowMachineGun")
		goto VentFinish

	//Red Grenade (Tier three)--------------------------------------------------------
	RedGrenade:
		TNT1 A 0 A_gunflash
		TNT1 A 0 A_playsound ("BlastMaster/RedGrenade",6)		
		TNT1 A 0 A_takeinventory ("BMheat",999)
		TNT1 A 0 A_giveinventory ("BlastMasterVented",1)
		TNT1 A 0 A_giveinventory ("BlastMasterFired",1)
		TNT1 A 0 A_Quake(2, 6, 0, 32)
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"SuperGrenade")
		ESHG B 0 Bright A_FireCustomMissile("RedGrenade")
		BMV6 EFGHHIIJJKKLL 1 bright
		BMGG A 3
		goto VentFinish
	SuperGrenade:
		ESHG B 0 Bright A_FireCustomMissile("SuperRedGrenade")
		BMV6 EFGHH 1
		TNT1 A 0 a_playsound ("BlastMaster/PowerGrenade",0)		
		BMV6 IIJJKKLL 1 bright
		BMGG A 3
		goto VentFinish

		
	
	VentFinish:
		BMGG A 3
		BMP6 ABCC 2
		TNT1 A 0 A_takeinventory ("BlastMasterFired",99)
		TNT1 A 0 A_takeinventory ("BlastMasterVented",99)
		TNT1 A 0 A_playsound ("BlastMaster/PumpDown",0)
		BMP6 DEFFG 2 A_FireCustomMissile ("BlastMasterSmoker",0,0,6,6)
		TNT1 A 0 A_playsound ("BlastMaster/PumpUp",0)
		BMP6 CBA 2
		BMGG A 1
		goto realready

	//Super Flamer (Overheat)--------------------------------------------------------
	OverHeatFire:
		TNT1 A 0 A_takeinventory ("BlastMasterFired",99)
		TNT1 A 0 A_takeinventory ("BlastMasterVented",99)
		TNT1 A 0 A_playsound ("BlastMaster/BlueFireStart",0)
		TNT1 A 0 A_playsound ("BlastMaster/RedFireStart",0)
		TNT1 A 0 A_playsound ("BlastMaster/RedFireLoop",6,1,1)
	OverHeatFireLoop:
		TNT1 A 0 A_gunflash
		TNT1 A 0 Bright A_FireCustomMissile ("RedVentFire",Frandom(-5, 5), 0, random(-1,1), random(-2,-1), 0, Frandom(-2, 2))
		TNT1 A 0 A_takeinventory ("BMOverHeat",1)
		TNT1 A 0 A_recoil (0.15)
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"SuperRedFire")
		BMV6 MN 1 bright
		TNT1 A 0 A_refire ("OverHeatCheck")
		TNT1 A 0 A_playsound ("BlastMaster/RedFireEnd",6)	
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"RedFinisherCheck")
		BMGG A 6 
		BMGG A 6 A_weaponready (WRF_NOPRIMARY)
		goto LockDown	
	OverHeatCheck:
		TNT1 A 0 A_jumpifinventory ("BMOverHeat",1,"OverHeatFireLoop")
		TNT1 A 0 A_playsound ("BlastMaster/RedFireEnd",6)	
		goto VentFinish

	SuperRedFire:
		TNT1 A 0
		TNT1 A 0 A_FireCustomMissile ("RedVentEmber1",Frandom(-5, 5), 0, random(-4,4), random(1,4), 0, Frandom(-5, 5))
		TNT1 A 0 A_FireCustomMissile ("RedVentEmber2",Frandom(-5, 5), 0, random(-4,4), random(1,4), 0, Frandom(-5, 5))
		TNT1 A 0 Bright A_FireCustomMissile ("RedVentFire",Frandom(-9, 9), 0, random(-3,3), random(-2,-1), 0, Frandom(-4, 4))
		TNT1 A 0 A_playsound ("BlastMaster/PowerFire",0)
		BMV6 MN 1 bright
		TNT1 A 0 A_refire ("OverHeatCheck")
		TNT1 A 0 A_playsound ("BlastMaster/RedFireEnd",6)
		goto RedFinisherCheck
	RedFinisherCheck:
		TNT1 A 0 A_jumpifinventory ("BMOverHeat",60,"SuperFinisher")
		goto LockDown
	SuperFinisher:
		TNT1 A 0 A_gunflash
		TNT1 A 0 A_playsound ("BlastMaster/RedGrenade",6)		
		TNT1 A 0 A_takeinventory ("BMOverHeat",60)
		BMGG A 0 A_jumpifinventory ("SuperVenter",1,"SuperGrenade")
		ESHG B 0 Bright A_FireCustomMissile("RedGrenade")
		BMV6 EFGHHIIJJKKLL 1 bright
		BMGG A 6
		goto LockDown
		

	Flash:
		TNT1 A 2 Bright A_Light(3)
		TNT1 A 2 Bright A_Light2
		TNT1 A 2 Bright A_Light1
		Goto LightDone
	}
}

actor GEPgrenade
{
	+notimefreeze
	projectile
	+bloodlessimpact
	+thruspecies
	+bright
	Species "Player"
	DeathSound "BMGGun/explode1"
	bouncefactor 0.9
	bouncecount 3
	gravity 0.60
	damage 20
	Radius 8
	height 8
	scale 1
	speed 30
	Obituary "%o was silently taken down by %k's grenade"
	Decal scorch

	states
	{
	spawn:
		GGRE A 2
		TNT1 A 0 A_SpawnItemEx("BlueVentEmber1",frandom(-2,2),frandom(-2,2),frandom(-2,2))
		TNT1 A 0 a_spawnitemex ("BlueVentEmber2",Frandom(-5,5),Frandom(-5,5),Frandom(-5,5),Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,0,160)
		Loop
	death:
		TNT1 A 0
		TNT1 A 0 a_nogravity
		TNT1 A 0 a_settranslucent (0.80,1)
		TNT1 A 1 a_explode (128,128,1,1,0)
		CLX1 A 2 a_setscale (0.70,0.70)
		CLX1 A 1 a_setscale (0.90,0.90)
		CLX1 B 1 a_setscale (1.20,1.20)
		CLX1 B 1 a_setscale (1.00,1.00)
		CLX1 C 2 
		CLX1 D 1 a_setscale (1.10,1.10)
		CLX1 D 1 a_setscale (1.20,1.20)
		CLX1 D 1 a_setscale (1.30,1.30)
		Stop
	}
}





actor GEPMissile : GEPGrenade
{
	damage 22
	speed 40
	DeathSound "BMGGun/explode2"
	states
	{
	spawn:
		GGRE A 2
		TNT1 A 0 A_SpawnItemEx("YellowVentEmber1",frandom(-2,2),frandom(-2,2),frandom(-2,2))
		TNT1 A 0 a_spawnitemex ("YellowVentEmber2",Frandom(-5,5),Frandom(-5,5),Frandom(-5,5),Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,0,160)
		loop
	death:
		TNT1 A 0
		TNT1 A 0 a_nogravity
		TNT1 A 1 a_explode (128,128,1,1,0)
		TNT1 A 0 a_settranslucent (0.80,1)
		CLX2 A 2 a_setscale (0.70,0.70)
		CLX2 A 1 a_setscale (0.90,0.90)
		CLX2 B 1 a_setscale (1.20,1.20)
		CLX2 B 1 a_setscale (1.00,1.00)
		CLX2 C 2 
		CLX2 D 1 a_setscale (1.10,1.10)
		CLX2 D 1 a_setscale (1.20,1.20)
		CLX2 D 1 a_setscale (1.30,1.30)
		Stop
	}
}


actor ClusterGEPMissile : GEPGrenade
{
	+nogravity
	-Doombounce
	DeathSound "BMGGun/explode3"
	bouncecount 0
	damage 25
	speed 50
	states
	{
	spawn:
		GGRE A 2
		TNT1 A 0 A_SpawnItemEx("RedVentEmber1",frandom(-2,2),frandom(-2,2),frandom(-2,2))
		TNT1 A 0 a_spawnitemex ("RedVentEmber2",Frandom(-5,5),Frandom(-5,5),Frandom(-5,5),Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,Frandom(-50,50)/20.0,0,160)
		loop
	death:
		TNT1 A 0
		TNT1 A 0 a_nogravity
		TNT1 A 1 a_explode (128,128,1,1,0)
		TNT1 AAAAAAAA 0 a_spawnitemex ("GEPFire",random (-3,3),random (-3,3),random (-3,3),random (-10,10),random (-12,12),random (-4,5),0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_settranslucent (0.80,1)
		CLX3 A 2 a_setscale (0.70,0.70)
		CLX3 A 1 a_setscale (0.90,0.90)
		CLX3 B 1 a_setscale (1.20,1.20)
		CLX3 B 1 a_setscale (1.00,1.00)
		CLX3 C 2 
		CLX3 D 1 a_setscale (1.10,1.10)
		CLX3 D 1 a_setscale (1.20,1.20)
		CLX3 D 1 a_setscale (1.30,1.30)
		Stop
	}
}


Actor GEPFire : RedVentFire 
{
	Speed 36
	Radius 10
	Height 10
	PROJECTILE
	+thruspecies
	+painless
	+bright
	+hexenbounce
	species "player"
	damage (10)
	Scale 0.60
	Renderstyle Add
	Alpha 0.90
	decal DoomimpScorch
	projectilekickback 500
	+SEEKERMISSILE
	
	bouncecount 3
	var int user_GEPFlameTimer;
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 a_jump (105,2)
		TNT1 A 0 a_setscale (scalex * -1,scaley) //Flip it horizontally

		TNT1 A 2
		TNT1 A 0 a_jump (190,"PainfulFlame")
		VBX4 ABC 1 A_SetScale (scalex * frandom(1.10,1.20),scaley * frandom(1.10,1.20))
		TNT1 A 0 a_scalevelocity (0.05)
		goto Floating
	PainfulFlame:
		TNT1 A 0
		TNT1 A 0 a_changeflag ("PAINLESS",0)
		VBX4 ABC 1 A_SetScale (scalex * frandom(1.10,1.20),scaley * frandom(1.10,1.20))
		TNT1 A 0 a_scalevelocity (0.05)
		goto Floating
	Floating:
		VBX4 ABC 2
		TNT1 A 0 A_SeekerMissile(70,90,SMF_LOOK,190,1)
		TNT1 A 0 a_scalevelocity (0.05)
		TNT1 A 0 a_setscale (scalex * -1,scaley) //Flip it horizontally
		
		TNT1 A 0 a_setuservar("User_GEPFlameTimer", User_GEPFlameTimer+1)
		TNT1 A 0 a_jumpif (user_GEPFlameTimer >= 90, "Death")
		loop
	Death:
		TNT1 A 0
		TNT1 A 0 a_changeflag ("NOINTERACTION",1)
		TNT1 A 0 a_scalevelocity (0.90)
		TNT1 A 0 a_fadeout (0.10)
		TNT1 AA 0 A_SpawnItemEx("RedVentEmber2",frandom(-2,2),frandom(-2,2),frandom(-8,-4),frandom(-1,1),frandom(-1,1),frandom(0,1))
		VBX4 BC 1 A_SpawnItemEx("RedVentEmber1",frandom(-2,2),frandom(-2,2),frandom(-8,-4),frandom(-1,1),frandom(-1,1),frandom(0,1))
		TNT1 A 0 a_scalevelocity (0.10)
	FadingOut:	
		VBX4 C 1 A_SetScale (scalex * frandom(1.10,1.20),scaley * frandom(1.10,1.20))
		TNT1 A 0 a_fadeout (0.20)
		Loop
	Crash:
	Xdeath:
		TNT1 A 0 A_SpawnItemEx("RedVentEmber2",frandom(-2,2),frandom(-2,2),frandom(-8,-4),frandom(-1,1),frandom(-1,1),frandom(0,1))
		TNT1 AAAAAAAAAAAAA 0 A_SpawnItemEx("RedVentEmber1",frandom(-2,2),frandom(-2,2),frandom(-8,-4),frandom(-3,3),frandom(-3,3),frandom(-4,-4))
		TNT1 A 0 a_playsound ("BlastMaster/BlueFireHit",0)
		VBX4 DEFGHIJ 1 A_SetScale (scalex * frandom(1.10,1.20),scaley * frandom(1.10,1.20))
		VBX4 J 1 a_fadeout (0.20)
		wait
	}
}


