#region Gnus
//$color 14

/*
fun fact: This gun is technically named after a tank from my Tiberian Sun mod
that also shoots Tiberium and is fuckhuge.

What a surprise.
*/

//Standard shot
#include "zscript/guns/projectile/Dreadful.txt"
#include "zscript/guns/projectile/CoreDreadful.txt"

//Strat blast
#include "zscript/guns/projectile/DreadnukeBlast.txt"

//Strat projectile
#include "zscript/guns/projectile/Dreadnuke.txt"
#include "zscript/guns/projectile/Corenuke.txt"

//Arbiter
#include "zscript/guns/projectile/Dreadarbiter.txt"
#include "zscript/guns/projectile/Corearbiter.txt"

class DreadfulSelected : Inventory { Default { Inventory.MaxAmount 1; } }

//Spawners
class MaceSpawner2 : RandomSpawner replaces Mace
{
	Default
	{
		DropItem "OldDreadful", 255, 2;
		DropItem "DraughTomeBringer", 255, 1;
		DropItem "PowersuitBringer", 255, 1;
	}
}

class OldDreadful : GuncasterWeapon //replaces BFG9000
{	
	Default
	{
		//$Title Old Dreadful
		Health 3; //This is for Hexen assembly.
		Inventory.PickupSound "Guncaster/Laugh1";
		Inventory.PickupMessage "$GOTDREADFUL";
		Obituary "$KILLDREADFUL";
		Tag "Old Dreadful";
		Weapon.UpSound "Dreadful/Up";
		Weapon.SelectionOrder 6;
		Weapon.AmmoGive 2;
		Weapon.AmmoType "TiberiumAmmo";
		Weapon.AmmoUse 1;
		Weapon.SlotNumber 7;
		Weapon.BobStyle 'InverseSmooth';
		Weapon.BobSpeed 1.0;
		Weapon.BobRangeY 0.8;
		Weapon.BobRangeX 1.0;
	}
	
	//Strat drop.
	override void PostBeginPlay ()
	{
		if(!bDROPPED && random(0,20) == 0)
		{
			A_DropItem("DreadfulStratGiver",-1,256);
		}
		Super.PostBeginPlay();
		Return;
	}
	
	//Hexen handling.
	override String PickupMessage () {
    if(gameinfo.gametype == Game_HEXEN)
        return "''Old Dreadful'' assembled, have a nice, freaking day! (7)";
    else
        return PickupMsg;
    }
	
	override Void AttachToOwner (actor user) {
		if(gameinfo.gametype == Game_HEXEN) {
			AmmoUse1 = 40;
			AmmoGive1 =  40;
			AmmoType1 = "BlueMana";
			AmmoUse2 = 40;
			AmmoGive2 = 40;
			AmmoType2 = "GreenMana";
			bPRIMARY_USES_BOTH = 1;
		}
		Super.AttachToOwner(user);
	}
		
	int GunzerkShot; //So the gun won't change the frames mid-through a firing anim.
	int GunzerkShot2;
	
	double GunzX; //A lil' positioning modifier when the gunzerk is on.
	
