class StompCooldown : Inventory { Default { Inventory.MaxAmount 600; } }
class ThreadingNotSoLightly : Inventory { Default { Inventory.MaxAmount 1; } }
class NoLookZone : Inventory { Default { Inventory.MaxAmount 1; } }

class GuncasterDoom : Guncaster
{
	Default
	{
		Player.ColorRange 112,127;
	
		Player.ColorSet 0, "Cygnis", 176, 191, 182;
		Player.ColorSet 1, "Neymathir", 160, 167, 163;
		Player.ColorSet 2, "Vermathin", 90, 100, 88;
		Player.ColorSet 3, "Surtra", 32, 47, 40;
		Player.ColorSet 4, "Azaron", 118, 127, 120;
		Player.ColorSet 5, "Leurith", 101, 111, 0;
		Player.ColorSet 6, "Withar", 128, 143, 135;
		Player.ColorSet 7, "Jackson", 64, 79, 71;
	}
	
	States
	{
	Spawn:
		CBG2 A 0 NoDelay A_JumpIfInventory("PowerSuitToken",1,4);
		UBG2 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYG2 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYG2 A 0;
		"####" "#" 1;
		"####" "#" 0 A_Jump(256,"Spawn");
		Goto Spawn;
	}
}

class GuncasterHexen : Guncaster
{
	Default
	{
		Player.ColorRange 186, 202;
		
		Player.ColorSet 0, "Cygnis", 164, 182, 176;
		Player.ColorSet 1, "Neymathir", 122, 145, 138;
		Player.ColorSet 2, "Vermathin", 33, 44, 39;
		Player.ColorSet 3, "Surtra", 164, 171, 169;
		Player.ColorSet 4, "Azaron", 186, 195, 191;
		Player.ColorSet 5, "Leurith", 0, 15, 0;
		Player.ColorSet 6, "Blain", 146, 161, 155;
		Player.ColorSet 7, "Xaeratustra", 231, 239, 239;
		Player.ColorSet 8, "Steelheart", 0, 31, 29;
		Player.ColorSet 9, "Aquarius", 217, 223, 221;
		Player.ColorSet 10, "Ernst", 67, 80, 80;
	}
	
	States
	{
	Spawn:
		CBG3 A 0 NoDelay A_JumpIfInventory("PowerSuitToken",1,4);
		UBG3 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYG3 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYG3 A 0;
		"####" "#" 1;
		"####" "#" 0 A_Jump(256,"Spawn");
		Goto Spawn;
	}
}

class GuncasterStrife : Guncaster
{
	Default
	{
		Radius 18; //Unless you wanna bypass the crystal key doorway with just one key, then remove this lol~
		MaxStepHeight 16;
		Player.ColorRange 96, 111;
		
		Player.ColorSet 0, "Cygnis", 64, 79, 235;
		Player.Colorset 1, "Neymathir", 80, 95, 224;
		Player.Colorset 2, "Vermathin", 1, 31, 7;
		Player.Colorset 3, "Crocodile", 32, 63, 47;
		Player.Colorset 4, "Zywiol", 144, 159, 151;
		Player.Colorset 5, "Crescend", 112, 127, 120;
		Player.Colorset 6, "Brownie", 176, 191, 183;
		Player.Colorset 7, "Rust", 208, 223, 208;
	}
	
	States
	{
	Spawn:
		CBG4 A 0 NoDelay A_JumpIfInventory("PowerSuitToken",1,4);
		UBG4 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYG4 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYG4 A 0;
		"####" "#" 1;
		"####" "#" 0 A_Jump(256,"Spawn");
		Goto Spawn;
	}
}

class GuncasterDummy : Guncaster
{
	Default
	{
		SeeSound "Guncaster/Meh";
		AttackSound "";
		DeathSound "Guncaster/Death";
	}
	States
	{
	Spawn:
		CYGG AB 20 A_Look;
		Loop;
	See:
		CYGG ABCDABCD 4 A_Chase;
		Loop;
	Missile:
		CYGG F 8 Bright;
		CYGG E 20;
		Goto See;
	Death:
		CYGG H 5;
		CYGG I 5 A_Scream;
		CYGG J 5 A_NoBlocking;
		CYGG K 5;
		CYGG LL 20;
		CYGG L -1;
		Stop;
	}
}

class Guncaster : PlayerPawn
{
	Class<Weapon> PreviousWeapon;	//I think it's pretty obvious what this is used for.
	
	Seekers Shepherd;
	Seekers	RoyalShepherd;
	Gc_NinjaData ninja_data;
	Gc_Swagger view_tilt;
	bool is_cycling_forwards;
	
	int ChargeFuel; //Deadmaker's sprint\charge fuel.
	int ChargeCooldown;
	
	int JumpCount;
	int TimesJumped;
	int GlideGraceTimer;
	int LedgeGraceTimer;
	int StompCooldown;
	int CurrentFlightState;
	int PoundUnderwaterTics;
	int MoneyArrowDistDivisor;
	
	bool GlideInitialized;
	bool PoundInitialized;
	bool GlideJumped;
	bool SlowFell;
	bool FirstEnteredAir;
	bool ClimbStarted;
	
	double SuitSpeedMult;
	double SuitJumpMult;
	double SuitScaleX;
	double SuitScaleY;
	double SuitViewHeight;
	double SuitAttackZ;
	double SuitStepHeight;
	int    SuitWeight;
	
	double DMSpeedMult;
	double DMJumpMult;
	double DMScaleX;
	double DMScaleY;
	double DMViewHeight;
	double DMAttackZ;
	double DMStepHeight;
	double DMClimbingHeight;
	int    DMWeight;
	
	double AirControl;
	double LedgeClimbReach;
	double LedgeClimbSpeed;
	double LedgeClimbHeight;
	double LedgeRefPrevZ;
	Actor  LedgeRef;
	Actor  MoneyPointer;
	
	// Ninja stuff.
	int    ninja_gracetics;
	int    ninja_graceticlength;
	int    ninja_elevatetics;
	int    ninja_elevateticlength;
	int    ninja_decaytics;
	int    ninja_decayticlength;
	int    ninja_avoidlevel;
	int    ninja_maxavoidlevel;
	double ninja_minvel;
	
	property GraceTicLength: ninja_graceticlength;
	property ElevateTicLength: ninja_elevateticlength;
	property DecayTicLength: ninja_decayticlength;
	property MaxResistLevel: ninja_maxavoidlevel;
	property NinjaVelocity: ninja_minvel;
	
	// User variables.
	
	// kd: This spell stuff is no longer necessary, but it doesn't hurt to
	// keep them around. They're used by the old shop only.
	int user_spellbuttons[4]; //The quick-selection thingamajib
	int user_spellshopindex[4];
	int user_spellitemindex[4];
	int user_spellisbound[4];
	int User_Ouch; //To determine for the Carlton Dance if you didn't get hit.
	int User_Carlton; //It's not unusual to be loved by anyone~
	int user_TurretIDs[3];
	
	property InitialJumpCount: JumpCount;
	property SuitSpeedMultiplier: SuitSpeedMult;
	property SuitJumpMultiplier: SuitJumpMult;
	property SuitScaleX: SuitScaleX;
	property SuitScaleY: SuitScaleY;
	property SuitViewHeight: SuitViewHeight;
	property SuitAttackZOffset: SuitAttackZ;
	property SuitMaxStepHeight: SuitStepHeight;
	property SuitMass: SuitWeight;
	
	property DMSpeedMultiplier: DMSpeedMult;
	property DMJumpMultiplier: DMJumpMult;
	property DMScaleX: DMScaleX;
	property DMScaleY: DMScaleY;
	property DMViewHeight: DMViewHeight;
	property DMAttackZOffset: DMAttackZ;
	property DMMaxStepHeight: DMStepHeight;
	property DMLedgeClimbHeight: DMClimbingHeight;
	property DMMass: DMWeight;
	
	property AirControl: AirControl;
	property LedgeClimbReach: LedgeClimbReach;
	property LedgeClimbSpeed: LedgeClimbSpeed;
	property LedgeClimbHeight: LedgeClimbHeight;
	property MoneyArrowDist: MoneyArrowDistDivisor;
	
	Enum FlightState
	{
		NORMAL,
		GLIDING,
		GROUNDPOUND,
		CLIMBING, // Yes.
	};
	
	// Binding and spell cycling:
	// Gc_Binds        Binds;
	// Gc_SpellCycle   SpellCycle;
	
	// IholdPlayerVariables player_data;
	
	//Chillgrasp stuff
	// Gc_GraspingAtStraws grasp;
	Gc_GraspThinker grasp;
	// Actor pimp;
	
	//Augur stuff.
	// Array <Actor> augur_in_scope;
	// bool clear_augur_targets;
	AugurBackground augur_fx;	// The fizzly particle effect when Augur-zooming.
	
	Default
	{
		Health 100;
		player.maxhealth 100;
		Radius 16;
		Height 56;
		Mass 100;
		PainChance 255;
		Player.SoundClass "Guncaster";
		Player.ForwardMove 1.33;
		Player.SideMove 1.33;
		Player.JumpZ 14.0;
		Player.GruntSpeed 24.0;
		Player.ViewHeight 51;
		Player.AirCapacity 3;
		Player.AttackZOffset 20;
		Player.UseRange 96;
		Player.DamageScreenColor "Purple";
		Player.DisplayName "Cygnis";
		Player.Face "DRG";
		Player.ColorRange 209, 224;
		//Player.FlechetteType "CasterPoisonBag";
		Player.SpawnClass "Any";
		BloodColor "Purple";

		Player.StartItem "VisionToggler";
		Player.StartItem "VisionCounter", 120;
		Player.StartItem "MenuWheelToggler";
		Player.StartItem "SheepGuidance";
		Player.StartItem "DynamiteQuickToss";
		Player.StartItem "GuncasterTauntItem";
		Player.StartItem "QuickHealItem";
		Player.StartItem "IronblastMissionControl";
		Player.StartItem "CustomPain";
		
		Player.StartItem "FirebreathTome";
		Player.StartItem "Longhorn";
		Player.StartItem "LonghornAmmo", 20;
		Player.StartItem "Dergfist";
		Player.StartItem "Mana", 100;
		Player.StartItem "DynamiteWeapon";
		Player.StartItem "DynamiteTossWeapon";

		Player.StartItem "HammerSpaceCounter", 10;
		Player.StartItem "FirebreathActive";
		Player.StartItem "TurretLimitCounter", 3;

		Player.WeaponSlot 1, "Dergfist";
		Player.WeaponSlot 2, "Longhorn";
		Player.WeaponSlot 3, "Strucker", "Ironblast";
		Player.WeaponSlot 4, "Pulverizer";
		Player.WeaponSlot 5, "DynamiteWeapon","Matriarch";
		Player.WeaponSlot 6, "Augur";
		Player.WeaponSlot 7, "OldDreadful";
		Player.WeaponSlot 9, "ATotallyUselessSomething";
		
		+THRUSPECIES
		+DONTBLAST
		+NOICEDEATH //Skull pop is a very annoying thing that also breaks multiplayer for lord knows what reason.
		+NOSKIN
		+DONTMORPH
		
		Species "Rrerr";
		
		//General damage types
		DamageFactor "Draugh", 0.0; //You silly bastards shouldn't damage your owner~
		DamageFactor "Fire", 0.5; //That's a dragon - he should shrug it off. I actually should make him completely immune from all the fire attacks, but let's not go completely crazy due to balance reasons. Or Heretic damage floors.
		DamageFactor "Ice", 1.25; //BAAAAD!
		DamageFactor "Falling", 0.0; //Apparently some levels, even if you have falling damage off, are complete dicks, and still make you suffer from that shit. This guy laughs at your smelly falling damage!

		//Spell damage types
		DamageFactor "Matriarch", 0.1; //Did someone say... cannon jumps? Well, not like he needs them... or that they work with such air control... but it's still awesome, hee. And still saves your skin in certain situations.
		DamageFactor "Slime", 0.75; //Heavy boots, that is.

		//Doom damage types
		DamageFactor "FuckRevenants", 0.5; //What says on the tin!
		DamageFactor "Bueller", 0.85; //Dem hitscanners should DIE.
		
		Player.Colorset 0, "Cygnis", 145, 160, 154;
		Player.Colorset 1, "Neymathir", 113, 128, 128;
		Player.Colorset 2, "Vermathin", 36, 47, 41;
		Player.Colorset 3, "Surtra", 145, 152, 150;
		Player.Colorset 4, "Azaron", 209, 218, 215, 225, 240, 185, 200; //, 225, 240, 185, 196, 0, 35, 66, 80
		Player.Colorset 5, "Leurith", 0, 15, 0, 225, 240, 66, 79;
		Player.Colorset 6, "Blain", 185, 200, 195;
		Player.Colorset 7, "Xaeratustra", 169, 176, 173;
		Player.Colorset 8, "Sealia", 194, 204, 202;
	
		Guncaster.InitialJumpCount 3; // How many times Cygnis can jump without boosters.
		Guncaster.SuitSpeedMultiplier 1.33; // Powersuit speed multiplier.
		Guncaster.SuitJumpMultiplier 1.5; // Powersuit jump height multiplier.
		Guncaster.SuitScaleX 1.4; // Scale.X while in suit.
		Guncaster.SuitScaleY 1.4; // ScaleY while in suit.
		Guncaster.SuitViewHeight 64.0; // View height while in suit.
		Guncaster.SuitAttackZOffset 30.0; // Attack Z offset while in suit.
		Guncaster.SuitMaxStepHeight 48.0; // Max step height while in suit.
		Guncaster.SuitMass 2000; //Heavy boi.
		
		Guncaster.AirControl 0.9; // Sucks that you have to override a huge virtual to do this per-player.
		
		Guncaster.DMSpeedMultiplier 0.7; //Pillow: Same as for suit, except for Deadmaker.
		Guncaster.DMJumpMultiplier 1.5;
		Guncaster.DMScaleX 2.0;		  	//Pillow: Temporary solution until I'll get my hands on sprites. Maybe. Some beautiful day.
		Guncaster.DMScaleY 2.0;
		Guncaster.DMViewHeight 108.0;	  //Pillow: Big Booper.
		Guncaster.DMAttackZOffset 80.0;
		Guncaster.DMMaxStepHeight 48.0;
		Guncaster.DMLedgeClimbHeight 78.0;
		Guncaster.DMMass 3000; //Heavier boi.
		
		Guncaster.LedgeClimbReach 8.0; // How far from the player we should trace, in map units, for a climbable ledge.
		Guncaster.LedgeClimbSpeed 3.0; // Z-velocity of climbing speed.
		Guncaster.LedgeClimbHeight 48.0; // The ledge height, above Cygnis' MaxStepHeight, he considers climbable. (24+48=64)
		
		Guncaster.MoneyArrowDist 64; // The total distance the money arrow will extend from you is divided by this.
		
		Guncaster.GraceTicLength 15; // How long it takes before ninjamode starts to decay.
		Guncaster.ElevateTicLength 10; // How long it takes for ninjamode to improve by one level.
		Guncaster.DecayTicLength 5; // How long it takes for ninjamode to decay by one level.
		Guncaster.MaxResistLevel 9; // The max number of levels of resistance against bulletpuffs.
		Guncaster.NinjaVelocity 19.0; // The max velocity Cygnis needs to reach for ninjamode to build.
	}
	
