// The Heresiarch him/itself ------------------------------------------------

class Heresiarch native
{
	Default
	{
		Health 5000;
		Painchance 10;
		Speed 16;
		Radius 40;
		Height 110;
		Mass 500;
		Damage 9;
		Monster;
		+FLOORCLIP
		+BOSS
		+DONTMORPH
		+NOTARGET
		+NOICEDEATH
		+DEFLECT
		+NOBLOOD
		SeeSound "SorcererSight";
		PainSound "SorcererPain";
		DeathSound "SorcererDeathScream";
		ActiveSound "SorcererActive";
		Obituary "$OB_HERESIARCH";
	}
	
	native void A_SorcSpinBalls();
	native void A_SpeedBalls();
	native void A_SorcBossAttack();
	native void A_SpawnFizzle();
	
	States
	{
	Spawn:
		SORC A 3;
		SORC A 2 A_SorcSpinBalls;
	Idle:
		SORC A 10 A_Look;
		Wait;
	See:
		SORC ABCD 5 A_Chase;
		Loop;
	Pain:
		SORC G 8;
		SORC G 8 A_Pain;
		Goto See;
	Missile:
		SORC F 6 Bright A_FaceTarget;
		SORC F 6 Bright A_SpeedBalls;
		SORC F 6 Bright A_FaceTarget;
		Wait;
	Attack1:
		SORC E 6 Bright;
		SORC E 6 Bright A_SpawnFizzle;
		SORC E 5 Bright A_FaceTarget;
		Goto Attack1+1;
	Attack2:
		SORC E 2 Bright;
		SORC E 2 Bright A_SorcBossAttack;
		Goto See;
	Death:
		SORC H 5 Bright;
		SORC I 5 Bright A_FaceTarget;
		SORC J 5 Bright A_Scream;
		SORC KLMNOPQRST 5 Bright;
		SORC U 5 Bright A_NoBlocking;
		SORC VWXY 5 Bright;
		SORC Z -1 Bright;
		Stop;
	}
}

// Base class for the balls flying around the Heresiarch's head -------------

class SorcBall native
{
	Default
	{
		Speed 10;
		Radius 5;
		Height 5;
		Projectile;
		-ACTIVATEIMPACT
		-ACTIVATEPCROSS
		+FULLVOLDEATH
		+CANBOUNCEWATER
		+NOWALLBOUNCESND
		BounceType "HexenCompat";
		SeeSound "SorcererBallBounce";
		DeathSound "SorcererBigBallExplode";
	}

	native void A_SorcBallOrbit();
	native void A_SorcBallPop();
	native void A_BounceCheck ();
	
	void A_SorcBallExplode()
	{
		bNOBOUNCESOUND = true;
		A_Explode(255, 255);
	}
}

// First ball (purple) - fires projectiles ----------------------------------

class SorcBall1 : SorcBall native
{
	States
	{
	Spawn:
		SBMP ABCDEFGHIJKLMNOP 2 A_SorcBallOrbit;
		Loop;
	Pain:
		SBMP A 5 A_SorcBallPop;
		SBMP B 2 A_BounceCheck;
		Wait;
	Death:
		SBS4 D 5 A_SorcBallExplode;
		SBS4 E 5;
		SBS4 FGH 6;
		Stop;
	}
}


// Second ball (blue) - generates the shield --------------------------------

class SorcBall2 : SorcBall native
{
	States
	{
	Spawn:
		SBMB ABCDEFGHIJKLMNOP 2 A_SorcBallOrbit;
		Loop;
	Pain:
		SBMB A 5 A_SorcBallPop;
		SBMB B 2 A_BounceCheck;
		Wait;
	Death:
		SBS3 D 5 A_SorcBallExplode;
		SBS3 E 5;
		SBS3 FGH 6;
		Stop;
	}
}

// Third ball (green) - summons Bishops -------------------------------------

class SorcBall3 : SorcBall native
{
	States
	{
	Spawn:
		SBMG ABCDEFGHIJKLMNOP 2 A_SorcBallOrbit;
		Loop;
	Pain:
		SBMG A 5 A_SorcBallPop;
		SBMG B 2 A_BounceCheck;
		Wait;
	Death:
		SBS3 D 5 A_SorcBallExplode;
		SBS3 E 5;
		SBS3 FGH 6;
		Stop;
	}
}


