ACTOR InsanityCacodemon : CerebralCaco
{
  Health 1800
  Speed 16
  Damagefactor "Normal", 0.65
  MeleeSound "caco/melee"
  Obituary "%o was suppressed by the onslaught of an Insanity Cacodemon."
  DropItem "BossLifeEssence" 150
  DropItem "BossArmorBonusMax" 150
  DropItem "DemonAmmoBox" 256 
  Tag "\c[i7]Insanity Cacodemon\c-"
  States
	{
  Spawn:
	IED9 A 10 A_Look
	Loop
  See:
	IED9 A 3 A_Chase
	TNT1 A 0 A_Jump(20,"Evade")
	TNT1 A 0 A_Jump(62,"Rush")
	Loop
  Rush:
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_SpawnItemEx("INCacoGhostA")	
	IED9 A 1 A_Chase
	TNT1 A 0 A_Jump(87,"See")
	Loop
  Evade:
	TNT1 A 0 A_Jump(128,7)
	TNT1 A 0 ThrustThing(Angle*256/360+64,14,0,0)
	IED9 AAAA 3 A_Chase
	TNT1 A 0 A_Stop
	Goto See
	TNT1 A 0 ThrustThing(Angle*256/360+192,14,0,0)		 
	IED9 AAAA 3 A_Chase
	TNT1 A 0 A_Stop		 
	Goto See
  Melee:
    IED9 BC 5 A_FaceTarget
	IED9 D 5 A_MeleeAttack
	IED9 CB 5 A_FaceTarget
	Goto See
  Missile:
	TNT1 A 0 A_jump(120,"homing","Shotgun","Wall1","Wall2","Twinwall","Awfuck","Awfuck2")
	IED9 B 5 A_FaceTarget
    IED9 C 5 bright A_FaceTarget
    IED9 D 5 A_FaceTarget
	IED9 D 0 bright A_CustomMissile("InsaneCacoballA", 24, 0, 0, 1)
    IED9 D 0 bright A_CustomMissile("InsaneCacoballA", 24, 0, -8, 1)
    IED9 D 5 bright A_CustomMissile("InsaneCacoballA", 24, 0, 8, 1)
	TNT1 A 0 A_jump(65,"Homing","Wall1","Wall2")
    Goto See 
  Homing:
	IED9 B 5 A_FaceTarget
    IED9 C 5 bright A_FaceTarget
    IED9 D 5 A_FaceTarget	
	IED9 D 5 Bright A_CustomMissile("InsaneCacoballB", 24, 0, 0, 1)
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
	IED9 D 5 Bright A_CustomMissile("InsaneCacoballB", 24, 0, 0, 1)
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
	IED9 D 5 Bright A_CustomMissile("InsaneCacoballB", 24, 0, 0, 1)
	Goto see
  Shotgun:
    IED9 BC 5 A_FaceTarget
	IED9 C 5 Bright A_FaceTarget
	IED9 DDDDDDDDDDDD 0 A_CustomMissile ("Insaneaccuserballs", 24, 9, frandom(-12.0,12.0),2,frandom(-12.0,12.0))
	IED9 DDDDDDDDDDDD 0 A_CustomMissile ("Insaneaccuserballs", 24, 9, frandom(-12.0,12.0),2,frandom(-12.0,12.0))
	IED9 DDDDDDDDDDDD 0 A_CustomMissile ("Insaneaccuserballs", 24, 9, frandom(-12.0,12.0),2,frandom(-12.0,12.0))
	IED9 DDDDDDDDDDDD 0 A_CustomMissile ("Insaneaccuserballs", 24, 9, frandom(-12.0,12.0),2,frandom(-12.0,12.0))
	IED9 D 8 Bright
	Goto See
  Wall1:
    IED9 BB 5 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 16, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 12, 1)
    IED9 B 0 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 8, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, 0, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -8, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -12, 1)
    IED9 B 0 A_FaceTarget
    IED9 B 2 bright A_CustomMissile("Insanespamball", 24, 0, -16, 1)
	IED9 B 4 bright
	TNT1 A 0 A_jump(65,"Wall2")
	TNT1 A 0 A_jump(40,"Twinwall")
    Goto See
  Wall2:
    IED9 BB 5 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -8, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -12, 1)
    IED9 B 0 A_FaceTarget
    IED9 B 2 bright A_CustomMissile("Insanespamball", 24, 0, -16, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, 0, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 16, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 12, 1)
    IED9 B 0 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 8, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 4, 1)
    IED9 B 0 A_FaceTarget
	IED9 B 4 bright
	TNT1 A 0 A_jump(65,"Wall1")
	TNT1 A 0 A_jump(40,"Twinwall")
    Goto See
  Twinwall:
    IED9 BB 5 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 16, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 12, 1)
    IED9 B 0 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 8, 1)
    IED9 C 2 bright A_CustomMissile("Insanespamball", 24, 0, 4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, 0, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -8, 1)
    IED9 D 2 bright A_CustomMissile("Insanespamball", 24, 0, -12, 1)
    IED9 B 0 A_FaceTarget
    IED9 B 2 bright A_CustomMissile("Insanespamball", 24, 0, -16, 1)
	IED9 B 4 bright
    IED9 BB 5 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("InsanespamballB", 24, 0, -4, 1)
    IED9 B 0 A_FaceTarget
    IED9 D 2 bright A_CustomMissile("InsanespamballB", 24, 0, -8, 1)
    IED9 D 2 bright A_CustomMissile("InsanespamballB", 24, 0, -12, 1)
    IED9 B 0 A_FaceTarget
    IED9 B 2 bright A_CustomMissile("InsanespamballB", 24, 0, -16, 1)
    IED9 D 2 bright A_CustomMissile("InsanespamballB", 24, 0, 0, 1)
    IED9 C 2 bright A_CustomMissile("InsanespamballB", 24, 0, 16, 1)
    IED9 C 2 bright A_CustomMissile("InsanespamballB", 24, 0, 12, 1)
    IED9 B 0 A_FaceTarget
    IED9 C 2 bright A_CustomMissile("InsanespamballB", 24, 0, 8, 1)
    IED9 C 2 bright A_CustomMissile("InsanespamballB", 24, 0, 4, 1)
    IED9 B 0 A_FaceTarget
	IED9 B 4 bright
	TNT1 A 0 A_jump(65,"Awfuck","Awfuck2")
    Goto See
  Awfuck:
    IED9 BB 5 A_FaceTarget
	IED9 CC 5 A_FaceTarget
	IED9 D 5 Bright A_CustomMissile("Insanesole", 24, 0, 0, 1)
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
	IED9 D 5 Bright A_CustomMissile("Insanesole", 24, 0, 0, 1)
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
	IED9 D 5 Bright A_CustomMissile("Insanesole", 24, 0, 0, 1)
	Goto see
  Awfuck2:
    IED9 BB 5 A_FaceTarget
	IED9 CC 5 A_FaceTarget
    IED9 C 5 bright A_FaceTarget
    IED9 D 5 A_FaceTarget	
	IED9 D 5 Bright A_CustomMissile("Insaneclusterspamball", 24, 0, 0, 1)
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
	IED9 D 5 Bright A_CustomMissile("Insaneclusterspamball", 24, 0, 0, 1)
	IED9 B 3 A_facetarget
	IED9 B 3 A_FaceTarget
	IED9 C 3 bright A_facetarget
    IED9 D 0 bright A_CustomMissile("Insaneclusterspamball", 24, 0, -8, 1)
    IED9 D 5 bright A_CustomMissile("Insaneclusterspamball", 24, 0, 8, 1)
	Goto See
  Pain:
	IED9 E 3
	IED9 E 3 A_Pain
	IED9 F 6
	TNT1 A 0 A_jump(80,"missile")
	Goto See
  Death:
  Xdeath:
	IED9 G 8
	TNT1 A 0 A_SpawnItemEx("GibbedGenerator")
	IED9 H 8 A_Scream
	IED9 I 8
	IED9 JK 8 A_NoBlocking
	IED9 L -1 A_SetFloorClip
	Stop
	}
}

