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





ACTOR ZandronumChaingunGuy // ripped from zandronum.pk3
{
	//$category "FBD Monsters"
	//$Sprite MPOSA1
	
	Game Doom
	SpawnID 2
	Health 70
	Radius 20
	Height 56
	Mass 100
	Speed 8
	PainChance 170
	Monster
	+FLOORCLIP
	SeeSound "chainguy/sight"
	PainSound "chainguy/pain"
	DeathSound "chainguy/death"
	ActiveSound "chainguy/active"
	AttackSound "chainguy/attack"
	Obituary "$OB_CHAINGUY"
	Dropitem "Chaingun"
	States
	{
	Spawn:
		CPOS AB 10 A_Look
		Loop
	See:
		CPOS AABBCCDD 3 A_Chase
		Loop
	Missile:
		CPOS E 10 A_FaceTarget
		CPOS FE 4 BRIGHT A_CPosAttack
		CPOS F 1 A_CPosRefire
		Goto Missile+1
	Pain:
		CPOS G 3
		CPOS G 3 A_Pain
		Goto See
	Death:
		CPOS H 5
		CPOS I 5 A_Scream
		CPOS J 5 A_NoBlocking
		CPOS KLM 5
		CPOS N -1
		Stop
	XDeath:
		CPOS O 5 
		CPOS P 5 A_XScream
		CPOS Q 5 A_NoBlocking
		CPOS RS 5
		CPOS T -1
		Stop
	Raise:
		CPOS N 5
		CPOS MLKJIH 5
		Goto See
	}
}

//***Che: cross-mod hardening: see ACTOR ChaingunGuy1: FBD_ChaingunGuy Replaces ChaingunGuy {} in Doom_Replacements.txt

