/*

===TRIDENT===

Heavy tri-barrel rocket launcher.
A single squeeze of the trigger arms a triple rocket barrage.
Holding it down will bypass that and launch single rockets.
Takes a moment to reload after a barrage, plan accordingly.

Don't use in close combat.

*/


actor TridentLauncher : Buran
{
	Weapon.SlotNumber 3
	Weapon.SelectionOrder 500
	Weapon.AmmoType "RocketAmmo"
	Weapon.AmmoUse1 1
	Weapon.AmmoGive 2
	Weapon.BobStyle smooth
	Weapon.BobRangeX 0.3
	Weapon.BobRangeY 0.4
	Weapon.BobSpeed 1
	Inventory.PickupMessage "Trident launcher."
	Inventory.PickupSound "Trident/Pickup"
	Obituary "%o was bombarded by %k."
	Tag "Trident"
	States
	{
	Ready:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("Trident/Equip",0,0.70)
		DVR1 ABCDEFGHH 2 A_WeaponReady
		Goto EmptyReady
	Deselect:
		TNT1 A 0
		TNT1 A 0 A_JumpIfHealthLower (1, "DeadLower")
		TNT1 A 0 A_JumpifNoAmmo ("EmptyLower")
		DVR5 A 1
		TNT1 A 0 A_PlaySound ("Trident/Chamber",0)
		DVR5 BCDDDE 1
		TNT1 A 0 A_PlaySound ("Trident/Holster",0,0.70)
		DVR5 FGH 1
		Goto Holster
	EmptyLower:
		DVR5 DDDE 1
		TNT1 A 0 A_PlaySound ("Trident/Holster",0,0.70)
		TNT1 A 0 A_TakeInventory ("RocketStack",99)
		DVR5 FGH 1
		Goto Holster
		
	
	RealReady:
		DVR2 A 1 A_WeaponReady
		Wait
	EmptyReady:
		TNT1 A 0
		DVR1 I 1 A_WeaponReady
		TNT1 A 0 A_JumpIfInventory ("RocketAmmo",1,"LoadRocket")
		Loop
	LoadRocket:	
		TNT1 A 0 A_JumpIfInventory ("RocketStack",1,"RocketReload")
		DVR1 I 2 A_WeaponReady
		TNT1 A 0 A_PlaySound ("Trident/Load",0)
		DVR1 JJ 1 A_WeaponReady
		DVR1 K 2 A_WeaponReady
		Goto RealReady
		
	Fire:
		TNT1 A 0 A_JumpIfNoAmmo ("DryFire")
		TNT1 A 0 A_JumpIfInventory ("RocketStack",1,"RocketReload")
		TNT1 A 0 A_PlaySound ("Trident/BeforeShot",0,0.90)
		DVR1 LM 2
		DVR2 A 3
		TNT1 A 0 A_Refire ("SingleRocket")
		
		DVR3 AA 1 Bright
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_GunFlash ("TripleRocketVolley",GFF_NOEXTCHANGE)
		DVR3 B 2 Bright
		TNT1 A 0 A_Recoil (8)
		TNT1 A 0 A_Quake(2, 5, 0, 32)
		DVR3 C 2 Bright
		DVR3 DEE 2
		DVR3 F 2
		TNT1 A 0 A_JumpIfNoAmmo ("EmptyReady")
		DVR3 G 2
		Goto RocketReload
	SingleRocket:
		DVR2 AA 1
		TNT1 A 0 A_PlaySound ("Trident/Fire",0)
		TNT1 A 0 A_GiveInventory ("UsingDeriverGun",1)
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile ("TridentMissile",0,1,0,0)
		TNT1 A 0 A_Quake(2, 5, 0, 32)
		DVR2 BC 2 Bright
		DVR2 DE 2
		DVR2 F 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_JumpIfNoAmmo ("EmptyReady")
		TNT1 A 0 A_PlaySound ("Trident/Chamber",0)
		DVR2 GHI 2 A_WeaponReady (WRF_NOPRIMARY)
		DVR2 J 1 A_WeaponReady (WRF_NOPRIMARY)
		DVR2 A 1 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_Refire ("SingleRocket")
		Goto RealReady
	DryFire:
		TNT1 A 0 A_PlaySound ("DShotgun/DryFire",0)
		DVR6 AB 2 A_WeaponReady (WRF_NOPRIMARY)
		DVR1 I 20 A_WeaponReady (WRF_NOPRIMARY)
		Goto EmptyReady
	//----------------------------------------------------------------------
	//Gunflash for triple rockets
	//----------------------------------------------------------------------
	TripleRocketVolley:
		TNT1 A 0
		TNT1 A 0 A_PlaySound ("Trident/Cluster",0)
		TNT1 A 0 A_GiveInventory ("UsingDeriverGun",1)
		TNT1 A 0 A_FireCustomMissile ("TripleMissile",0,1,0,0)
		TNT1 A 0 A_GiveInventory ("RocketStack",1)
		TNT1 A 0 A_JumpIfNoAmmo ("EndFlash")
		TNT1 A 0 A_FireCustomMissile ("TripleMissile",0,1,7,-9)
		TNT1 A 0 A_GiveInventory ("RocketStack",1)
		TNT1 A 0 A_JumpIfNoAmmo ("EndFlash")
		TNT1 A 0 A_FireCustomMissile ("TripleMissile",0,1,-7,-9)
		TNT1 A 0 A_GiveInventory ("RocketStack",1)
		TNT1 A 0 A_JumpIfNoAmmo ("EndFlash")
		TNT1 A 1
		Stop
	EndFlash:
		TNT1 A 0
		TNT1 A 1
		stop
		
		
	//----------------------------------------------------------------------
	//Reloading
	//----------------------------------------------------------------------
	RocketReload:
		DVR4 B 1 A_WeaponReady (WRF_NOPRIMARY)
		DVR4 C 3 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("Trident/Chamber",0)
		TNT1 A 0 A_TakeInventory ("RocketStack",1)
		TNT1 A 0 A_JumpIfInventory ("RocketStack",1,"ChamberCycle")
		Goto RealReady
	ChamberCycle:
		DVR4 DEFGA 2 A_WeaponReady (WRF_NOPRIMARY)
		TNT1 A 0 A_PlaySound ("Trident/Load",0)
		TNT1 A 0 A_JumpIfInventory ("RocketStack",1,"RocketReload")
		DVR4 B 1 A_WeaponReady (WRF_NOPRIMARY)
		DVR4 C 3 A_WeaponReady (WRF_NOPRIMARY)
		Goto RealReady


	Altfire:
		TNT1 A 0
		TNT1 A 2
		TNT1 A 0 A_Jump (256, "ParryStance")
		Goto AltfireEnd
	AltFireEnd:
		TNT1 A 0
		TNT1 A 2 A_WeaponReady
		Goto SilentReady
	SwordSheathe:
		TNT1 A 3 A_WeaponReady
		MGS6 AB 1 A_WeaponReady
		MGS6 CDEF 2 A_WeaponReady
		MGS6 G 1 A_WeaponReady
		TNT1 A 0 A_PlaySound ("MagSword/Sheathe1",0)
		MGS6 HI 1 A_WeaponReady
		TNT1 A 0 A_PlaySound ("MagSword/Sheathe2",0)
		MGS6 JJ 1 A_WeaponReady
		MGS6 KLKL 1 A_WeaponReady
		MGS6 L 3 A_WeaponReady
		MGS6 MRST 1 A_WeaponReady
		TNT1 A 1 A_WeaponReady
		Goto SilentReady
	SilentReady:
		TNT1 A 0
		DVR1 ABCDEFGHH 2 A_WeaponReady
		Goto EmptyReady

	}
}