// Sorcerer spell 1 (The burning, bouncing head thing) ----------------------

class SorcFX1 : Actor
{
	Default
	{
		Speed 7;
		Radius 5;
		Height 5;
		Projectile;
		-ACTIVATEIMPACT
		-ACTIVATEPCROSS
		-NOGRAVITY
		+FULLVOLDEATH
		+CANBOUNCEWATER
		+NOWALLBOUNCESND
		BounceFactor 1.0;
		BounceType "HexenCompat";
		SeeSound "SorcererBallBounce";
		DeathSound "SorcererHeadScream";
	}

	native void A_SorcFX1Seek();

	States
	{
	Spawn:
		SBS1 A 2 Bright;
		SBS1 BCD 3 Bright A_SorcFX1Seek;
		Loop;
	Death:
		FHFX S 2 Bright A_Explode(30, 128);
		FHFX SS 6 Bright;
		Stop;
	}
}


// Sorcerer spell 2 (The visible part of the shield) ------------------------

class SorcFX2 : Actor
{
	Default
	{
		Speed 15;
		Radius 5;
		Height 5;
		+NOBLOCKMAP
		+NOGRAVITY
		+NOTELEPORT
	}

	native void A_SorcFX2Split();
	native void A_SorcFX2Orbit ();

	states
	{
	Spawn:
		SBS2 A 3 Bright A_SorcFX2Split;
		Loop;
	Orbit:
		SBS2 A 2 Bright;
		SBS2 BCDEFGHIJKLMNOPA 2 Bright A_SorcFX2Orbit;
		Goto Orbit+1;
	Death:
		SBS2 A 10;
		Stop;
	}
}

// The translucent trail behind SorcFX2 -------------------------------------

class SorcFX2T1 : SorcFX2
{
	Default
	{
		RenderStyle "Translucent";
		Alpha 0.4;
	}
	States
	{
	Spawn:
		Goto Death;
	}
}


// Sorcerer spell 3 (The Bishop spawner) ------------------------------------

class SorcFX3 : Actor
{
	Default
	{
		Speed 15;
		Radius 22;
		Height 65;
		+NOBLOCKMAP
		+MISSILE
		+NOTELEPORT
		SeeSound "SorcererBishopSpawn";
	}

	native void A_SpawnBishop();
	native void A_SorcererBishopEntry();

	States
	{
	Spawn:
		SBS3 ABC 2 Bright;
		Loop;
	Death:
		SBS3 A 4 Bright;
		BISH P 4 A_SorcererBishopEntry;
		BISH ON 4;
		BISH MLKJIH 3;
		BISH G 3 A_SpawnBishop;
		Stop;
	}
}


// The Bishop spawner's explosion animation ---------------------------------

class SorcFX3Explosion : Actor
{
	Default
	{
		+NOBLOCKMAP
		+NOGRAVITY
		+NOTELEPORT
		RenderStyle "Translucent";
		Alpha 0.4;
	}
	States
	{
	Spawn:
		SBS3 DEFGH 3;
		Stop;
	}
}


// Sorcerer spell 4 (The purple projectile) ---------------------------------

class SorcFX4 : Actor
{
	Default
	{
		Speed 12;
		Radius 10;
		Height 10;
		Projectile;
		-ACTIVATEIMPACT
		-ACTIVATEPCROSS
		DeathSound "SorcererBallExplode";
	}

	native void A_SorcFX4Check();

	States
	{
	Spawn:
		SBS4 ABC 2 Bright A_SorcFX4Check;
		Loop;
	Death:
		SBS4 D 2 Bright;
		SBS4 E 2 Bright A_Explode(20, 128);
		SBS4 FGH 2 Bright;
		Stop;
	}
}


// Spark that appears when shooting SorcFX4 ---------------------------------

class SorcSpark1 : Actor
{
	Default
	{
		Radius 5;
		Height 5;
		Gravity 0.125;
		+NOBLOCKMAP
		+DROPOFF
		+NOTELEPORT
		RenderStyle "Add";
	}
	States
	{
	Spawn:
		SBFX ABCDEFG 4 Bright;
		Stop;
	}
}