ACTOR FBD_ChaingunGuy: ZandronumChaingunGuy 17846
{
	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!
	
	//$Sprite MPOSA1
	Health 80
	Radius 16
	Height 44
	Mass 100
	Speed 5
	PainChance 255
	PainChance "HelperMarineFatallity", 255 PainChance "HangingHook", 0
	PainChance "Kick", 255
	PainChance "Melee", 255 PainChance "Stealth", 255
	damagefactor "Avoid", 0.0
	damagefactor "GibRemoving", 0.0
	damagefactor "Crush", 5.0 DamageFactor "Fatality", 5.0 damagefactor "PussyGrab", 50.0
	damagefactor "TeleportRemover", 0.0
	PainChance "MonsterKnocked", 255
	damagefactor "explosiveimpact", 2.0
	//***Che
	damagefactor "Bfg10k", 2.0
	
	//***Che
	DamageFactor "FriendlyExplosion", 2.0
	
	var int user_head_tid;
	var int user_head_rel;
	var int user_head_scale;
	var int user_head_xyzf; /* 
		a packed value: 
		bits 0..7 =x+128, clamped to -128..127
		bits 8..15 =y+128, clamped to -128..127
		bits 16..23 =z, clamped to 1..255
		bit 29 is a command to assume an unique TID, used in monster-on-monster headshotting
		A zero value is a command to terminate
	*/
	
	var int user_head_type; 
	var int user_sleeping;
	var int user_item_no;
	var int user_serverside_sfchk;	

	
	damagefactor "saw", 1.2
	DamageFactor "ExtremePunches", 2.0
	damagetype "Melee"
	Monster
	//Translation "192:207=176:191"
	damagefactor "SSG", 50.0 // meaning he receives 2000 damage from the super shotgun's central short-range hitscan. Splat.
	MaxStepHeight 24
	MaxDropOffHeight 32
	damagefactor "Shotgun", 2.0
	+FLOORCLIP
    +MISSILEMORE
    +MISSILEEVENMORE
	+RANDOMIZE
	+DOHARMSPECIES
	DeathHeight 4
	BurnHeight 0
	Species "Zombies"
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0
    BloodType "FBD_Blood", "FBD_SawBlood", "FBD_SawBlood"
	SeeSound "grunt/sight"
	PainSound "grunt/pain"
	DeathSound "grunt/death"
	ActiveSound "grunt/active"
	AttackSound "weapons/minigunfire"
	damagefactor "explosiveimpact", 2.0
	//***Che
	damagefactor "Bfg10k", 2.0
	DropItem "DropedChaingunSpawner"
	Obituary "%o has been mowed down by a Zombie Commando."
	DamageFactor "CauseSplash", 0.0 DamageFactor "CauseObjectsToSplashSlime", 0.0 DamageFactor "CauseObjectsToSplashNukage", 0.0
	DamageFactor "CauseObjectsToSplashBlood", 0.0 DamageFactor "CauseObjectsToSplashLava", 0.0
	Tag "$FBD_COMMANDO" // "Minigun Zombie";
	DamageFactor "Head", 2.0
	
	PainChance "Argent", 255
	DamageFactor "Argent", 1.0
	
	damagefactor "Bullet792", 1.35
	damagefactor "SniperBullet", 1.35 // sniper rifle must be an one-hit-kill, 60 => 80	
	
	PainChance "PlummetAaah", 0 // bottomless pits in Chebskies-EDAY
	DamageFactor "PlummetAaah", 50.0 // doesn't scream, just dies	

	damagefactor "Killme", 1.0 // AOE inflicted by captured marines
	PainChance "Killme", 255

	PainChance "Ice", 255
	
	//***Che this damage type is now for subscribers only
	damagefactor "Stealth", 1.0
	PainChance "Stealth", 255	
	
	States
	{
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See

		
		Death.PlummetAaah:
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_CustomMissile ("FBD_ThrowedChaingunguy", 0, 0, 0, CMF_AIMDIRECTION, -90)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // give the scripts and actors time to run and access us
			Stop			
		WaitTargetsFatalityOut:
			//TNT1 A 0 A_PlaySound("grunt/sight", CHAN_VOICE)
			TNT1 A 0 A_Jump(256, "WTF1", "WTF2", "FallBackContinue")
		WTF1:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			MPOS A Random(5, 10) A_SetAngle(angle + Random(-60, 60))
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			Goto Missile 
		WTF2:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			MPOS A Random(5, 10) A_SetAngle(angle + Random(-20, 20))
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			Goto Missile 
			
		FallBack:
			//***Che: target, not "any player" //TNT1 A 0 A_CheckSight("Advance")
			TNT1 A 0 A_JumpIfTargetinLOS(1)
			Goto SeeContinue
			
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, 2)
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
	
		FallBackContinue:	
			TNT1 A 0 A_ChangeFLag("NODROPOFF", 1)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			MPOS D 2 A_FaceTarget
			MPOS D 2 A_Recoil(4)
			TNT1 A 0 A_jump(64, "Missile")
			
			MPOS C 2 A_FaceTarget
			MPOS C 2 A_Recoil(4)
			
			MPOS B 2 A_FaceTarget
			MPOS B 2 A_Recoil(3)
			
			MPOS A 2 A_FaceTarget
			MPOS A 2 A_Recoil(3)
			TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			Goto Missile			
		
/*			
		ReplaceVanilla:
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_SpawnItemEx ("VanillaChaingunguy",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERAMBUSHFLAG ,0)
			Stop
*/			
		
		Raise:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII") // should not have a headbox by now -- but what if?
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			CPOS N 5
			CPOS MLKJIH 5
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_CustomizeOnRez") // it runs OnRezMapScript
				// if the map prpvides one
			Goto See
			
		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", 2002) // 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			
			
		PotPourriSwap:
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
		PotPourriWait:			
			KYPP A 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 ("CommandoPotpourriSwapper",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:
			MPOS A 0 NODELAY A_JumpIf(CallAcs("GetPotPourri"), "PotPourriSwap")
		PotPourriCancel:	
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunMonster", 5) // 5 = default headbox
			TNT1 A 0 A_GiveInventory("TargetIsAFormerHuman", 1) //used by AOE DOT inflictors to reward players with soul ammo -- otherwise untraceable
			MPOS B 1
			Goto Stand
			
		Stand:
			//MPOS A 0
			//TNT1 A 0 A_JumpIf(user_serverside_sfchk >= 4, "StandSfestExtreme") // extreme slaughtermap optimization
		StandContinue:	
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			MPOS A 0 A_CheckSight("Stand2")
			
			MPOS BB 9 A_Look
			Loop
		Stand2:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			MPOS A 0 
			
			MPOS BB 15 A_Look
			"----" A 0 A_JumpIf(!user_head_tid, "StandSfestExtreme")
			TNT1 A 0 A_CheckSight("Stand2")
			Goto StandContinue
			
		StandSfestExtreme: // no headbox created until sees the player!
			MPOS B 15 A_Look
			Loop
			
		Idle:	
			TNT1 A 0
			MPOS A 0 A_GiveInventory("SKChaingunGuy", 1)
			MPOS A 0 A_JumpIfInTargetInventory("ChainguyguyContinue", 1, "MissileContinue")
		SearchForPlayer:
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 A_TakeInventory("EnemyMemory", 30)
			TNT1 A 0 A_GiveInventory("SKChaingunguy", 1)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			
			MPOS A 10 A_Look
			
			MPOS A 10 A_Look
			
			MPOS A 10 A_Look
			
			TNT1 A 0 A_SetAngle(angle - 40)
			
			MPOS A 10 A_Look
			
			TNT1 A 0 A_SetAngle(angle + 40)
			MPOS A 10 A_Look
			
			MPOS A 10 A_Look
			
			
			TNT1 A 0 A_Wander
			
			MPOS A 4 A_Look
			
			TNT1 A 0 A_Wander
			
			MPOS B 4 A_Look
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			
			TNT1 A 0 A_Wander
			
			MPOS C 4 A_Look
			
			TNT1 A 0 A_Wander
			
			MPOS D 4 A_Look
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			
			TNT1 A 0 A_jump(128, "SearchForPlayer")
			
			
			TNT1 A 0 A_Wander
			
			MPOS A 4 A_Look
			
			TNT1 A 0 A_Wander
			
			MPOS B 4 A_Look
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			
			TNT1 A 0 A_Wander
			
			MPOS C 4 A_Look
			
			TNT1 A 0 A_Wander
			
			MPOS D 4 A_Look
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			Goto SearchForPlayer
		VanillaSee:
			//***Che: TODO: implement!
			TNT1 A 0
			Goto Death.Desintegrate
			
		See:
			TNT1 A 0
			TNT1 A 0 A_ChangeFLag("NODROPOFF", 0)
			TNT1 A 0 A_TakeInventory("SKChaingunGuy", 1)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 15)
			
			// slaughtermap manage - warming the headbox up
			TNT1 A 0 A_JumpIf(!user_sleeping, 4) // forgo the expensive sight check if already awake
			TNT1 A 0 A_JumpIfInTargetInventory("IsPlayer", 1, 2) // bypass the sight check 
			TNT1 A 0 A_CheckSight(2) // out of sight of any player, AND attacking another monster, keep slumbering
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)				

			//TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, "VanillaSeeContinue")			
			
			
			TNT1 A 0 A_CheckSight("SeeNeverSeen")
			Goto SeeContinue
		
		SeeContinue:
			TNT1 A 0 A_CheckSight("SeeNeverSeen")
			
		SeeContinuePart2:	
			TNT1 A 0 A_GiveInventory("EverSeenTheplayer", 1)
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 12, "SearchForPlayer")
			
		SeeContinuePart36:
			TNT1 A 0 A_GiveInventory("EnemyMemory", 1)
			TNT1 A 0 A_TakeInventory("IsFiring", 1)
			
			// slaughtermap manage
			TNT1 A 0 A_JumpIf(!user_sleeping, 3) // forgo the expensive sight check if already awake
			TNT1 A 0 A_CheckSight(2) // do not consider ourselves awake if none of the players can see us
			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, 1)			
			TNT1 A 0 A_SetUserVar("user_serverside_sfchk", 1) // reply that we did the deed				
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			
			MPOS AAA 2 A_Chase
			
			MPOS BBB 2 A_Chase
			
			MPOS CCC 2 A_Chase
			
			MPOS DDD 2 A_Chase
			
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "ForgetFaster")//"Idle")
			Loop
			
		ForgetFaster:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("EnemyMemory", 4)
			Goto SeeContinuePart2
			
		SeeNeverSeen:
			
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("EverSeenThePlayer", 1, "SeeContinuePart2")
			//TNT1 A 0 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			
			MPOS AAA 2 A_Chase
			
			MPOS BBB 2 A_Chase
			
			MPOS CCC 2 A_Chase
			
			MPOS DDD 2 A_Chase
			
			TNT1 A 0 A_CheckSight("SeeNeverSeen")
			Goto SeeContinue
			
		VanillaMissile: 
			//***Che: TODO: implement!
			TNT1 A 0
			Goto Death.Desintegrate

		Missile:
			TNT1 A 0 
			
			// slaughtermap manage - warming the headbox up
			TNT1 A 0 A_JumpIf(!user_sleeping, 4) // forgo the expensive sight check if already awake
			TNT1 A 0 A_JumpIfInTargetInventory("IsPlayer", 1, 2) // bypass the sight check 
			TNT1 A 0 A_CheckSight(2) // out of sight of any player, AND attacking another monster, keep slumbering
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			
			TNT1 A 0 A_JumpIfInTargetInventory("IsLTGPlayer", 1, "LTGCheck")
		MissileContinueAfterLTGCheck:				
			
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")

			TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, "VanillaMissile")			
			
			TNT1 A 0 A_TakeInventory("EnemyMemory", 15)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -1, 1, 43)
			
			//TNT1 A 0 A_TakeInventory("CantFire", 1)
			//TNT1 A 0 A_CustomMissile("MonsterTargetCheck", 34, 0, 0, 0) 
			//TNT1 A 0 A_CustomMissile("MonsterTargetCheckFaster", 34, 0, 0, 0) 
			MPOS E 6 A_FaceTarget
			//TNT1 A 0 A_JumpIfInventory("CantFire",1, "SeeContinuePart36")
			
			TNT1 A 0 A_TakeInventory("SKChaingunGuy", 1)
			TNT1 A 0 A_PlaySound("CHAINSTA")
			
			
			//***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
			
			MPOS E 4 //A_FaceTarget
			
			
			//***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
			
			MPOS E 7 //A_FaceTarget
			
			
			//***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
			
			MPOS E 7 //A_FaceTarget
			
			
			//***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
			
			MPOS E 7 //A_FaceTarget
			TNT1 A 0 A_GiveInventory("IsFiring", 1)
			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
			
			MPOS E 1 //A_FaceTarget
			
			

		MissileContinue:
			
			TNT1 A 0
			TNT1 A 0 A_JumpIfTargetInLOS(2)
			TNT1 A 0 A_Jump(256, "MissileContinueNoLOS")
			
			TNT1 A 0 A_JumpIfCloser(500, 2)
			TNT1 A 0 A_Jump(200, 2)
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			
			MPOS F 1 BRIGHT A_CustomMissile("MonsterMinigunTracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			
			//***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
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -1, 1, 43)

			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS H 1 BRIGHT A_CustomMissile("Tracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			
			
			//***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

			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS F 1 BRIGHT A_CustomMissile("MonsterMinigunTracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			
			//***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

			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS H 1 BRIGHT A_CustomMissile("Tracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			
			//***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

			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			TNT1 A 0 A_JumpIfInTargetInventory("ChainguyguyContinue", 1, "MissileContinueRecheckLOS")
			
			//***Che
			//TNT1 A 0 A_CposRefire // cannot allow, includes A_FaceTarget as part of its action
			
			TNT1 A 0 A_JumpIfInTargetInventory("Enraged", 1, "MissileEnraredRefire")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3, 0, JLOSF_DEADNOJUMP)
			TNT1 A 0 A_Jump(216, "See") // probability 40 not to jump, https://zdoom.org/wiki/A_MonsterRefire 
			TNT1 A 0 A_Jump(256, "MissileContinueNoLOS")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "MissileContinueNoLOS")
			
			Goto MissileContinueRecheckLOS
		
		MissileEnraredRefire: //***Che: keeps firing in much longer bursts when enraged
			TNT1 A 0
			TNT1 A 0 A_Jump(32, "MissileContinueRecheckLOS")
			Goto MissileContinue
		
		//***Che
		MissileContinueNoLOS:
			
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -1, 1, 43)
			
			MPOS F 1 BRIGHT A_CustomMissile("MonsterMinigunTracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			
			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS H 1 BRIGHT A_CustomMissile("Tracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS F 1 BRIGHT A_CustomMissile("MonsterMinigunTracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			MPOS H 1 BRIGHT A_CustomMissile("Tracer", 34, 0, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-2, 2))
			TNT1 A 0 A_CustomMissile("EnemyMinigunBrass", 34, 0, -60, 2, random(20, 55))
			MPOS E 1 //A_FaceTarget 
			
			TNT1 A 0 A_PlaySound("FARMGN", 6)
			TNT1 A 0 A_PlaySound("CHGNSHOT", 5)
			
			TNT1 A 0 A_JumpIfInTargetInventory("ChainguyguyContinue", 1, "MissileContinueRecheckLOS")
			
			//TNT1 A 0 A_CposRefire // cannot allow, includes A_FaceTarget as part of its action
			TNT1 A 0 A_JumpIfTargetInLOS("MissileContinue", 0, JLOSF_DEADNOJUMP)
			TNT1 A 0 A_Jump(216, "See") // probability 40 not to jump, https://zdoom.org/wiki/A_MonsterRefire 
			TNT1 A 0
			Loop  //Goto MissileContinueNoLOS
		
		MissileContinueRecheckLOS:
			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"), "MissileContinueTargetInvisible")
			TNT1 A 0 A_JumpIfTargetInLOS("MissileContinue", 0, JLOSF_DEADNOJUMP)
			Goto MissileContinueNoLOS
			
		MissileContinueTargetInvisible:
			TNT1 A 0
			TNT1 A 0 A_Jump(240, "MissileContinueNoLOS")
			TNT1 A 0 A_FaceTarget // 1/16th chance, this repeats every 4 boolets so actual average chance is 1/64 per boolet
			Goto MissileContinueNoLOS
			
		MissileContinueForceFaceInvis:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2) // ONLY face if invisible, otherwise LOS check still applies
			TNT1 A 0 A_Jump(256, "MissileContinue")
			TNT1 A 0 A_FaceTarget
			Goto MissileContinue