actor TridentMissile
{
	Projectile
	Radius 5
	Height 5
	Speed 20
	Damage 20
	+thruspecies
	scale 2
	+randomize
	+bright
	decal scorch
	species "Player"
	DeathSound "Trident/Explode"


    var int user_ringangle;
	States
	{
	Spawn:
		TNT1 A 0		
		TR1R A 1
		goto Flight
	Flight:
        TR1R A 0 bright A_SpawnItemEx("TridentSmoke", frandom(-2, 2), 0, frandom(-2, 2), 0,0,0, frandom(0, 360))
        TR1R A 1 bright A_SpawnItemEx("TridentSmoke", frandom(-2, 2), 0, frandom(-2, 2), 0,0,0, frandom(0, 360))
		Loop

	Death:
		TNT1 A 0
		TNT1 A 0 A_SetTranslucent (0.90,1)
		TNT1 A 1 A_SetScale (0.50)
		TNT1 A 0 Radius_Quake (2,8,0,12,0)
		TNT1 A 0 A_Explode //(55,120,1,0,50)
	SmokeLoop:
		MISL B 0 A_SpawnItemEx("TridentRingParticle", 0,0,0, 32, 0, 0, user_ringangle)
		MISL B 0 A_SetUserVar("user_ringangle", user_ringangle + 10)
		TNT1 A 1 A_JumpIf(user_ringangle < 360, "SmokeLoop")
		goto ParticleSpawn

	ParticleSpawn:
		MISL B 0 A_JumpIf(z - floorz   < 1, "ParticleFloor")
		MISL B 0 A_JumpIf(ceilingz - z < 1, "ParticleCeiling")
		goto ParticleOther

	ParticleFloor:
		MISL BBBBBBBBBBBBBBBB 0 A_SpawnItemEx("DeriverFlare", frandom(-6, 6), frandom(-1, 1), frandom( 2,  6), frandom(4, 12), frandom(-3, 3), frandom(0, 10), frandom(0, 360))
		goto SmokeSpawn

	ParticleCeiling:
		MISL BBBBBBBBBBBBBBBB 0 A_SpawnItemEx("DeriverFlare", frandom(-6, 6), frandom(-1, 1), frandom(-6, -2), frandom(4, 12), frandom(-3, 3), frandom(-10, 0), frandom(0, 360))
		goto SmokeSpawn

	ParticleOther:
		MISL BBBBBBBBBBBBBBBB 0 A_SpawnItemEx("DeriverFlare", frandom(-6, 6), frandom(-1, 1), frandom(-3, 3), frandom(4, 12), frandom(-3, 3), frandom(-4, 8), frandom(0, 360))
		goto SmokeSpawn


	SmokeSpawn:
		MISL BBBBBB 0 A_SpawnItemEx("TridentSmoke",   frandom(-6, 6), frandom(-1, 1), frandom(-4, 4), frandom(-3, 3), 0,              frandom(-3, 3), frandom(0, 360))
	Explode:
		DMIS GHIJ 2 bright
		stop
	}
}

actor TripleMissile : TridentMissile
{
	Speed 40
}


actor RocketStack : inventory
{
	Inventory.RestrictedTo "Deriver"
	inventory.maxamount 3
}
