//Basis
class AnnihilationSpray : Actor
{
	Default
	{
		Scale 0.8;
		Alpha 0.8;
		RenderStyle "Add";
		DamageType "Annihilation";
		+NOINTERACTION
		+FORCEXYBILLBOARD
		+MTHRUSPECIES
	}
	
	States
	{
	Spawn:
		ANNH IJKLM 4 Bright;
		Stop;
	}
}

class AnnihilationShot1 : Actor
{
	Default
	{
		Radius 4;
		Height 8;
		Speed 2;
		Scale 0.2;
		Damage 5;
		Projectile;
		ProjectileKickback 400;
		RenderStyle "Add";
		Alpha 0.8;
		DamageType "Annihilation";
		Obituary "%o got caught in %k's annihilation. Enough said.";
		+DONTREFLECT
		+FOILINVUL
		+FORCEXYBILLBOARD
		+SEEKERMISSILE
		+LOOKALLAROUND
		+MTHRUSPECIES
	}
	
	int Counter;
	int Frames;
	int Shotcount;
	
	States
	{
	Spawn:
		"####" "#" 0 NoDelay { Counter = 24; }
	Frame:
		"####" "#" 0 A_JumpIf(Frames == 8, "FrameH");
		"####" "#" 0 A_JumpIf(Frames == 7, "FrameG");
		"####" "#" 0 A_JumpIf(Frames == 6, "FrameF");
		"####" "#" 0 A_JumpIf(Frames == 5, "FrameE");
		"####" "#" 0 A_JumpIf(Frames == 4, "FrameD");
		"####" "#" 0 A_JumpIf(Frames == 3, "FrameC");
		"####" "#" 0 A_JumpIf(Frames == 2, "FrameB");
		"####" "#" 0 A_JumpIf(Frames == 1, "FrameA");
	Reset:
		"####" "#" 0 { Frames = 1; }
	FrameA:
		ANNH A 0 A_Jump(256,"Main");
	FrameB:
		ANNH B 0 A_Jump(256,"Main");
	FrameC:
		ANNH C 0 A_Jump(256,"Main");
	FrameD:
		ANNH A 0 A_Jump(256,"Main");
	FrameE:
		ANNH E 0 A_Jump(256,"Main");
	FrameF:
		ANNH F 0 A_Jump(256,"Main");
	FrameG:
		ANNH G 0 A_Jump(256,"Main");
	FrameH:
		ANNH H 0 A_Jump(256,"Main");
	Main:
		"####" "#" 1 Bright {
			A_SeekerMissile(0,0,SMF_LOOK|SMF_CURSPEED,256);
			Counter--;
			Frames++;
			if(Counter <= 0) { Return ResolveState("Release"); }
			if(Frames >= 8) { Return ResolveState("Reset"); }
			Return ResolveState(Null);
		}
		Goto Frame;
	Release:
		TNT1 A 0 A_JumpIf(IsPointerEqual(AAPTR_TRACER, AAPTR_DEFAULT|AAPTR_NULL) == TRUE,  "NoTarget");
		TNT1 A 0 {
			A_SeekerMissile(90,90,SMF_LOOK|SMF_CURSPEED,256);
			A_FaceTracer();
			A_ScaleVelocity(15);
		}
	Looplet:
		ANNH ACEG 3 Bright { if(!GetCvar("GC_ToasterMode")) { A_SpawnItemEx("AnnihilationShot1Trail",0,0,0,0,0,0,0,SXF_CLIENTSIDE); } }
		Loop;
	Death:
		ANNH I 0 {
			A_PlaySound("Annihilation/Hit1",5,0.6);
			A_Explode(15,48,0);
		}
	NoTarget:
		ANNH IJKLM 4 Bright;
		Stop;
	}
}

class AnnihilationShot2 : AnnihilationShot1 //Non-aimin' shot
{
	Default
	{
		Speed 30;
	}
	
	States
	{
	Spawn:
		ANNH ACEG 3 Bright { if(!GetCvar("GC_ToasterMode")) { A_SpawnItemEx("AnnihilationShot1Trail",0,0,0,0,0,0,0,SXF_CLIENTSIDE); } }
		Loop;
	}
}

class AnnihilationShot1Trail : Actor
{
	Default
	{
		Scale 0.1;
		Alpha 0.8;
		RenderStyle "Add";
		+NOTONAUTOMAP
		+NOINTERACTION
		+FORCEXYBILLBOARD
	}
	
	States
	{
	Spawn:
		ANNH ABCDEFGHIJKM 1 Bright;
		Stop;
	}
}