//Attacks
ACTOR InsaneCacoballA 
{
Radius 8
Height 6
Speed 16
FastSpeed 24
Damage 6
Scale 1.0
ALPHA 0.95
PROJECTILE
RENDERSTYLE ADD
BounceType "Hexen"
BounceSound "InsaneBall/Bounce"
BounceFactor 1
WallBounceFactor 1
BounceCount 5
+EXPLODEONWATER
SeeSound "monsters/newfireshoot"
DeathSound "monsters/newfireexplode"
Damagetype "CacoComet"
Decal Cacoscorch
States
{
Spawn:
  IAL3 AB 4 Bright A_SpawnItem("Insaneballtrail",0,0)
  Loop
Death:
  TNT1 A 0
  TNT1 A 0 A_SpawnItemEx("RedParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
  TNT1 AAAA 0 A_CustomMissile("Kaboom10", 0, 0, random(0,360), 2, random(0,360))
  TNT1 AAAA 0 A_CustomMissile("SmokeFX4", 0, 0, random(0,360), 2, random(0,360))		
  IAL3 C 5 Bright A_Explode (25, 96)
  IAL3 DE 5 Bright
  stop
	}
}

Actor InsaneCacoballB : InsaneCacoballA
{
+SEEKERMISSILE
States
{
Spawn:
  TNT1 A 0 A_SeekerMissile (5,5, SMF_CURSPEED)
  IAL3 A 4 Bright A_SpawnItem("Insaneballtrail",0,0)
  TNT1 A 0 A_SeekerMissile (5,5, SMF_CURSPEED)
  IAL3 B 4 Bright A_SpawnItem("Insaneballtrail",0,0)
  loop
	}
}

Actor Insanespamball
{
    Radius 8
    Height 6
    Speed 15
    Damage 10
    PROJECTILE
	RENDERSTYLE ADD
	ALPHA 0.8
	SeeSound "monsters/newfireshoot"
	DeathSound "monsters/newfireexplode"
	Damagetype "CacoComet"
	Decal Cacoscorch
	States
	{
	Spawn:
	   IAL9 AAAABBBB 1 BRIGHT A_SpawnItemEx("InsaneballtrailB", 0, 0, 0, 0, 0, 0, 0, 128)
	   Loop
	Death:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("RedParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
		TNT1 AAAA 0 A_CustomMissile("Kaboom10", 0, 0, random(0,360), 2, random(0,360))
		TNT1 AAAA 0 A_CustomMissile("SmokeFX4", 0, 0, random(0,360), 2, random(0,360))		
	   IAL9 CDE 6 BRIGHT
	   Stop
	}
}

Actor InsanespamballB : Insanespamball
{
BounceType "Hexen"
BounceSound "Insaneball/bounce"
BounceFactor 1
WallBounceFactor 1
BounceCount 5
+EXPLODEONWATER
}

Actor Insaneaccuserballs : Insanespamball
{
Scale 0.35
BounceType "Hexen"
BounceSound "Insaneball/bounce"
BounceFactor 1
WallBounceFactor 1
BounceCount 7
+EXPLODEONWATER
	States
	{
	Spawn:
	   IAL9 AAAABBBB 1 BRIGHT A_SpawnItemEx("InsaneballtrailD", 0, 0, 0, 0, 0, 0, 0, 128)
	   Loop
	}
}

Actor Insaneaccuserballs2 : Insanespamball
{
Scale 0.25
BounceType "Hexen"
BounceSound "Insaneball/bounce"
BounceFactor 1
WallBounceFactor 1
BounceCount 7
+EXPLODEONWATER
	States
	{
	Spawn:
	   IAL9 AAAABBBB 1 BRIGHT A_SpawnItemEx("InsaneballtrailC", 0, 0, 0, 0, 0, 0, 0, 128)
	   Loop
	}
}

Actor Insaneclusterspamball
{
    Radius 8
    Height 6
    Speed 15
    Damage 10
    PROJECTILE
	RENDERSTYLE ADD
	ALPHA 0.8
	Scale 2
	SeeSound "monsters/newfireshoot"
	DeathSound "monsters/newfireexplode"
	Damagetype "CacoComet"
	Decal Cacoscorch
    States
    {
	Spawn:
		IAL9 A 1 A_CustomMissile("Insaneaccuserballs2",5,0, CMF_AIMOFFSET,random(0,360), random(0,360))
		IAL9 A 1 A_SpawnItemEx("InsaneballtrailB", 0, 0, 0, 0, 0, 0, 0, 128)
		IAL9 B 1
		Loop
	  Death:
	   TNT1 A 0
	   TNT1 A 0 A_SpawnItemEx("RedParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
	   TNT1 AAAA 0 A_CustomMissile("Kaboom10", 0, 0, random(0,360), 2, random(0,360))
	   TNT1 AAAA 0 A_CustomMissile("SmokeFX4", 0, 0, random(0,360), 2, random(0,360))		
	   IAL9 C 4 A_SetTranslucent(0.35)
	   IAL9 D 1 A_Explode(random(5,20),88)
	   IAL9 DDDDDDDEEEEEEE 1 A_CustomMissile("InsanespamballB",5,0, CMF_AIMOFFSET,random(0,360), random(0,360))
	   IAL9 E 2  A_Explode(random(5,20),99)
	    Stop
	 }
}

Actor Insanesole : Insanespamball
{
    Radius 12
    Height 24
    Speed 20
    Damage 10
    ExplosionDamage 45
    ExplosionRadius 64
    SeeSound "InsaneSoul/Fire"
    DeathSound "InsaneSoul/Explode"
	Damagetype "CacoComet"
    States
    {
    Spawn:
       SKUD CCCCDDDD 1 BRIGHT A_SpawnItemEx("Skulltrail", 0, 0, 0, 0, 0, 0, 0, 128)
       Loop
    Death:
	  TNT1 A 0
	  TNT1 A 0 A_SpawnItemEx("RedParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
	  TNT1 AAAA 0 A_CustomMissile("Kaboom10", 0, 0, random(0,360), 2, random(0,360))
	  TNT1 AAAA 0 A_CustomMissile("SmokeFX4", 0, 0, random(0,360), 2, random(0,360))	
       SKUD H 4 BRIGHT A_Mushroom("Insanespamball", 8)
       SKUD I 4 BRIGHT A_Explode
       SKUD JK 4 BRIGHT
       stop
    }
}

//Effects
ACTOR Insaneballtrail : BFG9500Trail
{
Scale 0.9
States
{
Spawn:
   TNT1 A 0
    TNT1 A 0 A_JumpIf(CallAcs("LCAEffectCheck"),"Toaster")
	TNT1 A 1
    IAL3 AB 3 A_FadeOut(0.35)
	Goto Spawn+3
    }
}

ACTOR InsaneballtrailB : BFG9500Trail
{
States
{
Spawn:
   TNT1 A 0
    TNT1 A 0 A_JumpIf(CallAcs("LCAEffectCheck"),"Toaster")
	TNT1 A 1
    IAL9 AB 3 A_FadeOut(0.35)
	Goto Spawn+3
    }
}

Actor InsaneballtrailC : InsaneballtrailB
{
Scale 0.25
}

Actor InsaneballtrailD : InsaneballtrailB
{
Scale 0.35
}


ACTOR Skulltrail : BFG9500Trail
{
States
{
Spawn:
    TNT1 A 0
    TNT1 A 0 A_JumpIf(CallAcs("LCAEffectCheck"),"Toaster")
	TNT1 A 1
    SKUD CD 3 A_FadeOut(0.35)
	Goto Spawn+3
    }
}


//Ghostly things
ACTOR INCacoGhostA
{
  Radius 2
  Height 2
  Speed 0
  Alpha 0.85
  Scale 1.0
  PROJECTILE
  RENDERSTYLE Translucent
  +CLIENTSIDEONLY
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_JumpIf(CallAcs("LCAEffectCheck"),"Toaster")
  Fade:
    TNT1 A 1
	IED9 A 2 A_FadeOut(0.15)
	Goto Fade+1
  Toaster:
    TNT1 A 0
    Stop
  }
}