	States
	{
	Spawn:
		CBGG A 0 NoDelay A_JumpIfInventory("PowerSuitToken",1,4);
		UBGG A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYGG A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYGG A 0;
		"####" "#" 1;
		"####" "#" 0 A_Jump(256,"Spawn");
		Goto Spawn;
	CarltonDragon:
		"####" A 0 A_JumpIfInventory("StrifeCounter",1,"Strife");
		"####" A 0 A_JumpIfInventory("HexenCounter",1,"Hexen");
		"####" A 0 A_JumpIfInventory("DoomCounter",1,"Doom");
	Heretic:
		CBDG A 0 A_JumpIfInventory("PowerSuitToken",1,4);
		UBDG A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYDG A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYDG A 0;
		"####" "#" 0;
		Goto Main;
	Doom:
		CBD2 A 0 A_JumpIfInventory("PowerSuitToken",1,4);
		UBD2 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYD2 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYD2 A 0;
		"####" "#" 0;
		Goto Main;
	Hexen:
		CBD3 A 0 A_JumpIfInventory("PowerSuitToken",1,4);
		UBD3 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYD3 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYD3 A 0;
		"####" "#" 0;
		Goto Main;
	Strife:
		CBD4 A 0 A_JumpIfInventory("PowerSuitToken",1,4);
		UBD4 A 0 A_JumpIfInventory("PowerSuitProtect",1,3);
		YYD4 A 0 A_JumpIfInventory("PowerSuitDraugh",1,2);
		CYD4 A 0;
		"####" "#" 0;
	Main:
		"####" CDEF 3;
		"####" GH 6;
		"####" FEDC 3;
		"####" AB 6;
		Goto CarltonDragon;
	See:
		"####" A 0 A_JumpIf(CountInv("PowerDeadmaker"), "SeeTheMaker"); //Lol.
		"####" A 0 A_JumpIf(CountInv("PowerSuitToken") && !GetCvar("GC_ForceNormalSteps"), "SeeSuit");
		"####" A 0 A_JumpIfInventory("PowerBerserkDamage",1,"SeeBerserk") ;
		
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,11);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		"####" A 0 {
			if(!CountInv("PowerSuitDraugh")  || CountInv("PowerSuitProtect")) { A_PlaySound("Guncaster/Move",0,0.3); }
			else if(random(0,3) == 0) 										  { A_PlaySound("Draughcaster/Move",0,0.3); }
		}
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 5;
		"####" A 0 A_Jump(256,3);
		"####" AB 9;
 		"####" A 0 A_SpawnItemEx("GuncasterStep",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION); //TIL that an actor NEEDS any velocity on X/Y plane to actually collide with shit. Fuck.
		"####" A 0 A_Jump(256,"Spawn"); //So retarded inherited playerclasses for doom and hexen will work correctly.
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		"####" A 0 {
			if(!CountInv("PowerSuitDraugh")  || CountInv("PowerSuitProtect")) { A_PlaySound("Guncaster/Move",0,0.3); }
			else if(random(0,3) == 0) 										  { A_PlaySound("Draughcaster/Move",0,0.3); }
		}
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" CD 5;
		"####" A 0 A_Jump(256,3);
		"####" CD 9;
 		"####" C 0 A_SpawnItemEx("GuncasterStep",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		
	SeeTheMaker:
		"####" A 0 A_JumpIfInventory("DeadmakerCharger",1,22);
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,12);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		//"####" A 0 A_PlaySound("Deadmaker/Move",0,0.3);
		"####" A 0 { if(CountInv("PowerSuitDraugh") && random(0,3) == 0) { A_PlaySound("Draughcaster/Move",0,0.3); } }
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 10;
		"####" A 0 A_Jump(256,3);
		"####" AB 12;
		