class AnnihilationShotBlast : AnnihilationShot1
{
	Default
	{
		Radius 11;
		Height 7;
		Speed 25;
		Damage 10;
		Scale 0.9;
	}
	
	States
	{
	Spawn:
		B122 AB 3 Bright { if(!GetCvar("GC_ToasterMode")) { A_SpawnItemEx("AnnihilationShotBlastTrail",0,0,0,0,0,0,0,SXF_CLIENTSIDE); } }
		Loop;
	Death:
		B122 CD 1 Bright;
		TNT1 A 0 {
			A_Explode(50,128,0);
			for(Shotcount = 0; Shotcount < 4; Shotcount++)
			{
				A_SpawnProjectile("AnnihilationShot2", 0, 0, frandom(0.0, 360.0), CMF_AIMDIRECTION|CMF_TRACKOWNER, frandom(90.0, -90.0));
			}
		}
		B122 E 1 Bright;
		B122 FGH 1 Bright;
		Stop;
	}
}

class AnnihilationShotBlastTrail : AnnihilationShot1Trail
{
	Default
	{
		Scale 0.4;
	}
}


//Non-tomed
class AnnihilationShot : AnnihilationShot1
{
	Default
	{
		Radius 12;
		Height 8;
		Speed 40;
		Damage 40;
		Scale 0.6;
		Alpha 1.0;
	}
	
	//Int User_MaxSpeed;
	//Int User_Acceleration;
	
	override void OnDestroy () {
		GuncasterSeeker.Remove(self, target);
	}
	
	States
	{
	Spawn:
		ANNH A 2 Bright NoDelay A_PlaySound("Annihilation/Loop1",5,0.6);
		ANNH A 0 {
			GuncasterSeeker.Make(self, target, 40, 4);
		}
	Wololo:
		ANNH ABCDEFGH 2 Bright {
			A_FaceTracer();
			for(Shotcount = 0; Shotcount < 4; Shotcount++)
			{
				A_SpawnProjectile("AnnihilationShot1",0,0,frandom(0.0, 360.0),CMF_AIMDIRECTION|CMF_TRACKOWNER,frandom(90.0, -90.0));
			}
		}
		Loop;
	Death:
		ANNH I 4 Bright {
			// Guncaster.RemoveSeeker(self);
			for(Shotcount = 0; Shotcount < 30; Shotcount++)
			{
				A_SpawnProjectile("AnnihilationSuperblast",0,0,frandom(0.0, 360.0),CMF_AIMDIRECTION|CMF_TRACKOWNER,frandom(90.0, -90.0));
			}
			A_PlaySound("Annihilation/Hit2",5,0.7);
			A_PlaySound("Annihilation/Hit3",6,0.7);
			A_BFGSpray("AnnihilationSpray",30,0,360,1280,90,40*random(1,4),BFGF_MISSILEORIGIN);
			A_SpawnItemEx("AnnihilationShotGLDEF",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
			A_Explode(150,192,0);
			OnDestroy();
		}
		ANNH JKLM 4 Bright;
		Stop;
	}
}

class AnnihilationShotFam : AnnihilationShot
{
	States
	{
	Spawn:
		ANNH A 2 Bright NoDelay A_PlaySound("Annihilation/Loop1",5,0.6);
		Goto Wololo;
	}
}

class AnnihilationShotGLDEF : Actor
{
	Default
	{
		+NOINTERACTION
		+NOTONAUTOMAP
	}
	
	States
	{
	Spawn:
		TNT1 A 35;
		Stop;
	}
}

//Tomed
class TomedAnnihilationShot : AnnihilationShot1
{
	Default
	{
		Radius 14;
		Height 10;
		Speed 40;
		Damage 80;
		Scale 0.9;
		Alpha 1.0;
	}
	
	//Int User_MaxSpeed;
	//Int User_Acceleration;
	
	override void OnDestroy () {
		GuncasterSeeker.Remove(self, target);
	}
	
