#region Gnus
//$color 14

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

class MourningGlory : GuncasterWeapon
{
    Default
    {
		//$Title Mourning Glory
		Inventory.PickupSound "Guncaster/Laugh1";
		Inventory.PickupMessage "$GETMOURNING";
		Obituary "%o was obliterated by %k's ''Mourning Glory''.";
		Tag "Mourning Glory";
		Weapon.UpSound "MourningGlory/Reload" ;
		Weapon.SelectionOrder 7;
		Weapon.AmmoGive 4;
		Weapon.AmmoType "MourningAmmo";
		Weapon.AmmoUse 1;
		Weapon.SlotNumber 5;
		Weapon.BobStyle 'InverseSmooth';
		Weapon.BobSpeed 1.0;
		Weapon.BobRangeY 1.0;
		Weapon.BobRangeX 0.8;
		//+AMMO_OPTIONAL
		Scale 0.8;
	}
	
	//Strat drop.
	override void PostBeginPlay()
	{
		if(!bDROPPED && random(0,20) == 0)
		{
			A_DropItem("MourningStratGiver",-1,256);
		}
		Super.PostBeginPlay();
		Return;
	}
	
	//Hexen handling.
	override Void AttachToOwner (actor user) {
		if(gameinfo.gametype == Game_HEXEN) {
			AmmoGive1 = 30;
			AmmoType1 = "GreenMana";
			AmmoUse1 = 15;
		}
		Super.AttachToOwner(user);
	}
	
	//Gunzerk ammo regen. Now that there's gunzerk regen list, not needed anymore.
	/*int Countdown, CountdownSummit, AmmoCount;
    Class<Inventory> AmmoClass;
	
	override void AttachToOwner(Actor user)
	{
		Countdown = 0;
        CountdownSummit = 270;
        AmmoCount = 1;
        AmmoClass = 'MourningAmmo';
		Super.AttachToOwner(user);
	}
	
	override void DoEffect() {
		AmmoRegen();
		Super.DoEffect();
    }
	
	void AmmoRegen() {
		let AmmoToCheck = Ammo(Owner.FindInventory(AmmoClass));
        if (AmmoToCheck.Amount < AmmoToCheck.MaxAmount && owner.CountInv("PowerGunzerking")) {
			Countdown++;
			if(Countdown >= CountdownSummit) {
				Owner.A_GiveInventory(AmmoClass, AmmoCount);
				Countdown = 0;
			}
        }
	}*/
	
	int LoopLeft2, LoopRight2; //Used by barrel.
	int RightMag, LeftMag; //Strat clips.
	int StratFired, StratLeftFired; //So mofo won't try to reload.
	int GunzerkShot, GunzerkShot2;
	
	double StratMod;
	double GunzX, GunzY;
	