 		"####" A 0 A_SpawnItemEx("DeadmakerStep",0,0,0,0.2,0,-15,0,SXF_TRANSFERPOINTERS|SXF_SETTARGET);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		//"####" A 0 A_PlaySound("Deadmaker/Move",0,0.3);
		"####" A 0 { if(CountInv("PowerSuitDraugh") && random(0,3) == 0) { A_PlaySound("Draughcaster/Move",0,0.3); } }
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" CD 10;
		"####" A 0 A_Jump(256,3);
		"####" CD 12;
 		"####" C 0 A_SpawnItemEx("DeadmakerStep",0,0,0,0.2,0,-15,0,SXF_TRANSFERPOINTERS|SXF_SETTARGET);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
	//Charging:
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,7);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		//"####" A 0 A_PlaySound("Deadmaker/Move",0,0.3);
		"####" A 0 { if(CountInv("PowerSuitDraugh") && random(0,3) == 0) { A_PlaySound("Draughcaster/Move",0,0.3); } }
		"####" AB 5;
 		"####" A 0 A_SpawnItemEx("DeadmakerStep",0,0,0,0.2,0,-15,0,SXF_TRANSFERPOINTERS|SXF_SETTARGET);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		//"####" A 0 A_PlaySound("Deadmaker/Move",0,0.3);
		"####" A 0 { if(CountInv("PowerSuitDraugh") && random(0,3) == 0) { A_PlaySound("Draughcaster/Move",0,0.3); } }
		"####" CD 5;
 		"####" C 0 A_SpawnItemEx("DeadmakerStep",0,0,0,0.2,0,-15,0,SXF_TRANSFERPOINTERS|SXF_SETTARGET);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		
	SeeBerserk: 
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,11);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		"####" A 0 {
			if(!CountInv("PowerSuitDraugh")  || CountInv("PowerSuitProtect")) { A_PlaySound("Guncaster/Move",0,0.3); }
			else if(random(0,3) == 0) 										  { A_PlaySound("Draughcaster/Move",0,0.3); }
		}
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 5;
		"####" A 0 A_Jump(256,3);
		"####" AB 9;
 		"####" A 0 A_SpawnItemEx("BerserkStep",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		"####" A 0 {
			if(!CountInv("PowerSuitDraugh")  || CountInv("PowerSuitProtect")) { A_PlaySound("Guncaster/Move",0,0.3); }
			else if(random(0,3) == 0) 										  { A_PlaySound("Draughcaster/Move",0,0.3); }
		}
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" CD 5;
		"####" A 0 A_Jump(256,3);
		"####" CD 9;
 		"####" C 0 A_SpawnItemEx("BerserkStep",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		
	SeeSuit:
		"####" A 0 A_JumpIfInventory("PowerBerserkDamage",1,"SeeSuitBerserk");
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,14);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		"####" A 0 A_CheckFloor("RightWhiz");
		"####" A 0 A_Jump(256,"RightNoes");
	RightWhiz:
		"####" A 0 A_PlaySound("Bishop/Move",0,0.6);
		"####" A 0 A_Jump(256,"RightNoes");
	RightNoes:
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 7;
		"####" A 0 A_Jump(256,3);
		"####" AB 10;
 		"####" A 0 A_SpawnItemEx("BishopStepRight",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		"####" A 0 A_CheckFloor("LeftWhiz");
		"####" A 0 A_Jump(256,"LeftNoes");
	LeftWhiz:
		"####" A 0 A_PlaySound("Bishop/Move",0,0.6);
		"####" A 0 A_Jump(256,"LeftNoes");
	LeftNoes:
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" CD 7;
		"####" A 0 A_Jump(256,3);
		"####" CD 10;
 		"####" C 0 A_SpawnItemEx("BishopStepLeft",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		
	SeeSuitBerserk:
		"####" A 0 A_JumpIfInventory("ThreadingNotSoLightly",1,14);
		"####" A 0 A_GiveInventory("ThreadingNotSoLightly",1);
		"####" A 0 A_CheckFloor("ZerkRightWhiz");
		"####" A 0 A_Jump(256,"ZerkRightNoes");
	ZerkRightWhiz:
		"####" A 0 A_PlaySound("Bishop/Move",7,0.6);
		"####" A 0 A_Jump(256,"ZerkRightNoes");
	ZerkRightNoes:
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 7;
		"####" A 0 A_Jump(256,3);
		"####" AB 10;
 		"####" A 0 A_SpawnItemEx("BishopZerkStepRight",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" A 0 A_TakeInventory("ThreadingNotSoLightly",1);
		"####" A 0 A_CheckFloor("ZerkLeftWhiz");
		"####" A 0 A_Jump(256,"ZerkLeftNoes");
    ZerkLeftWhiz:
		"####" A 0 A_PlaySound("Bishop/Move",7,0.6);
		"####" A 0 A_Jump(256,"ZerkLeftNoes");
	ZerkLeftNoes:
		"####" A 0 {
			if(!multiplayer && (GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH || 
			(invoker.GetCvar("cl_run") == 1 && GetPlayerInput(INPUT_BUTTONS) & BT_SPEED) ||
			(invoker.GetCvar("cl_run") == 0 && !(GetPlayerInput(INPUT_BUTTONS) & BT_SPEED))))
			{
				SetState(CurState+4);
			}
		}
		"####" AB 7;
		"####" A 0 A_Jump(256,3);
		"####" AB 10;
 		"####" C 0 A_SpawnItemEx("BishopZerkStepLeft",0,0,0,0.2,0,-10,0,SXF_NOCHECKPOSITION);
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
	Melee:
		"####" F 8 Bright;
		"####" A 0 A_Jump(256,"Missile");
		Goto Missile;
	Missile:
		"####" E 14;
		"####" A 0 A_JumpIf(Health <= 0, "Death"); //Safety jump in case you died with pulverizer doing its thing again.
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
	Pain.Crow:
	Pain.Crow2:
		"####" "#" 0 A_SetBlend("Black",0.8,35);
		Goto Pain;
	Pain:
		"####" G 0 A_JumpIfInventory("PowerSuitToken",1,3);
		"####" G 15 A_Pain;
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
		"####" G 0 A_PlaySound("Bishop/Pain",0,0.8);
		"####" G 0 A_JumpIf(Health < 50, 2);
		"####" G 0 A_Jump(128,"Spawn");
		"####" G 15 A_Pain;
		"####" A 0 A_Jump(256,"Spawn");
		Goto Spawn;
	Death:
	AltSkinDeath:
		"####" H 5;
		"####" I 5 A_PlayerScream;
		"####" J 5 A_NoBlocking;
		"####" K 5;
		"####" K 0 { //Death nuke.
			if(CountInv("TiberiumBomb")) {
				A_TakeInventory("TiberiumBomb",1);
				if(!CountInv("TibCore")) {
					A_SpawnItemEx("DreadfulFullBlast",0,0,0,0,0,0,0,SXF_SETTARGET);
				} else {
					A_SpawnItemEx("CoreDreadfulFullBlast",0,0,0,0,0,0,0,SXF_SETTARGET);
				}
			}
		}
	WaitForIt:
		"####" L 1;
		"####" L 0 {
			if(vel.x != 0 || vel.y != 0 || vel.z != 0)
			{
				Return ResolveState("WaitForIt");
			}
			else
			{
				If(!GetCvar("GC_ToasterGore")) { A_SpawnItemEx("PGC_GrowingBloodPool",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			}
			Return ResolveState(Null);
		}
		"####" L -1;
		Stop;
	XDeath:
	AltSkinXDeath:
		"####" H 5;
		"####" I 5 A_PlayerScream;
		"####" J 5 A_NoBlocking;
		"####" K 5;
		"####" K 0 { //Death nuke.
			A_SpawnItemEx("GC_GrowingBloodPool",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR);
			if(CountInv("TiberiumBomb")) {
				A_TakeInventory("TiberiumBomb",1);
				if(!CountInv("TibCore")) {
					A_SpawnItemEx("DreadfulFullBlast",0,0,0,0,0,0,0,SXF_SETTARGET);
				} else {
					A_SpawnItemEx("CoreDreadfulFullBlast",0,0,0,0,0,0,0,SXF_SETTARGET);
				}
			}
		}
	WaitForIt2:
		"####" L 1;
		"####" L 0 {
			if(vel.x != 0 || vel.y != 0 || vel.z != 0)
			{
				Return ResolveState("WaitForIt2");
			}
			else
			{
				If(!GetCvar("GC_ToasterGore")) { A_SpawnItemEx("PGC_GrowingBloodPool",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			}
			Return ResolveState(Null);
		}
		"####" L -1;
		Stop;
	Death.Acid:
		"####" G 1;
		"####" "#" 1 A_Playsound("Gumpop/Expand",5);
		"####" "###################################" 1 A_SetScale(Scale.X+frandom(0.01,0.025));
		"####" "#" 1 A_Playsound("Gumpop/Pop",5);
		"####" "#" 0 A_JumpIf(GetCvar("GC_ToasterGore"),"EndAcid");
		"####" "#" 0 {
			for(int i = 0 ; i < 6 ; i++) { A_SpawnItemEx("PCeilBloodLauncherLong",0,0,0,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			for(int i = 0 ; i < 2 ; i++) { A_SpawnItemEx("PXDeath1",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR);
										   A_SpawnItemEx("PXDeath2",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(14.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR);
										   A_SpawnItemEx("PXDeath3",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
										   A_SpawnItemEx("PXDeath4",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR);
			for(int i = 0 ; i < 8 ; i++) { A_SpawnItemEx("PGC_WallBlood",0,0,33,frandom(3.0,-3.0),frandom(2.0,-2.0),frandom(4.0,2.0),frandom(0.0,36.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			for(int i = 0 ; i < 4 ; i++) { A_SpawnItemEx("PInstestin",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			for(int i = 0 ; i < 24; i++) { A_SpawnItemEx("PGC_FlyingBlood",0,0,27,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			for(int i = 0 ; i < 6 ; i++) { A_SpawnItemEx("PGC_SuperGoreSpawner",0,0,25,frandom(5.0,-5.0),frandom(3.0,-3.0),frandom(10.0,4.0),frandom(0.0,360.0),SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			if(CountInv("TiberiumBomb")) {
				A_TakeInventory("TiberiumBomb",1);
				if(!CountInv("TibCore")) {
					A_SpawnItemEx("DreadfulFullBlast",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
				} else {
					A_SpawnItemEx("CoreDreadfulFullBlast",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
				}
			}
		}
	EndAcid:
		TNT1 A 0 {
			bSOLID = 0;
			bFLOORCLIP = 1;
			A_SetTranslation("DragonPaste");
		}
		XMED ABCDE 5;
	WaitForIt3:
		"####" E 1;
		"####" E 0 {
			if(vel.x != 0 || vel.y != 0 || vel.z != 0)
			{
				Return ResolveState("WaitForIt3");
			}
			else
			{
				If(!GetCvar("GC_ToasterGore")) { A_SpawnItemEx("PGC_GrowingBloodPool",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION|SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS|SXF_USEBLOODCOLOR); }
			}
			Return ResolveState(Null);
		}
		"####" "#" 1;
		Wait;
	}
	
	//Weapon switch functionality.
	static const string BlacklistedPrevWeapons [] = {
	"ThrowObjectWeapon",
	"DynamiteTossWeapon",
	"LedgeGrabWeapon",
	"EnvirosuitWeapon",
	"DraughsuitActivateWeapon",
	"DraughsuitDeactivateWeapon",
	"CygborgActivateWeapon",
	"CygborgDeactivateWeapon",
	"DeadmakerActivateWeapon",
	"DeadmakerDeactivateWeapon"//,
	//"DergfistSupreme"
	};
	
	// A generic function for setting the player's previous weapon, ignoring blacklisted weapons.
	void GC_SetPreviousWeapon() //(Guncaster playerref)
	{
		let playerref = Guncaster(self);
		Class<Weapon> CurrentWeapon = playerref.player.ReadyWeapon.GetClass();
		for(int i = 0; i < BlacklistedPrevWeapons.Size(); i++)
		{
			if(CurrentWeapon == BlacklistedPrevWeapons[i])
			{
				return; // Without doing anything.
			}
		}
		// If no blacklisted weapons are found, set the current as previous
		playerref.PreviousWeapon = CurrentWeapon;
		return;
	}
	
	override void BeginPlay () {
		super.BeginPlay();
	}
	
	override void PostBeginPlay() // Stuff that should be handled immediately after existing.
	{
		// Brotip: PostBeginPlay runs only when the player actor (or a voodoo doll) is created
		// (even on multiplayer respawn), not guaranteed once every map. If something needs to
		// be reinitialized every map, toss it into HandleItemReset().
		// (Yes, the Chillgrasp thinker's user is lost between map changes in multiplayer.)
		// Chillgrasp initialization is now done in OnRespawn.
	
		if (!player || !player.mo || player.mo != self)
		{ // For voodoo dolls.
			Super.PostBeginPlay();
			return;
		}
	
		// This token really provides us with a reason not to do these things again
		// after respawning in multiplayer.
		if(!CountInv("GameStarted"))
		{
			HandleGameSetup();	// Set up some necessary tokens for game start.
			GiveInventory("GameStarted", 1);
		}
		
		Super.PostBeginPlay();
	}
	
	// Deprecating that once cool Xaser check, m'boi.
	void HandleGameSetup()
	{
		//Deadmaker's Charge.
		ChargeFuel = 425;
		ChargeCooldown = 0;
	
		// Money setup.
		GiveInventory("Dosh",GetCVar("GC_Doshmeter"));
	
		// Doom setup.
		if(gameinfo.gametype == Game_DOOM)
		{
			GiveInventory("DoomCounter", 1);
		}
		// Heretic setup.
		else if(gameinfo.gametype == Game_HERETIC)
		{
			GiveInventory("HereticCounter", 1);
		}
		// Hexen setup.
		else if(gameinfo.gametype == Game_HEXEN)
		{
			GiveInventory("HexenCounter", 1);
		}
		// Strife setup. (It exists?)
		else if(gameinfo.gametype == Game_STRIFE)
		{
			GiveInventory("StrifeCounter", 1);
		}
		// "Can't detect which game" setup. (Defaults to Doom.)
		else
		{
			GiveInventory("DoomCounter", 1);
		}
		
		GiveInventory("IHoldPlayerVariables", 1); // Storage for people who die.
		
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			player_data.SetupForGameplay();
		}
	}
	
	override void Tick() // Stuff that should be handled every tic.
	{
		if (!player || !player.mo || player.mo != self || gamestate == GS_TITLELEVEL || health <= 0)
		{ // For voodoo dolls, titlemaps, and dead players.
			if(MoneyPointer)
			{
				MoneyPointer.Destroy();
			}
			Super.Tick();
			return;
		}
		
		HandleHealth();			// Health capacity.
		HandleMana();			// Mana regeneration and capacity.
		HandleFlight();			// Someone in the ZDoom Discord made the interesting suggestion of handling extra jumps in a Tick loop.
		HandlePlayerState();	// The handler for Deadmaker/Powersuit stuff.
		HandleGameWeapons();	// We only want this games' weapons.
		HandleGameItems();		// Same as above, just for items.
		HandleQuickToss();		// Quicktoss timer for dynamite.
		HandleMagAutoload();	// Supermag Autoloader.
		HandleNinjaMode();		// Running fast makes you dodge bullets! Or something.
		HandleRecharge();		// Of items that recharge.
		// HandleBinds();			// Handles the binds! You wouldn't believe it! (not anymore)
		HandleSeekers();		// Handles nuclear fission reactor. Jk, handles seekers.
		HandleInvulnerabilityCounter(); // Godmode counter for status bar eyes
		HandleDarkNithorCounter(); // To display correct mugshot for Draugh + Deadmaker
		view_tilt.Tick();		// don't rock the boat and keep on your swim vests
		
		//To make damn sure your dummy-ass won't change the weapon mid-activation.
		if(CountInv("CygborgActivateWeapon")) { A_SelectWeapon("CygborgActivateWeapon"); }
		if(CountInv("CygborgDeactivateWeapon")) { A_SelectWeapon("CygborgDeactivateWeapon"); }
		if(CountInv("DraughsuitActivateWeapon")) { A_SelectWeapon("DraughsuitActivateWeapon"); }
		if(CountInv("DraughsuitDeactivateWeapon")) { A_SelectWeapon("DraughsuitDeactivateWeapon"); }
		if(CountInv("DeadmakerActivateWeapon")) { A_SelectWeapon("DeadmakerActivateWeapon"); }
		if(CountInv("DeadmakerDeactivateWeapon")) { A_SelectWeapon("DeadmakerDeactivateWeapon"); }
		
		if(CountInv("PowerSuitDraugh"))
		{
			HandleDraughMove();	// People say they're afraid of shadows, which hide and obscure. But what they're really afraid of is the light - the truth.
		}
		
		if(gameinfo.gametype == Game_HEXEN)
		{
			HandleAssembly();	// Of weapon pieces into superweapons.
		}
		
		if(!(level.time % 35))
		{
			TakeInventory("GuncasterTauntTimer", 1);
		}
		
		if(CountInv("PhilosophersTome") || GetCVar("GC_Loadsamoney"))
		{
			MoneyMagnet();
		}
		
		// GLDEFS are kind of demanding. This is a stopgap solution.
		if(CountInv("PowerVeilVision"))
		{
			MoneyLocator();
		}
		else
		{
			CVar.GetCVar("GC_GoldDetected", player).SetBool(FALSE);
			if(MoneyPointer)
			{
				MoneyPointer.Destroy();
			}
		}
		
		// Little dance fix. Instead of relying on states to set this variable correctly
		// (in a player, which can change states at will, lol), check the current state
		// instead to see if we should tell the script to cancel dancing.
		if(InStateSequence(CurState, FindState("Pain")))
		{
			User_Ouch = 1;
		}
		else
		{
			User_Ouch = 0;
		}
		
		Super.Tick();
	}
	
	vector2 weapon_bob_offset;
	vector2 old_weapon_bob_offset;
	double old_delta_view;
	double delta_view;
	
	override vector2 BobWeapon (double t) {
		if(!player || !player.readyweapon) {
			return (0, 0);
		}
		
		if(!view_tilt.IsEnabled()) {
			return super.BobWeapon(t);
		}
		
		let weapon		= player.readyweapon;
		let vel_sq		= vel dot vel;
		let left		= (-sin(angle), cos(angle));
		let vel_side	= left dot vel.xy;
		
		let bob_force	= 60 * (weapon.bobrangex, weapon.bobrangey);
		let forw_f		= view_tilt.MovingPhase();
		let side_f		= view_tilt.SidewaysPhase();
		
		let bob_f	= (
			clamp(vel_side / 20, -1, 1),
			clamp(vel_sq / 400, -1, 1));
			
		let pend_ang = 30 * sin(view_tilt.BobAngle()) + 90;
		
		old_weapon_bob_offset	= weapon_bob_offset;
		weapon_bob_offset		= forw_f * (
			bob_force.x * bob_f.y * cos(pend_ang) * 0.4,
			bob_force.y * bob_f.y * (1 - sin(pend_ang)));
		
		weapon_bob_offset += (
			0.23 * side_f * bob_force.x,
			0.125 * abs(side_f) * bob_force.y);
		
		return t * weapon_bob_offset + (1 - t) * old_weapon_bob_offset;
	}
	
	// kd: This is arguably gzd's worst function. You really have to take it
	// all in and appreciate how many contradicting designs meet under the same
	// roof - which in itself has the dumbest possible name.
	
	override bool CheckFrozen() {
		if(0 < player.mo.CountInv("NoLookZone")) {
			player.cmd.yaw		= 0;
			player.cmd.pitch	= 0;
			player.cmd.roll		= 0;
			player.turnticks	= 0;
			
			// kd: And here comes the worst part. Take a good hard look. This
			// will *disable* view interpolation on the next frame.
			player.cheats		|= CF_INTERPVIEW;
		}
		
		return super.CheckFrozen();
	}
	
	void HandleHealth()
	{
		int DefaultMaxHealth = Default.MaxHealth;
		if(DefaultMaxHealth < 1) { DefaultMaxHealth = 100; } // The dehacked default of 0 isn't valid.
		
		// Simple function: change maximum health value dynamically.
		MaxHealth = DefaultMaxHealth +
				    (CountInv("PowerStimulant") * 10) +			//Pillow: Syringes bonus.
					(Int(CountInv("DraughCounter") / 4) * 10) + //Pillow: Draughsuits bonus, if you stack them.
					(CountInv("PowerDeadmaker") * 400);			//Pillow: Deadmaker bonus.
	}
	
	void HandleMana()
	{	
		let ManaAmmo = self.FindInventory("Mana");
		
		// First, set up its capacity.
		ManaAmmo.MaxAmount = GetDefaultByType("Mana").MaxAmount + 
							 (CountInv("PowerBooster") * 25) + 		//Pillow: Syringes bonus.
							 (CountInv("PowerSuitDraugh") * 75) + 	//Pillow: Draughsuit initial bonus.
							 (CountInv("DraughCounter") * 25) -
							 (CountInv("StridersLanternActive") * CountInv("StridersLantern") * 25);		//Pillow: Lantern penalty.
		
		// If mana is somehow over augmented capacity, reset it to that capacity.
		if(CountInv("Mana") > ManaAmmo.MaxAmount)
		{
			SetInventory(ManaAmmo.GetClassName(), ManaAmmo.MaxAmount);
		}
		
		// Next, handle its regeneration rate.
		if(GC_ManaRegenSpeed <= 0)
		{
			return; // Disabled, or invalid negative value.
		}
		else
		{
			if(!(level.time % ((GetDefaultByType("PowerSurge").MaxAmount-CountInv("PowerSurge")+GC_ManaRegenSpeed))))
			{
				GiveInventory("Mana", 1);
			}
		}
	}
	
	void HandleFlight()
	{
		int buttons = GetPlayerInput(MODINPUT_BUTTONS);
		int oldbuttons = GetPlayerInput(MODINPUT_OLDBUTTONS);
		int forwardmove = GetPlayerInput(MODINPUT_FORWARDMOVE);
		int sidemove = GetPlayerInput(MODINPUT_SIDEMOVE);
		int JumpLimit;
		
		// Always decrement ledge grace timer since it can be done from ground.
		if(LedgeGraceTimer)
		{
			LedgeGraceTimer--;
		}
	
		// Only run if in mid-air, not mid-water, no fly cheat.
		if(!player.OnGround && waterlevel < 2 && !(player.cheats & CF_FLY) && !bNoGravity)
		{
			
			// Decrement gliding state input time.
			if(GlideGraceTimer)
			{
				GlideGraceTimer--;
			}
			
			// Decrease stomp cooldown timer.
			if(StompCooldown > 0)
			{
				StompCooldown--;
			}
			
			// Disallow an immediate stomp after entering airspace.
			if(!FirstEnteredAir && !StompCooldown)
			{
				FirstEnteredAir = TRUE;
				StompCooldown = 15;
			}
			
			// Set total jump count.
			if(gameinfo.gametype & Game_DOOM || gameinfo.gametype & Game_STRIFE)
			{
				JumpLimit = JumpCount + CountInv("PowerLifter") + CountInv("PowerDeadmaker") * 16;
			}
			else
			{
				JumpLimit = JumpCount + CountInv("WingsOfWrath") + CountInv("PowerDeadmaker") * 16;
			}
			
			switch(CurrentFlightState)
			{
				// Gliding and groundpounding need to completely intercept movement to work.
				// So, they are separate states to normal flight jumping.
				case NORMAL:
				default:
					
					// Mid-air jumping.
					if(((buttons & BT_JUMP) && !(oldbuttons & BT_JUMP) && (TimesJumped < JumpLimit)) || GlideJumped)
					{
						// This bool bypasses the above check because it's already done somewhere else.
						GlideJumped = FALSE;
						
						// If we haven't just previously jumped, jump again.
						Vel.Z = JumpZ;
						TimesJumped++;
						
						// Sound.
						if(CountInv("PowerDeadmaker"))
						{
							A_PlaySound("Deadmaker/Fly",0);
						}
						else if(CountInv("PowerSuitToken"))
						{
							A_PlaySound("Bishop/Wings");
						}
						else
						{
							A_PlaySound("Wings/Movement");
						}
						
						// Effect (if applicable).
						if(CountInv("PowerSuitToken"))
						{
							GiveInventory("RocketPack_Emitter", 1);
						}
						
						// If the player is holding movement direction keys, also jump in that direction.
						// Or in Stanley's words: "Scout on crack". 
						A_ChangeVelocity((forwardmove/0x3200) * 12.0, (sidemove/-0x2800) * 12.0, Vel.Z, CVF_RELATIVE|CVF_REPLACE);
						// Apparently a weapon bob bug appears if this stops x/y velocity.
						// Harmless, but let's do something about it anyway.
						// Can I manually stop weapon bobbing from here?
						if(!forwardmove && !sidemove)
						{
							player.bob = 0.;
						}
						/*
						if(forwardmove)
						{
							Thrust((forwardmove/0x3200 * 8.0), Angle);
						}
						
						if(sidemove)
						{
							let SideAngle = Angle - 90;
							Thrust((sidemove/0x2800 * 8.0), SideAngle);
						}
						*/
					}
					
					// Slow fall.
					if((buttons & BT_JUMP) && (oldbuttons & BT_JUMP) && (Vel.Z < 0.05))
					{
							
						// Holding jump in mid-air reduces gravity greatly.
						// Holding it with Powersuit or Deadmaker on will make it negate completely.
						// Sound and effect, if applicable.
						
						if(CountInv("PowerSuitToken") || CountInv("PowerDeadmaker"))
						{
							A_ChangeVelocity(Vel.X,Vel.Y,0,CVF_REPLACE);
							A_SetGravity(0.0);
							GiveInventory("RocketGlide_Emitter", 1);
							A_PlaySound("Bishop/Glide", CHAN_7, 1.0, TRUE);
						}
						else
						{
							A_SetGravity(0.1);
						}
						
						SlowFell = TRUE;
					}
					else
					{
						// No gravity reduction otherwise.
						if(SlowFell)
						{
							Vel.Z -= 0.01;
							A_StopSound(CHAN_7);
							SlowFell = FALSE;
						}
						A_SetGravity(1.0);
					}
					
					// Ledge-climbing. See its function for more info.
					HandleLedgeClimb();
					// Stop processing the current flight state if it changes because of the above function.
					if(CurrentFlightState == CLIMBING)
					{
						break;
					}
					
					// Gliding.
					if((buttons & BT_FORWARD) && !(oldbuttons & BT_FORWARD))
					{
						// Only glide if the grace timer is still active.
						if(GlideGraceTimer)
						{
							GlideGraceTimer = 0;
							CurrentFlightState = GLIDING;
							break;

						}
						else
						{
							// Set the grace timer (in tics), so as to allow for a window between button taps.
							GlideGraceTimer = GetCVar("GC_GlideTimer");
						}
					}
					
					// Groundpounding.
					if((buttons & BT_CROUCH) && !StompCooldown)
					{
						CurrentFlightState = GROUNDPOUND;
					}
					break;
				
				case GLIDING:
					if(!GlideInitialized)
					{
						A_NoGravity(); // Nullify gravity.
						Vel = (0, 0, 0); // Annul velocity *once*. The script used to do this repeatedly.
						GlideInitialized = TRUE; // Done setting up gliding.
					}
					
					// Sound, if applicable.
					if(CountInv("PowerSuitToken") || CountInv("PowerDeadmaker"))
					{
						A_PlaySound("Bishop/Glide", CHAN_7, 1.0, TRUE);
					}
					
					// Effect, if applicable.
					if(CountInv("PowerSuitToken") || CountInv("PowerDeadmaker"))
					{
						GiveInventory("RocketGlide_Emitter", 1);
					}
					
					// Movement.
					// And allow for strafing while we're at it.
					// Pillow: Also added new fun functionality here~
					
					if(CountInv("PowersuitToken")  || CountInv("PowerDeadmaker")) {
						A_ChangeVelocity (Cos(Pitch) * 40.0, (sidemove/-0x2800 * 20.0), Sin(Pitch) * -40.0, CVF_RELATIVE|CVF_REPLACE);
					} else {
						A_ChangeVelocity(28.0, (sidemove/-0x2800 * 16.0), -1.5, CVF_RELATIVE|CVF_REPLACE); // Set movement.
					}
					
					/*
					if(sidemove)
					{
						let SideAngle = Angle - 90;
						Thrust((sidemove/0x2800 * 0.5), SideAngle);
					}
					*/
					// Hold forward to continue the glide, or let go to break it.
					if(!(oldbuttons & BT_FORWARD))
					{
						A_StopSound(CHAN_7);
						A_Gravity();
						GlideInitialized = FALSE;
						CurrentFlightState = NORMAL;
					}
					// Tap jump to break the glide immediately and jump, if any jumps are left.
					if((buttons & BT_JUMP) && !(oldbuttons & BT_JUMP) && (TimesJumped < JumpLimit))
					{
						GlideJumped = TRUE;
						A_StopSound(CHAN_7);
						A_Gravity();
						GlideInitialized = FALSE;
						CurrentFlightState = NORMAL;
					}
					// Crouch to go directly to ground pounding.
					if((buttons & BT_CROUCH) && !StompCooldown)
					{
						CurrentFlightState = GROUNDPOUND;
					}
					
					HandleLedgeClimb();
					break;
				
				case GROUNDPOUND:
					if(!PoundInitialized)
					{
						A_PlaySound("Stomp/Use");
						// Start with -60 Z velocity.
						// Hexen terminal velocity is -63u/s
						// but that's been fixed with a damagemobj
						// override.
						Vel.Z = -59.5;
						PoundInitialized = TRUE;
					}
					// Allow for very slight horizontal movement during a pound.
					A_ChangeVelocity((forwardmove/0x3200) * 8.0, (sidemove/-0x2800) * 8.0, Vel.Z-0.5, CVF_RELATIVE|CVF_REPLACE);
					// If the player jumps in the middle of a groundpound, break out of it.
					if(buttons & BT_JUMP && !(oldbuttons & BT_JUMP))
					{
						// Add some temporary velocity the player still has to deal with, but not too severe.
						// He has wings to flap out and counteract with, after all.
						Vel.Z = -20;
						PoundInitialized = FALSE;
						CurrentFlightState = NORMAL;
					}
					break;
					
				case CLIMBING:
					// Continue holding forward to climb.
					if((buttons & BT_FORWARD) && (oldbuttons & BT_FORWARD) && LedgeRef)
					{
						// First-time climb stuff.
						if(!ClimbStarted)
						{
							A_StopSound(CHAN_7);
							// Animation/sound stuff here.
							if(GetCVar("GC_LedgeImmersion"))
							{
								// Pillow: Notify the weapon that we're climbing here!
								GiveInventory("GCLedgeGrabbed", 1);
								A_StopSound(CHAN_VOICE);
							}
							A_NoGravity();
							TimesJumped = 0; // Reset jumps, you're technically touching ground.
							Vel.X = 0;
							Vel.Y = 0;
							ViewBob = 0;
							player.cheats |= CF_FROZEN;
							ClimbStarted = TRUE;
						}
						
						// Comparison against previous Z values of our ledge reference actor.
						if(LedgeRef.Pos.Z > LedgeRefPrevZ)
						{
							// The ledge reference actor was placed on a lift that is now moving up.
							// Continue to hang onto the elevator until it stops moving
							// (or until the reference actor is crushed by a conflicting ceiling).
							
							Vel.X = 0;
							Vel.Y = 0;
							SetInventory("GCLiftGrabbed", 1); // Toggle on the holding animation.
							
							if((buttons & BT_JUMP))
							{
								// If we're holding jump, clamber up and onto the moving lift.
								// First match the speed of the lift.
								Vel.Z = (LedgeRef.Pos.Z - LedgeRefPrevZ) + LedgeClimbSpeed;
								// If we're above the point where we should climb up, climb up.
								if(LedgeRef.Pos.Z < Pos.Z+MaxStepHeight+(LedgeRef.Pos.Z - LedgeRefPrevZ))
								{
									// We have climbed the ledge successfully, thrust the player onto it
									// and call it a day.
									VelFromAngle(LedgeClimbSpeed * 2, AngleTo(LedgeRef));
									LedgeClimbCleanup();
									break;
								}
							}
							else if(LedgeRef.Pos.Z > Pos.Z+ViewHeight)
							{
								// If the elevator is above a certain height, move with it.
								if(!Warp(LedgeRef, Pos.X, Pos.Y, LedgeRef.Pos.Z-ViewHeight, 0,
									WARPF_ABSOLUTEPOSITION|WARPF_USECALLERANGLE|WARPF_COPYVELOCITY|WARPF_WARPINTERPOLATION))
								{
									// If the expected position could not be warped to (such as
									// being interrupted by a ceiling), break ledge climbing.
									LedgeClimbCleanup();
									break;
								}
							}
							else
							{
								// Wait until the ledge reference thing is above a certain height to begin moving.
								Vel.Z = 0;
							}
							
							A_SetAngle(AngleTo(LedgeRef), SPF_INTERPOLATE);
							// Would've had the player aim up the elevator automatically, but eh, freelook's better
							//A_SetPitch(-asin((LedgeRef.Pos.Z - Pos.Z)/Distance3D(LedgeRef)), SPF_INTERPOLATE);
							// The previous Z value needs to be watched in this case.
							LedgeRefPrevZ = LedgeRef.Pos.Z;
							break;
						}
						else if(LedgeRef.Pos.Z < LedgeRefPrevZ)
						{
							// The ledge reference actor was placed on a lift that is now moving down.
							// Break climbing as a result (but also be polite and grant some velocity
							// since we started climbing anyway).
							Vel.Z += LedgeClimbSpeed;
							//A_SetPitch(0, SPF_INTERPOLATE);
							LedgeClimbCleanup();
							break;
						}
						// Neither condition was met, but the previous Z of the ledge thing needs watching for updates.
						LedgeRefPrevZ = LedgeRef.Pos.Z;
						SetInventory("GCLiftGrabbed", 0); // Toggle off the holding animation.
						
						// If we jump while ledge-grabbing, override all other ledge behavior and jump.
						if((buttons & BT_JUMP) && !(oldbuttons & BT_JUMP))
						{
							GlideJumped = TRUE;
							Vel.Z = 0;
							LedgeClimbCleanup();
							break;
						}
						
						// Comparison against the current Z value of our ledge reference actor.
						if(LedgeRef.Pos.Z < Pos.Z+MaxStepHeight)
						{
							// We have climbed the ledge successfully, thrust the player onto it
							// and call it a day.
							Vel.Z = LedgeClimbSpeed;
							VelFromAngle(LedgeClimbSpeed * 2, AngleTo(LedgeRef));
							//A_SetPitch(0, SPF_INTERPOLATE);
							LedgeClimbCleanup();
							break;
						}
						else
						{
							// We have not climbed the ledge yet, continue climbing it.
							Vel.Z = LedgeClimbSpeed;
							// Set the player's view to look toward the ledge reference.
							A_SetAngle(AngleTo(LedgeRef), SPF_INTERPOLATE);
							// I would set pitch to look at the ledge you're climbing,
							// but even as it interpolates it is too jerky.
							//A_SetPitch(asin((LedgeRef.Pos.Z - Pos.Z)/Distance3D(LedgeRef)), SPF_INTERPOLATE);
						}
					}
					
					// Or don't, to give up climbing.
					else
					{
						LedgeClimbCleanup();
					}
				break;
			}
		}
		else
		{
			if(CurrentFlightState == GROUNDPOUND)
			{
				if(player.onground)
				{
					if((CountInv("PowerBerserkDamage") || CountInv("PowerDeadmaker")) && CountInv("PowerMidasMode"))
					{
						GiveInventory("MidasBerserkStompItem",1);
					}
					else if(CountInv("PowerBerserkDamage") || CountInv("PowerDeadmaker"))
					{
						GiveInventory("BerserkStompItem",1);
					}
					else if(CountInv("PowerMidasMode"))
					{
						GiveInventory("MidasStompItem",1);
					}
					else
					{
						GiveInventory("StompItem",1);
					}
					StompCooldown = 60;
					PoundUnderwaterTics = 0;
					CurrentFlightState = NORMAL;
				}
				else if(waterlevel)
				{
					// A bit of an added reeuhlizum tweak here. If pounding into a body of water,
					// give a bit of leeway time before exiting the pound state (i.e. allow
					// a stomp actor time to spawn). If the floor isn't reached (too much
					// water resistance), give up and set normal flight state.
					if(PoundUnderwaterTics > 4)
					{
						CurrentFlightState = NORMAL;
						PoundUnderwaterTics = 0;
					}
					else
					{
						Vel.Z = -30;
						PoundUnderwaterTics++;
					}
				}
			}
			else
			{
				// If the ground is somehow touched during a ledge climb, clean up anyway.
				// Happens on rising elevators for some silly reason.
				if(CurrentFlightState == CLIMBING)
				{
					Vel.Z = LedgeClimbSpeed;
					VelFromAngle(LedgeClimbSpeed * 2, AngleTo(LedgeRef));
					LedgeClimbCleanup();
				}
				CurrentFlightState = NORMAL;
			}
			PoundInitialized = FALSE;
			if(GlideInitialized || SlowFell)
			{
				A_StopSound(CHAN_7); // Stop powersuit sounds.
				SlowFell = FALSE;
				GlideInitialized = FALSE;
			}
			FirstEnteredAir = FALSE;
			GlideGraceTimer = 0; // Reset glide input grace timer.
			TimesJumped = 0; // Reset jumps.
			// Don't break the fly cheat.
			if(!(player.cheats & CF_FLY) && !bNoGravity)
			{
				A_Gravity(); // Reset gravity.
			}
			
			// Ledge-climb from ground.
			if(buttons & BT_FORWARD && buttons & BT_USE)
			{
				HandleLedgeClimb();
				if(CurrentFlightState == CLIMBING)
				{
					Vel.Z = LedgeClimbSpeed;
				}
			}
		}
	}
	
	// Right now, this is simply called to from the flight states to prevent duplicate code.
	// It will take a bit more thought to completely export its handling to be autonomous.
	// (Or maybe it's better where it is.)
	void HandleLedgeClimb()
	{
		FLineTraceData ledgelinedata;
		bool ledgetracesuccess;
		double ledgeheight;
		double ledgeceiling;
		double aboveceiling;
		
		// If we are within ledge-climbing grace, don't even try.
		if(LedgeGraceTimer > 0)
		{
			return;
		}

		// Let me just reprototype this function in a comment block.
		ledgetracesuccess = FALSE;
		// First, detect a valid ledge. Scan from the top down.
		for(int ledgetrace = MaxStepHeight+LedgeClimbHeight; ledgetrace > MaxStepHeight; ledgetrace--)
		{
			// At the first ledge encountered, grab its data.
			if(LineTrace(Angle, Radius + LedgeClimbReach, 0, TRF_THRUACTORS|TRF_THRUHITSCAN, ledgetrace, 0, 0, ledgelinedata)
				&& ledgelinedata.HitType == ledgelinedata.TRACE_HitWall)
			{
				// Tried to use some native functions that weren't static. Have to use a friggen actor instead.
				LedgeRef = Spawn("LedgeSitter", (
					ledgelinedata.HitLocation.X + ledgelinedata.HitDir.X,
					ledgelinedata.HitLocation.Y + ledgelinedata.HitDir.Y,
					ledgelinedata.HitLocation.Z + 1.0));
				
				// Get the reference thing's floor height.
				ledgeheight = LedgeRef.GetZAt(0, 0, 0);
				
				// Get a ceiling height too so we don't climb toward a strange space.
				ledgeceiling = LedgeRef.GetZAt(0, 0, 0, GZF_CEILING);
				
				// Get the height of the ceiling above us to make sure we have enough room to climb past it.
				aboveceiling = GetZAt(0, 0, 0, GZF_CEILING);
				
				// And now that we have our data, we check for a laundry list of conditions.
				// First, ceiling height restrictions.
				if((pos.z+MaxStepHeight <= ledgeheight) && (pos.z+MaxStepHeight+LedgeClimbHeight >= ledgeheight)
					&& (ledgeceiling - ledgeheight >= FullHeight) && (aboveceiling - ledgeheight >= Fullheight))
				{
					// Then, line restrictions.
					if(ledgelinedata.Hit3DFloor)
					{
						// Short-circuit these line checks for a 3D floor.
						ledgetracesuccess = TRUE;
					}
					else if(ledgelinedata.HitLine.flags & Line.ML_TWOSIDED
					&& !(ledgelinedata.HitLine.flags & Line.ML_BLOCKING)
					&& !(ledgelinedata.HitLine.flags & Line.ML_BLOCK_PLAYERS)
					&& !(ledgelinedata.HitLine.flags & Line.ML_BLOCKEVERYTHING))
					{
						// Success on matching these line flags.
						ledgetracesuccess = TRUE;
					}
				}
				
				if(ledgetracesuccess)
				{
					//ClimbAngle = Angle;
					//LedgeRef = Spawn("LedgeSitter", (ledgelinedata.HitLocation.x, ledgelinedata.HitLocation.y, ledgeheight));
					LedgeRefPrevZ = LedgeRef.Pos.Z;
					CurrentFlightState = CLIMBING;
					return;
				}
				else if(LedgeRef)
				{
					LedgeRef.Destroy();
				}
			}
		}
	}
	
	// I've copy-pasted this shit into enough places.
	void LedgeClimbCleanup()
	{
		if(LedgeRef) // Remove the ledge reference.
		{
			LedgeRef.Destroy();
			LedgeRef = null;
		}
		ViewBob = 1.0;
		A_Gravity();
		SetInventory("GCLiftGrabbed", 0); // Toggle off the holding animation.
		player.cheats &= ~CF_FROZEN;
		ClimbStarted = FALSE;
		CurrentFlightState = NORMAL;
		LedgeGraceTimer = GetCVar("GC_LedgeTimer");
	}

	// Previous AttackZOffset solution:
	// floor(((1.07396 * player.viewz) - 36.4979) * player.crouchfactor
	void HandlePlayerState()
	{
		if(CountInv("PowerDeadmaker"))
		{
			A_TakeInventory("Dergfist",1);
			A_TakeInventory("DergfistSelected",1);
			A_TakeInventory("PowerSuitToken",1);
			A_TakeInventory("PowerSuitIronfeet",1);
			A_TakeInventory("PowerSuitProtect",1);
			A_TakeInventory("PowerSuit2Ironfeet",1);
			A_TakeInventory("PowerRegeneration",1);
			bWINDTHRUST = 0;
			
			A_SetScale(DMScaleX, DMScaleY);
			ViewHeight = DMViewHeight;
			AttackZOffset = player.viewz >= CeilingZ-4 ? CeilingZ - pos.Z - Height/2 - (12.0 * player.crouchfactor) : DMAttackZ;
			MaxStepHeight = DMStepHeight;
			JumpZ = GetDefaultByType(self.GetClass()).JumpZ * DMJumpMult;
			ForwardMove1 = GetDefaultByType(self.GetClass()).ForwardMove1 * DMSpeedMult;
			ForwardMove2 = GetDefaultByType(self.GetClass()).ForwardMove2 * DMSpeedMult;
			SideMove1 = GetDefaultByType(self.GetClass()).SideMove1 * DMSpeedMult;
			SideMove2 = GetDefaultByType(self.GetClass()).SideMove2 * DMSpeedMult;
			LedgeClimbSpeed = GetDefaultByType(self.GetClass()).LedgeClimbSpeed * 2;
			LedgeClimbHeight = DMClimbingHeight;
			Mass = DMWeight;
			SoundClass = "Deadmaker";
		}
		else if(CountInv("PowerSuitToken"))
		{
			A_TakeInventory("PowerSuitProtect",1); //Remove Envirosuit if you are in powersuit. It's a direct upgrade anyway.
			A_TakeInventory("PowerSuitIronfeet",1);
			bWINDTHRUST = 0;
			
			if(GetCvar("GC_NoExtraHeight"))
			{
				A_SetScale(GetDefaultByType(self.GetClass()).Scale.X, GetDefaultByType(self.GetClass()).Scale.Y);
				ViewHeight = GetDefaultByType(self.GetClass()).ViewHeight;
				AttackZOffset = GetDefaultByType(self.GetClass()).AttackZOffset;
				MaxStepHeight = GetDefaultByType(self.GetClass()).MaxStepHeight;
			}
			else
			{
				A_SetScale(SuitScaleX, SuitScaleY);
				ViewHeight = SuitViewHeight;
				AttackZOffset = player.viewz >= CeilingZ-4 ? CeilingZ - pos.Z - Height/2 - (12.0 * player.crouchfactor) : SuitAttackZ;
				MaxStepHeight = SuitStepHeight;
			}
			JumpZ = GetDefaultByType(self.GetClass()).JumpZ * SuitJumpMult;
			ForwardMove1 = GetDefaultByType(self.GetClass()).ForwardMove1 * SuitSpeedMult;
			ForwardMove2 = GetDefaultByType(self.GetClass()).ForwardMove2 * SuitSpeedMult;
			SideMove1 = GetDefaultByType(self.GetClass()).SideMove1 * SuitSpeedMult;
			SideMove2 = GetDefaultByType(self.GetClass()).SideMove2 * SuitSpeedMult;
			LedgeClimbSpeed = GetDefaultByType(self.GetClass()).LedgeClimbSpeed * 2;
			Mass = SuitWeight;
			if(!GetCvar("GC_ForceNormalSteps")) { SoundClass = "GCPowerSuit"; }
		}
		else
		{
			if(!CountInv("Dergfist")) { A_GiveInventory("Dergfist",1); }
			bWINDTHRUST = 1;
			A_SetScale(GetDefaultByType(self.GetClass()).Scale.X, GetDefaultByType(self.GetClass()).Scale.Y);
			ViewHeight = GetDefaultByType(self.GetClass()).ViewHeight;
			AttackZOffset = GetDefaultByType(self.GetClass()).AttackZOffset;
			MaxStepHeight = GetDefaultByType(self.GetClass()).MaxStepHeight;
			JumpZ = GetDefaultByType(self.GetClass()).JumpZ;
			ForwardMove1 = GetDefaultByType(self.GetClass()).ForwardMove1;
			ForwardMove2 = GetDefaultByType(self.GetClass()).ForwardMove2;
			SideMove1 = GetDefaultByType(self.GetClass()).SideMove1;
			SideMove2 = GetDefaultByType(self.GetClass()).SideMove2;
			LedgeClimbSpeed = GetDefaultByType(self.GetClass()).LedgeClimbSpeed;
			Mass = GetDefaultByType(self.GetClass()).Mass;
			SoundClass = "Guncaster";
		}
	}

	void HandleGameWeapons()
	{
		if(GetCvar("GC_Trogdor"))
		{
			A_TakeInventory("Dergfist",1);
			A_TakeInventory("DergfistSelected",1);
			A_GiveInventory("DergfistSupreme",1);
		}
		else if(!CountInv("PowerDeadmaker"))
		{
			A_GiveInventory("Dergfist",1);
			A_TakeInventory("DergfistSupremeSelected",1);
			A_TakeInventory("DergfistSupreme",1);
		}
	}
	
	Void HandleGameItems()
	{
		if(gameinfo.gametype == Game_HERETIC || gameinfo.gametype == Game_HEXEN)
		{
			A_TakeInventory("Amplifier",9);
			A_TakeInventory("Propane",99);
			A_TakeInventory("Gunzerk",9);
			A_TakeInventory("Berserk2",9);
			A_TakeInventory("RejuvCaps",99);
		}
		else
		{
			A_TakeInventory("TomeOfPowah",9);
			A_TakeInventory("RejuvPot",99);
			A_TakeInventory("GunzerkPot",9);
			A_TakeInventory("BerserkPot",9);
			A_TakeInventory("IronLizardPot",99);
			A_TakeInventory("HealPot",99);
		}
		if(gameinfo.gametype != Game_STRIFE)
		{
			A_TakeInventory("GCS_Stimpack",99);
			A_TakeInventory("GCS_Medipod",99);
			A_TakeInventory("GCS_Megahealth",9);
		}
	}
	
	void HandleQuickToss()
	{
		if(CountInv("DynamiteTossTimer"))
		{
			TakeInventory("DynamiteTossTimer", 1);
		}
		else if(CountInv("DynamiteTossCounter"))
		{
			TakeInventory("DynamiteTossCounter", 1);
		}
	}
	
	void HandleMagAutoload()
	{
		if(CountInv("SupermagJohnson") || CountInv("SupermagTheta"))
		{
			if(CountInv("IronblastMag") || CountInv("AugurMag")) {
				A_GiveInventory("SupermagTimer",1);
				if(CountInv("SupermagTimer") >= 210) // About six seconds.
				{
					A_TakeInventory("SupermagTimer",0);
					A_TakeInventory("IronblastMag",0);
					A_TakeInventory("AugurMag",0);
				}
			}
			else
			{
				A_TakeInventory("SupermagTimer",0);
			}

			if(CountInv("IronblastMag2") || CountInv("AugurMag2")) {
				A_GiveInventory("SupermagTimer2",1);
				if(CountInv("SupermagTimer2") >= 210)
				{
					A_TakeInventory("SupermagTimer2",0);
					A_TakeInventory("IronblastMag2",0);
					A_TakeInventory("AugurMag2",0);
				}
			}
			else
			{
				A_TakeInventory("SupermagTimer2",0);
			}
		}	
	}
	
	void HandleDraughMove()
	{
		// Maybe...
	}
	
	void HandleNinjaMode()
	{
		// Reinstated because it was discovered that checking
		// if we were damaged by a BulletPuff is E Z.
		
		// If we are above minimum velocity and below max ninja level,
		// start building ninja power!
		if((ninja_minvel <= vel.length()) && (ninja_avoidlevel < ninja_maxavoidlevel))
		{
			// Reset grace and decay when we start elevating.
			ninja_gracetics = 0;
			ninja_decaytics = 0;
			
			// Gained enough ninja elevation tics to advance one level.
			if(ninja_elevatetics >= ninja_elevateticlength)
			{
				ninja_avoidlevel++;
				ninja_elevatetics = 0;
			}
			// Don't have enough elevation tics. Keep advancing!
			else
			{
				ninja_elevatetics++;
			}
		}
		// Otherwise, start losing ninja power.
		else if((ninja_minvel > vel.length()) && (ninja_avoidlevel > 0))
		{
			// Reset elevation when we start decaying.
			ninja_elevatetics = 0;
			
			// There's a grace period before decay begins.
			// If that grace period runs out...
			if(ninja_gracetics >= ninja_graceticlength)
			{
				// Waited through enough decay tics to lose one level.
				if(ninja_decaytics >= ninja_decayticlength)
				{
					ninja_avoidlevel--;
					ninja_decaytics = 0;
				}
				// Don't have enough decay tics.
				else
				{
					ninja_decaytics++;
				}
			}
			// Keep running through the grace period.
			else
			{
				ninja_gracetics++;
			}
		}
		
		// Set the number of tokens to our max count, for the status bar.
		SetInventory("NinjaToken", ninja_avoidlevel);
	}
	
	void HandleRecharge()
	{
		//Deadmaker's sprint.
		if(CountInv("PowerDeadmaker") && ChargeFuel < 425 && level.time % 3 == 0) {  ChargeFuel = ChargeFuel + random(1,2); /*A_LogInt(ChargeFuel);*/ }
	}
	
	void HandleAssembly()
	{
		if(CountInv("PowersuitAssembled"))
		{
			self.player.PendingWeapon = Weapon(FindInventory("PowersuitAssembled"));
		}
		
		if(CountInv("DraughTomeAssembled"))
		{
			self.player.PendingWeapon = Weapon(FindInventory("DraughTomeAssembled"));
		}
	}
	
	// kd: The binds you set in the shop / spell wheel are handled here.
	// Three of these are called by EventHandlers of sorts! Yea...
	
	void ShopBind (uint bind, Gcs_ItemType handler, class <Inventory> item) {
		// I'll never learn!
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			player_data.Binds.Set(bind, handler, item);
		}
		
		// Binds.Set(bind, handler, item);
	}
	
	class <SharedTome> CurrentSpell () {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			return player_data.SpellEquip.CurrentSpell(self);
		}
		
		return NULL;
	}
	
	bool SetToSpell (class <SharedTome> tome) {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			return player_data.SpellEquip.MatchTome(tome);
		}
		
		return false;
	}
	
	void NextSpell () {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			player_data.SpellEquip.NextSpell();
			is_cycling_forwards = true;
		}
	}
	
	void PrevSpell () {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			player_data.SpellEquip.PreviousSpell();
			is_cycling_forwards = false;
		}
	}
	
	class <Inventory> BoundItem (uint bind) const {
		if(Gc_Binds.bind_keys <= bind) {
			return NULL;
		}
		
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			return player_data.Binds.m_item [bind];
		}
		
		return NULL;
	}
	
	void SetBind (
	uint				bind,
	Gcs_ItemType		handler,
	class <Inventory>	inv) {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			
			if(consoleplayer == PlayerNumber()) {
				console.printf(
					"%s \c[ice]%s \c-%s %i.",
					StringTable.Localize("$bind_item"),
					StringTable.Localize("$" .. inv.GetClassName() .. "_title"),
					StringTable.Localize("$bind_to_slot"),
					bind);
			}
			
			Gcs_ShopSounds.SetBind();
			player_data.Binds.Set(bind, handler, inv);
		}
	}
	
	void UseBind (uint bind) {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			player_data.Binds.Use(bind);
		}
	}
	
	void HandleBinds () {
		// Since the user keys are the same for setting as well as binding,
		// we really don't wanna activate a bind in the shop.
		if(1 <= CountInv("MenuWheelActive")) {
			return;
		}
		
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data ) {
			uint press =	  GetPlayerInput(INPUT_BUTTONS) &
							(~GetPlayerInput(INPUT_OLDBUTTONS));
		
					if(press & BT_USER1)	player_data.Binds.Use(0);
			else	if(press & BT_USER2)	player_data.Binds.Use(1);
			else	if(press & BT_USER3)	player_data.Binds.Use(2);
			else	if(press & BT_USER4)	player_data.Binds.Use(3);
		}
	}
	
	const seek_key = BT_RELOAD;
	
	static void MakeSeekerForPlayer (
	Actor	mo,
	Actor	owner,
	double	max_vel,
	double	acc) {
		let cast_owner = Guncaster(owner);
		
		if(cast_owner) {
			cast_owner.Shepherd.Add(mo, max_vel, acc);
		}
	}
	
	static void RemoveSeeker (Actor mo, Actor owner) {
		let cast_owner = Guncaster(owner);
		
		if(cast_owner) {
			cast_owner.Shepherd.Remove(mo);
		}
	}
	
	static void MakeRoyalSeekerForPlayer (
	Actor	mo,
	Actor	owner,
	double	max_vel,
	double	acc) {
		let cast_owner = Guncaster(owner);
		
		if(cast_owner) {
			cast_owner.RoyalShepherd.Add(mo, max_vel, acc);
		}
	}
	
	static void RemoveRoyalSeeker (Actor mo, Actor owner) {
		let cast_owner = Guncaster(owner);
		
		if(cast_owner) {
			cast_owner.RoyalShepherd.Remove(mo);
		}
	}
	
	// kd: Invulnerability is implied by cheats and powerups, so if we want
	// the hud statue eyes to glow in god mode, we gotta do it this way, cuz
	// I'm not adding a special case for something so specialised (that's what
	// gets me into Plunderbund).
	
	bool old_god_mode;
	
	void HandleInvulnerabilityCounter () {
		bool god_mode =
			player.cheats & (CF_GODMODE | CF_GODMODE2) ||
			0 < CountInv("PowerInvulnerable") ||
			0 < CountInv("PowerGodMode");
		
		if(god_mode && !old_god_mode) {
			A_GiveInventory("GodToken", 1);
		}
		
		else if(old_god_mode && !god_mode) {
			A_TakeInventory("GodToken", int.max);
		}
		
		old_god_mode = god_mode;
	}
	
	bool old_dark_nithor_mode;
	
	void HandleDarkNithorCounter () {
		bool dark_nithor_mode =
			0 < CountInv("PowerDeadmaker") &&
			0 < CountInv("PowerSuitDraugh");
		
		if(dark_nithor_mode && !old_dark_nithor_mode) {
			A_GiveInventory("DarkNithorToken", 1);
		}
		
		else if(!dark_nithor_mode && old_dark_nithor_mode) {
			A_TakeInventory("DarkNithorToken", 0x7fffffff);
		}
		
		old_dark_nithor_mode = dark_nithor_mode;
	}
	
	void HandleSeekers () {
		GuidePos guide_pos;
		guide_pos.FromPlayerAim(self);
		vector3 seek_pos = guide_pos.Get();
		
		Shepherd.All3d(seek_pos);
		Shepherd.AllFaceMoveDir();
		
		if(player.cmd.buttons & seek_key) {
			RoyalShepherd.All3d(seek_pos);
			RoyalShepherd.AllFaceMoveDir();
		}
		
		/* vector3 seek_pos = GCSheepBaton.TargetSeekPos(self, height: 41);
		
		// For sheep:
		Shepherd.EnsureNoNulls();
		Shepherd.AllSeekPos3d(seek_pos);
		Shepherd.AllFaceMoveDir();
		
		// For the emperor:
		if(GetPlayerInput(INPUT_BUTTONS) & seek_key) {
			RoyalShepherd.EnsureNoNulls();
			RoyalShepherd.AllSeekPos3d(seek_pos);
		} */
	}
	
	void MoneyLocator()
	{
		Actor ClosestMoneyPickup;
		int lowestdistance = 0x7FFFFFFF;
		let gvars = GC_GlobalVariables.Get();
		
		if(gvars.MoneyList.Size() <= 0)
		{
			CVar.GetCVar("GC_GoldDetected", player).SetBool(FALSE);
			if(MoneyPointer)
			{
				MoneyPointer.Destroy();
			}
			return;
		}
		
		// Find the closest dosh pickup.
		for(int i = 0; i < gvars.MoneyList.Size(); i++)
		{
			if(gvars.MoneyList[i] && Distance3D(gvars.MoneyList[i]) < lowestdistance)
			{
				lowestdistance = Distance3D(gvars.MoneyList[i]);
				ClosestMoneyPickup = gvars.MoneyList[i];
			}
		}
		if(ClosestMoneyPickup)
		{
			CVar.GetCVar("GC_GoldDetected", player).SetBool(TRUE);
			CVar.GetCVar("GC_GoldDistance", player).SetInt(lowestdistance);
		
			Vector3 Normal = (ClosestMoneyPickup.Pos - (Pos + (0, 0, height/2))) / lowestdistance;
			Vector3 NextPos = (Pos + (0, 0, height/2)) + Normal * (lowestdistance / MoneyArrowDistDivisor > 0 ? lowestdistance / MoneyArrowDistDivisor + 16 : 16);
			if(MoneyPointer)
			{
				MoneyPointer.A_Warp(AAPTR_DEFAULT, NextPos.X, NextPos.Y, NextPos.Z, 0, WARPF_ABSOLUTEPOSITION|WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE);
			}
			else
			{
				MoneyPointer = Spawn("MoneyPointer", NextPos);
				MoneyPointer.target = self;
			}
			MoneyPointer.A_Face(ClosestMoneyPickup, 0, 0);
		}
	}
	
	void MoneyMagnet()
	{
		let mymoney = self.FindInventory("Dosh");
		// Do not teleport money if the player is full of money or isn't moving.
		// The latter is a bugfix for Doom being unable to hand you things when
		// you aren't moving.
		if(mymoney && (mymoney.Amount == mymoney.MaxAmount && !GetCVar("GC_HoardingHeadache")))
		{
			return;
		}
		
		int grabrange;
		int tomed = (CountInv("PowerMidasMode") ? 2 : 
					CVar.FindCVar("GC_Loadsamoney").GetInt())
					+ CountInv("PowerTomeEffect");
		let gvars = GC_GlobalVariables.Get();
		switch(tomed)
		{
			default:
			case 3:
				grabrange = 16384;
				break;
			case 2:
				grabrange = 4096;
				break;
			case 1:
				grabrange = 512;
				break;
			case 0:
				grabrange = 384;
				break;
		}
		
		if(gvars.MoneyList.Size() )
		{
			// Find the nearest dosh item and drop it on ourselves.
			for(int i = 0; i < gvars.MoneyList.Size(); i++)
			{
				// If it is close enough...
				if(gvars.MoneyList[i] && Distance2D(gvars.MoneyList[i]) <= grabrange)
				{
					// Spawn the decorative money sparkle.
					Spawn("ShingSparkleSparkle", gvars.MoneyList[i].Pos);
					// Give the money to the player.
					Inventory(gvars.MoneyList[i]).Touch(self); //Warp(self, zofs:Height/2);
					// Move only one gold item per run.
					return;
				}
			}
		}
	}
	
	void HandleItemReset()
	{	// Zhs2: Rather cool that all of these functions translate well from ACS to ZScript.
		//Pillow: Removes spell-in-progress tokens,
		//so they won't stick around after haphazard map switch mid-casting.
		A_TakeInventory("SkullfireInProgress",1);
		A_TakeInventory("FlamewaveInProgress",1);
		A_TakeInventory("FrostbiteInProgress",1);
		A_TakeInventory("SpiritcannonInProgress",1);
		A_TakeInventory("HammersmiteInProgress",1);
		A_TakeInventory("GumpopInProgress",1);
		A_TakeInventory("SkypunchInProgress",1);
		A_TakeInventory("ThunderInProgress",1);
		A_TakeInventory("CorpseInProgress",1);
		A_TakeInventory("ThreadInProgress",1);
		A_TakeInventory("AnnihilationInProgress",1);
		A_TakeInventory("ApocalypseInProgress",1);
		A_TakeInventory("DarkpathInProgress",1);
		A_TakeInventory("CrowsInProgress",1);
		A_TakeInventory("PrismInProgress",1); 
		A_TakeInventory("BreathInProgress",1);
		A_TakeInventory("SheepshieldInProgress",1);

		//Sheepshield
		A_TakeInventory("SheepActive",1);
		A_TakeInventory("SheepOut",999);
		A_TakeInventory("SuperSheepOut",999);
		A_TakeInventory("SheepOut1",1);
		A_TakeInventory("SheepOut2",1);
		A_TakeInventory("SheepOut3",1);
		
		//Pulverizer Strat
		A_TakeInventory("LeadBallHeld",1);
		A_TakeInventory("LeadBallSize",999);
		// These no longer exist?
		//A_TakeInventory("RLeadBallHeld",1);
		//A_TakeInventory("RLeadBallSize",999);
		A_TakeInventory("LLeadBallHeld",1);
		A_TakeInventory("LLeadBallSize",999);

		A_TakeInventory("StormEngaged",999); //Tomed Thunderstruck
		A_TakeInventory("CasterFamiliarActive",999);	//Wyvern
		
		A_TakeInventory("DynamiteTossCounter",999); //TNT
		A_TakeInventory("DynamiteTossTimer",999);
		
		//Ironblast
		A_TakeInventory("IronblastMag",9);
		A_TakeInventory("IronblastMag2",9);
		
		if(CountInv("IronblastRevert"))
		{
			UseInventory(FindInventory("IronblastRevert"));
			A_TakeInventory("FloaterblastActive",1);
			A_TakeInventory("AnotherIronblast",1);
			A_TakeInventory("IronblastStratActive",1);
			if(CountInv("Ironblast"))
			{
				A_DropItem("IronblastDropped",1);
			}
			else
			{
				GiveInventory("IronblastDropped",1);
			}
		}
		
		// Pillow: Kick stuph, Cuz I keep forgetting about map transition not
		// going well with kicking while changing maps.
		
		A_TakeInventory("KickethThyHappend",1);
		
		//Draugh
		A_TakeInventory("DraughRiftwalking",1);
		A_TakeInventory("DraughWithdraw",1);
		while(CountInv("DraughOut"))
		{
			GiveInventory("DraughTome", 1);
			A_TakeInventory("DraughOut", 1);
		}
		
		// Pillow: Removes the riftwalking effects.
		bThruActors	= FALSE;
		bGhost		= FALSE;
		bNoTrigger	= FALSE;
		player.cheats &= ~CF_NOTARGET;
		
		//Vision refill
		GiveInventory("VisionCounter",120);
		
		//Philosopher's refill
		TakeInventory("MidasTimer",999);
		TakeInventory("MidasUsed",1);
		TakeInventory("MidasRecharger",1);
		
		// Stop dancing! This isn't a happy place!
		if(User_Carlton)
		{
			User_Carlton = 0;
		}
		// Clean up ledge stuff on transition.
		LedgeClimbCleanup();
		
		//Chillgrasp stuff between maps in multiplayer.
		if(!grasp)
		{
			grasp = new("Gc_GraspThinker");
			grasp.Init(self);
		}
		
		// Sheppard no Shepherding!
		Shepherd.Clear();
		RoyalShepherd.Clear();
		
		// Unfreeze people who had the shop open on the next map start.
		player.cheats &= ~CF_TOTALLYFROZEN;
		
		// you're that ninja...
		ninja_data = Gc_PlayerEventHandler.NinjaDataPtr();
		
		// I HAVE AN ANNOUNCEMENT TO MAKE - I AM DRUNK.
		view_tilt.Init(player);
	}
	
	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
	{
		bool selfDamage = source == self;
		bool disableDefFactors = deathmatch && !selfDamage && (source is "PlayerPawn");
		
		if (disableDefFactors) {
			flags |= DMG_NO_FACTOR;
		}

		//Coop thrust damage removal. Note that it does not prevent the most important part - the explosion damage push. What a load.
		if (!deathmatch && !selfDamage && (source is "PlayerPawn")) {
			if (CVar.GetCVar("teamdamage", Player).GetFloat() <= 0.0) {
				flags |= DMG_THRUSTLESS;
			}
		}
		
		//Voodoo doll tiberium nuke blow-up prevention. Not tested yet but it 'should' work.
		PlayerInfo Player = self.Player;
		if (!Player || !Player.mo || self != Player.mo) {
			if (mod == "Tiberium" || mod == "BlueTiberium") {
				return -1;
			}
		}
		
		//MINION, GIVE ME A BREAK~
		if(Source is "Draugh" || Source is "CasterFamiliar" || Source is "CasterFamiliar2") {
			return -1;
		}
		
		//STOOPID, STOOPID.
		if((mod == "Falling") || (mod == "InstantDeath")) {
            return -1;
        }
		
		// Ninjamode check, to avoid damage from hitscan attacks.
		// Strife, y u no inherit from BulletPuff
		if(
		inflictor && (
		inflictor is "BulletPuff" ||
		inflictor.CheckClass("StrifePuff") || (
		ninja_data && ninja_data.IsInflictor(inflictor.GetClassName()) )) )
		{
			damage = int(damage * ((ninja_maxavoidlevel + 1) - ninja_avoidlevel) / (ninja_maxavoidlevel + 1));
			//console.printf("Total hitscan damage at ninja level %i: %i", ninja_avoidlevel, damage);
		}
		
		return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
	}
	
	override void Die(Actor source, Actor inflictor, int dmgflags) // Stuff that is handled on death.
	{
		if(CheckInventory("PowerSuitItem2", 1))
		{	// Switch the Powersuit's state back to inactive.
			GiveInventory("PowerSuitItem", 1); // Give back the toggle up.
			TakeInventory("PowerSuitItem2", 1); // And take the toggle down.
			A_SetScale(GetDefaultByType(self.GetClass()).Scale.X, GetDefaultByType(self.GetClass()).Scale.Y);
			ViewHeight = GetDefaultByType(self.GetClass()).ViewHeight;
			AttackZOffset = GetDefaultByType(self.GetClass()).AttackZOffset;
			MaxStepHeight = GetDefaultByType(self.GetClass()).MaxStepHeight;
			JumpZ = GetDefaultByType(self.GetClass()).JumpZ;
			ForwardMove1 = GetDefaultByType(self.GetClass()).ForwardMove1;
			SideMove1 = GetDefaultByType(self.GetClass()).SideMove1;
		}
		
		if((CheckInventory("PowerSuitItem", 1) || CheckInventory("PowerSuitItem2", 1)) && deathmatch)
		{	// Drop the powersuit in deathmatch.
			TakeInventory("PowerSuitItem", 1);
			TakeInventory("PowerSuitItem2", 1);
			A_DropItem("PowerSuitItem", 1);
		}
		
		//Pillow: In case you died while having Draugh on yourself, it will give you him back.
		if(CountInv("DraughsuitItem"))
		{
			A_TakeInventory("DraughCounter",1);
			A_GiveInventory("DraughTome",1);
			A_TakeInventory("DraughsuitItem",1);
		}
		
		// People die when they are killed, but important variables shouldn't.
		let VarStorage = IHoldPlayerVariables(self.FindInventory("IHoldPlayerVariables"));
		if(VarStorage)
		{
			// All of these array variables have four fields, for four user buttons.
			for(int i = 0; i < 3; i++)
			{
				VarStorage.spellbuttons[i] = self.user_spellbuttons[i];
				VarStorage.spellshopindex[i] = self.user_spellshopindex[i];
				VarStorage.spellitemindex[i] = self.user_spellitemindex[i];
				VarStorage.spellisbound[i] = self.user_spellisbound[i];
			}
			
			VarStorage.grasp = grasp;
		}
		
		Gc_Shop_Entry.SendNetworkEvent("CloseShop");
		
		Super.Die(source, inflictor, dmgflags);
	}
	
	override void OnRespawn()
	{
		// Fun fact: this function fires at the beginning of a game too.
		
		// Bring my variables back!
		let VarStorage = IHoldPlayerVariables(self.FindInventory("IHoldPlayerVariables"));
		if(VarStorage)
		{
			// All of these array variables have four fields, for four user buttons.
			for(int i = 0; i < 3; i++)
			{
				self.user_spellbuttons[i] = VarStorage.spellbuttons[i];
				self.user_spellshopindex[i] = VarStorage.spellshopindex[i];
				self.user_spellitemindex[i] = VarStorage.spellitemindex[i];
				self.user_spellisbound[i] = VarStorage.spellisbound[i];
			}
			
			if(VarStorage.grasp)
			{
				grasp = VarStorage.grasp;
			}
			else
			{
				grasp = new("Gc_GraspThinker");
				grasp.Init(self);
			}
		}
		
		// LET'S HEAD OVER THERE REALLY REALLY FAST. IF SOMETHING GETS IN OUR
		// WAY - SHOOT IT!
		view_tilt.Init(player);
		
		// player_data = VarStorage;
		Super.OnRespawn();
		return;
	}
	
	override void MovePlayer ()
	{
		let player = self.player;
		UserCmd cmd = player.cmd;

		// [RH] 180-degree turn overrides all other yaws
		if (player.turnticks)
		{
			player.turnticks--;
			Angle += (180. / TURN180_TICKS);
		}
		else
		{
			Angle += cmd.yaw * (360./65536.);
		}

		player.onground = (pos.z <= floorz) || bOnMobj || bMBFBouncer || (player.cheats & CF_NOCLIP2);

		// killough 10/98:
		//
		// We must apply thrust to the player and bobbing separately, to avoid
		// anomalies. The thrust applied to bobbing is always the same strength on
		// ice, because the player still "works just as hard" to move, while the
		// thrust applied to the movement varies with 'movefactor'.

		if (cmd.forwardmove | cmd.sidemove)
		{
			double forwardmove, sidemove;
			double bobfactor;
			double friction, airfriction, movefactor;
			double fm, sm;
			
			// Normal friction = ORIG_FRICTION, normal movefactor = ORIG_FRICTION_FACTOR
			if(player.onground)
			{
				if(CountInv("PowerSuitToken"))
				{
					// Powersuit overrides Envirosuit, grants full movement on any surface.
					self.friction = 1.0;
					friction = ORIG_FRICTION;
					movefactor = ORIG_FRICTION_FACTOR;
				}
				else if(CountInv("PowerSuitProtect"))
				{
					if(GetCvar("GC_SpikeBoots"))
					{
						// Mofuckin' glue boots.
						self.friction = 0.9;
						friction = ORIG_FRICTION;
						movefactor = ORIG_FRICTION_FACTOR*1.9;
					}
					else
					{
						// Just regular friction negation.
						self.friction = 1.0;
						friction = ORIG_FRICTION;
						movefactor = ORIG_FRICTION_FACTOR;
					}
				}
				else
				{
					// No effect, normal walking.
					self.friction = 1.0;
					[friction, movefactor] = GetFriction();
				}
			}
			else
			{
				// Don't fuck with airspeed, we do that later.
				self.friction = 1.0;
				[friction, movefactor] = GetFriction();
			}
			bobfactor = friction < ORIG_FRICTION ? movefactor : ORIG_FRICTION_FACTOR;
			if (!player.onground && !bNoGravity && !waterlevel)
			{
				// [RH] allow very limited movement if not on ground.
				// Zhs2: If that's what the player's aircontrol is set to, that is.
				movefactor *= self.aircontrol ? self.aircontrol : level.aircontrol;
				bobfactor *= self.aircontrol ? self.aircontrol : level.aircontrol;
			}

			fm = cmd.forwardmove;
			sm = cmd.sidemove;
			[fm, sm] = TweakSpeeds (fm, sm);
			fm *= Speed / 256;
			sm *= Speed / 256;

			// When crouching, speed and bobbing have to be reduced
			if (CanCrouch() && player.crouchfactor != 1)
			{
				fm *= player.crouchfactor;
				sm *= player.crouchfactor;
				bobfactor *= player.crouchfactor;
			}

			forwardmove = fm * movefactor * (35 / TICRATE);
			sidemove = sm * movefactor * (35 / TICRATE);

			if (forwardmove)
			{
				Bob(Angle, cmd.forwardmove * bobfactor / 256., true);
				ForwardThrust(forwardmove, Angle);
			}
			if (sidemove)
			{
				let a = Angle - 90;
				Bob(a, cmd.sidemove * bobfactor / 256., false);
				Thrust(sidemove, a);
			}

			if (!(player.cheats & CF_PREDICTING) && (forwardmove != 0 || sidemove != 0))
			{
				PlayRunning ();
			}

			if (player.cheats & CF_REVERTPLEASE)
			{
				player.cheats &= ~CF_REVERTPLEASE;
				player.camera = player.mo;
			}
			
			if(!player.onground && self.aircontrol && !waterlevel && !bNoGravity)
			{
				//level.airfriction = 1.; // Fuck you Baltimore!
				// Friction seems to be a thing that is applied based on level settings.
				if(self.aircontrol <= 1/256.)
				{
					airfriction = 1.;
				}
				else
				{
					// Friction is inversely proportional to the amount of control
					airfriction = self.aircontrol * -0.0941 + 1.0004;
				}
				// It was never externalized for actor use. So, let's apply it here.
				if (player && player.mo && player.mo == self && airfriction != 1.)
				{
					// Apply only to players, not voodoo dolls.
					Vel.X *= airfriction;
					Vel.Y *= airfriction;
				}
			}
			
			//Console.Printf("Velocity is %f", Vel.Length());
		}
	}
	
	override void CheckCrouch(bool totallyfrozen)
	{
		let player = self.player;
		UserCmd cmd = player.cmd;
		
		/*	This is totally stupid. Why negate buttons under certain conditions
			when you can just disallow their functions under said conditions?
		if (cmd.buttons & BT_JUMP)
		{
			cmd.buttons &= ~BT_CROUCH;
		}
		*/
		if (CanCrouch() && player.health > 0 && level.IsCrouchingAllowed() && !(cmd.buttons & BT_JUMP))
		{
			if (!totallyfrozen)
			{
				int crouchdir = player.crouching;

				if (crouchdir == 0)
				{
					crouchdir = (cmd.buttons & BT_CROUCH) ? -1 : 1;
				}
				else if (cmd.buttons & BT_CROUCH)
				{
					player.crouching = 0;
				}
				if (crouchdir == 1 && player.crouchfactor < 1 && pos.Z + height < ceilingz)
				{
					CrouchMove(1);
				}
				else if (crouchdir == -1 && player.crouchfactor > 0.5)
				{
					CrouchMove(-1);
				}
			}
		}
		else
		{
			player.Uncrouch();
		}

		player.crouchoffset = -(ViewHeight) * (1 - player.crouchfactor);
	}
	
	int SpellIndex () const {
		let player_data = IholdPlayerVariables(FindInventory("IholdPlayerVariables"));
		
		if(player_data) {
			return player_data.SpellEquip.SpellIndex();
		}
		
		return 0;
	}
}

class GC_PlayerEventHandler : EventHandler
{
	override void PlayerEntered(PlayerEvent e)
	{
		PlayerInfo player = players[e.PlayerNumber];
		
		if(player.mo is "Guncaster")
		{
			Guncaster(player.mo).HandleItemReset();
			InitIconHandling();
		}
	}
	
	override void WorldTick ()
	{
		PlayerInfo player = players [consoleplayer];
		
		if(!player || !player.mo) {
			return;
		}
		
		TickFirebreathIcon(player.mo);
		TickSigilIcon(player.mo);
	}
	
	// kd: Ninja stuff. The gcninja lumps get read (they're just lists of
	// actors / inflictors you wanna have the ninja effect on) and then passed
	// to the player.
	
	protected Gc_NinjaData ninja_data;
	
	override void OnRegister () {
		ninja_data = new("Gc_NinjaData");
		
		if(ninja_data) {
			ninja_data.UseAllNinjaLumps();
		}
	}
	
	static Gc_NinjaData NinjaDataPtr () {
		let handler = Gc_PlayerEventHandler(Find("Gc_PlayerEventHandler"));
		
		if(handler) {
			return handler.ninja_data;
		}
		
		return NULL;
	}
	
	// kd: The Firebreath and Sigil icons can change. Here's when and how.

	const sigil_levels = 5;

	protected bool						old_green_mode;
	protected bool						old_blue_mode;
	protected bool						old_bishop_mode;
	protected int						old_sigil_count;
	protected Gc_SpellIcons				icon_data;
	
	// kd: In hindsight, might've wanted to keep the spell list pointer in the
	// sbar data handler, too, but it's just 5 lines, so...
	
	// Anyway, from time to time, these spells have changing icons. We keep
	// their pointer for no reason in particular than "it's a femtosecond
	// faster to do when the time comes".
	protected int						firebreath_index;
	protected int						sigil_index;

	void InitIconHandling ()
	{
		old_green_mode	= false;
		old_blue_mode	= false;
		old_sigil_count	= 0;
		let sbar_data	= Gc_SbarData(Gc_SbarData.Find("Gc_SbarData"));
		
		if(sbar_data) {
			icon_data = sbar_data.SpellIconsPtr();
		}
		
		// kd: Opposite of syntactic sugar.
		let spell_data	= Gc_SpellCollectionLoad(
			Gc_SpellCollectionLoad.Find("Gc_SpellCollectionLoad"));
		
		if(spell_data) {
			let spell_list		= spell_data.LocalSpellPtr();
			firebreath_index	= spell_list.IndexForTome("FirebreathTome");
			sigil_index			= spell_list.IndexForTome("SigilTome");
		}
	}

	void TickFirebreathIcon (Actor mo)
	{
		bool has_blue		= 0 < mo.CountInv("TibCore");
		bool bishop_mode	= 0 < mo.CountInv("PowerSuitToken");
		bool green_mode		= !has_blue && bishop_mode;
		bool blue_mode		=  has_blue && bishop_mode;
		
		bool blue_on	=  blue_mode   && !old_blue_mode;
		bool green_on	=  green_mode  && !old_green_mode;
		bool bishop_off	= !bishop_mode &&  old_bishop_mode;
		
		if(green_on)
		{
			icon_data.LocalSetTomeIcon(
				consoleplayer, firebreath_index, "tb2bk0");
		}
		
		if(blue_on)
		{
			icon_data.LocalSetTomeIcon(
				consoleplayer, firebreath_index, "tb22k0");
		}
		
		if(bishop_off)
		{
			icon_data.LocalResetTomeIcon(consoleplayer, firebreath_index);
		}
		
		old_green_mode	= green_mode;
		old_blue_mode	= blue_mode;
		old_bishop_mode	= bishop_mode;
	}

	void TickSigilIcon (Actor mo)
	{
		static const String letters [] =
		{
			"a", "b", "c", "d", "e"
		};
		
		int sigil_count = mo.CountInv("SigilTome");
		
		if(sigil_count != old_sigil_count)
		{
			String sprite_name = "bsts" ..
				letters [clamp(sigil_count - 1, 0, sigil_levels - 1)] .. "0";
			icon_data.LocalSetTomeIcon(consoleplayer, sigil_index, sprite_name);
		}
		
		old_sigil_count = sigil_count;
	}
}

class GodToken : Inventory {
	default {
		Inventory.MaxAmount 1;
	}
}

class DarkNithorToken : Inventory {
	default {
		Inventory.MaxAmount 1;
	}
}

//This is probably the weirdest way to handle taunt buttons... but whatever. If it works, it ain't stupid!
class GuncasterTauntTimer : Inventory { Default { Inventory.MaxAmount 999; } }

class GuncasterTauntItem : CustomInventory
{
	Default
	{
		Inventory.Amount 1;
		-INVENTORY.INVBAR
	}
	
	int user_Carlton;
	
	states
	{
	Spawn:
		TNT1 A -1;
		Stop;
	Use:
		TNT1 A 0 A_JumpIf(CountInv("GuncasterTauntTimer") && !invoker.User_Carlton, "Nope");
		TNT1 A 0 A_Jump(256,"Taunt01","Taunt02","Taunt03","Taunt04","Taunt05",
		"Taunt06","Taunt07","Taunt08","Taunt09","Taunt10","Taunt11","Taunt12",
		"Taunt13","Taunt14","Taunt15","Taunt16","Taunt17","Taunt18","Taunt19",
		"Taunt20","Taunt21","Taunt22","Taunt23","Taunt24","Taunt25","Taunt26",
		"Taunt27","Taunt28","Taunt29","Taunt30","Taunt31","Taunt32","Taunt33",
		"Taunt34","Taunt35");
	Taunt01:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt01",2);
		Fail;
	Taunt02:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",6);
		TNT1 A 0 A_PlaySound("GC/Taunt02",2);
		Fail;
	Taunt03:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt03",2);
		Fail;
	Taunt04:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",3);
		TNT1 A 0 A_PlaySound("GC/Taunt04",2);
		Fail;
	Taunt05:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",6);
		TNT1 A 0 A_PlaySound("GC/Taunt05",2);
		Fail;
	Taunt06:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",3);
		TNT1 A 0 A_PlaySound("GC/Taunt06",2);
		Fail;
	Taunt07:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt07",2);
		Fail;
	Taunt08:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt08",2);
		Fail;
	Taunt09:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt09",2);
		Fail;
	Taunt10:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt10",2);
		Fail;
	Taunt11:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt11",2);
		Fail;
	Taunt12:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt12",2);
		Fail;
	Taunt13:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt13",2);
		Fail;
	Taunt14:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt14",2);
		Fail;
	Taunt15:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt15",2);
		Fail;
	Taunt16:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt16",2);
		Fail;
	Taunt17:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt17",2);
		Fail;
	Taunt18:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt18",2);
		Fail;
	Taunt19:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt19",2);
		Fail;
	Taunt20:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt20",2);
		Fail;
	Taunt21:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt21",2);
		Fail;
	Taunt22:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",6);
		TNT1 A 0 A_PlaySound("GC/Taunt22",2);
		Fail;
	Taunt23:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt23",2);
		Fail;
	Taunt24:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",11);
		TNT1 A 0 A_PlaySound("GC/Taunt24",2);
		Fail;
	Taunt25:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt25",2);
		Fail;
	Taunt26:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",6);
		TNT1 A 0 A_PlaySound("GC/Taunt26",2);
		Fail;
	Taunt27:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",5);
		TNT1 A 0 A_PlaySound("GC/Taunt27",2);
		Fail;
	Taunt28:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt28",2);
		Fail;
	Taunt29:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",1);
		TNT1 A 0 A_PlaySound("GC/Taunt29",2);
		Fail;
	Taunt30:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt30",2);
		Fail;
	Taunt31:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",3);
		TNT1 A 0 A_PlaySound("GC/Taunt21",2);
		Fail;
	Taunt32:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",2);
		TNT1 A 0 A_PlaySound("GC/Taunt22",2);
		Fail;
	Taunt33:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",3);
		TNT1 A 0 A_PlaySound("GC/Taunt23",2);
		Fail;
	Taunt34:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",3);
		TNT1 A 0 A_PlaySound("GC/Taunt34",2);
		Fail;
	Taunt35:
		TNT1 A 0 A_GiveInventory("GuncasterTauntTimer",4);
		TNT1 A 0 A_PlaySound("GC/Taunt35",2);
		Fail;
	Nope:
		TNT1 A 0;
		Fail;
	}
}

//Quick-heal item. REVOLVER OCELOT.
Class QuickHealItem : CustomInventory
{
	Default
	{
		Inventory.Amount 1;
		Inventory.MaxAmount 1;
		Inventory.InterHubAmount 1;
		Inventory.PickupSound "";
		Inventory.UseSound "";
		Inventory.PickupMessage "Verbosen Verbosen Hosen werde Geschlossen.";
		//+INVENTORY.INVBAR
		+INVENTORY.UNDROPPABLE
	}
	
	transient CVar AutoHealCVar, AutoHealLimitCVar;
	
	override void DoEffect()
	{
		if(!AutoHealCVar)
		{
			AutoHealCVar = CVar.GetCVar("GC_AutoHeal", owner.player);
		}
		if(!AutoHealLimitCVar)
		{
			AutoHealLimitCvar = CVar.GetCVar("GC_AutoHealLimit", owner.player);
		}
		if(AutoHealCVar && AutoHealLimitCVar && owner.player &&
			AutoHealCVar.GetInt() && owner.Health > 0 && owner.Health < AutoHealLimitCvar.GetInt())
		{
			owner.UseInventory(self);
		}
		
		Super.DoEffect();
		return;
	}
	
	States
	{
	Spawn:
		MBAG A -1;
		Stop;
	Use:
		TNT1 A 0 //A_JumpIf(CallACS("Can I Heal"), 1)
		{
			if(invoker.owner.Health < PlayerPawn(invoker.owner).MaxHealth)
			{
				return ResolveState("Heal");
			}
			return ResolveState(Null);
		}
		Fail;
	Heal:
		TNT1 A 0 A_JumpIf(CountInv("StrifeCounter"), "StrifeHealer");
		TNT1 A 0 A_JumpIf(CountInv("HexenCounter") || CountInv("HereticCounter"), "RavenHealer");

	//Doom and unassigned.
		TNT1 A 0 A_JumpIf(CountInv("PowerMedbagFake") || !CountInv("Medbag"), "UsePod");
		TNT1 A 0 UseInventory(FindInventory("MedBag")); //ACS_NamedExecuteAlways("MedbagHealing");
		Fail;

	//Hexen.
	RavenHealer:
		TNT1 A 0 A_JumpIf(CountInv("PowerMedbagFake") || !CountInv("Medbag"), "UsePot");
		TNT1 A 0 UseInventory(FindInventory("MedBag")); //ACS_NamedExecuteAlways("MedbagHealing");
		Fail;
	UsePot:
		TNT1 A 0 A_JumpIf(CountInv("HealPot"),1);
		Fail;
		TNT1 A 0 A_PlaySound("Pot/Use");
		TNT1 A 0 A_TakeInventory("HealPot",1);
		TNT1 A 0 A_GiveInventory("Health",25);
		Fail;

	//Strife.
	StrifeHealer:
		TNT1 A 0 A_JumpIf(CountInv("PowerMedbagFake") || !CountInv("Medbag"), "UsePod");

		TNT1 A 0 UseInventory(FindInventory("MedBag")); //ACS_NamedExecuteAlways("MedbagHealing");
		Fail;
	UsePod:
		TNT1 A 0 A_JumpIf(CountInv("GCS_Stimpack"),"HealStim");
		TNT1 A 0 A_JumpIf(CountInv("GCS_Medipod"),"HealPod");
		TNT1 A 0 A_JumpIf(CountInv("GCS_Megahealth"),"HealMega");
		Fail;
	HealStim:
		TNT1 A 0 A_PlaySound("Capsule/Use");
		TNT1 A 0 A_TakeInventory("GCS_Stimpack",1);
		TNT1 A 0 A_GiveInventory("Health",10);
		Fail;
	HealPod:
		TNT1 A 0 A_PlaySound("Capsule/Use");
		TNT1 A 0 A_TakeInventory("GCS_Medipod",1);
		TNT1 A 0 A_GiveInventory("Health",25);
		Fail;
	HealMega:
		TNT1 A 0 A_PlaySound("Capsule/Use");
		TNT1 A 0 A_TakeInventory("GCS_Medipod",1);
		TNT1 A 0 A_GiveInventory("Health",200);
		Fail;
	} 
}

//Variable storage.
class IHoldPlayerVariables : Inventory
{
	int spellbuttons[4];
	int spellshopindex[4];
	int spellitemindex[4];
	int spellisbound[4];
	
	Gc_GraspThinker 	grasp;
	Gc_Binds			Binds;
	GCSpellEquip		SpellEquip;

	Default
	{
		Inventory.MaxAmount 1;
		+INVENTORY.UNDROPPABLE
	}
	
	void SetupForGameplay () {
		if(!owner) {
			return;
		}
		
		Binds.Init(owner);
		SpellEquip.Reset(owner);
	}
}

//Steps, effects and such.

class GuncasterStep : Actor
{
	Default
	{
		Radius 10;
		Projectile;
		+BLOODLESSIMPACT
		+DONTBLAST
		-ACTIVATEMCROSS
		-ACTIVATEIMPACT
		+NOTIMEFREEZE
	}
	
	States
	{
	Spawn:
		TNT1 A 1;
		Stop;
	Death:
		TNT1 A 0 A_SpawnItemEx("GuncasterStepConnect",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}
class GuncasterStepConnect : Actor
{
	Default
	{
		+NOINTERACTION
		+NOTIMEFREEZE
		-ACTIVATEIMPACT
		//+NOTONAUTOMAP
	}
	
	int Counter;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			Counter = 25;
			A_PlaySound("Guncaster/Step",6,0.3);
			if(CountInv("PowerSuitProtect",AAPTR_TARGET) && !CountInv("PowerSuitToken",AAPTR_TARGET) && target.GetCvar("GC_SpikeBoots"))
			{
				A_PlaySound("SpikedBoots/Step",5,0.15);
			}
		}
		goto Looplet;
	Looplet:
		TNT1 A 1 {
			A_Warp(AAPTR_TARGET,0,0,-10.0,0,WARPF_NOCHECKPOSITION);
			Counter--;
			Return A_JumpIf(Counter <= 0, "Null");
		}
		Loop;
	}
}

class BerserkStep : GuncasterStep
{
	States
	{
	Spawn:
		TNT1 A 1;
		Stop;
	Death:
		TNT1 A 0 { If(!CountInv("AugurZoomed",AAPTR_TARGET)) { A_QuakeEx(1,1,1,4,0,128,"none",QF_SCALEDOWN); } }
		TNT1 AAAAAA 0 A_SpawnItemEx("BerserkStep_Effect",
			frandom(3.0,-3.0),frandom(3.0,-3.0),frandom(3.0,-3.0),
			frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(0.5,0.1),
			frandom(0.0,360.0),SXF_CLIENTSIDE|SXF_TRANSFERPOINTERS,0);
		TNT1 A 4 A_SpawnItemEx("GuncasterZerkStepConnect",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class GuncasterZerkStepConnect : GuncasterStepConnect
{
	States
	{
	Spawn:
		TNT1 A 0 NoDelay { 
			Counter = 25;
			A_PlaySound("Berserk/Step",6,0.4);
			if(CountInv("PowerSuitProtect",AAPTR_TARGET) && !CountInv("PowerSuitToken",AAPTR_TARGET) && target.GetCvar("GC_SpikeBoots"))
			{
				A_PlaySound("SpikedBoots/Step",5,0.2);
			}
		}
		goto Looplet;
	}
}

//Powersuit
class BishopStepRight : GuncasterStep
{
	States
	{
	Death:
		TNT1 A 0 A_SpawnItemEx("BishopStepConnectRight",0,5,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class BishopStepLeft : BishopStepRight
{
	States
	{
	Death:
		TNT1 A 0 A_SpawnItemEx("BishopStepConnectLeft",0,-5,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class BishopStepConnectRight : GuncasterStepConnect
{
	Default
	{
		DamageType "Shoelaces";
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay; //A_SpawnItemEx("BishopFootprintRight",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
		TNT1 A 0 A_Jump(256,"Rest");
		Goto Rest;
	Rest:
		TNT1 A 0 {
			If(CountInv("PowerMidasMode",AAPTR_TARGET)) { A_Explode((125),12,0,0,12,0,0,"BulletPuff","SuperMidasShoelaces"); }
			Else { A_Explode((125),12,0,0,12); }
			Counter = 25;
			A_PlaySound("Bishop/Step",6,0.3);
			A_PlaySound("Bishop/Thud",5,0.3);
			A_SpawnItemEx("BishopStepDustSpawner",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
			if(!CountInv("AugurZoomed",AAPTR_TARGET)) { A_QuakeEx(1,1,1,15,0,128,"none",QF_SCALEDOWN); }
		}
		Goto Looplet;
	Looplet:
		TNT1 A 1 {
			A_Warp(AAPTR_TARGET,0,0,-25.0,0,WARPF_NOCHECKPOSITION);
			Counter--;
			Return A_JumpIf(Counter <= 0, "Null");
		}
		Loop;
	}
}

class BishopStepConnectLeft : BishopStepConnectRight
{
	Default
	{
		DamageType "Shoelaces";
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay; //A_SpawnItemEx("BishopFootprintLeft",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
		TNT1 A 0 A_Jump(256,"Rest");
	}
}

//Powersuit zerk
class BishopZerkStepRight : BishopStepRight
{
	Default
	{
		DamageType "SuperShoelaces";
	}
	
	States
	{
	Death:
		TNT1 A 0 A_SpawnItemEx("BishopZerkStepConnectRight",0,5,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class BishopZerkStepLeft : BishopStepRight
{
	Default
	{
		DamageType "SuperShoelaces";
	}
	
	States
	{
	Death:
		TNT1 A 0 A_SpawnItemEx("BishopZerkStepConnectLeft",0,-5,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class BishopZerkStepConnectRight : BishopStepConnectRight
{
	States
	{
	Rest:
		TNT1 A 0 {
			If(CountInv("PowerMidasMode",AAPTR_TARGET)) { A_Explode((125),12,0,0,12,0,0,"BulletPuff","SuperMidasShoelaces"); }
			Else { A_Explode((125),12,0,0,12); }
			Counter = 25;
			A_PlaySound("Bishop/Step",6,0.3);
			A_PlaySound("Bishop/Thud",5,0.3);
			A_SpawnItemEx("BishopStepDustSpawner",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
			if(!CountInv("AugurZoomed",AAPTR_TARGET)) { A_QuakeEx(1,1,1,15,0,128,"none",QF_SCALEDOWN); }
		}
		TNT1 AAAAAA 0 A_SpawnItemEx("BerserkStep_Effect",
			frandom(3.0,-3.0),frandom(3.0,-3.0),frandom(3.0,-3.0),
			frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(0.5,0.1),
			frandom(0.0,360.0),SXF_TRANSFERPOINTERS|SXF_TRANSFERPOINTERS);
	Looplet:
		TNT1 A 1 {
			A_Warp(AAPTR_TARGET,0,0,-25.0,0,WARPF_NOCHECKPOSITION);
			Counter--;
			Return A_JumpIf(Counter <= 0, "Null");
		}
		Loop;
	}
}

class BishopZerkStepConnectLeft : BishopZerkStepConnectRight
{
	States
	{
	Spawn:
		TNT1 A 0 NoDelay A_SpawnItemEx("BishopFootprintLeft",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
		TNT1 A 0 A_Jump(256,"Rest");
		Goto Rest;
	}
}

//Stuff
class BishopFootprintRight : Actor
{
	Default
	{
		Renderstyle "Translucent";
		Alpha 0.6;
		+NOTIMEFREEZE;
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay A_JumpIf(CallACS("WaterBollocks") == True, "Null");
		TNT1 A 0 A_JumpIf(CallACS("FrostbiteBollocks") >= 1, "Null");
		BTPR A 105 A_CheckSight("Null");
		Loop;
	}
}

class BishopFootprintLeft : BishopFootprintRight {}

class BishopStepDustSpawner : Actor
{
	Default
	{
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	int Counter;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay { Counter = random(10,15); }
	Phase1:
		TNT1 A 0 {
			A_SpawnItemEx("WalkerDust",0,0,0,frandom(2.0,1.0),0,frandom(1.0,0.5),frandom(0.0,360.0),SXF_CLIENTSIDE,20);
			Counter--;
			Return A_JumpIf(Counter >= 1, "Phase1");
		}
	Phase2Setup:
		TNT1 A 0 { Counter = random(2,7); }
	Phase2:
		TNT1 A random(1,2) {
			A_SpawnItemEx("WalkerDust",0,0,0,frandom(2.0,1.0),0,frandom(1.0,0.5),frandom(0.0,360.0),SXF_CLIENTSIDE,20);
			Counter--;
			A_JumpIf(Counter >= 1, "Phase2");
		}
		Stop;
	}
}

class WalkerDust : Actor
{
	Default
	{
		Radius 4;
		Height 8;
		Speed 20;
		Renderstyle "Translucent";
		Projectile;
		BounceFactor 0.6;
		WallBounceFactor 0.6;
		Scale 0;
		Alpha 0;
		+BOUNCEONWALLS
		+THRUACTORS
		+NOTRIGGER
		+NOTIMEFREEZE
	}
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			A_ScaleVelocity(frandom(0.8,1.2));
			A_FadeIn(frandom(0.1,0.2));
			A_SetScale(frandom(0.1,0.15));
		}
	FrameSetup:
		TNT1 A 0 A_Jump(256,"FrameA","FrameB","FrameC","FrameD");
	FrameA:
		DUST A 0;
	FrameB:
		DUST B 0;
	FrameC:
		DUST C 0;
	FrameD:
		DUST D 0;
	Main:
		"####" "#" 0 A_SetScale(Scale.X + frandom(0.002,0.005));
		"####" "#" 1 A_FadeOut(frandom(0.004,0.007));
		Loop;
	}
}

//Powersuit Jet
class RocketPackEmitter : Powerup
{
	override void DoEffect()
	{
		owner.A_SpawnItemEx("Rocketpack_Flare",-48+frandom(1.0,-1.0),frandom(1.0,-1.0),25+frandom(1.0,-1.0),0,0,0,0,SXF_CLIENTSIDE,20);
		owner.A_SpawnItemEx("Rocketpack_Cloud",-48+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-1.0,1.0),frandom(1.0,-1.0),frandom(-2.0,-6.0),0,SXF_SETTARGET,20);
		owner.A_SpawnItemEx("Rocketpack_Smoke",-48+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-1.0,1.0),frandom(1.0,-1.0),frandom(-2.0,-6.0),0,SXF_CLIENTSIDE,20);
		owner.A_SpawnItemEx("Rocketpack_Ember",-48+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-1.0,1.0),frandom(1.0,-1.0),frandom(-2.0,-6.0),0,SXF_CLIENTSIDE,224);
		owner.A_SpawnItemEx("Rocketpack_GLDEF",frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(-1.0,1.0),frandom(1.0,-1.0),frandom(-1.0,-3.0),0,SXF_CLIENTSIDE);
	}
}

class RocketPack_Emitter : PowerupGiver
{
	Default
	{
		Powerup.Type "RocketPackEmitter";
		Powerup.Duration 20;
		Inventory.MaxAmount 0;
		+INVENTORY.AUTOACTIVATE
	}
}

class Rocketglide_Emitter : CustomInventory
{
	Default
	{
		Inventory.MaxAmount 0;
		+INVENTORY.AUTOACTIVATE
	}
	States
	{
	Spawn:
		TNT1 A 0;
		Stop;
	Use:
		TNT1 A 0 A_SpawnItemEx("Rocketpack_Flare",-55+frandom(3.0,-3.0),frandom(3.0,-3.0),25+frandom(3.0,-3.0),0,0,0,0,SXF_CLIENTSIDE,20);
		TNT1 A 0 A_SpawnItemEx("Rocketpack_Cloud",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_SETTARGET,20);
		TNT1 A 0 A_SpawnItemEx("Rocketpack_Smoke",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE,20);
		TNT1 A 0 A_SpawnItemEx("Rocketpack_Ember",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE,224);
		TNT1 A 0 A_SpawnItemEx("Rocketpack_GLDEF",frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(-3.0,-1.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE);
		Stop;
	}
}

class Rocketkick_Emitter : Actor
{
	Default
	{
		Projectile;
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	int Counter;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay { Counter = 15; }
	Looplet:
		TNT1 A 1 {
			A_Warp(AAPTR_MASTER,0,0,0,0,WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION);
			A_SpawnItemEx("Rocketpack_Flare",-55+frandom(3.0,-3.0),frandom(3.0,-3.0),25+frandom(3.0,-3.0),0,0,0,0,SXF_CLIENTSIDE,20);
			A_SpawnItemEx("Rocketpack_Cloud",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_SETTARGET,20);
			A_SpawnItemEx("Rocketpack_Smoke",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE,20);
			A_SpawnItemEx("Rocketpack_Ember",-55+frandom(5.0,-5.0),frandom(5.0,-5.0),25+frandom(5.0,-5.0),frandom(-6.0,-2.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE,224);
			A_SpawnItemEx("Rocketpack_GLDEF",frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(-3.0,-1.0),frandom(1.0,-1.0),frandom(1.0,-1.0),0,SXF_CLIENTSIDE);
			Counter--;
			Return A_JumpIf(Counter <= 0, "Null");
		}
		Loop;
	}
}

class Rocketpack_GLDEF : Actor
{
	Default
	{
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	States
	{
	Spawn:
		TNT1 A 15;
		Stop;
	}
}

class Rocketpack_Flare : Actor
{
	Default
	{
		RenderStyle "Add";
		Scale 0.25;
		Alpha 0.95;
		+NOGRAVITY
		+NOINTERACTION
		+THRUGHOST
		+DONTSPLASH
		+NOTIMEFREEZE
	}
	
	States
	{
		Spawn:
			FLER A 1 Bright NoDelay {
				A_FadeOut(0.3);
				A_SetScale(Scale.X - FRandom(0.005, 0.0075));
				Return A_JumpIf(Scale.X <= 0.0, "Null");
			}
			Loop;
	}
}

class Rocketpack_Cloud : Actor
{
	Default
	{
		Alpha 0.65;
		RenderStyle "Add";
		+NOINTERACTION
		+NOGRAVITY
		+FORCEXYBILLBOARD
		+NOTONAUTOMAP
		+NOTIMEFREEZE
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256, "SpriteA", "SpriteB", "SpriteC", "SpriteD",
										 "SpriteE", "SpriteF", "SpriteG", "SpriteH");
		SpriteA:
			CLOD A 0 A_Jump(256, "FadeIn");
		SpriteB:
			CLOD B 0 A_Jump(256, "FadeIn");
		SpriteC:
			CLOD C 0 A_Jump(256, "FadeIn");
		SpriteD:
			CLOD D 0 A_Jump(256, "FadeIn");
		SpriteE:
			CLOD E 0 A_Jump(256, "FadeIn");
		SpriteF:
			CLOD F 0 A_Jump(256, "FadeIn");
		SpriteG:
			CLOD G 0 A_Jump(256, "FadeIn");
		SpriteH:
			CLOD H 0 A_Jump(256, "FadeIn");
		FadeIn:
			"####" "#" 0 Bright A_SetScale(frandom(0.5, 0.6));
			Goto Idle;
		Idle:
			"####" "#" 2 Bright A_Jump(190, "FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 Bright {
				A_FadeOut(0.035);
				A_Explode(5,48,0);
				A_ScaleVelocity(frandom(1.01, 1.03));
				A_SetScale(Scale.X - frandom(0.01, 0.03));
				Return A_JumpIf(Scale.X <= 0, "Null");
			}
			Loop;
	}
}

class Rocketpack_Smoke : Rocketpack_Cloud
{
	Default
	{
		Alpha 0.0;
		RenderStyle "Translucent";
	}
	
	States
	{
		Spawn:
		    TNT1 A 4;
			TNT1 A 0 A_Jump(256, "SpriteA", "SpriteB", "SpriteC", "SpriteD");
		SpriteA:
			DYMI A 0 A_Jump(256, "FadeIn");
		SpriteB:
			DYMI B 0 A_Jump(256, "FadeIn");
		SpriteC:
			DYMI C 0 A_Jump(256, "FadeIn");
		SpriteD:
			DYMI D 0 A_Jump(256, "FadeIn");
		FadeIn:
			"####" "#" 0 A_SetScale(FRandom(0.3, 0.4));
			Goto RealFadeIn;
		RealFadeIn:
			"####" "#" 1 A_FadeIn(FRandom(0.01, 0.03));
			"####" "#" 0 A_JumpIf(Alpha >= 0.35, "Idle");
			Loop;
		Idle:
			"####" "#" 5 A_Jump(200, "FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 {
				A_FadeOut(FRandom(0.02,0.025));
				A_ScaleVelocity(0.96);
				A_SetScale(Scale.X + FRandom(0.02, 0.025));
			}
			Loop;
	}
}

class Rocketpack_Ember : Rocketpack_Cloud
{
	Default
	{
		Alpha 0.99;
		RenderStyle "Add";
	}
	
	States
	{
		Spawn:
			TNT1 A 0 NoDelay A_Jump(256, "SpriteA","SpriteB","SpriteC",
										 "SpriteD","SpriteE","SpriteF");
		SpriteA:
			EMBR A 0 A_Jump(256, "FadeIn");
		SpriteB:
			EMBR B 0 A_Jump(256, "FadeIn");
		SpriteC:
			EMBR C 0 A_Jump(256, "FadeIn");
		SpriteD:
			EMBR D 0 A_Jump(256, "FadeIn");
		SpriteE:
			EMBR E 0 A_Jump(256, "FadeIn");
		SpriteF:
			EMBR F 0 A_Jump(256, "FadeIn");
		FadeIn:
			"####" "#" 0 Bright A_SetScale(FRandom(0.035, 0.055));
			Goto Idle;
		Idle:
			"####" "#" 2 Bright A_Jump(200, "FadeOut");
			Loop;
		FadeOut:
			"####" "#" 1 Bright {
				A_Weave(FRandom(0.9, 1.0), FRandom(0.9, 1.0),
							FRandom(70, 90), FRandom(70, 90));
				A_ChangeVelocity(Vel.X * FRandom(0.93, 0.99),
										  Vel.Y * FRandom(0.93, 0.99),
										  Vel.Z - FRandom(0.1, 0.2),
										  CVF_REPLACE);
				A_SetScale(Scale.X - FRandom(0.0025, 0.0015));
				Return  A_JumpIf(Scale.X <= 0.0, "Null");
			}
			Loop;
	}
}

class LedgeSitter : Actor
{
	Default
	{
		Height 2;
		Radius 2;
		Renderstyle "None";
		+DONTSPLASH
		+DONTTHRUST
		+THRUACTORS
		+MOVEWITHSECTOR
		+NOTIMEFREEZE
	}
	
	States
	{
		Spawn:
		TNT1 A 1;
		Loop;
	}
}

// Custom damage multipliers, woo
class CustomPain : Inventory
{
	override void ModifyDamage(int damage, Name damageType, out int newdamage, bool passive)
	{
		// Attack damage
		if(!passive && damage > 0)
		{
			newdamage = damage * GetCvar("GC_PlayerAttackMult");
		}
		// Defense damage
		if(passive && damage > 0)
		{
			newdamage = damage * GetCvar("GC_PlayerDefenseMult");
		}
	}
}

class MoneyPointer : Actor
{
	Default
	{
		Radius 1;
		Height 2;
		Renderstyle "Add";
		+NOINTERACTION
		+NOTRIGGER
		+NOTIMEFREEZE
	}
	
	States
	{
		Spawn:
			POIN T 0;
			POIN T 1 {
				if(!target || !target.CountInv("PowerVeilVision"))
				{
					return ResolveState("Null");
				}
				return ResolveState(null);
			}
			Loop;
	}
}

//Deadmaker stuff.
class DeadmakerCharger : Inventory { Default { Inventory.MaxAmount 1; } }

class DeadmakerStep : Actor
{
	Default
	{
		Radius 10;
		Height 12;
		Projectile;
		+BLOODLESSIMPACT
		+DONTBLAST
		-ACTIVATEIMPACT
		+NOTIMEFREEZE
	}
	
	int count;
	
	States
	{
	Spawn:
		TNT1 A 1 NoDelay;
		Stop;
	Death:
		TNT1 A 0 A_SpawnItemEx("DeadmakerStepConnect",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class DeadmakerStepConnect : Actor
{
	Default
	{
		Projectile;
		DamageType "SuperShoelaces";
		-ACTIVATEIMPACT
		+FORCERADIUSDMG
		+NOINTERACTION
		+NOTIMEFREEZE
	}
	
	int count;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			count = 35;
			if(!CountInv("AugurZoomed",AAPTR_TARGET)) { A_QuakeEx(1,1,2,8,0,128,"none",QF_SCALEDOWN); }
			If(CountInv("PowerMidasMode",AAPTR_TARGET)) { A_Explode((250),72,0,0,72,0,0,"BulletPuff","SuperMidasShoelaces"); }
			Else { A_Explode((250),96,0,0,72); }
			A_SpawnItemEx("BishopStepDustSpawner",0,0,0,0,0,0,0,SXF_CLIENTSIDE);
			A_PlaySound("Deadmaker/Step",5);
		}
		TNT1 A 1 {
			count--;
			A_Warp(AAPTR_TARGET,0,0,-42.0,0,WARPF_NOCHECKPOSITION);
			Return A_JumpIf(count <= 0, "Null");
		}
		Wait;
	}
}