	States
	{
	Spawn:
		ANNH A 2 NoDelay Bright A_PlaySound("Annihilation/Loop2",5,0.6);
		ANNH A 0 {
			GuncasterSeeker.Make(self, target, 40, 3);
			Counter = 20;
			/*A_SetUserVar("User_MaxSpeed", 40 << 16);
			A_SetUserVarFloat("User_Acceleration", 10.0  << 16);
			ACS_NamedExecuteAlways("KD Laser Track", 0);*/
		}
	Wololo:
		ANNH ABCDEFGH 2 Bright {
			A_FaceTracer();
			for(Shotcount = 0; Shotcount < 10; Shotcount++)
			{
				A_SpawnProjectile("AnnihilationShot1",0,0,frandom(0.0, 360.0),CMF_AIMDIRECTION|CMF_TRACKOWNER,frandom(90.0, -90.0));
			}
		}
		Loop;
	Death:
		TNT1 A 0 {
			OnDestroy();
			A_PlaySound("Annihilation/Hit4",5,0.8);
			A_QuakeEx(9,9,7,70,0,8192,"none",QF_SCALEDOWN|QF_WAVE,1.0,1.0,2.0);
			A_QuakeEx(9,9,9,70,0,8192,"none",QF_SCALEDOWN);
			A_Explode(300,256,0);
			A_BFGSpray("AnnihilationSpray",40,0,360,2048,90,40*random(1,4),BFGF_MISSILEORIGIN);
			A_SpawnItemEx("TomedAnnihilationShotGLDEF",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
			A_SpawnItemEx("AnnihilationBoom",0,0,0,0,0,0,0,SXF_TRANSFERPOINTERS);
		}
		TNT1 A 3 {
			A_SpawnProjectile("AnnihilationSuperblast",0,0,frandom(0.0, 360.0),CMF_AIMDIRECTION|CMF_TRACKOWNER,frandom(90.0, -90.0));
			Counter--;
			Return A_JumpIf(Counter <= 0, "End");
		}
		Wait;
	End:
		TNT1 A 105;
		Stop;
	}
}

//Familiar shot
class TomedAnnihilationShotFam : TomedAnnihilationShot
{
	States
	{
	Spawn:
		ANNH A 2 NoDelay A_PlaySound("Annihilation/Loop2",5,0.6);
		Goto Wololo;
	}
}

class TomedAnnihilationShotGLDEF : Actor
{
	Default
	{
		+NOINTERACTION
		+NOTONAUTOMAP
	}
	
	States
	{
	Spawn:
		TNT1 A 50;
		Stop;
	}
}

class AnnihilationBoom : Actor
{
	Default
	{
		+NOINTERACTION
	}
	
	int Cycler;
	int Pitcher;
	
	States
	{
	Spawn:
		TNT1 A 0 NoDelay {
			Pitcher = 0;
			A_SetPitch(Pitch + 80); 							//Default position.
			A_SpawnItemEx("AnnihilationSuperblast",0,0,0,0,0,25.0,0,SXF_TRANSFERPOINTERS);
		}
	Cycle1:
		TNT1 A 0 { Cycler = 18; }								//one projectile every 20 degrees.
	Cycle2:
		TNT1 A 0 {
			Cycler--; 											//Projectile launched? Remove one from the cycle.
			A_SpawnItemEx("AnnihilationSuperblast",0,0,0,
				cos(-pitch)*25,0,sin(pitch)*25,
				Angle,SXF_TRANSFERPITCH|SXF_TRANSFERPOINTERS);  //Here it gooooes.
			A_SetAngle(Angle + 20); 							//Projectile launched? Turn it a bit.
			Return A_JumpIf(Cycler <= 0, "SwitchGear"); 		//Are we done with this ring? Then let's pump the pitch a notch.
		}
		Loop;
	SwitchGear:
		TNT1 A 0 {
			Pitcher++;
			A_SetPitch(Pitch - 10, SPF_FORCECLAMP);				//Move it up a pinch.
			Return A_JumpIf(Pitcher >= 16, "Death"); 			//Did we hit the upper head? Well, that's all, folks.
		}
		Goto Cycle1;
	Death:
		TNT1 A 0 A_SpawnItemEx("AnnihilationSuperblast",0,0,0,0,0,-25.0,0,SXF_TRANSFERPOINTERS);
		Stop;
	}
}

class AnnihilationSuperblast : AnnihilationShot1
{
	Default
	{
		Radius 14;
		Height 10;
		Speed 25;
		Damage 5;
		Scale 0.5;
		Alpha 1.0;
	}
	
	States
	{
	Spawn:
		ANNH ABCDEFGH 3 Bright { if(!GetCvar("GC_ToasterMode")) { A_SpawnItemEx("AnnihilationShotBlastTrail",0,0,0,0,0,0,0,SXF_CLIENTSIDE); } }
		Loop;
	Death:
		ANNH I 0 {
			A_Explode(50,192,0);
			for(Shotcount = 0; Shotcount < 3; Shotcount++)
			{
				A_SpawnItemEx("AnnihilationShotBlast",0,0,0,frandom(25.0,20.0),0,frandom(25.0,-25.0),frandom(0.0,360.0),SXF_TRANSFERPOINTERS);
			}
		}
		ANNH IJKLM 2 Bright;
		Stop;
	}
}