	States
	{
	Spawn:
		MORG X -1;
		Stop;

	SelectStuff:
		TNT1 A 0 {
			//A_Overlay(99,"Debug");
			invoker.LoopLeft2 = 0;
			invoker.LoopRight2 = 0;
			invoker.RightMag = 0;
			invoker.LeftMag = 0;
			invoker.GunzerkShot = 0;
			invoker.GunzerkShot2 = 0;
			invoker.StratFired = 0;
			invoker.StratLeftFired = 0;
			if(CountInv("MourningStratActive")) { invoker.StratMod = 0.25; }
			else { invoker.StratMod = 1.0; }
			A_GiveInventory("MourningSelected",1);
			A_SetCrosshair(52);
		}
		Goto SelectLoop;
		
	DeselectStuff:
		TNT1 A 0 {
			invoker.LoopLeft2 = 0;
			invoker.LoopRight2 = 0;
			invoker.StratFired = 0;
			invoker.StratLeftFired = 0;
			A_TakeInventory("MourningSelected",1);
		}
		Goto DeselectLoop;
	/*Debug:
		TNT1 A 35 {
			A_Log(String.Format("WeapAction %i", invoker.WeapAction));
			A_Log(String.Format("LeftHand %i", invoker.LeftHand));
		}
		Loop;*/

	//STRAT
	
	StratSwitch:
		MORG A 0 A_JumpIf(CountInv("MourningStratActive"),"StratSwitchOff");
		MORG A 0 {
			invoker.LoopRight = 0;
			invoker.LeftHand = 1;
			A_GiveInventory("MourningStratActive");
			invoker.StratMod = 0.2;
			A_PlaySound("Matriarch/Pull",5,0.7);
			if(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking")) { A_Overlay(3,"LeftStratSwitch"); }
			//else { A_Overlay(-2,"RightStrat2"); }
		}
		MORG AAAAAAAAA 1 {
			static const double x[] = {1.0, 3.0, 6.0, 10.0, 12.0,
									   13.0, 14.0, 15.0, 14.0};
			static const double y[] = {1.0, 2.0, 3.0, 5.0, 8.0,
									   13.0, 14.0, 15.0, 14.0};
			int g = invoker.LoopRight++;				
			A_OverlayOffset(OverlayID(), x[g] + invoker.GunzX, y[g] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 { invoker.LoopRight = 0; }
		MRSG AAAAA 1 {
			static const double x[] = {13.0, 9.0, 4.0, 2.0, 1.0};
			static const double y[] = {10.0, 6.0, 3.0, 2.0, 1.0};
			int g = invoker.LoopRight++;
			A_OverlayOffset(OverlayID(), x[g] + invoker.GunzX, y[g] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MRSG A 0 {
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY,WOF_INTERPOLATE);
			invoker.LoopRight = 0;
			invoker.LeftHand = 0;
			A_GiveInventory("MourningStratActive",1);
		}
		Goto RightActive;
	LeftStratSwitch:
		MORG A 0 {
			invoker.LoopLeft = 0;
			A_OverlayFlags(OverlayID(),PSPF_FLIP|PSPF_MIRROR,1);
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY);
		}
		MORG AAAAAAAAA 1 {
			static const double x2[] = {1.0, 3.0, 6.0, 10.0, 12.0,
										13.0, 14.0, 15.0, 14.0};
			static const double y2[] = {1.0, 2.0, 3.0, 5.0, 8.0,
										13.0, 14.0, 15.0, 14.0};
			int g2 = invoker.LoopLeft++;
			A_OverlayOffset(OverlayID(), x2[g2] + invoker.GunzX, y2[g2] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 { invoker.LoopLeft = 0; }
		MRSG AAAAA 1 {
			static const double x2[] = {13.0, 9.0, 4.0, 2.0, 1.0};
			static const double y2[] = {10.0, 6.0, 3.0, 2.0, 1.0};
			int g2 = invoker.LoopLeft++;
			A_OverlayOffset(OverlayID(), x2[g2] + invoker.GunzX, y2[g2] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MRSG A 0 {
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY,WOF_INTERPOLATE);
			invoker.LoopLeft = 0;
		}
		Goto LeftActive;
		
	StratSwitchOff:
		MRSG A 0 {
			invoker.LoopRight = 0;
			invoker.LeftHand = 1;
			A_TakeInventory("MourningStratActive");
			invoker.StratMod = 1.0;
			A_PlaySound("Matriarch/Pull",5,0.7);
			if(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking")) { A_Overlay(3,"LeftStratSwitchOff"); }
			//else { A_Overlay(-2,"RightStrat2"); }
		}
		MRSG AAAAAAAAA 1 {
			static const double x[] = {1.0, 3.0, 6.0, 10.0, 12.0,
									   13.0, 14.0, 15.0, 14.0};
			static const double y[] = {1.0, 2.0, 3.0, 5.0, 8.0,
									   13.0, 14.0, 15.0, 14.0};
			int g = invoker.LoopRight++;
			A_OverlayOffset(OverlayID(), x[g] + invoker.GunzX, y[g] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 { invoker.LoopRight = 0; }
		MORG AAAAA 1 {
			static const double x[] = {13.0, 9.0, 4.0, 2.0, 1.0};
			static const double y[] = {10.0, 6.0, 3.0, 2.0, 1.0};
			int g = invoker.LoopRight++;
			A_OverlayOffset(OverlayID(), x[g] + invoker.GunzX, y[g] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 {
			A_OverlayOffset(OverlayID(),invoker.GunzX, invoker.GunzY, WOF_INTERPOLATE);
			invoker.LeftHand = 0;
			invoker.LoopRight = 0;
			A_TakeInventory("MourningStratActive",1);
		}
		Goto RightActive;
	LeftStratSwitchOff:
		MRSG A 0 {
			invoker.LoopLeft = 0;
			A_OverlayFlags(OverlayID(),PSPF_FLIP|PSPF_MIRROR,1);
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY);
		}
		MRSG AAAAAAAAA 1 {
			static const double x2[] = {1.0, 3.0, 6.0, 10.0, 12.0,
										13.0, 14.0, 15.0, 14.0};
			static const double y2[] = {1.0, 2.0, 3.0, 5.0, 8.0,
										13.0, 14.0, 15.0, 14.0};
			int g2 = invoker.LoopLeft++;
			A_OverlayOffset(OverlayID(), x2[g2] + invoker.GunzX, y2[g2] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 { invoker.LoopLeft = 0; }
		MORG AAAAA 1 {
			static const double x2[] = {13.0, 9.0, 4.0, 2.0, 1.0};
			static const double y2[] = {10.0, 6.0, 3.0, 2.0, 1.0};
			int g2 = invoker.LoopLeft++;
			A_OverlayOffset(OverlayID(), x2[g2] + invoker.GunzX, y2[g2] + invoker.GunzY, WOF_INTERPOLATE);
		}
		MORG A 0 {
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY,WOF_INTERPOLATE);
			invoker.LoopLeft = 0;
		}
		Goto LeftActive;
	
	RightStrat2:
		MRSG A 0 A_JumpIf(CountInv("MourningStratActive"),2);
		MORG A 0;
		"####" AAAAAAAAAAAAAA 1 {
			static const double x[] = {1.0, 3.0, 6.0, 10.0, 12.0, 13.0, 14.0,
									   15.0, 14.0, 13.0, 9.0, 4.0, 2.0, 1.0};
			static const double y[] = {1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 14.0,
									   15.0, 14.0, 10.0, 6.0, 3.0, 2.0, 1.0};
			int g2 = invoker.LoopLeft++;	
			A_OverlayOffset(OverlayID(), x[g2] + invoker.GunzX, y[g2] + invoker.GunzY, WOF_INTERPOLATE);
		}
		"####" A 0 { invoker.LoopLeft = 0; }
		Goto RightActive;
	
	//RIGHT SIDE
	
	RightActive:
		"####" "#" 0 {
			if(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking")) {
				invoker.GunzX = 35;
				invoker.GunzY = 5;
			} else {
				invoker.GunzX = 0;
				invoker.GunzY = 0;
			}
			A_OverlayOffset(OverlayID(),invoker.GunzX,invoker.GunzY);
		}
		MRSG A 0 A_JumpIf(CountInv("MourningStratActive"),2);
		MORG A 0;
		"####" "#" 1;
        "####" "#" 0 {
			//Strat switch.
			If(CountInv("MourningStrat") &&
				!invoker.weapSwitch && !invoker.LeftHand && !invoker.WeapAction &&
				!CountInv("MenuWheelActive") && GetPlayerInput(INPUT_BUTTONS) & BT_RELOAD) {
				Return ResolveState("StratSwitch");
			}
			
			//Fire.
			If(!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!invoker.weapSwitch && !invoker.LeftHand && !CountInv("MenuWheelActive") && 
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("MainFire");
			}
			
			//Gunzerk fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) &&
				!CountInv("MenuWheelActive") && 
				!invoker.WeapSwitch && GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
				Return ResolveState("MainFire");
			}
			Return ResolveState(Null);
		}
		Loop;
		
	//FIRE
	StratFireActivate:
		MRSG A 0 { invoker.WeapAction++; invoker.LeftHand = 1; }
	StratFire:
		MRSG A 0 {
			//If full, stop charging.
			if(
			  (Invoker.RightMag >= 10 && OverlayID() == -3) ||
			  (Invoker.LeftMag >= 10 && OverlayID() == 3)
			  )
			{
				Return ResolveState("StratCharged");
			}
			
			//If not enough shells, stop loading.
			if(
			   Invoker.RightMag + Invoker.LeftMag >= CountInv("MourningAmmo")
			  )
			{
				Return ResolveState("StratCharged");
			}
			if(OverlayID() == -3) { invoker.RightMag++; A_Overlay(-4,"Null"); } //Charge up.
			else 				  { invoker.LeftMag++; A_Overlay(2,"Null"); }
			A_PlaySound("MourningGlory/Reload",6,0.8);
			Return ResolveState(Null);
		}
		MRSR AAABBBCCC 1 {
			static const double xpos[] = { 1.0, 2.0, 2.0, 1.0, 0.0, -1.0, -1.0, -1.0, 0.0 };
			static const double ypos[] = { 1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0, 0.0 };
			
			if(OverlayID() == -3) {
				int rsize = 9;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int pos = invoker.LoopRight;
				A_OverlayOffset(OverlayID(), xpos[pos] + invoker.GunzX, ypos[pos] + invoker.GunzY, WOF_INTERPOLATE); 
			} else {
				int lsize = 9;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int pos2 = invoker.LoopLeft;
				A_OverlayOffset(OverlayID(), xpos[pos2] + invoker.GunzX, ypos[pos2] + invoker.GunzY, WOF_INTERPOLATE);
			}
		}
		MRSG A 5 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; }
			else { invoker.LoopLeft = 0; }
		}
		MRSG A 0 {
			//Fire.
			If(!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && !CountInv("MenuWheelActive") &&
				!invoker.weapSwitch && OverlayID() == -3 && /*!invoker.LeftHand &&*/
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("StratFire");
			}
			//Gunzerk left fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && OverlayID() == 3 &&
				!CountInv("MenuWheelActive") && !invoker.WeapSwitch && GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("StratFire");
			}
			//Gunzerk right fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && OverlayID() == -3 &&
				!CountInv("MenuWheelActive") && !invoker.WeapSwitch && GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
				Return ResolveState("StratFire");
			}
			Return ResolveState(Null);
		}
		Goto StratMainFire;
	StratCharged:
		MRSG A 1;
		MRSG A 0 {
			//Fire.
			If(!(GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && !CountInv("MenuWheelActive") &&
				!invoker.weapSwitch && OverlayID() == -3 && /*!invoker.LeftHand &&*/
				GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("StratCharged");
			}
			//Gunzerk left fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && OverlayID() == 3 &&
				!CountInv("MenuWheelActive") && !invoker.WeapSwitch && GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK) {
				Return ResolveState("StratCharged");
			}
			//Gunzerk right fire.
			If((GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking")) && OverlayID() == -3 &&
				!CountInv("MenuWheelActive") && !invoker.WeapSwitch && GetPlayerInput(INPUT_BUTTONS) & BT_ALTATTACK) {
				Return ResolveState("StratCharged");
			}
			Return ResolveState(Null);
		}
		Goto StratMainFire;
		
	MainFire:
		"####" A 0 A_JumpIf(CountInv("MourningStratActive"),"StratFireActivate");
	StratMainFire:
		"####" A 0 A_JumpIf(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"),2);
		"####" A 0 A_CheckReload;
		"####" A 0 A_JumpIf(OverlayID() == 3,3);
		"####" A 0 A_JumpIfNoAmmo("RightActive");
		"####" A 0 A_Jump(256,2);
		"####" A 0 A_JumpIfNoAmmo("LeftActive");
		"####" "#" 0 {
			if(!CountInv("MourningStratActive")) {
				invoker.WeapAction++;
				invoker.LeftHand = 1;
			}
			if(OverlayID() == -3) {
				if(CountInv("MourningStratActive")) { invoker.StratFired = 1; }
				A_Overlay(-4,"MainFire2");
			} else {
				if(CountInv("MourningStratActive")) { invoker.StratLeftFired = 1; }
				A_Overlay(2,"MainFire2");
			}
			
			//Gunzerk recoil modifier.
			invoker.GMod = GetCVar("GC_Gunslinger") || CountInv("PowerGunzerking") ? 0.5 : 1.0;
			
			//Projectile.
			if(!(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) { //Regular shot.
			
				if(CountInv("GladiusBarrel") >= 3) {
					A_FireProjectile("MourningShell4",0,1,2,2);
				}
				else if(CountInv("GladiusBarrel") >= 2) {
					A_FireProjectile("MourningShell3",0,1,2,2);
				}
				else if(CountInv("GladiusBarrel") >= 1) {
					A_FireProjectile("MourningShell2",0,1,2,2);
				}
				else {
					A_FireProjectile("MourningShell",0,1,2,2);
				}

				A_FireProjectile("Mourning_Flare",0,0,2,2);
				for(invoker.Loopler = 0; invoker.Loopler <= 15; invoker.Loopler++)
				{
					A_FireProjectile("Mourning_Ember",frandom(22.0,-22.0),0,2,2,FPF_NOAUTOAIM,frandom(22.0,-12.0));
					A_FireProjectile("Mourning_Cloud",frandom(18.0,-18.0),0,2,2,FPF_NOAUTOAIM,frandom(18.0,-18.0));
					A_FireProjectile("Gunsmoke_Large",frandom(12.0,-12.0),0,2,2,FPF_NOAUTOAIM,frandom(12.0,-12.0));
				}
			}
			else if(OverlayID() == -3) { //Gunzerk right.
				invoker.GunzerkShot = 1;
				
				if(CountInv("GladiusBarrel") >= 3) {
					A_FireProjectile("MourningShell4",0,1,9,-3);
				}
				else if(CountInv("GladiusBarrel") >= 2) {
					A_FireProjectile("MourningShell3",0,1,9,-3);
				}
				else if(CountInv("GladiusBarrel") >= 1) {
					A_FireProjectile("MourningShell2",0,1,9,-3);
				}
				else {
					A_FireProjectile("MourningShell",0,1,9,-3);
				}
				A_FireProjectile("Mourning_Flare",0,0,9,-3);
				for(invoker.Loopler = 0; invoker.Loopler <= 15; invoker.Loopler++)
				{
					A_FireProjectile("Mourning_Ember",frandom(22.0,-22.0),0,12,-3,FPF_NOAUTOAIM,frandom(22.0,-12.0));
					A_FireProjectile("Mourning_Cloud",frandom(18.0,-18.0),0,12,-3,FPF_NOAUTOAIM,frandom(18.0,-18.0));
					A_FireProjectile("Gunsmoke_Large",frandom(12.0,-12.0),0,12,-3,FPF_NOAUTOAIM,frandom(12.0,-12.0));
				}
			}									  
			else {						//Gunzerk left.
				invoker.GunzerkShot2 = 1;
				
				if(CountInv("GladiusBarrel") >= 3) {
					A_FireProjectile("MourningShell4",0,1,-9,-3);
				}
				else if(CountInv("GladiusBarrel") >= 2) {
					A_FireProjectile("MourningShell3",0,1,-9,-3);
				}
				else if(CountInv("GladiusBarrel") >= 1) {
					A_FireProjectile("MourningShell2",0,1,-9,-3);
				}
				else {
					A_FireProjectile("MourningShell",0,1,-9,-3);
				}
				A_FireProjectile("Mourning_Flare",0,0,-9,-3);
				for(invoker.Loopler = 0; invoker.Loopler <= 15; invoker.Loopler++)
				{
					A_FireProjectile("Mourning_Ember",frandom(22.0,-22.0),0,-12,-3,FPF_NOAUTOAIM,frandom(22.0,-12.0));
					A_FireProjectile("Mourning_Cloud",frandom(18.0,-18.0),0,-12,-3,FPF_NOAUTOAIM,frandom(18.0,-18.0));
					A_FireProjectile("Gunsmoke_Large",frandom(12.0,-12.0),0,-12,-3,FPF_NOAUTOAIM,frandom(12.0,-12.0));
				}
			}								 
			
			//Cruft.
			A_PlaySound("MourningGlory/Fire",1,0.85); //Matriarch/Fire
			A_PlaySound("MourningGlory/Add",5,0.85);
			A_SetBlend("Yellow",0.15,15);
			A_Recoil(10.0 * invoker.Gmod * (CountInv("PowerDeadmaker") ? 0.1 : 1.0) * (CountInv("PowerSuitToken") ? 0.1 : 1.0) * GetCvar("GC_PhysicalRecoil"));
			A_AlertMonsters();
			if(GetCvar("GC_QuakeRecoil")) { A_QuakeEx(8, 8, 5, 15, 0, 64, "", QF_SCALEDOWN); }
			
			//Strat loaded remover.
			if(OverlayID() == -3 && invoker.RightMag) { invoker.RightMag--; }
			else if(OverlayID() == 3 && invoker.LeftMag) { invoker.LeftMag--; }
		}
		MRSF A 0 A_JumpIf(CountInv("MourningStratActive"),2);
		MORF A 0;
		"####" A 1 Bright {
			A_OverlayOffset(OverlayID(),1+invoker.GunzX,1+invoker.GunzY,WOF_INTERPOLATE);
			if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.99); }
			A_SetPitch(pitch - 0.5 * GetCvar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod, SPF_INTERPOLATE);
			A_SetAngle(angle + (OverlayID() == -3 ? -0.5 : 0.5) * GetCvar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod, SPF_INTERPOLATE);
		}
		"####" B 1 Bright {
			A_OverlayOffset(OverlayID(),6+invoker.GunzX,6+invoker.GunzY,WOF_INTERPOLATE);
			if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.97); }
			A_SetPitch(pitch - 1.5 * GetCvar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod, SPF_INTERPOLATE);
			A_SetAngle(angle + (OverlayID() == -3 ? -1.5 : 1.5) * GetCvar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod, SPF_INTERPOLATE);
		}
		MRSG A 0 A_JumpIf(CountInv("MourningStratActive"),2);
		MORG A 0;
		"####" BBBBBB 1 {
			//Position.
			static const double pos[] = { 9.0, 13.0, 17.0, 18.0, 19.0, 20.0 };
			static const double zoom[] = { 0.95, 0.945, 0.94, 0.93, 0.92, 0.91 }; 
			static const double factor[] = { -3.0, -1.5, -1.0, -0.75, -0.5, -0.25 };
			
			//Right side.
			if(OverlayID() == -3) {
			
				//Increment array.
				int rsize = 6;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int right = invoker.LoopRight;

				//Apply position.
				A_OverlayOffset(OverlayID(), pos[right] + invoker.GunzX, pos[right] + invoker.GunzY, WOF_INTERPOLATE);

				//Apply zoom.
				A_ZoomFactor(zoom[right]);
				
				//Apply recoil.
				double shift = factor[right] * GetCVar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod;

				A_SetPitch(pitch + shift, SPF_INTERPOLATE);
				A_SetAngle(angle + shift, SPF_INTERPOLATE);
				
				//Strat fire.
				if(invoker.RightMag && invoker.LoopRight >= 5) { invoker.LoopRight = 0; Return ResolveState("StratMainFire"); }
				Return ResolveState(Null);
			}
			//Left side.
			else
			{
				//Increment array.
				int lsize = 6;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int left = invoker.LoopLeft;
				
				//Apply position.
				A_OverlayOffset(OverlayID(), pos[left] + invoker.GunzX, pos[left] + invoker.GunzY, WOF_INTERPOLATE);
				 
				 //Apply zoom.
				 A_ZoomFactor(zoom[left]);
				 
				 //Apply recoil.
				double shift2 = factor[left] * GetCVar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod;
				
				A_SetPitch(pitch + shift2, SPF_INTERPOLATE);
				A_SetAngle(angle - shift2, SPF_INTERPOLATE);
				
				//Strat fire.
				if(invoker.LeftMag  && invoker.LoopLeft >= 5) { invoker.LoopLeft = 0; Return ResolveState("StratMainFire"); }
				Return ResolveState(Null);
			}
		}
		"####" B 9 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; } else { invoker.LoopLeft = 0; }
			A_OverlayOffset(OverlayID(),21+invoker.GunzX,21+invoker.GunzY,WOF_INTERPOLATE);
			if(GetCvar("GC_ZoomRecoil")) { A_ZoomFactor(0.9); }
		}
		"####" BBBBBBBB 1 {
			//Position.
			static const double pos[] = { 20.0, 19.0, 17.0, 14.0, 10.0, 5.0, 1.0, 0.0 };
			static const double zoom[] = { 0.91, 0.93, 0.95, 0.97, 0.98, 0.99, 0.995, 1.0 }; 
			static const double factor[] = { 0.5, 0.75, 1.25, 1.5, 1.0, 0.75, 0.5, 0.25 };
			
			//Right side.
			if(OverlayID() == -3) {
			
				//Increment array.
				int rsize = 8;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int right = invoker.LoopRight;

				//Apply position.
				A_OverlayOffset(OverlayID(), pos[right] + invoker.GunzX, pos[right] + invoker.GunzY, WOF_INTERPOLATE);

				//Apply zoom.
				A_ZoomFactor(zoom[right]);
				
				//Apply recoil.
				double shift = factor[right] * GetCVar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod;

				A_SetPitch(pitch + shift, SPF_INTERPOLATE);
				A_SetAngle(angle + shift, SPF_INTERPOLATE);
			}
			//Left side.
			else
			{
				//Increment array.
				int lsize = 8;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int left = invoker.LoopLeft;
				
				//Apply position.
				A_OverlayOffset(OverlayID(), pos[left] + invoker.GunzX, pos[left] + invoker.GunzY, WOF_INTERPOLATE);
				 
				 //Apply zoom.
				 A_ZoomFactor(zoom[left]);
				 
				 //Apply recoil.
				double shift2 = factor[left] * GetCVar("GC_WeaponRecoil") * invoker.Gmod * invoker.StratMod;
				
				A_SetPitch(pitch + shift2, SPF_INTERPOLATE);
				A_SetAngle(angle - shift2, SPF_INTERPOLATE);
			}
		}
		"####" A 5 {
			if(OverlayID() == -3) { invoker.LoopRight = 0; if(CountInv("MourningStratActive")) { invoker.StratFired = 0; invoker.LeftHand = 0; invoker.WeapAction--; return ResolveState("RightActive"); } return State(Null); }
			else { invoker.LoopLeft = 0; if(CountInv("MourningStratActive")) { invoker.StratFired = 0; invoker.LeftHand = 0; invoker.WeapAction--; return ResolveState("LeftActive"); } return State(Null); }
			return ResolveState(Null);
		}
		"####" A 0 {
			A_PlaySound("MourningGlory/Reload",6,0.8);
			//Casing.
			if(!(GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) {
				A_FireProjectile("MourningShellCasingSpawnerLeft",0,0,8,-12,FPF_NOAUTOAIM);
			}
			if(OverlayID() == -3 && (GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) {
				A_FireProjectile("MourningShellCasingSpawnerLeft",0,0,12,-14,FPF_NOAUTOAIM);
			}
			else if(OverlayID() == 3 && (GetCvar("GC_Gunslinger") || CountInv("PowerGunzerking"))) {
				A_FireProjectile("MourningShellCasingSpawner",0,0,-12,-14,FPF_NOAUTOAIM);
			}
		}
		MORR AAABBBCCC 1 {
			static const double xpos[] = { 1.0, 2.0, 2.0, 1.0, 0.0, -1.0, -1.0, -1.0, 0.0 };
			static const double ypos[] = { 1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0, 0.0 };
			
			if(OverlayID() == -3) {
				int rsize = 9;
				if(invoker.LoopRight + 1 < rsize) { invoker.LoopRight++; }
				int pos = invoker.LoopRight;
				
				
				A_OverlayOffset(OverlayID(), xpos[pos] + invoker.GunzX, ypos[pos] + invoker.GunzY, WOF_INTERPOLATE); 
			} else {
				int lsize = 9;
				if(invoker.LoopLeft + 1 < lsize) { invoker.LoopLeft++; }
				int pos2 = invoker.LoopLeft;
				
				
				A_OverlayOffset(OverlayID(), xpos[pos2] + invoker.GunzX, ypos[pos2] + invoker.GunzY, WOF_INTERPOLATE);
			}
		}
		MORG A 8;
		MORG A 0 { if(OverlayID() == -3) { invoker.LoopRight = 0; } else { invoker.LoopLeft = 0; }
				   invoker.LeftHand = 0;
				   invoker.WeapAction--; }
		MORG A 0 A_JumpIf(OverlayID() == 3,"LeftActive");
		Goto RightActive;
		
	MainFire2:
		TNT1 A 2 {
			A_OverlayOffset(OverlayID(),11 + invoker.GunzX, 11 + invoker.GunzY);
			if(OverlayID() == 2) { A_OverlayFlags(2,PSPF_MIRROR|PSPF_FLIP,1); }
		}
		MORG CCCCCC 1 {
			static const double barrelpos[] = { 11.0, 21.0, 29.0, 32.0, 34.0, 36.0 };
			
			if(OverlayID() == -4)
			{
				int brsize = 6;
				if(invoker.LoopRight2 + 1 < brsize) { invoker.LoopRight2++; }
				int right2 = invoker.LoopRight2;
				
				A_OverlayOffset(OverlayID(), barrelpos[right2] + invoker.GunzX, barrelpos[right2] + invoker.GunzY, WOF_INTERPOLATE);
			} else {
				int blsize = 6;
				if(invoker.LoopLeft2 + 1 < blsize) { invoker.LoopLeft2++; }
				int left2 = invoker.LoopLeft2;
				
				A_OverlayOffset(OverlayID(), barrelpos[left2] + invoker.GunzX, barrelpos[left2] + invoker.GunzY, WOF_INTERPOLATE);
			}
		}
		MORG C 4 { if(OverlayID() == -4) { invoker.LoopRight2 = 0; } else { invoker.LoopLeft2 = 0; } A_OverlayOffset(OverlayID(),37 + invoker.GunzX,37 + invoker.GunzY,WOF_INTERPOLATE); }
		MORG C 1 A_OverlayOffset(OverlayID(),36 + invoker.GunzX,36 + invoker.GunzY,WOF_INTERPOLATE);
		MORG C 4 A_OverlayOffset(OverlayID(),35 + invoker.GunzX,35 + invoker.GunzY,WOF_INTERPOLATE);
		MORG CCCCCCCCC 1 {
			static const double barrelpos[] = { 33.0, 31.0, 27.0, 22.0, 16.0, 9.0,
												4.0, 2.0, 0.0 };
			if(OverlayID() == -4)
			{
				int brsize = 9;
				if(invoker.LoopRight2 + 1 < brsize) { invoker.LoopRight2++; }
				int right2 = invoker.LoopRight2;
				
				A_OverlayOffset(OverlayID(), barrelpos[right2] + invoker.GunzX, barrelpos[right2] + invoker.GunzY, WOF_INTERPOLATE);
			} else {
				int blsize = 9;
				if(invoker.LoopLeft2 + 1 < blsize) { invoker.LoopLeft2++; }
				int left2 = invoker.LoopLeft2;
				
				A_OverlayOffset(OverlayID(), barrelpos[left2] + invoker.GunzX, barrelpos[left2] + invoker.GunzY, WOF_INTERPOLATE);
			}
		}
		MORG C 0 { if(OverlayID() == -4) { invoker.LoopRight2 = 0; } else { invoker.LoopLeft2 = 0; } }
		Stop;
		
	//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,invoker.GunzY);
		}
		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("DeadPunchEnter");
				}
				Return ResolveState(Null);
		}
		Loop;
		MRSG A 0 A_JumpIf(CountInv("MourningStratActive"),2);
		MORG A 0;
		"####" A 1;
		"####" A 0 A_JumpIf(!invoker.WeapSwitch && !CountInv("MenuWheelActive") && GetPlayerInput(INPUT_BUTTONS) & BT_ATTACK, "MainFire");
        Loop;
	}
}

#endregion