	States
	{
	Spawn:
		BFGG X 0 NoDelay {
			If(multiplayer && !(self.SpawnFlags & MTF_SINGLE) && sv_noweaponspawn)
			{
				Return ResolveState("Null");
			}
			A_SpawnItemEx("BFGMarker",0,0,0,0,0,0,0,SXF_SETTRACER);
			A_PlaySound("Dreadful/Loop",2,0.9,1);
			Return ResolveState(Null);
		}
		BFGG X 1;
		Wait;

	SelectStuff:
		TNT1 A 0 {
			invoker.GunzerkShot = 0;
			invoker.GunzerkShot2 = 0;
			A_GiveInventory("DreadfulSelected");
			A_SetCrosshair(50);
		}
		Goto SelectLoop;
	SelectLoop:
		TNT1 A 1 A_Raise;
		Loop;
		
	DeselectStuff:
		TNT1 A 0 {
			A_TakeInventory("DreadfulSelected");
		}
		Goto DeselectLoop;
	
	//STRAT
	
	StratSwitch:
		BFGG N 0 A_JumpIf(CountInv("OldDreadfulStratActive"),"StratDeactivate");
		BFGG N 0 {
			If((CountInv("HexenCounter") && CountInv("GreenMana") >= 150 && CountInv("BlueMana") >= 150) || 
			(!CountInv("HexenCounter") && CountInv("TiberiumAmmo") >= 8)) { Return ResolveState(Null); }
			Return ResolveState("OuttaJuice");
		}
		BFGG N 0 {
			if((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && !invoker.LeftHand) {
				A_Overlay(-3,"RightStratActivate");
				A_Overlay(3,"LeftStratActivate");
				Return ResolveState(Null);
			}
			invoker.WeapAction++;
			invoker.LeftHand = 1;
			A_PlaySound("Dreadful/Supercharge",1,0.8);
			A_GiveInventory("OldDreadfulStratActive",1);
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(2,1,1,55,0,24,"",QF_SCALEDOWN); }
			Return ResolveState(Null);
		}
		BSC1 A 0 A_JumpIf(CountInv("TibCore"),2);
		BSG1 A 0;
		"####" ABCDEFGHIJKLMNOPQRMNOPQR random(1,2) Bright {
			if(CountInv("TibCore")) { A_SetBlend("10 45 FF",frandom(0.05,0.075),3); }
			else 					{ A_SetBlend("50 FF 10",frandom(0.05,0.075),3); }
			A_SetAngle(Angle + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetPitch(Pitch + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(2,2,2,5,0,64,"",QF_SCALEDOWN); }		
		}
		"####" STUVWXYZ random(1,2) Bright {
			if(CountInv("TibCore")) { A_SetBlend("10 45 FF",frandom(0.05,0.075),3); }
			else 					{ A_SetBlend("50 FF 10",frandom(0.05,0.075),3); }
			A_SetAngle(Angle + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetPitch(Pitch + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(2,2,2,5,0,64,"",QF_SCALEDOWN); }
		}
		
		BSC2 A 0 A_JumpIf(CountInv("TibCore"),2);
		BSG2 A 0;
		"####" ABCDE random(1,2) Bright {
			if(CountInv("TibCore")) { A_SetBlend("10 45 FF",frandom(0.05,0.075),3); }
			else 					{ A_SetBlend("50 FF 10",frandom(0.05,0.075),3); }
			A_SetAngle(Angle + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetPitch(Pitch + Frandom(0.5,-0.5) * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(2,2,2,5,0,64,"",QF_SCALEDOWN); }
		}
		"####" F 0 {
			if(CountInv("TibCore")) {
				A_SetBlend("10 45 FF",0.4,45);
			} else {
				A_SetBlend("50 FF 10",0.4,45);
			}
		}
		"####" FGHIJ random(1,2) Bright;
		//BFGG N 0 A_StopSound(6);
		BFGG N 10;
		//BFGG N 0 A_PlaySound("Dreadful/Loop2",6,0.6,1);
		
		BSCI A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGI A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		"####" A 0 {
			invoker.WeapAction--;
			invoker.LeftHand = 0;
		}
		Goto RightStratActive;
		
	RightStratActivate:
		"####" A 0 {
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
			invoker.WeapAction++;
			invoker.LeftHand = 1;
		}
		BFGG N 10;
		BFGG N 0 A_GiveInventory("OldDreadfulStratActive");
		BSCI A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGI A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		"####" A 0 {
			invoker.WeapAction--;
			invoker.LeftHand = 0;
		}
		Goto RightActive;
	LeftStratActivate:
		BFGG N 10 {
			A_OverlayFlags(OverlayID(),PSPF_FLIP|PSPF_MIRROR,1);
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
		}
		BSCI A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGI A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		Goto LeftActive;
		
	StratDeactivate:
		"####" A 0 {
			invoker.WeapAction++;
			invoker.LeftHand = 1;
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
			A_TakeInventory("OldDreadfulStratActive",1);
			if(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) { A_Overlay(3,"LeftStratDeactivate"); }
		}
		BSCE A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGE A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		BFGG N 10;
		"####" N 0 {
			A_TakeInventory("OldDreadfulStratActive");
			invoker.WeapAction--;
			invoker.LeftHand = 0;
		}
		Goto RightActive;
	LeftStratDeactivate:
		"####" "#" 0 {
			A_OverlayFlags(OverlayID(),PSPF_FLIP|PSPF_MIRROR,1);
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
		}
		BSCE A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGE A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		BFGG N 10;
		Goto LeftActive;
		
	//RIGHT SIDE
	
	RightActive:
		BFCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGG A 0;
		"####" AABBCCDDCCBB 1
		{
			if(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) { invoker.GunzX = 40; }
			else { invoker.GunzX = 0; }
			
			//Strat.
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
			If(CountInv("OldDreadfulStratActive")) {
				Return ResolveState("RightStratActive");
			}
			
			//A_PlaySound("Dreadful/Loop",6,0.4,1); //Resigned from it so it won't conflict with spells and everything.
			//Strat switch.
			If(CountInv("OldDreadfulStrat") &&
				!invoker.weapSwitch  && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				GetPlayerInput(INPUT_BUTTONS) & BT_RELOAD) {
				Return ResolveState("StratSwitch");
			}
			
			//Fire.
			If(!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!invoker.weapSwitch  && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("MainFire");
			}
			
			//Gunzerk fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!invoker.WeapSwitch  && !CountInv("MenuWheelActive") &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
				Return ResolveState("MainFire");
			}
			Return ResolveState(Null);
		}
		Loop;
	RightStratActive:
		BSCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGG A 0;
		"####" ABCDEFGHIJKLMNOP 1
		{
			if(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) { invoker.GunzX = 40; }
			else { invoker.GunzX = 0; }
			
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
		
			//A_PlaySound("Dreadful/Loop2",6,0.4,1);
			//Strat switch.
			If(CountInv("OldDreadfulStrat") &&
				!invoker.weapSwitch && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				GetPlayerInput(INPUT_BUTTONS) & BT_RELOAD) {
				Return ResolveState("StratSwitch");
			}
			
			//Fire.
			If(!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!invoker.weapSwitch && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("MainFire");
			}
			
			//Gunzerk fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!invoker.WeapSwitch && !CountInv("MenuWheelActive") && GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
				Return ResolveState("MainFire");
			}
			Return ResolveState(Null);
		}
		Goto RightActive;
		
	//LEFT SIDE
	
	LeftActive:
		TNT1 A 0 {
			if(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) {
				A_OverlayFlags(3,PSPF_MIRROR|PSPF_FLIP,1);
			} else {
				A_OverlayFlags(3,PSPF_MIRROR|PSPF_FLIP,0);
			}
			A_OverlayOffset(OverlayID(),invoker.GunzX,0);
		}
		TNT1 A 0 A_JumpIf(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking"),3);
		TNT1 A 1;
		TNT1 A 0 {
				If(!invoker.WeapSwitch && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
					Return ResolveState("Cast");
				}
				If(!invoker.WeapSwitch && !CountInv("MenuWheelActive") && !invoker.LeftHand &&
				!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && GetCvar("GC_Trogdor") &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ZOOM) {
					Return ResolveState("DeadPunchStart");
				}
				Return ResolveState(Null);
		}
		Loop;
		BFCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGG A 0;
		"####" AABBCCDDCCBB 1 {
			//Strat.
			If(CountInv("OldDreadfulStratActive")) {
				Return ResolveState("LeftStratActive");
			}
			//A_PlaySound("Dreadful/Loop",6,0.4,1);
			If(!invoker.WeapSwitch && !CountInv("MenuWheelActive") &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("MainFire");
			}
			Return ResolveState(Null);
		}
        Loop;
	LeftStratActive:
		BSCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGG A 0;
		"####" ABCDEFGHIJKLMNOP 1 {
			//A_PlaySound("Dreadful/Loop",6,0.4,1);
			If(!invoker.WeapSwitch && !CountInv("MenuWheelActive") &&
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("MainFire");
			}
			Return ResolveState(Null);
		}
		Goto LeftActive;
		
	//FIRE
	
	OuttaJuice:
		BFGG N 15 {
			//A_StopSound(6);
			invoker.WeapAction++;
			if(OverlayID() == -3 && !(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) { invoker.LeftHand = 1; }
		}
		BFGG N 0 {
			invoker.WeapAction--;
			if(OverlayID() == -3 && !(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) { invoker.LeftHand = 0; }
			Return ResolveState(Null);
		}
		BFGG A 0 A_JumpIf(OverlayID() == 3,"LeftActive");
		Goto RightActive;
		
	MainFire:
		"####" A 0 A_JumpIfNoAmmo("OuttaJuice");
		//"####" A 0 { if(CountInv("ArbiterModuleActive") && CountInv("TiberiumAmmo") < 2) { Return ResolveState("OuttaJuice"); } Return ResolveState(Null); }
		BFCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGG A 0;
		"####" A 0 {
			invoker.WeapAction++;
			if(OverlayID() == 3) { invoker.LeftHand = 1; }
			if(CountInv("OldDreadfulStratActive")) { Return ResolveState("StratFire"); }
			A_PlaySound("Dreadful/Fire",1,0.4);
			Return ResolveState(Null);
		}
		"####" DCBA 2;
		"####" N 15;
		"####" ABCD 2 Bright;
		
		BFCF A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGF A 0;
		"####" A 1 Bright { A_OverlayOffset(OverlayID(),1+invoker.GunzX,2,WOF_INTERPOLATE); if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.99); } }
		"####" B 1 Bright { A_OverlayOffset(OverlayID(),3+invoker.GunzX,5,WOF_INTERPOLATE); if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.97); } }
		"####" A 0 {
			//Cruft.
			A_PlaySound("Dreadful/Add",5,0.5);
			A_AlertMonsters();
			invoker.GMod = GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking") ? 0.5 : 1.0;
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(7, 7, 7, 25, 0, 24, "none", QF_SCALEDOWN); }
			
			A_Recoil(25.0 * invoker.Gmod * (CountInv("PowerDeadmaker") ? 0.1 : 1.0) * (CountInv("PowerSuitToken") ? 0.1 : 1.0) * GetCvar("GC_PhysicalRecoil"));
			
			//Projectile.
			If(!CountInv("Tibcore")) {
				A_SetBlend("Green",0.2,15);
				if(!CountInv("ArbiterModuleActive")) {
					A_FireProjectile("Dreadball",0,1,15 * (OverlayID() == -3 ? 1.0 : -1.0) + (OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15); //DreadEmpoweredBall
				} else {
					A_FireProjectile("DreadArbiterBall",0,1,15 * (OverlayID() == -3 ? 1.0 : -1.0) + (OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15); //DreadEmpoweredBall
				}
			}
			Else
			{
				A_SetBlend("Blue",0.2,15);
				if(!CountInv("ArbiterModuleActive")) {
					A_FireProjectile("CoreDreadball1",0,0,15.000 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15), -12.0);
					A_FireProjectile("CoreDreadball2",0,0, 4.608 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15),   6.0);
					A_FireProjectile("CoreDreadball3",0,1,25.392 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15),   6.0);
				} else {
					A_FireProjectile("CoreDreadArbiterBall1",0,0,30.000 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15), -24.0);
					A_FireProjectile("CoreDreadArbiterBall2",0,0, 9.216 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15),  12.0);
					A_FireProjectile("CoreDreadArbiterBall3",0,1,50.784 * (OverlayID() == -3 ? 1.0 : -1.0) + ((OverlayID() == -3 ? invoker.GunzX : -invoker.GunzX) * 0.15),  12.0);
				}
			}
		}
		"####" C 1 Bright {
			A_OverlayOffset(OverlayID(),5+invoker.GunzX,8,WOF_INTERPOLATE);
			if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.95); }
			A_SetPitch(pitch - 2.5 								* GetCvar("GC_WeaponRecoil") * invoker.Gmod, SPF_INTERPOLATE);
			A_SetAngle(angle - (OverlayID() == -3 ? 2.5 : -2.5) * GetCvar("GC_WeaponRecoil") * invoker.Gmod, SPF_INTERPOLATE);
		}
		"####" D 1 Bright {
			A_OverlayOffset(OverlayID(),8+invoker.GunzX,13,WOF_INTERPOLATE);
			if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.91); }
			A_SetPitch(pitch - 2.0 								* GetCvar("GC_WeaponRecoil") * invoker.Gmod, SPF_INTERPOLATE);
			A_SetAngle(angle - (OverlayID() == -3 ? 2.0 : -2.0) * GetCvar("GC_WeaponRecoil") * invoker.Gmod, SPF_INTERPOLATE);
		}
		BFCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGG A 0;
		"####" DCBANNNAABBCCDDCCBB 1 {
			//Position.
			static const double dreadx[] = { 10.0, 11.0, 12.0, 13.0, 14.0,
											 13.0, 12.0, 11.0, 10.0, 9.0,
											 8.0, 7.0, 6.0, 5.0, 4.0,
											 3.0, 2.0, 1.0, 0.0 };
			static const double dready[] = { 16.0, 17.0, 18.0, 19.0, 19.0,
											 18.0, 16.0, 14.0, 11.0, 9.0,
											 8.0, 7.0, 6.0, 5.0, 4.0,
											 3.0, 2.0, 1.0, 0.0 };
										
			//Zoom.
			static const double dreadzoom[] = { 0.88, 0.86, 0.85, 0.84, 0.83,
												0.83, 0.84, 0.85, 0.86, 0.87,
												0.89, 0.9, 0.91, 0.93, 0.95,
												0.97, 0.98, 0.99, 1.0 }; 
			//Recoil.
			static const double dreadfactor[] = { -1.0, -0.5, -0.25, -0.25, -0.25,
												  -0.1, 0.0, 0.1, 0.25, 0.25,
												  0.5, 0.5, 0.5, 0.5, 0.25,
												  0.25, 0.25, 0.1, 0.1 };
			//Right side.
			if(OverlayID() == -3) {
			
				//Increment array.
				int rsize = 19;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int right = invoker.LoopRight;

				//Apply position.
				A_OverlayOffset(OverlayID(),  dreadx[right] + invoker.gunzX, dready[right], WOF_INTERPOLATE);

				//Apply zoom.
				A_ZoomFactor(dreadzoom[right]);
				
				//Apply recoil.
				double shift = dreadfactor[right] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift, SPF_INTERPOLATE);
				A_SetAngle(angle + shift, SPF_INTERPOLATE);
			}
			//Left side.
			else
			{
				int lsize = 19;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int left = invoker.LoopLeft;
				
				A_OverlayOffset(OverlayID(), dreadx[left] + invoker.GunzX, dready[left], WOF_INTERPOLATE);
				 
				 A_ZoomFactor(dreadzoom[left]);
				 
				double shift2 = dreadfactor[left] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift2, SPF_INTERPOLATE);
				A_SetAngle(angle - shift2, SPF_INTERPOLATE);
			}
		}
		"####" A 3 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; }
			else				  { invoker.LoopLeft = 0; }
			A_SetPitch(pitch + 0.1 								* GetCvar("GC_WeaponRecoil")  * invoker.Gmod, SPF_INTERPOLATE);
			A_SetAngle(angle + (OverlayID() == -3 ? 0.1 : -0.1) * GetCvar("GC_WeaponRecoil")  * invoker.Gmod, SPF_INTERPOLATE);
		}
		"####" BCDCB 2;
		"####" A 0 {
			invoker.WeapAction--;
			if(OverlayID() == 3) { invoker.LeftHand = 0; }
		}
		"####" A 0 A_JumpIf(OverlayID() == 3,"LeftActive");
		Goto RightActive;
		
   StratFire:
		BSCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGG A 0;
		"####" A 0 {
			If((CountInv("HexenCounter") && CountInv("GreenMana") >= 150 && CountInv("BlueMana") >= 150) || 
			(!CountInv("HexenCounter") && CountInv("TiberiumAmmo") >= 8)) { Return ResolveState(Null); }
			A_TakeInventory("OldDreadfulStratActive",1);
			invoker.WeapAction--;
			Return ResolveState("OuttaJuice");
		}
		"####" A 0 {
			if(OverlayID() == 3) { invoker.LeftHand = 1; }
			A_PlaySound("Dreadful/Fire",1,0.4);
		}
		"####" ACEGIKMOACEGIKMOACEGIKMOACEGIKM 1 Bright A_OverlayOffset(OverlayID(),frandom(1.0,-1.0)+invoker.GunzX,frandom(1.0,-1.0),WOF_INTERPOLATE);
		
		BSCF A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGF A 0;
		"####" A 1 Bright { if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.99); } }
		"####" B 1 Bright { if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.97); } }
		"####" A 0 {
			A_PlaySound("Dreadful/Add",5,0.5);
			A_PlaySound("Dreadful/AltFire",4,0.4);
			
			A_Recoil(40.0 * invoker.Gmod * (CountInv("PowerDeadmaker") ? 0.1 : 1.0) * (CountInv("PowerSuitToken") ? 0.1 : 1.0) * GetCvar("GC_PhysicalRecoil"));
			A_AlertMonsters();
			if(!CountInv("TibCore"))
			{
				A_FireProjectile("SuperDreadball",0,0,15,0);
				A_SetBlend("Green",0.3,80);
			}
			else
			{
				A_FireProjectile("SuperCoreDreadball",0,0,15,0);
				A_SetBlend("Blue",0.3,80);
			}
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(8, 8, 8, 35, 0, 24, "none", QF_SCALEDOWN); }
			if(CountInv("HexenCounter")) {
				A_TakeInventory("GreenMana",150,TIF_NOTAKEINFINITE);
				A_TakeInventory("BlueMana",150,TIF_NOTAKEINFINITE);
			}
			else
			{
				A_TakeInventory("TiberiumAmmo",8,TIF_NOTAKEINFINITE);
			}
		}
		"####" CDEFGHIJKLMNOPPQQ 1 {
			//Position.
			static const double dreadpos[] = { 2.0, 8.0, 13.0, 19.0, 25.0,
											  29.0, 32.0, 34.0, 35.0, 36.0,
											  35.0, 34.0, 30.0, 26.0, 21.0,
											  17.0, 12.0 };
			//Zoom.
			static const double dreadzoom2[] = { 0.95, 0.91, 0.88, 0.86, 0.85,
												0.84, 0.83, 0.82, 0.83, 0.84,
												0.85, 0.86, 0.87, 0.89, 0.91,
												0.93, 0.95 }; 
			//Recoil.
			static const double dreadfactor2[] = { -5.5, -3.5, -2.0, -1.0, -0.75,
												  -0.5, -0.25, -0.1, 0.0, 0.1,
												   0.25, 0.5, 0.75, 1.0, 1.25,
												   1.25, 1.0 };
			//Right side.
			if(OverlayID() == -3) {
			
				//Increment array.
				int rsize = 17;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int right = invoker.LoopRight;

				//Apply position.
				A_OverlayOffset(OverlayID(), dreadpos[right] + invoker.gunzX, dreadpos[right], WOF_INTERPOLATE);

				//Apply zoom.
				A_ZoomFactor(dreadzoom2[right]);
				
				//Apply recoil.
				double shift = dreadfactor2[right] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift, SPF_INTERPOLATE);
				A_SetAngle(angle + shift, SPF_INTERPOLATE);
			}
			//Left side.
			else
			{
				int lsize = 17;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int left = invoker.LoopLeft;
				
				A_OverlayOffset(OverlayID(),  dreadpos[left] + invoker.GunzX, dreadpos[left], WOF_INTERPOLATE);
				 
				 A_ZoomFactor(dreadzoom2[left]);
				 
				double shift2 = dreadfactor2[left] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift2, SPF_INTERPOLATE);
				A_SetAngle(angle - shift2, SPF_INTERPOLATE);
			}
		}
		"####" A 0 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; }
			else				  { invoker.LoopLeft  = 0; }
		}
		BFCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BFGG A 0;
		"####" AANN 2 {
			//Position.
			static const double dreadpos2[] = { 7.0, 3.0, 1.0, 0.0 };
			//Zoom.
			static const double dreadzoom3[] = { 0.97, 0.98, 0.99, 1.0 }; 
			//Recoil.
			static const double dreadfactor3[] = { 1.0, 0.75, 0.5, 0.25 };
			//Right side.
			if(OverlayID() == -3) {
			
				//Increment array.
				int rsize = 4;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int right = invoker.LoopRight;

				//Apply position.
				A_OverlayOffset(OverlayID(), dreadpos2[right] + invoker.gunzX, dreadpos2[right], WOF_INTERPOLATE);

				//Apply zoom.
				A_ZoomFactor(dreadzoom3[right]);
				
				//Apply recoil.
				double shift = dreadfactor3[right] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift, SPF_INTERPOLATE);
				A_SetAngle(angle + shift, SPF_INTERPOLATE);
			}
			//Left side.
			else
			{
				int lsize = 4;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int left = invoker.LoopLeft;
				
				A_OverlayOffset(OverlayID(), dreadpos2[left] + invoker.GunzX, dreadpos2[left], WOF_INTERPOLATE);
				
				 A_ZoomFactor(dreadzoom3[left]);
				 
				double shift2 = dreadfactor3[left] * GetCVar("GC_WeaponRecoil") * invoker.GMod;
				A_SetPitch(pitch + shift2, SPF_INTERPOLATE);
				A_SetAngle(angle - shift2, SPF_INTERPOLATE);
			}
		}
		BFGG N 105 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; A_OverlayOffset(OverlayID(),invoker.GunzX,0); }
			else				  { invoker.LoopLeft  = 0; A_OverlayOffset(OverlayID(),invoker.GunzX,0); }
			//A_StopSound(6);
		}
		BFGG A 0 A_JumpIf(random(0,3) == 0 && !(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking")), "ComeOnAndSlam");
		BFGG A 0 {
			invoker.WeapAction--;
			if(OverlayID() == 3) { invoker.LeftHand = 0; }
			
			If((CountInv("HexenCounter") && CountInv("GreenMana") >= 150 && CountInv("BlueMana") >= 150) ||
			  (!CountInv("HexenCounter") && CountInv("TiberiumAmmo") >= 8))
			{
				If(OverlayID() == -3) {
					Return ResolveState("RightActive");
				}
				Else if(OverlayID() == 3) {
					Return ResolveState("LeftActive");
				}
			}
			A_TakeInventory("OldDreadfulStratActive",1);
			Return ResolveState(Null);
		}
		"####" A 0 A_JumpIf(OverlayID() == 3,"LeftActive");
		Goto RightActive;
	ComeOnAndSlam:
		BFGG N 0 {
			invoker.LoopRight = 0;
			invoker.Loopler++;
			
			if(invoker.Loopler > 2) {
				invoker.Loopler = 0;
				invoker.LoopRight = 0;
				Return ResolveState("AndWelcomeToTheJam");
			}
			Return ResolveState(Null);
		}
		BFGG NNNNNNNNNNNNNN 1 {
			static const double dreadx2[] = {  1.0,  3.0, 6.0, 9.0, 11.0, 12.0, 13.0,
											   12.0, 11.0, 9.0, 6.0,  3.0,  1.0,  0.0 };
			static const double dready2[] = {  1.0,  3.0,  6.0, 11.0, 15.0, 17.0, 18.0,
											   17.0, 15.0, 11.0,  6.0,  3.0,  1.0,  0.0 };
			static const double dreadp2[] = {  0.25,  0.5,  0.75,  1.0,  0.75,  0.5,  0.25,
											  -0.25, -0.5, -0.75, -1.0, -0.75, -0.5, -0.25 };
			static const double dreada2[] = { -0.25, -0.5, -0.75, -1.0, -0.75, -0.5, -0.25,
											   0.25,  0.5,  0.75,  1.0,  0.75,  0.5,  0.25 };
			
			int slamsize = 14;
			if(invoker.LoopRight + 1 < slamsize) { invoker.LoopRight++; }
			int slam = invoker.LoopRight;
			
			A_OverlayOffset(OverlayID(), dreadx2[slam], dready2[slam], WOF_INTERPOLATE);
			A_SetPitch(Pitch + dreadp2[slam], SPF_INTERPOLATE);
			A_SetAngle(Angle + dreada2[slam], SPF_INTERPOLATE);
		}
		Loop;
	AndWelcomeToTheJam:
		BFGG N 35 { A_PlaySound("Guncaster/Meh",2); }
		BFGG N 0 A_Overlay(3,"BangYourGun"); //You know you want to do it~
		"####" N 15;
		"####" N 1 A_OverlayOffset(OverlayID(),2,2,WOF_INTERPOLATE);
		"####" N 1 { A_OverlayOffset(OverlayID(),3,7,WOF_INTERPOLATE); A_PlaySound("Punch/Hit",5,0.7); }
		"####" N 1 A_OverlayOffset(OverlayID(),19,25,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),30,42,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),32,45,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),33,46,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),31,44,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),29,42,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),27,41,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),25,27,WOF_INTERPOLATE);
		"####" A 1 {
			A_OverlayOffset(OverlayID(),15,17,WOF_INTERPOLATE);
			A_PlaySound("Dreadful/Reboot2",5,0.8);
			If(CountInv("TibCore")) { A_SetBlend("Blue",0.5,80); }
			Else { A_SetBlend("Green",0.5,80); }
		}
		"####" N 1 A_OverlayOffset(OverlayID(),8,7,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),3,3,WOF_INTERPOLATE);
		"####" N 1 A_OverlayOffset(OverlayID(),1,1,WOF_INTERPOLATE);
		"####" N 4 A_OverlayOffset(OverlayID(),0,0,WOF_INTERPOLATE);
		"####" N 0 {
			A_OverlayOffset(OverlayID(),0,0,WOF_INTERPOLATE);
			A_PlaySound("Dreadful/Reboot",1);
			//"####" A 0 A_PlaySound("Dreadful/Loop2",6,0.4,1);
		}
		BSCI A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGI A 0;
		"####" ABCDEFGHIJKLMNOP 1;
		
		BSCG A 0 A_JumpIf(CountInv("TibCore"),2);
		BSGG A 0;
		"####" ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP 1;
		"####" A 0 { invoker.WeapAction--; invoker.LeftHand = 0; }
		Goto RightActive;
		
	BangYourGun:
		TNT1 A 0 A_OverlayFlags(OverlayID(),PSPF_FLIP,1);
		C1DP A 0 A_JumpIf(CountInv("PowerDeadmaker") && CountInv("PowerSuitDraugh"),6);
		C1NP A 0 A_JumpIf(CountInv("PowerDeadmaker"),5);
		C1CP A 0 A_JumpIf(CountInv("PowerSuitToken"),4);
		C1YP A 0 A_JumpIf(CountInv("PowerSuitProtect"),3);
		C1YP A 0 A_JumpIf(CountInv("PowerSuitDraugh"),2);
		C1GP A 0;
		"####" A 1 A_OverlayOffset(OverlayID(),2,157);
		"####" A 1 A_OverlayOffset(OverlayID(),12,137,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),25,106,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),38,74,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),38,48,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),39,41,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),37,37,WOF_INTERPOLATE);
		"####" A 8 A_OverlayOffset(OverlayID(),36,36,WOF_INTERPOLATE);
		"####" E 1 {
			A_OverlayOffset(OverlayID(),61,49);
			A_SetPitch(Pitch + 7.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 7.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),89,71);
			A_SetPitch(Pitch + 6.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 6.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),100,86,WOF_INTERPOLATE);
			A_SetPitch(Pitch + 5.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 5.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),112,103,WOF_INTERPOLATE);
			A_SetPitch(Pitch + 3.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 3.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),105,98,WOF_INTERPOLATE);
			A_SetPitch(Pitch + 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),100,94,WOF_INTERPOLATE);
			A_SetPitch(Pitch + 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),95,87,WOF_INTERPOLATE);
			A_SetPitch(Pitch + 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle - 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 A_OverlayOffset(OverlayID(),89,77,WOF_INTERPOLATE);
		"####" A 1 {
			A_OverlayOffset(OverlayID(),80,68,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),60,60,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),58,50,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),49,44,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_OverlayOffset(OverlayID(),38,37,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		
		"####" A 1 {
			A_OverlayOffset(OverlayID(),36,36,WOF_INTERPOLATE);
			A_SetPitch(Pitch - 2.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 2.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 2.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 1.0 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.5 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1 {
			A_SetPitch(Pitch - 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
			A_SetAngle(Angle + 0.25 * GetCvar("GC_WeaponRecoil"), SPF_INTERPOLATE);
		}
		"####" A 1;
		
		"####" A 1 A_OverlayOffset(OverlayID(),37,37,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),39,41,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),38,48,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),38,74,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),25,106,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),12,137,WOF_INTERPOLATE);
		"####" A 1 A_OverlayOffset(OverlayID(),2,157,WOF_INTERPOLATE);
		"####" A 0 A_Overlay(3,"LeftActive");
		Stop;
	}
}

#endregion
