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





ACTOR ArachnotronPotpourriChecker: AbstractPotpourriChecker
{
	Radius 36
	Height 64
}

Actor ArachnotronBossCubeSpawner: AbstractBossCubeSpawner
{
	Radius 36
	Height 64
	States
	{
		DoSummon:	
			TNT1 A 0 A_GiveInventory("SummonsCount", 1, AAPTR_TRACER)
			TNT1 A 0 A_SpawnItemEx("ThiccTeleportFog")
			TNT1 A 1 A_SpawnItemEx("FBD_Arachnotron1",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0,user_stid)
			Stop
	}
}

ACTOR FBD_Arachnotron1: ZandronumArachnotron 17859 
{
	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!
	
	//***Che: cross-mod hardening: see ACTOR Arachnotron1: FBD_Arachnotron1 Replaces Arachnotron {} in Doom_Replacements.txt
	
	
	//$category "FBD Monsters"
	
	Monster
	+FLOORCLIP
	+BOSSDEATH
    GibHealth 20
	Radius 36 // replaces radius 64 of the native class
	// Height 64 inherited from native
	// he inherits Height 64 from the native class
    damagefactor "Crush", 10.0
	damagefactor "Avoid", 0.0
	damagefactor "GibRemoving", 0.0 PainChance "HangingHook", 0
	SeeSound "baby/sight"
	PainSound "SPIPAIN2"
	DeathSound "baby/death"
	ActiveSound "baby/active"
	damagefactor "TeleportRemover", 0.0
	DamageFactor "CauseSplash", 0.0 DamageFactor "CauseObjectsToSplashSlime", 0.0 DamageFactor "CauseObjectsToSplashNukage", 0.0
	DamageFactor "CauseObjectsToSplashBlood", 0.0 DamageFactor "CauseObjectsToSplashLava", 0.0
	
    BloodType "ArachnotronBlood", "ArachnotronFBD_SawBlood", "ArachnotronBlood"
	MaxStepHeight 24
	DropItem "Berserker" 5
	MaxDropOffHeight 24
	PainChance "Kick", 255
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0
    Damage 25
	Speed 7
	Species "Spider"
	//+DONTHURTSPECIES 
	+DONTHARMCLASS //***Che This flag was previously named DONTHURTSPECIES, which was a misleading name that could lead to believe its effect was that of DONTHARMSPECIES. https://zdoom.org/wiki/Actor_flags#DONTHARMCLASS
    Scale 1.1
	Health 750
	DeathHeight 4
	BurnHeight 0
	
	Tag "$ARACHNOTRON" // "Arachnotron";
	Obituary "$OB_BABY"
	
	var int user_sleeping;
	var int user_item_no;
	var int user_serverside_sfchk;
	

	PainChance "Argent", 255
	DamageFactor "Argent", 1.0
	
	var int user_bleeding_angle;
	var int user_strafe_dir; // the circle-strafing does not seem to work
	
	PainChance "Bullet792", 160 // machineguns and snip[er rifles not aimed
	PainChance "SniperBullet", 170 // sniper rifle aimed	
	
	damagefactor "Killme", 1.0 // AOE inflicted by captured marines
	PainChance "Killme", 255

	PainChance "Ice", 96
	
	States
	{
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See
		
		Death.KillMe:
		Death.Taunt:
			BSPI I 3
			BSPI III 8 A_Pain
			TNT1 A 0 A_SetUserVar("user_bleeding_angle", random(-110,110))
			BSPI IIIIIIIIIIIIIII 3 A_CustomMissile ("Brutal_LiquidBlood2", 40, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			Goto Death
			//TNT1 A 0 A_ChangeFlag("SOLID", 0)
			//TNT1 A 0 A_SpawnItem("FBD_Arachnotron1")
			//Stop
			
			
		PotPourriSwap:
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
		PotPourriWait:			
			KYPP B 5 A_JumpIf(CallAcs("FBD_GetMapRandomizerReady"), 1) // a two-second delay to allow re-randomizing on loading an auto-save
			Loop
			TNT1 A 0 A_Jumpif(!CallAcs("GetPotPourriChance", 33), "PotPourriNoSwap")
			
			TNT1 A 0 A_ChangeFlag("SOLID", 0)
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)
			TNT1 A 0 A_SpawnItemEx ("ArachnotronPotpourriSwapper",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERAMBUSHFLAG | SXF_TRANSFERPOINTERS | SXF_TRANSFERSPECIAL | SXF_CLEARCALLERSPECIAL | SXF_CLEARCALLERTID  ,0, tid)
			TNT1 A 30
			Stop	
		PotPourriNoSwap:
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 1)
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 1)
			Goto PotPourriCancel			

		Spawn:
			BSPI A 0 NODELAY A_JumpIf(CallAcs("GetPotPourri"), "PotPourriSwap")
		PotPourriCancel:
			// Also replaces BDCHeckClassicMonsters with a different mechanism
			// The slaughter-aware blood checks the parent monster and goes low-res automatically			
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunMonster")
			TNT1 A 0 A_SetUserVar("user_strafe_dir", Random(0, 1))
			BSPI A 2 
			BSPI A 6 A_Look
		Stand:
			BSPI A 13 A_Look
			Loop
		Pain.Killme:
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			Goto Missile
		See:
		See2:	
			//TNT1 A 0 A_SpawnItemEx("FootSep", 0, 0, 20, 0, 0)
			
			// 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			
			
			
			BSPI A 1 A_PlaySound("baby/walk", 1)
		SeeContinue1:	
			BSPI AABBBCCC 1 A_Chase("", "")
			BSPI D 1
			BSPI DDDEEEFFF 1 A_Chase
			TNT1 A 0 A_GiveInventory("EnemyMemory", 1)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 20, "ForgetTarget")
			Loop
		
		SeeNeverSeen:
			//TNT1 A 0 A_SpawnItemEx("FootSep", 0, 0, 20, 0, 0)
			BSPI A 1 A_PlaySound("baby/walk", 1)
			BSPI AABBBCCC 1 A_Chase("", "")
			BSPI D 1
			BSPI DDDEEEFFF 1 A_Chase
			Loop
			
		
		ForgetTarget:	
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 A_TakeInventory("EnemyMemory", 30)
		SearchPlayer:
		Idle:
			BSPI AA 10 A_Look
			TNT1 A 0 A_SetAngle(angle - 40)
			BSPI AA 10 A_Look
			TNT1 A 0 A_SetAngle(angle + 40)
			BSPI AA 10 A_Look
			
			BSPI A 0 A_PlaySound("baby/walk", 1)
			BSPI A 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI B 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI C 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI A 0 A_PlaySound("baby/walk", 1)
			BSPI D 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI E 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI F 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI DDEEFF 1 A_Wander
			
			TNT1 A 0 A_Jump(128, "SearchPlayer")
			BSPI A 0 A_PlaySound("baby/walk", 1)
			BSPI A 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI B 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI C 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI A 0 A_PlaySound("baby/walk", 1)
			BSPI D 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI E 3 A_Look
			TNT1 AA 0 A_Wander
			BSPI F 3 A_Look
			TNT1 AA 0 A_Wander
			
			Goto SearchPlayer
		
		Missile:
			BSPI A 20 BRIGHT A_FaceTarget
			TNT1 A 0 A_TakeInventory("EnemyMemory", 5)
			TNT1 A 0 A_TakeInventory("RepeaterCount", 12)
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRighht", 1)
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIf(!CheckClass("FBD_Arachnotron1", AAPTR_TARGET, true), 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")				
			
		MissileContinue:	
		
			//***Che: do NOT adjust aim if target goes out of sight or is invisible
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 8)
			TNT1 A 0 A_JumpIfTargetInLOS(6)
			
			TNT1 A 0 A_JumpIf(user_strafe_dir, 3)
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerLeft12", 25, 0, angle + 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_Jump(256, 4)
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerRight12", 25, 0, angle - 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_Jump(256, 2)
			
			TNT1 A 0 A_FaceTarget // <-- A_JumpIfTargetInLOS
			
			BSPI G 4 // <-- A_JumpIfInTargetInventory("PowerInvisibility"
			
			// circle-strafing lowers his fire rate: from 9 to 11 tics per shot
			
			TNT1 A 0 A_JumpIfInventory("CircleStrafeLeft", 1, "StrafeLeft")
			TNT1 A 0 A_JumpIfInventory("CircleStrafeRight", 1, "StrafeRight")			
		
			BSPI G 2
			
			TNT1 A 0 A_SetUserVar("user_strafe_dir", 1 - user_strafe_dir)
			
			Goto MissileAfterStrafing
			
		StrafeLeft:
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_SetAngle(angle + 90)
			TNT1 A 0 A_Recoil(4)
			TNT1 A 0 A_SetAngle(angle - 90)		
			BSPI E 2 A_PlaySound("baby/walk", 1)
			BSPI B 2
			Goto MissileAfterStrafing
		StrafeRight:
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)
			TNT1 A 0 A_SetAngle(angle - 90)
			TNT1 A 0 A_Recoil(4)
			TNT1 A 0 A_SetAngle(angle + 90)		
			BSPI B 2  A_PlaySound("baby/walk", 1)
			BSPI E 2
			
		MissileAfterStrafing:
			TNT1 A 0 A_Stop
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			
			TNT1 A 0 A_JumpIf(waterlevel > 0, "ShortUnderwater")
			
			TNT1 A 0 A_JumpIfInventory("IsAKinSlayer", 1, "FireKinslayerMissile")
			BSPI H 3 BRIGHT A_CustomMissile("EnemyPlasmaBall",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			TNT1 A 0 A_GiveInventory("RepeaterCount", 1)
			TNT1 A 0 A_JumpIfInventory("RepeaterCount", 5, "MissileSpidRefire")
			
			Goto MissileContinue
		FireKinslayerMissile:	
			BSPI H 3 BRIGHT A_CustomMissile("EnemyPlasmaBall_KS",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			TNT1 A 0 A_GiveInventory("RepeaterCount", 1)
			TNT1 A 0 A_JumpIfInventory("RepeaterCount", 5, "MissileSpidRefire")
			
			Goto MissileContinue
		
		ShortUnderwater:
			BSPI G 2
			TNT1 A 0 A_PlaySound("KYBFGSPR", 7)
			BSPI H 1 
			"----" AAAA 0 A_CustomMissile("BUBULZ",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			"----" AAAA 0 A_CustomMissile("ExplosionBubulz",25,0,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_RadiusGive("ElectricShock", 120, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_ElectrocuteSelf", 50)
			TNT1 A 0 A_GiveInventory("RepeaterCount", 1)
			TNT1 A 0 A_JumpIfInventory("RepeaterCount", 5, "MissileSpidRefire")
			
			Goto MissileContinue
		
			
		MissileSpidRefire:
			TNT1 A 0 A_TakeInventory("RepeaterCount", 5)
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "ForgetTarget")
			
			// The count is affected by his missiles hitting a wall nearby
			// so there is no change in his behavior if he is not hitting a nearby wall
			// But 6 such hits interrupt him even if target is in LOS
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "See") 
			
			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:
			BSPI I 3
			BSPI I 3 A_Pain
			TNT1 A 0 A_TakeInventory("ArachnotronChasisLastHit")
			Goto See2
		Pain.Argent: // inflicted by ghost souls spammed by super archviles
		
			TNT1 A 0 HealThing(75)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 30, 60, 25)	
			
			BSPI I 3
			BSPI I 3 A_Pain
			TNT1 A 0 A_TakeInventory("ArachnotronChasisLastHit")

			Goto MissileContinue // results in spraying in a random direction if target is out of sight
		Pain.Kick:
			TNT1 A 0 A_FaceTarget
			BSPI I 6
			BSPI I 6 A_Pain
			Goto See2
		Death.Electric:
			TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
		Death:
			BSPI I 4 A_Scream
			TNT1 A 0 A_JumpIfInventory("ArachnotronChasisHits", 4, "CheckXDeath")
			Goto NormalDeath
			
		CheckXDeath:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("ArachnotronChasisLastHit", 2, "dEATH.stOMP")
		NormalDeath:
			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 AAAAAAAA 0 A_CustomMissile ("FBD_Bloodmist", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeathSpiderNew1", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("XDeathSpiderNew2", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 A 0 A_SpawnItem("BigBloodSpot")
			BSPI K 6 A_NoBlocking
			BSPI LMNO 8
			BSPI P 1 A_BossDeath
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadSpider",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
		
		
		XDeath.Electric:
		Death.SuperPlasma:
		Death.Plasma: 
		Death.Plasma2:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
			TNT1 A 0
			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 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK 7 A_CustomMissile ("PlasmaSmoke", 15, 0, random (0, 360), 2, random (70, 110))
			CARB K -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))
			BSPI LLLL 2 A_CustomMissile ("FlameTrails", 45, 0, random (0, 360), 2, random (50, 130))
			BSPI MMMM 2 A_CustomMissile ("FlameTrails", 30, 0, random (0, 360), 2, random (50, 130))
			BSPI NNNN 2 A_CustomMissile ("FlameTrails", 25, 0, random (0, 360), 2, random (50, 130))
			BSPI 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 KK 2 A_SpawnItem("YellowFlare",0,20)
			ID22 F 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			CARB KK 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 K 5 A_CustomMissile ("PlasmaSmoke", 30, 0, random (0, 360), 2, random (70, 110))
			Loop	
		Rest:	
			CARB K -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 A_JumpIfIntargetInventory("FistsSelected", 1, 1)
			Goto Death
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_SpawnItemEx("Cell", 0, 0, 40, 0, 0, 0, 0, 0, 128)
			//TNT1 A 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, 5, 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("ArachnotronFatality", 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("ArachnotronFatality2", 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:			
			
		//***Che: uncommenting this
		Death.Cut:
			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))
			
			// This, will respawn as an aracnorb -- *if* it spawns succesfully
			TNT1 A 0 A_CustomMissile ("XDeathArachnotronHead", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 130))
			
			TNT1 A 0 A_Scream
			//TNT1 A 0 A_NoBlocking
			ARF2 F 16
			ARF2 G 8
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_BossDeath
			// This, won't respawn
			TNT1 A 0 A_SpawnItemEx("NoLegsSpider",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0) // "nolegs" is actually legs only
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		
		Death.Stomp:
			TNT1 A 0
			ARXD ABCD 4
		XDeath:
			
			//***Che: restoring this, XDeathRare was not used anywhere
			TNT1 A 0 
			TNT1 A 0 A_Jump(26, "XDeathRare")
			
			TNT1 A 0 A_NoBlocking
			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), 2, random (0, 360))
			EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_SpawnItem ("SplatteredLarge")
			
			TNT1 AA 0 A_CustomMissile ("SpiderLeg", 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 AAAA 0 A_CustomMissile ("XDeathSpiderNew1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeathSpiderNew2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAA 0 A_CustomMissile ("PEPart2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAA 0 A_CustomMissile ("BloodMistExtraBig", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			ARXD I 0 A_BossDeath
			TNT1 A 0 A_SpawnItemEx("XFBD_DeadSpider",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Goto XBurns
		XBurns:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("BrutalCounter", 20, "XSmokes")
			TNT1 A 0 A_GiveInventory("BrutalCounter")
			TNT1 AA 2 A_SpawnItem("YellowFlare",0,20)
			TNT1 A 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			TNT1 AA 2 A_SpawnItem("YellowFlare",0,20)
			TNT1 A 0 A_CustomMissile ("FlameTrails", 20, 0, random (0, 360), 2, random (70, 110))
			TNT1 A 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 A 5 A_CustomMissile ("PlasmaSmoke", 40, 0, random (0, 360), 2, random (70, 110))
			Loop	
		XRest:	
			TNT1 A 0
			TNT1 A -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

		Crush:
			TNT1 A 0
			TNT1 AAAAA 0 A_CustomMissile ("Brutal_FlyingBloodTrail8", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 360))
			TNT1 AAAA 0 A_SpawnItemEx ("BodyRemovalThing",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 1 A_XScream
			TNT1 A -1
			Stop
		
		XDeathRare:
			TNT1 A 0 A_CustomMissile ("XDeathArachnotronHead", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 130))
			TNT1 AA 0 A_CustomMissile ("SpiderLeg", 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))
			XBSP A 6 //A_NoBlocking
			XBSP BCD 6
			XBSP D 1 A_BossDeath
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx("XFBD_DeadSpider",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Goto XBurns
		   
		   
		Death.Ice:
		Death.Freeze:
		Death.Frost:
		Death.Frost:
			TNT1 A 0 A_NoBlocking // freeze deaths are permanent
			TNT1 A 0 A_SpawnItemEx("FrozenArachnotron",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_BossDeath
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop 
			
		Death.IOS_Frost:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItemEx("PermafrostArachnotron",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_BossDeath
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop 			
		
		Death.Massacre:
			Goto Death
		
		Raise:
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			BSPI P 5
			BSPI 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", 2019) // 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			
			
	}
}

Actor ArachnotronRaisedByVile: FBD_Arachnotron1 {
	States {
		Spawn:
			TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			BSPI 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 Arachnotron1_PP: FBD_Arachnotron1
{
	States
	{
		PotPourriSwap:
			TNT1 A 0
			Goto PotPourriCancel		
	}
}

Actor EnemyPlasmaBall : Plasma_Ball Replaces PlasmaBall2 //PlasmaBall75 Replaces PlasmaBall2
{
	Damage (random(10,15))
	SeeSound "PLSM9"
	DamageType Plasma
	Speed 22
	//+DONTHURTSPECIES // only affects the firing monster
	Species "Spider"
	
	var int user_not_close;
	
	+SEEKERMISSILE // to receive the real target (our target's target) in our tracer pointer
	+HITMASTER // to receive someone we hit in our master pointer on hit
	
	//***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
	{
		KinslayerAdjust:
			TNT1 A 0 A_ChangeFlag("MTHRUSPECIES", 0)
			TNT1 A 0 A_ChangeFlag("THRUSPECIES", 0)
			Goto FlyAware
			
		Spawn:
			//***Che: this silently fails, jump does not happen
			// turning this actor from a fastprojectile to a regular missile fixes that --
			// proving it is a game engine bug / feature
			// I hack around this using a switch on the arachnotron's side
			//  and a separate non-thruspecies missile (see below)
			//TNT1 A 0 NODELAY A_JumpIfInventory("IsAKinSlayer", 1, "KinslayerAdjust", AAPTR_TARGET)
			//PLSS A 1 A_JumpIfInTargetInventory("IsAKinSlayer", 1, "KinslayerAdjust")
			TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("PlasmaBallTrails")
		FlyAware:
			PLSS ABABABABABABAB 1 Bright A_JumpIf(waterlevel > 0, "Underwater") //A_SpawnItem("BlueFlareSmall")
			
			//after distance of 300 (14 frames), stop reacting to hitting map geometry
			TNT1 A 0 A_SetUserVar("user_not_close", 1)
		Fly:
			PLSS ABAB 1 Bright A_JumpIf(waterlevel > 0, "Underwater") //A_SpawnItem("BlueFlareSmall")
			Loop
	
		Underwater:
			TNT1 A 0 A_Stop
			TNT1 A 0 A_PlaySound("KYBFGSPR", 7)
			TNT1 A 0 A_RadiusGive("ElectricShock", 120, RGF_MONSTERS | RGF_PLAYERS) 	
		Death: // hit a wall
			//TNT1 A 0 A_SpawnItem ("PlasmaPuff", 0)
			//TNT1 A 0 A_SpawnItem ("RailPuff", 0)
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
			//TNT1 A 0 A_SpawnItem("BluePlasmaRife")
			TNT1 AAAAA 0 A_CustomMissile ("BluePlasmaParticle", 0, 0, random (0, 360), 2, random (0, 360))
			
			
			TNT1 A 1 A_JumpIf(user_not_close, 2) // don't do this farther away than 300 map units
			TNT1 A 0 A_GiveInventory("RepeaterCount", 1, AAPTR_TARGET) // influences him to stop firing sooner
			// by increasing the probability he'd stop firing. Also, after accumulating 6 of these
			// he will stop firing even with target in LOS.			
			
			TNT1 B 1 A_Explode(6,50,0)
			TNT1 B 4
			TNT2 AA 9 A_CustomMissile ("PlasmaSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Stop
			
		XDeath: // hit a bleeding actor
			TNT1 A 0
			TNT1 B 1 A_Explode(6,50,0)
			
			// hitting the intended taraget encourages the arachnotron to keep firing
			TNT1 A 0 A_JumpIf(IsPointerEqual(AAPTR_TRACER, AAPTR_MASTER), "RegisterTargetHit")
			
			// otherwise the same effect as hitting map geometry
			TNT1 A 1 A_JumpIf(user_not_close, 2) // don't do this farther away than 300 map units
			TNT1 A 0 A_GiveInventory("RepeaterCount", 2, AAPTR_TARGET)
			
		ActorHitSFX:	
			
			TNT1 A 0 A_JumpIfCloser(200, "ActorHitSFXLo") // closer to the arachnotron, the missile's target 
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 AAA 0 A_CustomMissile ("BluePlasmaParticle", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 1
			Stop

		ActorHitSFXLo:
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 1
			Stop

		RegisterTargetHit:	
			TNT1 A 0 A_JumpIfInTargetLOS(1, 120, JLOSF_CLOSENOFOV, 600, 200) 
				// only react if the arachnotron can see this and is closer than 600 map units
			Goto ActorHitSFX

			// if hits target, keep shooting indefinitely
			TNT1 A 0 A_TakeInventory("RepeaterCount", 10, 0, AAPTR_TARGET)	
			Goto ActorHitSFX
	}
}


Actor EnemyPlasmaBall_KS : EnemyPlasmaBall
{
	-MTHRUSPECIES
	-THRUSPECIES
}


/*
Actor EnemyPlasmaBallSfest: EnemyPlasmaBall { // is DUMB, no advanced reactions
	States {
		Spawn:
			PLSS ABAB 1 Bright
			Loop
		Crash:
		Death:
		XDeath:
			TNT1 A 0
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_Explode(6,50,0)
			TNT1 A 0
			Stop
	
	}
}

Actor EnemyPlasmaBallSfest_KS: EnemyPlasmaBallSfest
{
	-MTHRUSPECIES
	-THRUSPECIES
}
*/



Actor FBD_DeadSpider: FBD_CurbstompedMarine
{
    Scale 1.1
	damagefactor "Crusher", 50.0
    Mass 1000
	Radius 36 //***Che otherwise raising failures //32
    Health 200
	+NOBLOOD
	+CORPSE
    damagefactor "Blood", 0.0
    damagefactor "Trample", 0.0
	States
		{
		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", 2019), "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 ("ArachnotronRaisedByVile",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, 20, 0, 0) //"ArachnotronRaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2019) // see _mob_list.xlsx
			Stop			
		//***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
			BSPI 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
			BSPI P 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			BSPI P -1
			Stop
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			BSPI PPPPP 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death
		Death.SniperBullet:
		Death.Bullet792:
			TNT1 A 0
			TNT1 A 0 A_Jump(96, "Death.Taunt")
		Death.Cut:
		Death.Minigun:
		Death:
			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))
			EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_SpawnItem ("SplatteredLarge")
			TNT1 AA 0 A_CustomMissile ("SpiderLeg", 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 AAAAA 0 A_CustomMissile ("SpiderPart1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath5", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath6", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 90))
			TNT1 AAAAAA 0 A_CustomMissile ("BloodMistExtraBig", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			
			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
		 
	}
}



Actor XFBD_DeadSpider: FBD_DeadSpider
{
	Scale 1.1
	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
			ARXD L 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
			ARXD L 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARXD L -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop 
		LandOnLava:
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARXD LLL 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death
	}
}



Actor RapedArachnotron: FBD_DeadSpider // Doomguy stuck his leg in his eye. So painful.
{	
	Scale 1.0
	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
			ARF1 O 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
			ARF1 O 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARF1 O -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop    
			
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARF1 OOOOO 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			Goto Death			
		Death.Cut:
		Death.SniperBullet:
		Death.Bullet792:		
        Death.Minigun:
		Death:
			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 AA 0 A_CustomMissile ("SpiderLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			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
	}
}

		
		
Actor NoLegsSpider: FBD_DeadSpider
	//***Che: name misleading, is *legs only* platform after a fatality 
	// where Doomguy rips the brain off (or chainsaw horizontal swing)

{
	Scale 1.0
	+NOBLOOD
	Health 999//999999999999
	States{
		Raise:
			Stop // viles do not raise machinery -- and the brain part is elsewhere
			
		//***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
			ARF2 H 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
			ARF2 H 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			ARF2 H -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop 
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			ARF2 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH 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:
		Deathh.Flames:
		
			// nothing but legs!
		
			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))
			EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 AAAA 0 A_CustomMissile ("SpiderLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))			
			
			TNT1 A 0 A_NoBlocking
			TNT1 A 30 // no rez
	}
}		



ACTOR SpiderPart1
{
    Radius 1
    Height 8
    Speed 12
    Scale 1.3
	Mass 1
    +NOBLOCKMAP
	+MISSILE
    +NOTELEPORT
    +MOVEWITHSECTOR
    +CLIENTSIDEONLY
    +RIPPER
    +BLOODLESSIMPACT 
	damagetype Blood
    SeeSound "misc/xdeath4"
    DeathSound "misc/xdeath1"
	Decal BloodSuper
    States
    {
		Spawn:
			TNT1 A 0 A_JumpIf(waterlevel > 1, "Splash")
			ID22 ABCD 2 A_CustomMissile("BloodTrails",0,0,180,2)
			Loop
		Death:
			ID22 E 1 A_SpawnItem("Brutal_BloodSpot",0,0,0,1)
			
			//***Che
			ID22 E 30
			TNT1 A 0 ACS_NamedExecuteAlways("BDCheckFloorType", 0, 0, 0, 0)
			ID22 E 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava")
	
			ID22 E -1
			Stop
			TNT1 A 1
		LandOnLava:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("GoreLandingOnLava", random(-5, 5), random(-5, 5))
			ID22 EEE 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-15, 15), random(-15, 15))
			CARB S -1
			Stop
			
		 Splash:
			TNT1 A 0
			Stop
    }
}



ACTOR SpiderPart2
{
    Radius 1
    Height 8
    Speed 12
    Scale 2.0
	Mass 1
    +NOBLOCKMAP
	+MISSILE
    +NOTELEPORT
    +MOVEWITHSECTOR
    +CLIENTSIDEONLY
    +RIPPER
    +BLOODLESSIMPACT 
    +DOOMBOUNCE
    BounceFactor 0.5
	damagetype Blood
    SeeSound "misc/xdeath4"
    DeathSound "misc/xdeath1"
	Decal BloodSuper
    States
    {
		Spawn:
			TNT1 A 0 A_JumpIf(waterlevel > 1, "Splash")
			ID22 ABCD 2 A_CustomMissile("BloodTrails",0,0,180,2)
			Loop
			
		
		Death:
			ID22 F 1 A_SpawnItem("Brutal_BloodSpot",0,0,0,1)
			
			//***Che
			ID22 F 30
			TNT1 A 0 ACS_NamedExecuteAlways("BDCheckFloorType", 0, 0, 0, 0)
			ID22 F 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava")
			
			ID22 F -1
			Stop
			TNT1 A 1
		LandOnLava:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("GoreLandingOnLava", random(-5, 5), random(-5, 5))
			ID22 FFFF 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-15, 15), random(-15, 15))
			CARB S -1
			Stop				
			
		Splash:
			TNT1 A 0
			Stop
    }
}













ACTOR CrawlingDyingSpider: AbstractDyingGuy
{
    Radius 16 //***Che: aracnorb radius //12
    Height 24
    Speed 9
	Health 100
	PainSound "grunt/pain"
	damagefactor "Kick", 100.0 //***Che: now has fatality, must die in one hit! //0.1
	damagefactor "Melee", 0.1
	damagefactor "SuperPunch", 0.1
	damagefactor "SuperKick", 0.1
	damagefactor "Extremepunches", 100.0 //0.1
	PainChance "Kick", 255
	PainChance "SuperKick", 255
	PainChance "SuperPunch", 255
	PainChance "Extremepunches", 255
	PainChance 255
	damagefactor "trample", 2.0
	+SHOOTABLE
    +FLOORCLIP
	//+NOBLOCKMAP
    +LOOKALLAROUND
	+FRIGHTENED
	+SOLID
	var int user_death_timer;
    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("CrawlingDyingSpiderFatality", 1)
			TNT1 A 0 A_NoBlocking
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop	
	
		Raise: // Aracnorb, nor arachnotron. With legs lost, it rises in its wild form, floating and shooting mind blasts
			// 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", 2017), "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 ("AracnorbRaisedByVile",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, 22, 0, 0) //"AracnorbRaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2017) // see _mob_list.xlsx
			Stop
		Spawn:
			NAHC B 1 A_Look
			Goto See
		See:
			NAHC ABCD 10 A_Chase
			NAHC 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)
			NAHC EFGH 5
			
			//***Che
			NAHC 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
			NAHC H 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava")			
			
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			NAHC H -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			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))
			NAHC IJKLMN 5
			
			//***Che
			NAHC 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
			NAHC N 3
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "LandOnLava2")				
			
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			NAHC N -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
			
		LandOnLava: 
			TNT1 AAAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			NAHC 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))
			NAHC 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
			NAHA 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)
			
			NAHA A 2 A_FaceTarget
			Goto Fly
		
		Fly:
			NAHA ABCDEFGH 3 A_CheckFloor("See")
			NULL A 0 A_JumpIf (momz == 0, "See")
			TNT1 A 0
			Loop
	
	}
}



// ***Che:
ACTOR DeadCrawlingSpider: FBD_DeadSpider
{
	Radius 16 // aracnorb radius
	Height 12
	
	States {
		Raise:// Aracnorb, nor arachnotron. With legs lost, it rises in its wild form, floating and shooting mind blasts
			// 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", 2017), "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 ("AracnorbRaisedByVile",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, 22, 0, 0) //"AracnorbRaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2017) // see _mob_list.xlsx
			Stop	
		Spawn:
			TNT1 A 0 // for descendants to move their former spawn stuff here (not to repeat when Stay repeats from pain)
			Goto StayContinue
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			NAHC G 5 A_PlaySOund("misc/xdeath5", 1)
		StayContinue:	
			NAHC H 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
			NAHC H 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			NAHC H -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
		Death:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItemEx("SplatCrawlingSpider",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop		
	}
}



// its apawn animation is part of the death/ fatality
ACTOR SplatCrawlingSpider: DeadCrawlingSpider	
{
	States {
		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))
			NAHC IJKLMN 5
			Goto StayContinue
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			NAHC M 5 A_PlaySOund("misc/xdeath5", 1)
		StayContinue:	
			NAHC 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
			NAHC N 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			NAHC N -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
		Death:
			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	
	}
}	


