// *** MODIFIED BY CHEBMASTER
// I mark most important places modified by me with //***Che -- unless I forget to.






Actor Arachnotron2BossCubeSpawner: ArachnotronBossCubeSpawner
{
	States
	{
		DoSummon:	
			TNT1 A 0 A_GiveInventory("SummonsCount", 1, AAPTR_TRACER)
			TNT1 A 0 A_SpawnItemEx("ThiccTeleportFog")
			TNT1 A 1 A_SpawnItemEx("FBD_Arachnotron2",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0,user_stid)
			Stop
	}
}

//===========================================================================
//
// Arachnotron2
//
//===========================================================================
ACTOR FBD_Arachnotron2: FBD_Arachnotron1 17613 {

	// see ACTOR BD_Arachnotron2: FBD_Arachnotron2 2542 {} in Doom_Replacements.txt

	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!

	//$category "FBD Monsters"
	Scale 1.4
	Health 1250
	Obituary "$ARACHNOTRON2_O" // "%o was killed by an Ancient Arachnotron.";
	Tag "$ARACHNOTRON2" //"Ancient Arachnotron";
	
	PainChance "Ice", 48
	
	States
	{
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See
		
		Pain.Killme:
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			Goto Missile
			
		//***Che: these were missing -- resulting in reusing arachnotron's
		Death.Killme:
		Death.Taunt:	
			TNT1 A 0
			Goto Death
			
		Spawn:
			ARAC A 1 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			ARAC A 7
			
		Stand:
			ARAC AB 10 A_Look
			Loop

			
		Idle: // without this, the game engine puts him into his Spawn state when he loses target 
				//-- and that wrecks havok with the init scripts!
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
			Goto Stand			
		See:
			ARAC A 20
		SeeContinue1:		
			ARAC A 1 A_BabyMetal
		SeeContinue2:	
		
			// slaughtermap manage
			TNT1 A 0 A_JumpIf(!user_sleeping, 3) // forgo the expensive sight check if already awake
			TNT1 A 0 A_CheckSight(2)
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			TNT1 A 0 A_JumpIf(user_serverside_sfchk != -1, 3) // -1 means ACS commands us to do the radiusgive
			// A_RadiusGive is:
			//  1. serverside-only: the call is skipped on the client; only if a player is involved, a network command to update his item count is sent, otherwise the item count only increases on the server
			//  2. iterates over all actors in an infinitely tall square column checking their flags and coordinates
			//  3. performs expensive precision radius calculation (using a square root) unless RGF_CUBE is given (which results in cheaper delta per-coordinate comparison)
			//  4. performs expensive sight check, for each thing that passes flag and radius checks, unless RGF_NOSIGHT is given
			TNT1 A 0 A_RadiusGive("SfestCounterServerside", 500, RGF_MONSTERS | RGF_CUBE | RGF_NOSIGHT, 2)	// count us as two		
			TNT1 A 0 A_SetUserVar("user_serverside_sfchk", 1) // reply that we did the deed	
			
		
			ARAC ABBCC 1 A_Chase
			ARAC D 1 A_BabyMetal
			ARAC DEEFF 1 A_Chase
			Goto SeeContinue1 //See+1

		Missile:
			ARAC A 15 BRIGHT A_FaceTarget
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIf(!CheckClass("Arachnotron2", AAPTR_TARGET, true), 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")
			TNT1 A 0
			
		MissileContinue:	
			TNT1 A 0
			
			//***Che: do NOT adjust aim if target goes out of sight or is invisible
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
			TNT1 A 0 A_JumpIfTargetInLOS(2)
			TNT1 A 0 A_Jump(256, 2)
			TNT1 A 0 A_FaceTarget
			
			ARAC G 6 
			TNT1 A 0 A_PlaySound("PAILGF2")
		MissileLaunch:	
			TNT1 A 0
			//TNT1 A 0 A_JumpIfInventory("IAmSfestMonster", 1, "MillileLaunchSfest")
			ARAC H 2 BRIGHT A_CustomMissile("PurplePlasmaBall",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			ARAC H 1 BRIGHT //A_SpidRefire
			//***Che
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "MissileSpidRefireAtInvisible")
			Goto MissileSpidRefire
/*			
		MillileLaunchSfest:	
			TNT1 A 0
			ARAC H 2 BRIGHT A_CustomMissile("PurplePlasmaBallSfest",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			ARAC H 1 BRIGHT //A_SpidRefire
			//***Che
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "MissileSpidRefireAtInvisible")
			Goto MissileSpidRefire
*/			
			
		MissileSpidRefireAtInvisible:
			TNT1 A 0 A_Jump(64, "See")
			Goto MissileContinue
		MissileSpidRefire:
			TNT1 A 0 A_JumpIfTargetInLOS("MissileSpidRefire2", 0, JLOSF_DEADNOJUMP)
			TNT1 A 0 A_Jump(10, "MissileSpidRefire2") // https://zdoom.org/wiki/A_MonsterRefire
			Goto See
		MissileSpidRefire2:
			TNT1 A 0
			Goto MissileContinue //Missile+5
			
		Pain:
			ARAC I 3
			ARAC I 3 A_Pain
			Goto SeeContinue1 //See+1
			
		Pain.Argent:
		
			TNT1 A 0
			TNT1 A 0 HealThing(99)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 40, 70, 35)
		
			ARAC I 3
			ARAC I 3 A_Pain
			Goto MissileContinue // results in spraying in a random direction if target is out of sight		
			
		Death:
			TNT1 A 0 A_Jump(101, "RareDeath")
			TNT1 A 0 A_Jump(128, "Death2")
			ARAC J 8 A_Scream
			 TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			 TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAA 0 A_CustomMissile ("SmallBrainPiece", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAAA 0 A_CustomMissile ("FBD_Bloodmist", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeathSpiderNew1", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AA 0 A_CustomMissile ("XDeathSpiderNew2", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			ARAC K 6 //A_NoBlocking
			ARAC LMNO 8
			ARAC P 1 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			
			// the dead bodies are +GHOST and the player is +THRUGHOST, so no, this won't cause player to get stuck suddenly
			
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadSpiderDark",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		Death2:
			AR4C J 8 A_Scream
			 TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			 TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAA 0 A_CustomMissile ("SmallBrainPiece", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAAA 0 A_CustomMissile ("FBD_Bloodmist", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeathSpiderNew1", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AA 0 A_CustomMissile ("XDeathSpiderNew2", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			AR4C K 6 A_NoBlocking
			AR4C LMNO 8
			AR4C P 1 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadSpiderDark3",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		RareDeath:
			TNT1 A 0 A_Jump(128, "RareDeath2")
			ARAC Q 5
			TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_SpawnItemEx ("BarrelKaboom",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AAAAA 0 A_CustomMissile ("SuperGoreSpawner", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("SuperGoreSpawner", 0, 0, random (0, 180), 2, random (0, 180))
			TNT1 AA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			 TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAA 0 A_CustomMissile ("SpiderPart1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("SpiderPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("PEPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			ARAC R 6 A_NoBlocking
			ARAC STUV 6
			ARAC W 2 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadSpiderDark2",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			Goto XBurns
			
		RareDeath2:
			AR4C Q 5
			TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_SpawnItemEx ("BarrelKaboom",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AAAAA 0 A_CustomMissile ("SuperGoreSpawner", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("SuperGoreSpawner", 0, 0, random (0, 180), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			 TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAA 0 A_CustomMissile ("SpiderPart1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("SpiderPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("PEPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			 TNT1 AAAAAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			AR4C R 6 A_NoBlocking
			AR4C STUV 6
			AR4C W 2 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadSpiderDark4",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			Goto XBurns
			
			
		Death.Cutless:  // BD doesn't include any sources of this damage type
			TNT1 A 0
			TNT1 A 0 A_Jump(114,"XDeath")
			Goto Death
		
		Death.SuperPlasma:
		Death.Plasma:
		Death.Electric:
		Death.Plasma2:
			TNT1 A 0 A_BossDeath
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 AAA 0 A_CustomMissile ("FBD_FlyingBlood", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeathBurnedMeat3", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			EXPL AAAAAA 0 A_CustomMissile ("ExplosionSmoke", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 360))
			CARB QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ 7 A_CustomMissile ("PlasmaSmoke", 15, 0, random (0, 360), 2, random (70, 110))
			CARB Q -1 //***Che: Gibbed monsters -- ONLY the gibbed monsters -- may use this
				//   to auto-respawn on nightmare and be raised by viles.
				// Employing this on a destructible corpse results in that corpse
				//   respawning on nightmare as a corpse (or worse, as a burning hollering demon)
				// If a monster's death state spawns a destructible corpse,
				//   the respawning/raising is relegated to that corpse
				//   and the monster MUST use Stop instead
			Stop
			
		Death.Fire:
			TNT1 A 0
			TNT1 A 0 A_BossDeath
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 AAA 0 A_CustomMissile ("PEPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			ARAC LLLL 2 A_CustomMissile ("FlameTrails", 45, 0, random (0, 360), 2, random (50, 130))
			ARAC MMMM 2 A_CustomMissile ("FlameTrails", 30, 0, random (0, 360), 2, random (50, 130))
			ARAC NNNN 2 A_CustomMissile ("FlameTrails", 25, 0, random (0, 360), 2, random (50, 130))
			ARAC OOOO 2 A_CustomMissile ("FlameTrails", 25, 0, random (0, 360), 2, random (50, 130))
			TNT1 A 0 A_Playsound("props/redfire")
			Goto Burns
		Burns:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("BrutalCounter")
			CARB QQ 2 A_SpawnItem("YellowFlare",0,20)
			ID22 F 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			CARB QQ 2 A_SpawnItem("YellowFlare",0,20)
			ID22 F 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			ID22 F 0 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_JumpIfInventory("BrutalCounter", 30, "Smokes")
			Loop
		Smokes:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("BrutalCounter", 60, "Rest")
			TNT1 A 0 A_GiveInventory("BrutalCounter")
			CARB Q 5 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			Loop	
		Rest:	
			CARB Q -1 //***Che: Gibbed monsters -- ONLY the gibbed monsters -- may use this
				//   to auto-respawn on nightmare and be raised by viles.
				// Employing this on a destructible corpse results in that corpse
				//   respawning on nightmare as a corpse (or worse, as a burning hollering demon)
				// If a monster's death state spawns a destructible corpse,
				//   the respawning/raising is relegated to that corpse
				//   and the monster MUST use Stop instead
			Stop

		Death.Fatality:
			TNT1 A 0
			TNT1 A 0 A_Pain
			TNT1 A 0	
			TNT1 A 0 A_FaceTarget
			//TNT1 AAA 0 A_SpawnItemEx("HealthPlusFatalityBonus", 0,0,20, random (-1, 1),random (-1, 1),8, 0, SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION)
			//TNT1 AA 0 A_SpawnItemEx("ArmorShardFatalityBonus", 0,0,20, random (-1, 1),random (-1, 1),8, 0, SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION)
			TNT1 A 0 ACS_NamedExecuteAlways("DropFatalityBonuses", 0, 15, 10, 0) // 0, health, armor, 0 -- rounded down to nearest 2
			TNT1 A 0 A_Jump(128, "Death.Fatality2")
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("Arachnotron2FatalityA", 1)
			TNT1 A 1 A_BossDeath
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop
		Death.Fatality2:	
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("Arachnotron2FatalityB", 1)
			TNT1 A 1 A_BossDeath
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop

	//***Che:
		Death.Psionic:
		Death.Cut: // otherwise, results in arachnotron death when killed via chainsaw
			
		Death.Saw:
		Death.Tear:
		
			TNT1 AAAAA 0 A_CustomMissile ("Guts2", 14, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAA 0 A_CustomMissile ("CeilBloodLauncher", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			TNT1 AAAAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAA 0 A_CustomMissile ("XDeath2", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAAAAAAA 0 A_CustomMissile ("PlayerFlyingBlood", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			// This is what should get resurrected
			TNT1 A 0 A_CustomMissile ("XDeathArachnotronHead2", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 130))
			
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			ARAC X 16
			ARAC YZ 8
			TNT1 A 0 A_Jump(64, 3)
			TNT1 A 3 A_SpawnItemEx("NoLegsSpider2", 0,1,1, 1,1,0, 0,SXF_NOCHECKPOSITION,0) // moves forward right at the speed of 1.4
			Stop
			TNT1 AAA 0
			TNT1 A 0 A_SpawnItemEx("ArachnoTurretFrame2", 0,1,1, 1,1,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)		
			Stop
		Death.Crush:
		Death.BlackHole:
		Death.QuadBlast:
		XDeath:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
			ARAC J 4
			TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_SpawnItemEx ("BarrelKaboom",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			
			TNT1 A 0 A_Jump(64, "XDeathRare")
			TNT1 AAAAA 0 A_CustomMissile ("SuperGoreSpawner", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("SuperGoreSpawner", 0, 0, random (0, 180), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAA 0 A_CustomMissile ("SpiderPart1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("SpiderPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("PEPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			ARAC Q 6 A_NoBlocking
			ARAC RSTUV 6
			ARAC W 1 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("XFBD_DeadSpider2",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			Goto XBurns
		XBurns:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("BrutalCounter", 20, "XSmokes")
			TNT1 A 0 A_GiveInventory("BrutalCounter")
			TNT1 WW 2 A_SpawnItem("YellowFlare",0,20)
			ID22 F 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			TNT1 WW 2 A_SpawnItem("YellowFlare",0,20)
			ARAC W 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			ARAC W 0 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			Loop
		XSmokes:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("BrutalCounter", 100, "XRest")
			TNT1 A 0 A_GiveInventory("BrutalCounter")
			TNT1 W 5 A_CustomMissile ("PlasmaSmoke", 40, 0, random (0, 360), 2, random (70, 110))
			Loop	
		XRest:	
			TNT1 A 0 // nothing left: we should have dropped a rezzable corpse earlier
			Stop

		XDeathRare:
			TNT1 A 0 A_CustomMissile ("XDeathArachnotronHead2", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 130))
			TNT1 AA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAAAAA 0 A_CustomMissile ("CeilBloodLauncherLong", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 130))
			ARAC Q 6 A_NoBlocking
			ARAC RSTUV 6
			ARAC W 1 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("XFBD_DeadSpider2",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			Goto XBurns
		   
			
		Raise:
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			ARAC P 5
			ARAC ONMLKJ 5
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_CustomizeOnRez") // it runs OnRezMapScript
				// if the map prpvides one
			Goto SeeContinue1 //See+1
			
		FallbackRaise: // we were put into this state by the superarchvile AOE raising, our height is hopelessly kaput and we have to spawn a substitute
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_ChangeFlag("COUNTKILL", 0)
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2018) // see _mob_list.xlsx
			Stop
			
		FallbackRezSuccess:
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30
			Stop			
			
		Death.Ice:
		Death.Freeze:
		Death.Frost:
			TNT1 A 0
			TNT1 A 0 A_NoBlocking // freeze deaths are permanent
			TNT1 A 0 A_SpawnItemEx("FrozenAncientArachnotron",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop 
		Death.IOS_Frost:
			TNT1 A 0
			TNT1 A 0 A_NoBlocking 
			TNT1 A 0 A_SpawnItemEx("PermafrostAncientArachnotron",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop 			
	}
}



Actor Arachnotron2RaisedByVile: FBD_Arachnotron2 {
	States {
		Spawn: 
			ARAC P 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			

			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			
/*			//***Che this was the original BD animation. I replaced it with standard FBD raising SFX of blood mist
			TNT1 A 2 A_CustomMissile ("RealFlameTrailsSmall", 6, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("PentagramSpawner", 1, 60)
			TNT1 A 2 A_CustomMissile ("RealFlameTrailsSmall", 6, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("PentagramSpawner", 1, 60)
			TNT1 A 0 A_SpawnItem("TeleportFog")	
*/			
			
			ARAC PONMLKJ 5

			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_CustomizeOnRez") // it runs OnRezMapScript
				// if the map prpvides one
			Goto See		

	}
}



Actor FBD_DeadSpiderDark: FBD_CurbstompedMarine
{
    Radius 36 //***Che otherwise raising failures //20
    Height 12
    Scale 1.3
    +SHOOTABLE
    +NOTELEPORT
    +MOVEWITHSECTOR
    +CORPSE
	-SOLID
	+THRUACTORS
	damagefactor "Crusher", 50.0
    Mass 1000
    Health 250
    damagefactor "Blood", 0.0
    damagefactor "Trample", 0.0
	States
    {
		//***Che
		Spawn:
			TNT1 A 0
			TNT1 A 0  // makes the blood it emits go lo-res 
			  // if slaughtercount is over half the slaughter limit (i.e. 600) at the moment of spawning
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			ARAC P 5 A_CheckFloor("Land")
			Loop
		Land:	
			TNT1 A 0 ACS_NamedExecuteAlways("BDCheckFloorType", 0, 0, 0, 0)
			ARAC P 30
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava") // ancestor's generic charred meatsplosion
			ARAC P -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARAC PPPPP 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death			
		Raise:
			// note: the frame letter of the "----" (keep previous) sprite is ignored
			"----" A 0
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_NoBlocking // the raising code deep in C++ makes it solid

			"----" A 0 A_JumpIf(!CallAcs("EnoughSpaceToRezNormally", 2018), "FallbackRaise")
			// The vile had already copied his friendliness and target to this corpse.
			// A_SpawnItem(Ex) automatically copy friendliness
			//   and target, but only if both the spawner and the spawnee are monsters.
			"----" A 0 A_ChangeFlag("COUNTKILL", 0)
			"----" A 0 A_ChangeFlag("ISMONSTER", 1)
			"----" A 0 A_SpawnItemEx ("Arachnotron2RaisedByVile",0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			"----" A 1 A_Jump(256, "OnRezSfx")
			Wait //Zandronum client repeats the last frame while it waits for a status update from the server
			
		FallbackRaise:
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			//"----" A -1 ACS_NamedExecuteAlways("FallbackRez", 0, 21, 0, 0) // "Arachnotron2RaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2018) // see _mob_list.xlsx
			Stop
		Death.Cut:
		Death.Cutless:
		Death:
			TNT1 A 0 A_SpawnItemEx ("GibsZ",-3,-3)
			TNT1 A 0 A_SpawnItemEx ("GibsZ",3,3)
			TNT1 AAA 0 A_CustomMissile ("SpiderPart1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("SpiderPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeathSpiderNew1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath2", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath3", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath4", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
	}
}
   
Actor FBD_DeadSpiderDark2: FBD_DeadSpiderDark
{
	States
		{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			ARAC W 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			ARAC W 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARAC W -1  ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop 
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARAC WWWW 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death				
			
}}

Actor FBD_DeadSpiderDark3: FBD_DeadSpiderDark
{

	States
	{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			AR4C p 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			AR4C p 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			AR4C p -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop 
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			AR4C ppp 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death			
}}

Actor FBD_DeadSpiderDark4: FBD_DeadSpiderDark
{

	States
		{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			AR4C W 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			AR4C W 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			AR4C W -1  ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			//ARXD L -1 //***Che There is no such frame!
			Stop 
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			AR4C WWWW 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death			
	}
}


Actor XFBD_DeadSpider2: FBD_DeadSpiderDark
{
	States{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			ARAC W 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			ARAC W 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARAC W -1  ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop 
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARAC WWWWWW 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death			
	}
}
			
Actor NoLegsSpider2: FBD_DeadSpiderDark //FBD_DeadSpider
{
	//***Che: again, the class name is misleading. It's *legs only* platform
	//  after the fatality where Doomguy rips the brain off
	-CORPSE
	+NOBLOOD
	Health 999 //999999999999
	States{
		Raise:
			Stop // no raising this one - raise the brain instead.
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			ARA2 A 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			ARA2 A 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARA2 A -1 // no rez
			Stop 
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARA2 AAAAAAA 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death
		Death:
		Death.Cut:
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun:
		Death.Burn:
		Death.Fire:
		Death.Flames:			
			// boom
			TNT1 A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AAA 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("BDExplosionparticles3", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAA 0 A_CustomMissile ("MediumExplosionFlames", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 360))
			
			// flying legs
			TNT1 AAAA 0 A_CustomMissile ("SpiderLeg2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
	}
}				

ACTOR ArachnoTurretFrame2 : NoLegsSpider2
{
	Radius 32
	Height 60
	Health 20
	Scale 1.3
	DamageFactor "Fatality", 2.0
	+SHOOTABLE
    -SOLID
	+FLOORCLIP
    +NOTELEPORT
    +MOVEWITHSECTOR
    +CORPSE
	
	States
	{
		Spawn:
			ARA2 B 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARAC XX 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARA2 BB 2 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARA2 BB 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARA2 BB 4 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARA2 B 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARAC XX 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 6 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			ARA2 BB 2 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 0 A_SpawnItem("Spark_UpOnce", 0, 15)
			TNT1 A 0 A_SpawnItem ("ShoqueAzul", 0, 17)
			ARAC X 1 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			Goto Death

		Death:
			ARAC Z 6
			TNT1 A 0 A_SpawnItemEx("NoLegsSpider2", 0, 1, 1, 1, 1)
			stop
	}
}
 

Actor RapedArachnotron2: FBD_DeadSpiderDark //FBD_DeadSpider

{
	Scale 1.0 //sprite already scaled
	Health 200 
	States
		{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			ARF5 N 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			ARF5 N 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARF5 N -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARF5 NNNNNNN 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")	
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
	}
}
		

ACTOR PurplePlasmaBall: FastProjectile
{
	Radius 6
	Height 6
	Speed 55
	Scale 0.55
	DamageType Blackhole
	Damage 0
	Decal StunnerScorch
	RenderStyle Add
	SeeSound "PAILGF3"
	DeathSound "PAILGD3"
	Projectile
	
	//***Che
	-NOBLOCKMAP // without this, A_RadiusGive does not see them 
	 // and so projectile-destroying effects do not work
	 // see Demon EleTech gun's ligtning element alt fire. 
	
	states
	{
		Spawn:
			PBAL H 1 BRIGHT A_SpawnItem("PinkIonFlare",0,0)
			PBAL H 1 A_SpawnItem("PinkIonFlare",0,0)
			Loop
		Death:
			TNT1 A 0 A_SpawnItem ("IonPuff", 0)
			TNT1 A 0 A_Explode(24,40,1)
			TNT1 AAAAA 19 A_CustomMissile ("PlasmaSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Stop
	}
}


ACTOR PurplePlasmaBallSfest: PurplePlasmaBall {
	States {
		Spawn: 
			PBAL H 2 BRIGHT A_SetScale(0.55, -0.55)
			PBAL H 2 BRIGHT A_SetScale(-0.55, 0.55)
			PBAL H 2 BRIGHT A_SetScale(-0.55, -0.55)
			PBAL H 2 BRIGHT A_SetScale(0.55, 0.55)
			Loop
		Death:
			TNT1 A 0 A_SpawnItem ("IonPuff", 0)
			TNT1 A 0 A_Explode(24,40,1)
			Stop
	}
}

ACTOR MarinePurplePlasmaBall: PurplePlasmaBall
{
	+MTHRUSPECIES
	+THRUSPECIES
	Species "Marine"
}

ACTOR IonPuff: BulletPuff
{
	RenderStyle Add
	Alpha 0.95
	+NOBLOCKMAP
	+NOGRAVITY
	+CLIENTSIDEONLY
	Scale 1.1
	Translation "192:207=250:254"
	states
	{
		Spawn:
			PBEX A 0 BRIGHT// A_SpawnItem("BlueFlare",0,0)
			FIR5 ABCDE 1 Bright A_SpawnItem("PinkFlare" ,0)
			FIR5 FGHIJKLMNOP 1 Bright A_FadeOut(0.04)
			stop
	}
}

Actor PinkFlare : Flare_General
{
	states
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_Jump(128,2)
			LENP A 2 bright
			stop
			TNT1 A 0
			LENP B 2 bright
			stop
	}
}

Actor PinkIonFlare : Flare_General
{
	alpha 0.4
	scale 0.15
	states
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_Jump(128,2)
			LENP A 1 bright
			stop
			TNT1 A 0
			LENP B 1 bright
			stop
	}
}


ACTOR SpiderLeg2
{
    Radius 8
    Height 8
	Speed 12
	Mass 1
    +NOBLOCKMAP
	+MISSILE
    +NOTELEPORT
    +DONTSPLASH
	+DOOMBOUNCE
    +MOVEWITHSECTOR
    +CLIENTSIDEONLY
	SeeSound "misc/xdeath4"
    DeathSound "misc/xdeath3"
	BounceFactor 0.3
	BounceCount 3
    States
    {
		Spawn:
			TNT1 A 0 A_JumpIf(waterlevel > 1, "Death")
			XDS2 ABCDEFGH 2
			Loop
		Death:
			XDS2 I 9009
			Stop
    }
}

ACTOR XDeathArachnotronHead2: XDeath1
{
    Speed 12
	Gravity 0.9
	+DONTSPLASH
    DeathSound "none"
	SeeSound "none"
	+SKYEXPLODE
	-CORPSE
	Decal none
    Scale 1.4 //1.0
    States
    {
		Spawn:
			NAHB ABCDEFGH 4
			Loop
		Death:
			TNT1 A 0
			//TNT1 A 0 A_Jump(128, "CleanDeath")
			TNT1 A 0 A_SpawnItemEx("CrawlingDyingSpider2",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			Stop
		CleanDeath:
			TNT1 AAAAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			NAHD IJKLMN 5
			
			//***Che
			TNT1 A 0 A_ChangeFlag("MISSILE", 0)
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			NAHD N 30
			TNT1 A 0 ACS_NamedExecuteAlways("BDCheckFloorType", 0, 0, 0, 0)
			NAHD N 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava")				
			
			NAHD N -5 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			NAHD NNNNNNN 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")	
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		Raise:
			// note: the frame letter of the "----" (keep previous) sprite is ignored
			"----" A 0
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_NoBlocking // the raising code deep in C++ makes it solid

			"----" A 0 A_JumpIf(!CallAcs("EnoughSpaceToRezNormally", 2018), "FallbackRaise")
			// The vile had already copied his friendliness and target to this corpse.
			// A_SpawnItem(Ex) automatically copy friendliness
			//   and target, but only if both the spawner and the spawnee are monsters.
			"----" A 0 A_ChangeFlag("COUNTKILL", 0)
			"----" A 0 A_ChangeFlag("ISMONSTER", 1)
			"----" A 0 A_SpawnItemEx ("Arachnotron2RaisedByVile",0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			"----" A 1 A_Jump(256, "OnRezSfx")
			Wait //Zandronum client repeats the last frame while it waits for a status update from the server
			
		FallbackRaise:
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			//"----" A -1 ACS_NamedExecuteAlways("FallbackRez", 0, 21, 0, 0) // "Arachnotron2RaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2018) // see _mob_list.xlsx
			Stop
    }
}

Actor CrawlingDyingSpider2: CrawlingDyingSpider {
	Scale 1.4
	Radius 36 //***Che: otherwise, raising failures
	States {
		Death.Kick:
		Death.Extremepunches:
		Death.Fatality:
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("CrawlingDyingSpider2Fatality", 1)		
			TNT1 A 1 A_NoBlocking
			Stop
			
		Raise:
			// note: the frame letter of the "----" (keep previous) sprite is ignored
			"----" A 0
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_NoBlocking // the raising code deep in C++ makes it solid
			

			"----" A 0 A_JumpIf(!CallAcs("EnoughSpaceToRezNormally", 2018), "FallbackRaise")
			// The vile had already copied his friendliness and target to this corpse.
			// A_SpawnItem(Ex) automatically copy friendliness
			//   and target, but only if both the spawner and the spawnee are monsters.
			"----" A 0 A_ChangeFlag("COUNTKILL", 0)
			"----" A 0 A_ChangeFlag("ISMONSTER", 1)
			"----" A 0 A_SpawnItemEx ("Arachnotron2RaisedByVile",0,0,0, 0,0,0, 0,SXF_TRANSFERPOINTERS | SXF_NOCHECKPOSITION)
			"----" A 1 A_Jump(256, "OnRezSfx")
			Wait //Zandronum client repeats the last frame while it waits for a status update from the server
			
		FallbackRaise:
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			//"----" A -1 ACS_NamedExecuteAlways("FallbackRez", 0, 21, 0, 0) // "Arachnotron2RaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2018) // see _mob_list.xlsx
			Stop
		Spawn:
			NAHD B 1 A_Look
			Goto See
		See:
			NAHD ABCD 10 A_Chase
			NAHD A 0 A_Pain
			TNT1 A 0 A_SpawnItemEx("FBD_FlyingBlood", 0, 0, 10, 0, 0)
			
			TNT1 A 0 A_SetUserVar("user_death_timer", user_death_timer + 1) //A_GiveInventory("DeathTimer1", 1)
			TNT1 A 0 A_JumpIf(user_death_timer >= 12, "GotoDeath") //A_JumpIfInventory("DeathTimer1", 12, "GotoDeath")
			Loop
			
		GotoDeath:
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			NAHD EFGH 5
			
			//***Che
			NAHD H 30
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava", 0, 0, 0, 0) // this one doen not emit smoke and uses marker item instead of user var
			NAHD H 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava")			
			
			NAHD H -1
			Stop
		
		Death:
			TNT1 A 0 A_NoBlocking
			TNT1 AAAAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			NAHD IJKLMN 5
			
			//***Che
			NAHD N 30
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava", 0, 0, 0, 0) // this one doen not emit smoke and uses marker item instead of user var
			NAHD N 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava2")				
			
			NAHD N -5
			Stop
			
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			NAHD HHHHHHHH 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")	
			
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop

		LandOnLava2: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			NAHD NNNNNNN 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")	
			
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
			
		Pain.SuperPunch:
		Pain.SuperKick:
		Pain.Kick:
		Pain.Extremepunches:
			TNT1 A 0 A_FaceTarget
			NAHB A 1 A_Pain
			TNT1 A 0 ThrustThing(angle*256/360+128, 5, 0, 0)
		Pain.ExplosiveImpact:
			TNT1 A 0 ThrustThingZ(0,50,0,1)
			
			NAHB A 2 A_FaceTarget
			Goto Fly
		
		Fly:
			NAHB ABCDEFGH 3 A_CheckFloor("See")
			NULL A 0 A_JumpIf (momz == 0, "See")
			TNT1 A 0
			Loop			
	
	}
}

ACTOR SplatCrawlingSpider2: FBD_DeadSpiderDark
{
	States 
	{
		// raises as an ancient arachnotron, unlike the regular crawling spider who rises as an aracnorb
		Spawn:
			TNT1 A 0 
			TNT1 AAAAAAAAAAAA 0 A_CustomMissile ("SmallBrainPiece", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			NAHD IJKLMN 5
			Goto StayContinue
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			NAHD M 5 A_PlaySOund("misc/xdeath5", 1)
		StayContinue:	
			NAHD N 5 
			TNT1 A 0 A_CheckFloor("Slide")  // if this goes before the non-zero frame, we have an infinite loop!
			Loop
		Slide:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(momx != 0 || momy != 0, "Stay") // not until the actor stops sliding		
		Land:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			NAHD N 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			NAHD N -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		Death:
		Death.Cut:
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun:
		Death.Burn:
		Death.Fire:
		Death.Flames:
		LandOnLava:		
			TNT1 A 0 A_NoBlocking
			TNT1 AAAAAA 0 A_CustomMissile ("SmallBrainPiece", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
	}
}

#include Spid_Mind.txt