/* //***Che: this was unused		
		SpecialAttack:
			
			MPOS E 10 A_FaceTarget 
			
			TNT1 A 0 A_CustomMissile("FireFightFlare", 34, 10, 15, 25)
			MPOS F 10 //A_CustomMissile("CommandoGrenade",10,0,0,0)
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			MPOS E 10
			Goto SeeContinue
*/			
		GotoStealthKill:
			TNT1 A 1
			TNT1 A 0 A_Explode(100, 1, 1)
			TNT1 A 1
			Goto See	
			
		Pain.Melee:
			MPOS G 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			TNT1 A 0 A_JumpIfInventory ("SKChaingunGuy", 1, "GotoStealthKill")
			
			MPOS G 4 A_Pain
			TNT1 A 0 A_TakeInventory("IsFiring", 1)
			Goto See
			
		Pain.Stealth:
			TNT1 A 0
			TNT1 A 0 A_Pain
			TNT1 A 0 A_JumpIfInventory ("SKChaingunguy", 1, "GotoStealthKill")
			//TNT1 A 0 A_JumpIfInventory ("IsDown", 1, "GroundExecution")
			Goto See
			
		GroundExecution:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("ExecuteDownedZombieman", 1)
			TNT1 A 0 A_GiveToTarget("GoSpecial", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		Pain:
		Pain.Cut:
		Pain.Saw:
		Pain.Head:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("IsFiring", 1, "Pain.IsFiring")
			
			TNT1 A 0 A_TakeInventory("SKChaingunGuy", 1)
			MPOS G 2 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			
			MPOS G 2 A_Pain
			TNT1 A 0 A_TakeInventory("IsFiring", 1)
			Goto SeeContinue
			
		Pain.IsFiring:	
			CPDR A 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -1, -1, 42)
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile("MonsterMinigunTracer", 32, 15, random(-3, 3) + angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-22, -18))
			//A_CustomMissile ("MonsterMinigunTracer", 32, 15, 0, 2, -20)
			CPDR B 3 BRIGHT
			Goto MissileContinueForceFaceInvis //MissileContinue
			
		Pain.Argent: // inflicted by ghost souls spammed by super archviles
			TNT1 A 0
			TNT1 A 0 A_Pain
			//TNT1 A 0 A_JumpIfInventory("IsFiring", 1, 2) // skip clear target
			//TNT1 A 0 A_ClearTarget
			TNT1 A 0 HealThing(25)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 10, 46, 0)	
			
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			
			Goto Pain // also takes care to not interrupt firing

		Pain.HeavyImpact:
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 ThrustThingZ(0,20,0,1)
			TNT1 A 0 A_Recoil(6)
			Goto Pain
			
		Pain.LowKick:
		Pain.Kick:
		Pain.BlackHole: // inflicted by ancient arachnotron
		Pain.Decaptate:
		Pain.HeadPlasma:
			TNT1 A 0 A_Pain
			TNT1 A 0 A_TakeInventory("IsFiring", 1)
			TNT1 A 0 A_TakeInventory("SKChaingunGuy", 1)
			TNT1 A 0
			TNT1 A 0 ThrustThingZ(0,15,0,1)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil (3)
			MPOS G 2 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			CPBK A 2 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 38)
			CPBK B 2 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 36)
			CPBK C 2

			CPBK C 8 A_Pain

			CPBK D 8

			CPBK C 8 A_Pain
			CPBK D 8

			CPBK C 8 A_Pain
			CPBK D 8

			CPBK C 8 A_Pain
			CPBK D 8

			CPBK B 4
			CPBK A 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 38)
			MPOS G 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -4, 0, 44)
			Goto See
			
			
		
		Death.MonsterShotgunBullet:
		Death.Shotgun:
		Death.HKFT:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_CustomMissile ("SuperWallRedBlood", 42, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 20))
			TNT1 A 0 A_JumpIfCloser(50, "Death.SSG")
			TNT1 A 0 A_Jump(24,"Death.Arm")
			TNT1 A 0 ThrustThingZ(0,30,0,1)
			TNT1 A 0 A_Recoil(6)
			TNT1 A 0 A_JumpIfInventory("IsFiring", 1, "Death.Rare")
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPHM AB 4
			TNT1 A 0 
			CPHM CD 4 A_JumpIf((MomY == 0), "TakeASit")
			CPHM EF 4
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("DeadChaingunGuy_KilledByMinorHead", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			
			Stop
			
		Death:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_JumpIfInventory("IsFiring", 1, "Death.Rare")
			TNT1 AAA 0 A_SpawnItem("Blood", 0, 40)
			TNT1 A 0 A_Jump(96,"Death.Rare")
			TNT1 A 0 A_Jump(64,"Death.Arm")
			CPOD A 8 A_Scream
			CPOD B 6 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPOD CDEFG 6
			TNT1 A 0 
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadChaingunGuy1", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
		
		Death.Electric:				
			TNT1 A 0
			TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
			CPOD A 8 A_Scream
			CPOD B 6 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPOD CDEFG 6
			TNT1 A 0 
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("FBD_DeadChaingunGuy1", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop	
			
		Death.Rare:
			// did NOT include any headbox spam, these empty lines were there from the beginning
			TNT1 A 0
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil(2)
			CPDR A 3 A_Scream
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 32, 15, 0, 2, -20)
			CPDR B 3 BRIGHT
			
			CPDR A 3
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 32, 15, 0, 2, -20)
			CPDR B 3 BRIGHT
			

			CPDR C 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 24, 15, -20, 2, -20)
			CPDR D 2 BRIGHT
			
			CPDR C 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 24, 15, -20, 2, -20)
			CPDR D 2 BRIGHT
			
			CPDR E 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 24, 15, -20, 2, 20)
			CPDR F 2 BRIGHT
			
			CPDR G 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 24, 15, -10, 2, 40)
			CPDR H 2 BRIGHT
			
			TNT1 A 0 A_Recoil(1)
			CPDR I 2
			TNT1 A 0 A_JumpIf((MomY == 0), "TakeASit")
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 24, 15, -10, 2, 40)
			CPDR J 2 BRIGHT
			TNT1 A 0 A_JumpIf((MomY == 0), "TakeASit")
			
			CPDR K 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 12, 15, -20, 2, 40)
			CPDR L 2 BRIGHT
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			CPDR M 2
			TNT1 A 0 A_SpawnItem ("RifleCaseSpawn", 0, 30,0)
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 12, 15, -20, 2, 20)
			CPDR N 2 BRIGHT
			
			CPDR M 2
			
			TNT1 A 0 A_CustomMissile ("MonsterMinigunTracer", 12, 15, -20, 2, 20)
			CPDR N 2 BRIGHT
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			
			
			TNT1 A 0 A_SpawnItemEx("DeadChaingunguyCPDRO",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_ChangeFlag("CORPSE", 0) // fun fact, vile resurrection only cares about three things:
				// 1. the CORPSE flag
				// 2. the actor having a Raise state (all FBD_CurbstompedMarine descendants do)
				// 3. the current frame's duration being -1
				// Sooo... is TNT1 A -1 secret *invisible* food for the fat archvile trolls?
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) //-1
			Stop
		
		TakeASit:
			TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 6, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 A 0
			TNT1 A 0 A_SpawnItem("GrowingBloodPool")
			
			TNT1 A 0 A_SpawnItemEx("DeadChaingunguy_Slumped", 10,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			// no need to delay, had enough frames to let the headbox deleting script run
			
			// slumped corpses *cannot* be raised/respawned! (a fundamental limitation)
			Stop
		
			
		Death.OriginalGibz: //***Che this doesn't seem to be used anywhere
			TNT1 A 0 
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathChainArm", 35, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_CustomMissile ("XDeath1", 35, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_CustomMissile ("XDeath2", 35, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AAA 0 A_CustomMissile ("SmallBrainPiece", 35, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_XScream
			TNT1 O 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPSC ABCDEFGH 4
			CPSC H 1
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("DeadChaingunGuy_Half", 3,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
		
		Death.DropedChaingunSpawner:
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun:
		Death.Arm:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 AA 0 A_CustomMissile ("FBD_Bloodmist", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			TNT1 A 0 A_CustomMissile ("XDeathChainArm", 45, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath1", 45, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))

			CPOD H 10 A_Scream
			CPOD I 5
			CPOD I 1 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_SpawnItemEx ("BrutalizedCommando1", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		XDeath:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
			TNT1 A 0 
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_FaceTarget
			// ChainXDeath is a pure gore spawner
			TNT1 A 0 A_CustomMissile ("ChainXDeath", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			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
			
			
		HeadExploder:
			TNT1 A 0 A_Jump(72, "Death.HeadExplode")
			Goto Death.HeadMinor
			
		Death.Head:
			TNT1 A 0
			//***Che: are managed by my new headboxes that dispense those damage types directly
			//TNT1 A 0 A_JumpIfInTargetInventory("HasPlasmaWeapon", 1, "Death.Plasma")
			//TNT1 A 0 A_JumpIfInTargetInventory("HasCutingWeapon", 1, "Death.decaptate")
			TNT1 A 0 A_JumpIfInTargetInventory("MinigunSelected", 1, "Death.headExplode")
			TNT1 A 0 A_JumpIfHealthLower(-30, "Death.HeadExplode")
			TNT1 A 0 A_JumpIfInTargetInventory("RandomHeadExploder", 1, "HeadExploder")
		Death.HeadMinor:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_PlaySound("misc/xdeath4", CHAN_VOICE)
			TNT1 AA 0 A_CustomMissile ("FBD_Bloodmist", 60, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			TNT1 AAAAA 0 A_CustomMissile ("BrainBlood", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("SmallBrainPiece", random (45, 55), random (5, -5), random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 A 0 A_CustomMissile ("SmallBrainPiece", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SuperWallRedBlood", 46, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			CPHM I 6
			CPHM J 6 A_Scream
			CPHM C 6 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPHM DEF 6 
			TNT1 A 0 
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx ("DeadChaingunGuy_KilledByMinorHead", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		Death.Melee:
			 
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory ("SKChaingunGuy", 1, "StealthKill")
		Death.Kick:
		Death.HeavyImpact:
		Death.BlackHole:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			CPHM A 9 A_FaceTarget
			TNT1 A 0 A_Recoil(5)
			CPHM B 9 A_Scream
			CPHM C 8 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPHM DEF 8 
			TNT1 A 0 
			TNT1 A 0 A_SpawnItemEx ("DeadChaingunGuy_KilledByMinorHead", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		//***Che:
		Death.Psionic:
		Death.HeadStun:
		Death.headExplode:
			
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_XScream
			TNT1 A 0 A_SpawnItem("ChaingunguyHeadExplode", 0, 50)
			CPHS AAA 2 A_CustomMissile ("Brutal_LiquidBlood2", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx("BrutalizedCommandoLostHead", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) //-1
			Stop
			
			
		Death.decaptate:
		Death.CCFT:
			TNT1 A 0
			TNT1 A 0 A_CustomMissile ("MuchBlood3", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_XScream
			TNT1 A 0 A_SpawnItemEx ("XDeathChaingunguyHeadBeheaded", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			CPHS AAA 2 A_CustomMissile ("Brutal_LiquidBlood2", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx("BrutalizedCommandoLostHead2", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
		Death.cut:
		Death.Saw:
			TNT1 O 0 A_Jump(220, 2)
			Goto Death
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathChainArm", 35, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathChainLeg", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_XScream
			TNT1 O 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_CustomMissile ("XDeathGuts", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			CPSC ABCDEFGH 8
			CPSC H 1
			TNT1 A 0 
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 1 A_SpawnItemEx ("DeadChaingunGuy_Half", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
			
			
		
		Death.Shrapnel:
			TNT1 A 0
			TNT1 A 0 A_JumpIfHealthLower(-50, 4)
			TNT1 A 0 A_SpawnItem("MuchBlood", 0, 32)
			TNT1 A 0 ThrustThingZ(0, 30, 0, 0)
			TNT1 A 0 A_Jump(128, "Death.Head")
			Goto Death
			TNT1 AA 0
			TNT1 A 0 A_Jump(256, "Death.ExplosiveImpact", "Death.Leg")
			Goto Death
			
		Death.ExplosiveImpact:
		Death.Landmine:
		Death.LandMine2:
		//***Che
		Death.FriendlyExplosion:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 ThrustThingZ(0,40,0,1)
			TNT1 A 0 A_SpawnItemEx("MuchBlood2", 0, 0, 40)
			TNT1 AA 0 A_CustomMissile ("XDeath1", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("SuperWallRedBlood", 46, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAAAA 0 A_CustomMissile ("BloodMistLarge", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (20, 90))
			TNT1 A 0 A_CustomMissile ("XDeathChainArm", 62, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathChainLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath1", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAAAAA 0 A_CustomMissile ("BloodMistLarge", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (20, 90))
			TNT1 AAAAAAAAAAA 0 A_CustomMissile ("BrainBlood", 50, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
		
			CPDE A 1 A_Scream
			CPDE A 1 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPDE A 2 A_CheckFloor ("Dead.Landmine")
			CPDE BCDEFGH 2 A_CheckFloor ("Dead.Landmine")
			CPDE A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnitemEx("DeadChaingunguyCPDEI", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
		
		Dead.Landmine:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItem ("Ploft")
			TNT1 AAAA 0 A_SpawnItem ("Blood")
			CPDE I 1
			TNT1 A 0 A_SpawnItemEx("DeadChaingunguyCPDEI", 0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop
		
		Death.Plasma: 
		Death.Plasma2:
		Death.HeadPlasma:
		XDeath.Electric:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Stop
			PBR1 A 6 A_XScream
			TNT1 AAAA 0 A_CustomMissile ("BluePlasmaFireNonStatic", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAA 0 A_CustomMissile ("Blood", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAA 0 A_CustomMissile ("BloodMistSmall", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			PBR1 B 6 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
			TNT1 A 0 A_SpawnItemEx("TinyBurningPiece", random (-15, 15), random (-15, 15))
			TNT1 AA 0 A_SpawnItemEx("TinyBurningPiece2", random (-35, 35), random (-35, 35))
			TNT1 AA 0 A_SpawnItemEx("TinyBurningPiece3", random (-45, 45), random (-45, 35))
			PBR1 CCDD 3 A_CustomMissile ("BluePlasmaFireNonStatic", 32, 0, random (0, 360), 2, random (0, 180))
			PBR1 EEFF 3 A_CustomMissile ("BluePlasmaFireNonStatic", 24, 0, random (0, 360), 2, random (0, 180))
			PBR1 GG 3 A_CustomMissile ("BluePlasmaFireNonStatic", 22, 0, random (0, 360), 2, random (0, 180))
			PBR1 H -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.Bfg10k: //***Che changed damage type from extreme to custom
		Death.SuperPlasma:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_XScream
			TNT1 A 0 
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			XBRN AA 2 BRIGHT A_SpawnItem("BlueFlare",0,43)
			TNT1 AAAA 0 A_CustomMissile ("FBD_Blood", 30, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			TNT1 A 0 A_CustomMissile ("XDeathBurnedArm", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedSkull", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat3", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))

			XBRN BB 2 BRIGHT A_SpawnItem("BlueFlare",0,43)
			TNT1 A 0 A_CustomMissile ("FBD_Blood", 30, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			XBRN CC 2 BRIGHT A_SpawnItem("BlueFlare",0,43)
			TNT1 AAAAA 0 A_CustomMissile ("PlasmaParticleX", 48, 0, random (0, 360), 2, random (0, 360))
			TNT1 AAA 0 A_CustomMissile ("BigPlasmaParticleX", 42, 0, random (0, 360), 2, random (0, 360))
			
			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
			
		Death.GreenFire:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 AAAA 0 A_CustomMissile ("FBD_Blood", 30, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			TNT1 A 0 A_CustomMissile ("XDeathBurnedArm", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedSkull", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat2", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat3", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			EXPL AAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("GreenFlameTrails", 50, 0, random (0, 360), 2, random (0, 360))
			XBRN AAAA 2 BRIGHT A_SpawnItem("GreenFlare",0,43)
			
			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

		Death.fire:
		Death.burn:
		Death.flames:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 
			TNT1 A 0 A_SpawnItemEx("BurningcHAINGUNGUY", 0,0,10, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop


		Death.Throwable:
			Goto Death
			
		Death.Desintegrate:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_SpawnItem("DesintegratedHuman")
			TNT1 A 0 A_Stop
			TGIB ABCDEFGHIJKLMNOPQ 4
			TGIB 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 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Pain
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_SpawnItemEx("Clip", 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 A 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, 5, 0) // 0, health, armor, 0 -- rounded down to nearest 2
			TNT1 A 0 A_JumpIfIntargetInventory("IsPlayer", 1, 1)
			Goto Death.ExplosiveImpact
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 
			TNT1 A 0 A_Jump(130,5)
			TNT1 A 0 A_GiveToTarget("ComandoFatality", 1)
			Stop
			TNT1 AAAAAAA 0
			TNT1 A 0 A_GiveToTarget("ComandoFatality2", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop
			
		Death.HelperMarineFatallity:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 1 A_Pain
			TNT1 A 0 A_Chase("","")
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking 
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)			
			TNT1 A 0 A_GiveToTarget("ComandoFatality", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop		
			
			
		Death.Eat:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_Scream
			TNT1 A 0 
			TNT1 A 0 A_GiveToTarget("ComandoFatality",1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop

			
		Death.Stomp:
			TNT1 A 0
			// if 15% random chance or the cyberdemon is below us, be catapulted violently
			TNT1 A 0 A_JumpIf(Random(0,100) < 15 || CallAcs("GetZDeltaToTarget") < - 32, "Death.ExtremePunches") 			
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")		
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			CPHM CDE 2 
			TNT1 AA 0 A_SpawnItem("MeatDeathSmall")
			TNT1 AAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 180))
			TNT1 AAAA 0 bright A_CustomMissile ("XDeath1", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 180))
			TNT1 AA 0 bright A_CustomMissile ("XDeath2b", 55, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 180))
			TNT1 AA 0 bright A_CustomMissile ("XDeath3b", 55, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 180))
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItem ("CrushedRemains")
			TNT1 A 1
			TNT1 A 1 A_XScream
			
			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 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")	
			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 //***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	

		Pain.KillMe:
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			Goto Missile
		Pain.HurrDurrMeHazGrenaed: // an imp informing the surrounding monsters that he has caught a grenade and is holding it staring at it dumbly
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIfInventory("IsFiring", 1, "Pain.IsFiring")
			Goto Missile
		Death.KillMe:
		Death.Taunt:
		Death.Avoid:
		Death.YouMustDuck:
		Death.HurrDurrMeHazGrenaed: 

			// spin our minigun up menacingly then keel over dead while shooting the floor
			TNT1 A 0
			// the headbox does nothing at this point, but it can bleed!
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -1, 1, 43)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_PlaySound("grunt/sight", CHAN_VOICE)
			TNT1 A 0 A_PlaySound("CHAINSTA", CHAN_WEAPON)
			MPOS E 30 
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			Goto Death.Rare
			
			//TNT1 A 0 A_ChangeFlag("SOLID", 0)
			//TNT1 A 0 A_SpawnItem("ChaingunGuy") //***Che: TRAVESTY! Fully healing a nearly ded monster + breaking map scripting if it had a  special!
			//Stop
			
		Death.ExtremePunches:
		Death.DHFT:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			//TNT1 A 0 A_JumpIfInTargetInventory("HeavyStrikeRight", 1, "HeavyPunchRight")
			//TNT1 A 0 A_JumpIfInTargetInventory("HeavyStrikeLeft", 1, "HeavyPunchLeft") 
			//TNT1 A 0 A_JumpIfInTargetInventory("HeavyStrikeUpper", 1, "HeavyPunchUpper")
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_CustomMissile ("ExtremePunchedChaingunguy", 8, 0, random (175, 185), 2, random (10, 20))
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory
			Stop
			 
		Death.Blast:
		Death.SSG:
		Death.Railgun:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			MPSD A 1 A_Pain
			MPSD A 1 A_FaceTarget
			TNT1 A 0 A_SpawnItem("Muchblood2", 0, 40)
			
			TNT1 AAA 0 bright A_CustomMissile ("SuperGoreSpawner", 35, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 A 0 A_CustomMissile ("MeatDeath", 0, 0, random (0, 360), 2, random (0, 160))
			//TNT1 AAAA 0 A_CustomMissile ("XDeath1", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 A 0 A_CustomMissile ("XDeath2", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 A 0 A_CustomMissile ("XDeath3", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 AAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodMuchFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			//TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 46, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAA 0 A_CustomMissile ("FBD_Bloodmist", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 A 0 A_CustomMissile ("XDeathChainArm", 62, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathChaingunguyHeadOnXDeath", 62, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 
			TNT1 A 0 A_SpawnItemEx("BrutalizedCommandoBlasted",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory
			Stop
			
		StealthKill:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")			
			TNT1 A 0 A_JumpIfInTargetInventory("IsPlayer", 1, 1)
			Goto Death
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("GoSpecial", 1)
			TNT1 A 0 A_GiveToTarget("SKChaingunGuy", 1)
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_Die("Stealthy")
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory
			Stop
		Death.Stealthy:
			TNT1 A 0
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory and the scripts to run
			Stop
		
		Death.Ice:
		Death.Freeze:
		Death.Frost:
			//***Che: freeze deaths are permanent
			//TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
			//TNT1 A 0 A_ChangeFlag("SOLID", 0)
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItemEx("FrozenChaingunguy",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory and the scripts to run
			Stop
			
		Death.IOS_Frost: // EDAY final boss
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItemEx("PermafrostChaingunguy",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the spawned gore to access our inventory and the scripts to run
			Stop			
		
		Death.Massacre:
			Goto Death
		
		Death.PussyGrab:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Pain
			//TNT1 A 0 A_Chase("","") // jumps to idle if loses target!
			//TNT1 A 0 A_Pain
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_GiveToTarget("GrabbedAChaingunguy", 1)
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // wait for the scripts to run
			Stop
			
			
		LTGCheckExtreme: // extreme outfits, 25% chance to treat the player as naked on each attack.
			TNT1 A 0 A_JumpIfCloser(600, 1)
			Goto MissileContinueAfterLTGCheck
			TNT1 A 0 A_JumpIfInTargetInventory("LTGExtreme", 1, 1)
			Goto MissileContinueAfterLTGCheck
			TNT1 A 0 A_Jump(64, "LTGCheckB")
			Goto MissileContinueAfterLTGCheck
		LTGCheck:
			TNT1 A 0 A_JumpIfInTargetInventory("IsDressed", 1, "LTGCheckExtreme")
		LTGCheckB:	
			TNT1 A 0 A_JumpIfInventory("AlreadyPerformedLTGCatCall", 1, "LTGCheck2")
			
			TNT1 A 0 A_JumpIfCloser(900, 1)
			Goto MissileContinueAfterLTGCheck
			
			TNT1 A 0 A_GiveInventory("AlreadyPerformedLTGCatCall", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 3, 0, 40)

			TNT1 A 0 A_PlaySound("commando/catcall", CHAN_VOICE)
			TNT1 A 0 A_Jump(16, "LTGCheckRare")
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 38)
			CPBK A Random (60, 90) A_FaceTarget
			Goto See
		
		LTGCheckRare:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 36)
			CPBK BCBCBCBCBC 6 A_FaceTarget // a very rude hand motion
			Goto See

		LTGCheck2:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_PlaySound("commando/catcall", CHAN_VOICE)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 38)
			CPBK A Random (30, 90) A_FaceTarget
			TNT1 A 0 A_JumpIfTargetInLOS("MissileContinueAfterLTGCheck")
			Goto See				
	}
}

Actor ChaingunGuyRaisedByVile: FBD_ChaingunGuy {
	// a separate actor in case the raising fails due to insufficient space.
	// if i made the corpse itself play the raising animation 
	// and then spawning failed, it would look like a game bug.
	States 
	{
		Spawn:
			TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 5)
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_GiveInventory("TargetIsAFormerHuman", 1) //used by AOE DOT inflictors to reward players with soul ammo -- otherwise untraceable
			
			CPOS TSRQPO 3
			CPHM JA 3
			//CPOS NMLKJIH 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 ChaingunGuy1_PP: FBD_ChaingunGuy
{
	States
	{
		PotPourriSwap:
			TNT1 A 0
			Goto PotPourriCancel		
	}
}


//***Che: notably, chaingun guy corpses just explode into gore when destroyed. 
// There is no multi-step progression of gradual destruction, unlike imps or sombies. 

Actor FBD_DeadChaingunGuy1: FBD_CurbstompedMarine
{
    Radius 16 //***Che otherwise raising failures //12
    Height 12
    +SHOOTABLE
    +NOTELEPORT
    +MOVEWITHSECTOR
    +CORPSE
	+FLOORCLIP
	-SOLID
	+THRUACTORS
	damagefactor "Crush", 50.0
    Mass 1000
    Health 100
    damagefactor "Blood", 0.0
    damagefactor "Trample", 0.0
	States
		{
		//***Che
		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", 2002), "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 ("ChaingunGuyRaisedByVile",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, 11, 0, 0) //"ChaingunGuyRaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2002) // 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
			CPOD G 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
			CPOD G 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPOD G -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPOD GGG 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			// charred skeleton face down
			NJEX A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
				
	}
}

Actor DeadChaingunGuy_NoHead: FBD_DeadChaingunGuy1
{
	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
			CPHD F 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
			CPHD F 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPHD F -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPHD FFFF 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop				
	}
}
		
Actor DeadChaingunGuy_NoHeadEXPLODED: FBD_DeadChaingunGuy1
{
	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
			CPHS F 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
			CPHS F 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPHS F -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPHS FFF 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}
		
		

Actor DeadChaingunGuy_Half: FBD_DeadChaingunGuy1
{
	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
			CPHS F 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
			CPHS F 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPHS F -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPHS FFF 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}
		
Actor DeadChaingunGuyCPDRO: FBD_DeadChaingunGuy1
{
	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
			CPDR 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
			CPDR O 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPDR O -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)               
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPDR OOO 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop				
	}
}		


Actor BrutalizedDeadChaingunGuy: FBD_DeadChaingunGuy1
{
	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
			CFTB C 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
			CFTB C 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CFTB C -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CFTB CCCCC 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop				
	}
}

Actor SuperBrutalizedDeadChaingunGuy: FBD_DeadChaingunGuy1
{
	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
			CFTB D 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
			CFTB D 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CFTB D -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CFTB DDD 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}

Actor DeadChaingunGuy_KilledByMinorHead: FBD_DeadChaingunGuy1
{
	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
			CPHM F 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
			CPHM F 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPHM F -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPHM FFFF 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}

actor BrutalizedDeadCommando1: FBD_DeadChaingunGuy1
{
    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
			CPOD 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
			CPOD L 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPOD L -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPOD LLL 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}
	   
	   
actor BrutalizedCommandoLegs: FBD_DeadChaingunGuy1
{
    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
			CPOD S 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
			CPOD S 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPOD S -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPOD SSSS 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
			
		Death:
			TNT1 AA 0 A_CustomMissile ("XDeath1", 45, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2", 45, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3", 45, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeathChainLeg", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop   
	}
}
	   
	   
	   
	   
	   
	   
Actor DeadChaingunguy_Slumped: AbstractSlumpedBodyWithHeadbox //FBD_ZombiemanTorso
{
	+NOPAIN
	Health 200
	+NOBLOCKMONST
	Height 22
	Radius 6
	Scale 0.9
	States{
		Spawn:
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunMonster", 12) // dying guy headbox	
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 22, 1) // force create
		SitSlumped:
			TNT1 A 0
			TNT1 A 0 A_Recoil(6)
			BR95 A 6
			TNT1 A 0 A_JumpIf(momx < 0, "LayDown")
			TNT1 A 0 A_JumpIf(momy < 0, "LayDown")
			TNT1 A 0 A_JumpIf(momx > 0, "LayDown")
			TNT1 A 0 A_JumpIf(momy > 0, "LayDown")
			//TNT1 A 0 A_SpawnItemEx("HeadshotTarget20", 0, 0, 22)
			//***Che
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava", 0, 0, 0, 0)
			BR95 A 16
			TNT1 A 0 A_JumpIfInventory("IsOverLava", 1, "Death")
			Loop  
		LayDown:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItemEx("FBD_DeadChaingunGuy1",radius + 16,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // give the spawned corpse time to access our inventory
			Stop
		XDeath:
		Death.Explosives:
		Death.ExplosiveImpact:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItem("ChainXDeath")
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // give the spawned corpse time to access our inventory
			Stop	
		
		Death.Head:
		Death.HeadStun:
		Death.HeadPlasma:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItemEx("ChaingunguyHeadExplode", 0, 0, 22)
			TNT1 A 0 A_SpawnItem("DeadChaingunguy_Slumped_NoHead")
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // give the spawned corpse time to access our inventory
			Stop
			
		Death:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (150, 210), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 32, 0, random (150, 210), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("Xdeath3", 16, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodMuchFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("XDeathChainArm", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			//TNT1 A 0 A_SpawnItem("DeadChaingunguyJustLegsAreLeft")
			TNT1 A 30 // slumped bodies are not raiseable/respawnable
			Stop
	}
}
		
		
		
actor DeadChaingunguyMPSDD: FBD_DeadChaingunGuy1
{
    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
			MPSD D 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
			MPSD D 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			MPSD D -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			MPSD DDD 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
	}
}

actor DeadChaingunguyCPDEI: FBD_DeadChaingunGuy1
{
    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
			CPDE I 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
			CPDE I 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			CPDE I -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		LandOnLava:
			TNT1 A 0
			TNT1 AAA 0 A_SpawnItemEx("GoreLandingOnLava", random(-14, 14), random(-14, 14))
			CPDE IIII 10 A_CustomMissile ("SmallSmoke", 1, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("CharredMeatsplosion")
			TNT1 A 0 A_SpawnItem("GoryAshesSafe")
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}



		
Actor DeadChaingunguy_Slumped_NoHead: FBD_ZombiemanTorso
{
	+NOPAIN
	Height 22
	Scale 0.9
	States{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
		Sit:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("FBD_CheckFloorIsLava_V", 0, 0, 0, 0) // also spawns smoke for 30 tics if succeeds
			BR95 B 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")
			BR95 B 70
			Loop
		XDeath:
		Death.Explosives:
		Death.ExplosiveImpact:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
			TNT1 A 0 A_NoBlocking
			TNT1 A 30 A_SpawnItem("ChainXDeath")
			Stop	
		Death:
			TNT1 A 0 A_NoBlocking
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (150, 210), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 32, 0, random (150, 210), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("Xdeath3", 16, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("FBD_FlyingBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodMuchFaster", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), CMF_AIMDIRECTION, random (0, 40))
			TNT1 AAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("XDeathChainArm", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 90))
			//TNT1 A 0 A_SpawnItem("DeadChaingunguyJustLegsAreLeft")
			TNT1 A 30 // slumped bodies are not raiseable/respawnable
			Stop	
	}
}	   