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







ACTOR VilePotpourriChecker: AbstractPotpourriChecker
{
	Radius 20
	Height 56
}

Actor VileBossCubeSpawner: AbstractBossCubeSpawner
{
	Radius 20
	Height 56
	States
	{
		DoSummon:	
			TNT1 A 0 A_GiveInventory("SummonsCount", 1, AAPTR_TRACER)
			TNT1 A 0 A_SpawnItemEx("TeleportationFog")
			TNT1 A 1 A_SpawnItemEx("FBD_Archvile",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0,user_stid)
			Stop
	}
}

ACTOR ZandronumArchvile // ripped from zandronum.pk3
{
	Game Doom
	SpawnID 111
	Health 700
	Radius 20
	Height 56
	Mass 500
	Speed 15
	PainChance 10
	Monster
	MaxTargetRange 896
	+QUICKTORETALIATE 
	+FLOORCLIP 
	+NOTARGET
	SeeSound "vile/sight"
	PainSound "vile/pain"
	DeathSound "vile/death"
	ActiveSound "vile/active"
	MeleeSound "vile/stop"
	Obituary "$OB_VILE"
	States
	{
	Spawn:
		VILE AB 10 A_Look
		Loop
	See:
		VILE AABBCCDDEEFF 2 A_VileChase
		Loop
	Missile:
		VILE G 0 BRIGHT A_VileStart
		VILE G 10 BRIGHT A_FaceTarget 
		VILE H 8 BRIGHT A_VileTarget
		VILE IJKLMN 8 BRIGHT A_FaceTarget 
		VILE O 8 BRIGHT A_VileAttack
		VILE P 20 BRIGHT
		Goto See
	Heal:
		VILE "[\]" 10 BRIGHT
		Goto See
	Pain:
		VILE Q 5   
		VILE Q 5 A_Pain
		Goto See
	Death:
		VILE Q 7
		VILE R 7 A_Scream
		VILE S 7 A_NoBlocking
		VILE TUVWXY 7
		VILE Z -1
		Stop
	}
}


ACTOR FBD_Archvile: ZandronumArchvile 17624
{
	//***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 TehArchvile: FBD_Archvile Replaces Archvile {} in Doom_Replacements.txt
	
	//$category "FBD Monsters"
	
	Game Doom
	SpawnID 111
	//$Sprite DIABB1
	Tag "$ARCHVILE"
	Obituary "$ARCHVILE_O"
	Radius 20
	Height 56
	
	// so that he can be resurrected manually by simply setting the SOLID flag
	DeathHeight 56//4
	BurnHeight 56//0	
	
	
	MaxStepHeight 24
	MaxDropoffHeight 32
	
    damagefactor "Crush", 10.0
	damagefactor "Head", 1.2
	Mass 500
	Speed 15
	Health 700
	GibHealth 30
	PainChance 10
	PainChance "Kick", 90
	PainChance "HeadStun", 90	
	PainChance "Decaptate", 90
	damagefactor "Avoid", 0.0 PainChance "HangingHook", 0
	damagefactor "GibRemoving", 0.0
	DamageFactor "CauseSplash", 0.0 DamageFactor "CauseObjectsToSplashSlime", 0.0 DamageFactor "CauseObjectsToSplashNukage", 0.0
	DamageFactor "CauseObjectsToSplashBlood", 0.0 DamageFactor "CauseObjectsToSplashLava", 0.0
	BloodType "FBD_Blood", "FBD_SawBlood", "FBD_SawBlood"
	Monster
	MaxTargetRange 896
	+QUICKTORETALIATE 
	+FLOORCLIP 
	+NOTARGET
    DamageType Burn
	DropItem "DemonRuneMix", 5
	SeeSound "vile/sight"
	PainSound "vile/pain"
	DeathSound "vile/death"
	ActiveSound "vile/active"
	MeleeSound "vile/stop"
	damagefactor "TeleportRemover", 0.0
	//Obituary "%o was exploded by an Arch-Vile."
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0

	//Tag "Archvile"
	
	var int user_head_tid;
	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_rel;
	var int user_head_scale;	
	var int user_head_type;
	var int user_sleeping; // serverside only. If 1, the headbox adjust script clocks the headbox down. 
	 //If slaughtercount is higher that the cheating threshold (2400),
	 // then each head adjust decreases the headboxes countdown (the higher the slaughtercount, the faster)
	 // and delets it at the next call if the countdown had reached zero.
	 // After that, the headbox is only auto-created again when the monster wakes up 
	 //  (i.e. enters his See state with any player in LOS)
	var int user_item_no; // helps detecting lost scripts detached from their actor
	var int user_serverside_sfchk; // on client, always 0. 
	// on server, -1 means a command for DECORATE to perform A_RadiusGive,
	// 1 decorate replies it had performed A_RadiusGive
	// 4 the headbox adjust script signals it had deleted the headbox
	


	
	
	var int user_bleeding_angle; // this monster's, for head stun animation
	
	damagefactor "Argent", 0.0
	
	var int user_aggro_at_head; // required for the ACS script "FBD_TryReAggroAtHead"
	
	PainChance "Bullet792", 160 // machineguns and snip[er rifles not aimed
	PainChance "SniperBullet", 255 // sniper rifle aimed	

	
	damagefactor "Killme", 1.0 // AOE inflicted by captured marines
	PainChance "Killme", 255
	
	var int user_attacking; // a crutch to compensate for CheckActorState() not existing in Zandronum
	
	Species "Vile" // to avoid self-harm from lingering effects by superarchviles
	
	PainChance "Ice", 255
	
	States
	{
		Spawn:
			//***Che: fixed sript 177 ruining TIDs and thus scripted maps
			DIAB B 0 NODELAY ACS_NamedExecuteAlways("FBD_WolfensteinCheck")

			DIAB B 0 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", 5) // vile headbox
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile")
			
			
			//MARN A 0 ACS_ExecuteAlways(177, 0, 0, 0, 0)//Check if you are playing on an Wolfenstein level
			//TNT1 A 0 ACS_NamedExecuteAlways("FBD_WolfensteinCheck", 0, 0, 0, 0)
			DIAB B 7 // the fixed script does not break TID but runs longer, with delays
						// slaughtermap init takes 5 tics
			
			
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See
			
		Stand:	
			TNT1 A 0
			//TNT1 A 0 A_JumpIf(user_serverside_sfchk >= 4, "StandSfestExtreme") // extreme slaughtermap optimization
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			DIAB B 20 A_Look
			"----" A 0 A_JumpIf(!user_head_tid, "StandSfestExtreme")
			Loop
			
		StandSfestExtreme:
			DIAB BBBBBB 20 A_Look
			Loop		
		
		// archvile does NOT have "FallbackRaise" state so cannot be raised by AOE effects
		
		Raise:
			DIAB V 0
			TNT1 A 0 A_JumpIfInventory("IAmRaiseable", 1, "RaiseReally")
		RaiseJustKidding:
			DIAB V 1 A_ChangeFlag("CORPSE", 0)
			//Goto Death.CrushedBodies // latest GZDoom gives an error on this!
			Goto Death.Desintegrate
		RaiseReally:	
		
//***TODO: add a unique sound effect to this!
			TNT1 A 0 A_PlaySound("vile/active", CHAN_VOICE)
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunMonster", 5) 
			DIAB VUVWVUVWV 5
			DIAB UTSR 8
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_CustomizeOnRez") // it runs OnRezMapScript
				// if the map prpvides one			
			Goto See
		RespawnOnNightmare:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_head_tid", 0)
			TNT1 A 0 A_SetUserVar("user_head_type", 5) // vile headbox
			
			// provide special effects
			TNT1 A 0 A_SpawnItemEx("TeleportationFog",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			
			DIAB VUVWVUVWV 5
			DIAB UTSR 8
			Goto See
		ReplaceVanilla:
			//TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)
			//TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			//***Che: tsk, tsk. Breaking maps by losing monsters' TID and special? Not cool.
			//TNT1 A 0 A_SpawnItemEx ("VanillaArchvile",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERAMBUSHFLAG  ,0)
			//TNT1 A 0 A_SpawnItemEx ("VanillaArchvile",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERAMBUSHFLAG | SXF_TRANSFERSPECIAL ,0)
			TNT1 A 0 A_GiveInventory("IAmClassicMonster", 1)
			Goto Stand
		PotPourriSwap:
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
		PotPourriWait:	
			KYPP F 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 ("VilePotpourriSwapper",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
			
		Idle: // without this, the game engine puts him into his Spawn state when he loses target 
				//-- and that wrecks havok with the init scripts!
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
			TNT1 A 0 A_SetUserVar("user_attacking", 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			Goto Stand
		See:
			TNT1 A 0
			TNT1 A 0 A_TakeInventory("DuckYouFool", 1)
			TNT1 A 0 A_SetUserVar("user_attacking", 0)
			
		SeeContinue:	
			// slaughtermap manage
			
			// agressively check LOS to players and clock the headbox down
			// (because vile never falls dormant! had to place this chek somewhere)
			
			TNT1 A 0 A_CheckSight(3) 
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			TNT1 A 0 A_Jump(256, 3)
			TNT1 A 0 A_JumpIf(user_sleeping, 2)
			TNT1 A 0 A_SetUserVar("user_sleeping", 1) 
			
			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", 11, 0, 55)
			DIAB AA 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			DIAB BB 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck") // player ssg short-range tracer relayed by headbox
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 15, 4, 60)
			DIAB CC 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 0, 57)
			DIAB DD 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			
			//Copy-paste x2, to make the LOS check less frequent:
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 11, 0, 55)
			DIAB AA 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			DIAB BB 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 15, 4, 60)
			DIAB CC 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 0, 57)
			DIAB DD 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")

			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 11, 0, 55)
			DIAB AA 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			DIAB BB 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 15, 4, 60)
			DIAB CC 2 A_VileChase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 0, 57)
			DIAB DD 2 A_VileChase
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			
			TNT1 A 0 A_Jump(64, "MaybeFireAGhostSoul")
			
			Loop
		MaybeFireAGhostSoul: // to be overridden by descendant super viles
			TNT1 A 0
			Goto SeeContinue
		Missile:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_attacking", 1)
			TNT1 A 0 A_JumpIfInTargetInventory("IsInATank", 1, "MissileAntiTank")
			
			// agressively check LOS to players and clock the headbox down
			// (because vile never falls dormant! had to place this chek somewhere)
		
		MissileAntiTank: // regular viles do not change attack patterns. 
			//But superviles descending from this class switch to special anti-tank tactics

/*
			TNT1 A 0 A_CheckSight(3) 
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			TNT1 A 0 A_Jump(256, 3)
			TNT1 A 0 A_JumpIf(user_sleeping, 2)
			TNT1 A 0 A_SetUserVar("user_sleeping", 1) 	
*/			

			//***Che: attack bruisers and bosses by headshotting them
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_TryReAggroAtHead",1,1,TIDtoHate)
			
//			TNT1 A 0 A_JumpIfInventory("IAmSfestMonster", 1, "MissileSfest")
		
		GenericVileFlame:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -13, -1, 53)
			DIAB E 0 BRIGHT A_VileStart
			
			DIAB E 10 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck") // player ssg short-range tracer relayed by headbox	
			DIAB E 1 A_VileTarget 
			
			DIAB E 7 A_VileTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			
			DIAB E 1 A_VileTarget 
			
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB E 3 A_FaceTarget
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB F 3 BRIGHT A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB F 3 A_FaceTarget 
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB F 3 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			DIAB E 3 A_FaceTarget
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, 35, random (0, 40), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("SmallFlameTrails", 85, -35, random (0, 40), 2, random (0, 160))
			
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB F 3 BRIGHT A_FaceTarget
			
			DIAB J 3 BRIGHT A_FaceTarget 
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 21, 6, 41)
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB KL 3 BRIGHT A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB M 3 BRIGHT A_FaceTarget 
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, -3, 49)
			DIAB N 3 BRIGHT A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB O 3 BRIGHT A_VileAttack
			DIAB P 3 BRIGHT
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, 1)
			Goto See
			DIAB P 24
			Goto See
			
/*		
		MissileSfest:	
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_attacking", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -13, -1, 53)
			DIAB E 0 BRIGHT A_VileStart
			DIAB E 10 A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck") // player ssg short-range tracer relayed by headbox
			DIAB E 1 A_VileTarget
			DIAB E 7 A_VileTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB E 1 A_VileTarget 
			DIAB E 3 A_FaceTarget
			DIAB F 3 BRIGHT A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			DIAB F 3 A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			DIAB F 3 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB E 1 A_VileTarget 
			DIAB E 3 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB F 3 BRIGHT A_FaceTarget
			DIAB J 3 BRIGHT A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 21, 6, 41)
			DIAB KL 3 BRIGHT A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB M 3 BRIGHT A_FaceTarget 
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, -3, 49)
			DIAB N 3 BRIGHT A_FaceTarget 
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "DuckFlameInterrupted")
			DIAB O 3 BRIGHT A_VileAttack
			DIAB P 3 BRIGHT
			TNT1 A 0 A_JumpIfInventory("DuckYouFool", 1, "Duck")
			TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, 1)
			Goto See
			DIAB P 24
			Goto See		
*/			
		Heal:
			TNT1 A 0 
			TNT1 A 0 A_SpawnItem("PentagramSpawner") // spawns *in front* of the vile
				// as per A_SpawnItem with distance of zero
				// (uses vile radius + pentagram radius)
			
			
			//***Che: the frame DIBR X here is radically different from DIBR X in BD21!
			// I frankensteined horns to retouched DIBR X from BD 22 
			//   where he holds his arms out instead of up.
			// The arms up frame is now DIBR Y, only used in derivative archviles
			//   for extra nasty attacks
			//   like a BFG-like AOE mass resurrection
			DIBR X 10 BRIGHT ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -8, 0, 60)
			
			//DIBR Y 10 requires ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -20, 0, 60)
			
			// old BD21 frame //ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -15, 0, 50)
			
			// this makes him too too brokenly OP
			//TNT1 A 0 A_CustomMissile("AoeRaiseInflictorShortRange", 60, 0, angle, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, -90)	
			
			Goto See
		DuckFlameInterrupted:
			TNT1 A 0
			TNT1 A 0 A_VileTarget("FlamethrowerBurningStuffNoSelfHarm") // spawn damaging fire at the target (see Fire.txt)	
		Duck:
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 1)
			TNT1 A 0 A_Recoil(2)
			DIAB Y 10 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 9, 0, 37) // z from hitbox height - headbox height - 1, not from the sprite!
		LeapBackAndSpray:
			TNT1 A 0
			DIAB Y 1 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 9, 0, 37)
			DIAB Y 1 A_FaceTarget
			TNT1 A 0 ThrustThingZ(0,20,0,1)
			TNT1 A 0 A_Recoil(12)
			DIAB Y 4 // otherwise check floor fires before he lifts off
			DIAB YYYYYYYYYYYYYYYYYYYYYYY 2 A_CheckFloor("LandFromTheLeapAndFire")
		LandFromTheLeapAndFire:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -8, 0, 60)
			DIBR X 5 BRIGHT A_CustomMissile("SummoningFlash_1", 50, 0, angle, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -20, 0, 60)
			DIBR Y 5 BRIGHT A_CustomMissile("SummoningFlash_2", 50, 0, angle, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, 0)
			
			// not just a lost soul, a *minion* lost soul!
			DIBR Y 10 A_PainAttack("InstaAggroMinionLostSoul") 
				//A_PainAttack
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			TNT1 A 0 A_TakeInventory("DuckYouFool", 1)
			Goto Missile // and then start flaming immediately!
		Pain:
			TNT1 A 0
			TNT1 A 0 A_TakeInventory("DuckYouFool", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -19, -7, 54)
			DIAB Q 5   
			DIAB Q 5 A_Pain
			Goto See

		Pain.Kick:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -19, -7, 54)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil(8)
			DIAB Q 10 A_Pain  
			DIAB Q 10
			Goto See
		
		Pain.Decaptate: // head hit with chainsaw or axe
		Pain.HeadStun: //headshot inflicted > 250 damage && advanced headshot profile chosen in settings
			TNT1 A 0
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 54, -7, random(0,360), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (-90, 90))
			TNT1 A 0 A_SetUserVar("user_bleeding_angle", random(-80, 80))
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -19, -7, 54)
			TNT1 A 0 A_Jump(128, 14)
			DIAB QQQQQQ 3 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (25, 45))
			TNT1 A 0 A_Pain
			DIAB QQQQQQ 3 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (35, 55))
			TNT1 A 0 A_Pain
			DIAB QQQQQQ 3 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (25, 45))
			TNT1 A 0 A_Pain
			DIAB QQQQQ 3 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (35, 55))
			DIAB QQQQ 6 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (45, 55))
			DIAB QQQQ 8 A_CustomMissile ("Brutal_LiquidBlood2", 54, -7, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (25, 35))
			Goto Missile
			
		Death.Head: // splatter brains, then fall with a mangled head
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_PlaySound("misc/xdeath4")
			TNT1 AAAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 40, 0, random (0, 360), 2| CMF_TRACKOWNER, random (30, 90))
			TNT1 A 0 A_CustomMissile ("Brains2", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("Brains3", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("SmallBrainPieceFast", random (45, 55), random (5, -5), random (170, 190), 2, random (-10, 10))
			TNT1 AAAAA 0 A_CustomMissile ("SmallBrainPiece", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("Teeth", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			VID2 ABCDE 4
			//TNT1 A 0 A_SpawnItem("FBD_DeadArchvileVID2G")
			TNT1 A 3 A_SpawnItemEx ("FBD_DeadArchvileVID2G",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			//TNT1 A -1
			Stop
		
		Death.HeadStun: //***Che splatter brains, then fall without a head
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_PlaySound("misc/xdeath4")
			TNT1 AAAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 40, 0, random (0, 360), 2| CMF_TRACKOWNER, random (30, 90))
			TNT1 A 0 A_CustomMissile ("Brains2", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("Brains3", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("SmallBrainPieceFast", random (45, 55), random (5, -5), random (170, 190), 2, random (-10, 10))
			TNT1 AAAAA 0 A_CustomMissile ("SmallBrainPiece", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("Teeth", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking

			Goto BeheadedFall
			
		Death.Decaptate: //***Che spawn a head projectle, then fall without a head 
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_PlaySound("misc/xdeath4")
			TNT1 AAAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 40, 0, random (0, 360), 2| CMF_TRACKOWNER, random (30, 90))
			//TNT1 A 0 A_CustomMissile ("XDeathArchvileHead", 56, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileHead", 0,0,56, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
		
		BeheadedFall: //***Che uses new sprites frankensteined by Chebmaster from BD22's VID2	
			VYD2 ABCDE 4
			TNT1 A 3 A_SpawnItemEx ("FBD_DeadArchvileVYD2G",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			
			//TNT1 A -1
			Stop			

		Death:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Jump(64, "Death.ARm")
			
		Death.Simple:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Scream 
			TNT1 A 0 A_NoBlocking
			DIAB RSTUVWX 5 A_CustomMissile("MuchBlood", 40, 0, random (0, 360), 2, random (0, 160))//A_SpawnItem ("MuchBlood", 40)
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			//TNT1 A 0 A_SpawnItem("FBD_DeadArchvile")
			TNT1 A 30 A_SpawnItemEx ("FBD_DeadArchvile",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			//TNT1 A -1
			Stop
			
		
		Death.Arm:
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun:
			TNT1 A 0
			TNT1 A 0 A_Scream 
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_NoBlocking
			TNT1 AA 0 A_CustomMissile ("XDeath1", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			//TNT1 A 0 A_CustomMissile ("XDeathArchvileArm", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 AAA 0 A_CustomMissile ("MuchBlood", 50, 0, random (0, 360), 2, random (0, 160)) //A_SpawnItem ("MuchBlood", 50)
			VID2 HHIJ 5
			
			//***Che: this was FAILING RELIABLY, resulting in archvile vanishing and only his arm remaining
			//TNT1 A 0 A_SpawnItem("DyingArchvileNoArm")
			
			// the dying archvile, too, checks our inventory for the raiseable marker
			TNT1 A 30 A_SpawnItemEx ("DyingArchvileNoArm",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			//TNT1 A -1
			Stop
			
		Death.Shotgun:
		Death.SSG:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Jump(96, "Death.ARm")
			TNT1 A 0 A_Jump(96, "Death.Cut")
			TNT1 A 0 A_JumpIfInTargetInventory("SSGSelected", 1, "BrutalDeath")
			TNT1 A 0 A_Jump(96, "BrutalDeath")
			TNT1 A 0
			Goto Death
		
		Death.Desintegrate: // bfg9k, unmaker
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Scream
			TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
			TNT1 AA 0 A_SpawnItemEx("TinyBurningPiece", random (-15, 15), random (-15, 15))
			TNT1 AAA 0 A_SpawnItemEx("TinyBurningPiece2", random (-35, 35), random (-35, 35))
			Goto RippedOpen
			
		Death.Cut:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Scream
			//TNT1 A 0 A_CustomMissile ("XDeathArchvileArm", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			//TNT1 A 0 A_CustomMissile ("XDeathArchvile", 42, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvile", 0,0,42, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			Goto RippedOpen	
			
		Death.Deletus:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_NoBlocking
			TNT1 A 30 // give the script time to run
			Stop	
			
		BrutalDeath:
		Death.Saw:
		Death.Blast:
			
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItem("SplatteredLarge")
			TNT1 A 0 A_Scream
			//TNT1 AA 0 A_CustomMissile ("XDeathArchvileArm", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			//TNT1 A 0 A_CustomMissile ("XDeathArchvileHead", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileHead", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
		RippedOpen:
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_CustomMissile ("XDeath2", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeath3", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 40, 0, random (0, 360), 2, random (0, 160))//A_SpawnItem("MuchBlood2", 0, 40)
			TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), 2, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), 2, random (60, 120))
			TNT1 A 0 A_NoBlocking
			VID3 A 3
			VID3 AAAAAAAAAAAAAAAAAAAAA 2 A_CustomMissile ("Brutal_LiquidBlood", 46, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 45))
			VID3 BCDEFGHIJK 3
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 30 A_SpawnItemEx("FBD_DeadArchvileVID3L",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			//TNT1 A -1
			Stop


		XDeath:
		Death.ExplosiveImpact: // rocket splash
		Death.FriendlyExplosion:
		Death.Explosives: // revenant fireball
		Death.Bfg10k: //***Che changed damage type from extreme to custom	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")			
			TNT1 A 0 A_SpawnItem("SplatteredLarge")
			TNT1 A 0 A_XScream
			TNT1 A 0 A_Jump(96, "Death.Saw")
			
			//***Che: palette-shiftability required by descendant superviles
			
			//TNT1 A 0 A_CustomMissile ("XDeathArchvile", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvile", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			//TNT1 A 0 A_CustomMissile ("XDeathArchvileArm", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)	
			//TNT1 AA 0 A_CustomMissile ("XDeathArchvileLeg", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 120))
			TNT1 AA 0 A_SpawnItemEx ("XDeathArchvileLeg", 0,0,32, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_CustomMissile ("XDeath2", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeath3", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 40, 0, random (0, 360), 2, random (0, 160))//A_SpawnItem("MuchBlood2", 0, 40)
			TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), 2, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), 2, random (60, 120))
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SpawnItem ("BigBloodSpot")
			// | SXF_TRANSFERTRANSLATION
			
			// prevent vile raising but not nightmare respawning
			TNT1 A 0 A_JumpIfInventory("IAmRaiseable", 1, 2)
			TNT1 A 0 A_ChangeFlag("CORPSE", 0)
			TNT1 A -1 //***Che: ChebMaster's blunder of a lifetime: produces an invulnerable ghost! ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		
			
		Death.SuperPlasma:
		Death.Plasma: 
		Death.Plasma2:
		Death.HeadPlasma:
		Death.Electric:
		
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItem("BarrelExplosionSmokeColumn")
			TNT1 AA 0 A_SpawnItemEx("TinyBurningPiece", random (-15, 15), random (-15, 15))
			TNT1 AAA 0 A_SpawnItemEx("TinyBurningPiece2", random (-35, 35), random (-35, 35))
			TNT1 AAAA 0 A_CustomMissile ("BluePlasmaFireNonStatic", 42, 0, random (0, 360), 2, random (0, 180))
			TNT1 A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_Stop
			TNT1 AA 0 A_SpawnItemEx("TinyBurningPiece3", random (-45, 45), random (-45, 35))
			TNT1 A 0
			TNT1 A 0 A_Scream
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_CustomMissile ("XDeathBurnedMeat", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 40, 0, random (0, 360), 2, random (0, 160))//A_SpawnItem("MuchBlood2", 0, 40)
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), 2, random (60, 120))
			TNT1 A 0 A_NoBlocking
			XVIP ABCDEFGHIJKLMNOPQ 2 
			
			// prevent vile raising but not nightmare respawning
			TNT1 A 0 A_JumpIfInventory("IAmRaiseable", 1, 2)
			TNT1 A 0 A_ChangeFlag("CORPSE", 0)
			XVIP Q -1 //***Che: ChebMaster's blunder of a lifetime: produces an invulnerable ghost! ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
			
		Death.Fire:
		Death.Burn:
		Death.Flames:
			TNT1 A 0
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_Playsound("props/redfire")
			TNT1 AAA 0 A_CustomMissile ("FBD_FlyingBlood", 50, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat3", 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 ("XDeathBurnedMeat", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			CARB MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 2 A_CustomMissile ("FlameTrails", 15, 0, random (0, 360), CMF_AIMDIRECTION, random (70, 130))
			CARB MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 10 A_CustomMissile ("SmallSmoke", 15, 0, random (0, 360), CMF_AIMDIRECTION, random (70, 130))
			
			// prevent vile raising but not nightmare respawning
			TNT1 A 0 A_JumpIfInventory("IAmRaiseable", 1, 2)
			TNT1 A 0 A_ChangeFlag("CORPSE", 0)
			CARB M -1 //***Che: ChebMaster's blunder of a lifetime: produces an invulnerable ghost! ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop

		Death.Fatality:
			TNT1 A 0 A_Pain
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_JumpIfIntargetInventory("FistsSelected", 1, 1)
			Goto BrutalDeath
			TNT1 A 0 A_FaceTarget
			//TNT1 AAAA 0 A_SpawnItemEx("HealthPlusFatalityBonus", 0,0,20, random (-1, 1),random (-1, 1),8, 0, SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION)
			//TNT1 AAAA 0 A_SpawnItemEx("ArmorShardFatalityBonus", 0,0,20, random (-1, 1),random (-1, 1),8, 0, SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION)
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_Jump(128, "Death_Fatality2")
			TNT1 A 0 A_GiveToTarget("ArchvileFatality", 1) // deliberately chosen NOT to make fatalized archviles raiseable
			TNT1 A 0 ACS_NamedExecuteAlways("DropFatalityBonuses", 0, 20, 20, 0) // 0, health, armor, 0 -- rounded down to nearest 2
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop
			
		
		Death_Fatality2:
			TNT1 A 0
			TNT1 A 0 A_GiveToTarget("ArchvileFatality2", 1)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			
			Stop
			
			

		Crush:
			TNT1 A 0
			TNT1 AAAA 0 A_SpawnItemEx ("BodyRemovalThing",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 1 A_XScream
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop

		Pain.KillMe:
		Pain.Taunt:
			TNT1 A 0 HealThing(1)
			Goto Missile
		Death.KillMe:
		Death.Taunt:
		
		// these two only concern descendant super viles
		Death.Avoid:
		Death.RailAvoid:
			//TNT1 A 0 A_ChangeFlag("SOLID", 0)
			//TNT1 A 0 A_SpawnItem("ArchVile")
			//Stop
			
			// pretend to attack, then keel over dead
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			DIAB E 0 BRIGHT A_VileStart
			DIAB E 10 A_FaceTarget 
			DIAB E 1 A_VileTarget 
			DIAB E 7 A_VileTarget
			DIAB E 1 A_VileTarget 
			DIAB E 3 A_FaceTarget
			DIAB F 3 
			TNT1 A 30 A_Die
			Wait // Surprise, surprise: Zandronum multiplayer client *skips* A_Die, as it does the jumps!

		
		Death.Ice:
		Death.Freeze:
		Death.Frost:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			//TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
			//TNT1 A 0 A_ChangeFlag("SOLID", 0)
			TNT1 A 0 A_NoBlocking //***Che in my version, freeze death is permanent
			TNT1 A 0 A_SpawnItemEx ("FrozenArchvile",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop
	}
}

ACTOR VileRaisedByVile: Fbd_ArchVile {
	States {
		Spawn:
			DIAB V 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 5) // vile headbox //ACS_NamedExecuteAlways("SlaughtermapInit", 0, -1, 0, 0) // do not increase global count
			
			TNT1 A 0 A_SetUserVar("user_head_type", 5) // vile headbox
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile", 1)
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) // obviously
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			DIAB VUVWVUVWV 5
			DIAB UTSR 8
			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 VileRaisedByScript: Fbd_ArchVile {
	States {
		Spawn:
			DIAB V 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 5) // vile headbox //ACS_NamedExecuteAlways("SlaughtermapInit", 0, -1, 0, 0) // do not increase global count
			
			TNT1 A 0 A_SetUserVar("user_head_type", 5) // vile headbox
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile", 1)
			// skip marking as raiseable
			
			// provide special effects
			TNT1 A 0 A_SpawnItemEx("TeleportationFog",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			DIAB VUVWVUVWV 5
			DIAB UTSR 8
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_CustomizeOnRez") // it runs OnRezMapScript
				// if the map prpvides one
			Goto Idle		
	}
}


ACTOR FBD_ArchvileFire2 Replaces ArchvileFire
{
	Game Doom
    Scale 1.0
	+NOBLOCKMAP +NOGRAVITY
	RenderStyle Add
	
	Alpha 0.8
	States
	{
	Spawn:
		TNT1 A 1 bright A_StartFire
		INFE ABCDEF 1 bright A_Fire
		INFE G 1 bright A_FireCrackle
		INFE HIJKLM 1 bright A_Fire
		INFE N 1 bright A_FireCrackle
		INFE OPQRS 1 bright A_Fire
		INFE T 1 bright A_FireCrackle
		TNT1 A 2
		Stop
		
	}
}

actor FBD_DeadArchvile: FBD_CurbstompedMarine
{
	Radius 20 //***Che otherwise raising failures
	-CORPSE // sets this only if spawner has IAmRaiseable in its inventory
	States
    {
		//***Che
		Raise: 
			// ! The ancestor class does *already* have a raise state
			
			// Archviles will count archvile corpses as raiseable, and try raising them
			// BUT the corpses just asplode unless left by a special archvile
			// or you play on a Hordes/Doubles difficulty.
			
			"----" A 0
			// a double check
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			
			"----" A 0 A_JumpIfInventory("IAmRaiseable", 1, 1)
			Goto FadeOutAndVanish 
			
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_NoBlocking // the raising code deep in C++ makes it solid
			"----" A 0 A_JumpIf(!CallAcs("EnoughSpaceToRezNormally", 2006), "FallbackRaise") //NOTE: if there *is* enough space, this script shifts the activator to precisely align to integer x,y, up to ~0.9999 map units
			// 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 ("VileRaisedByVile",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_ChangeFlag("CORPSE", 0)
			"----" A 0 A_JumpIfInventory("IAmRaiseable", 1, 1)
			Goto FadeOutAndVanish
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2006) // see _mob_list.xlsx
			Stop			
			
		RespawnOnNightmare:
			// the special effects are provided by the raised actor
			"----" A 0
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			
			"----" A 3 A_SpawnItemEx ("VileRaisedByScript",0,0,0) // deliberately NOT using the nocheckposition flag to fail if there is not enough space
			"----" A 10 // wait 10 tics to be destroyed by the spawned monster
			"----" A 0 A_ChangeFlag("SHOOTABLE", 0)
			//"----" A -1 ACS_NamedExecuteAlways("FallbackRez", 0, 3, 0, 0) //"VileRaisedByScript"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRezMkII", 2007) // see _mob_list.xlsx
			Stop

		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmarer respawn ACS scripts require this for vile corpses
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			DIAB X 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
			DIAB X 30
			"----" A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			DIAB X -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
			
			
		//***Che: cloning (and modifying to emit correct body parts)
		//  *all* death states from the ancestor because the CORPSE flag needs special treatment!
		
		Death:	
		Death.ExplosiveImpact:
		Death.FriendlyExplosion:
			TNT1 A 0
			TNT1 A 0 A_SpawnItem("Gibz")
			TNT1 A 0 A_NoBlocking
			TNT1 AA 0 A_CustomMissile ("XDeath1", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2b", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvile", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 AA 0 A_SpawnItemEx ("XDeathArchvileLeg", 0,0,32, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)
			TNT1 AAAAAAAA 0 A_CustomMissile ("SmallSuperGore", 10, 0, random (0, 360), 2, random (10, 170))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistSmall", 35, 0, random (0, 360), 2, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 15, 0, random (0, 360), 2, random (0, 60))
			TNT1 A 3 A_SpawnItem("MediumBLoodSpot", 0, 10)
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop

		Death.plasma:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
		Death.Electric:
		
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_CustomMissile ("XDeathBurnedMeat", 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 AAA 0 A_CustomMissile ("ExplosionSmoke", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 360))
			TNT1 A 3
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop
		Death.TeleportRemover:
		Death.GibRemoving:
			TNT1 A 0
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_ChangeFlag("NOCLIP", 1)
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
			TNT1 A 0 A_ChangeFlag("NOBLOCKMAP", 1)
			Stop
			

			TNT1 AAAAA 0 A_CustomMissile ("XDeath1", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 30))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 30))
			TNT1 AAAA 0 A_CustomMissile ("FBD_Bloodmist", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 30))
			TNT1 AAAAAAA 0 A_CustomMissile ("XDeathSkinPiece2", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (10, 30))
			TNT1 AAAA 0 A_CustomMissile ("XDeathSkinPiece1", 5, 0, random (0, 360), CMF_AIMDIRECTION, random (10, 130))
			TNT1 AAAA 0 A_CustomMissile ("SmallSuperGore", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (10, 30))
			TNT1 A 0 A_SpawnItem("SplatteredSmall")
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop
			 
		Death.Desintegrate: // bfg9k, unmaker
			TNT1 A 0
			TNT1 AAAA 0 A_CustomMissile ("Brutal_FlyingBloodFake", 0, 0, random (0, 360), 2, random (0, 90))
			TNT1 A 0 A_CustomMissile ("FBD_FlyingBlood", 7, 0, random (0, 360), 2, random (30, 60))
			TNT1 AA 0 A_CustomMissile ("BloodMistSmall", 7, 0, random (0, 360), 2, random (30, 60))
			TNT1 A 0 A_SpawnItem("Gibz")
			TNT1 A 0 A_SpawnItem("MeatDeathSmall")
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop	
			 
			 
		Death.CrushedBodies: // AOE (8 in a radius of 10) inflicted by BodyRemovalThing, 
			// which is spawned by all monsters in the end of their Crush state, 
			// which they enter when crushed by ceiling
			
			TNT1 A 0 A_NoBlocking
			TNT1 AA 0 A_SpawnItem("MeatDeathSmall")
			
			TNT1 A 0 A_SetAngle(0)
			TNT1 A 0 bright A_CustomMissile ("SuperGoreSpawner2", 1, -40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 bright A_CustomMissile ("SuperGoreSpawner2", 1, 40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 A_CustomMissile ("XDeath1", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2b", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 1, -40, random (0, 360), 2, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 1, 40, random (0, 360), 2, random (30, 90))
			TNT1 A 0 A_SetAngle(90)
			TNT1 A 0 bright A_CustomMissile ("SuperGoreSpawner2", 1, -40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 bright A_CustomMissile ("SuperGoreSpawner2", 1, 40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 A_CustomMissile ("XDeath1", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2b", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 1, -40, random (0, 360), 2, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 1, 40, random (0, 360), 2, random (30, 90))
			TNT1 A 0 A_SpawnItem ("CrushedRemains")
			TNT1 A 1
			TNT1 A 1 A_XScream
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop 		
		
		
		LandOnLava:
			"----" A 0
			"----" AAA 0 A_SpawnItemEx("BloodDropLandingOnLava", random(-16, 16), random(-16, 16)) // short lived smoking fires, clientside
			"----" A 1 A_Jump(256, "Death.Burn") // descendants may (rarely) override Death.Burn
			Wait
		Death.Burn:
		Death.Fire:
		Death.Flames:
			TNT1 A 0 A_SpawnItemEx ("GoryAshesSafe",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			Goto Death.Plasma // goto is NOT inheritance-aware
			
		Death.Freeze:
		Death.Ice:
		Death.Frost:
		Death.IOS_Frost:
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_PlaySound ("ice/crackle/short")
			TNT1 AAAAAAAAAAAAA 0 A_CustomMissile ("XIceChunk1", 12, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAAAAAAAAAA 0 A_CustomMissile ("XIceChunk2", 12, 0, random (0, 360), 2, random (0, 160))
			
			// size 2x
			TNT1 AAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("XIceChunk2b", 12, 0, random (0, 360), 2, random (0, 160))
			
			TNT1 AAAAAAAAAAAAA 0 A_CustomMissile ("XIceChunk3", 12, 0, random (0, 360), 2, random (40, 120))
			TNT1 A 1
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare")
			Stop			
	}
}
	   
	   

	   
	   
	   
	   
actor FBD_DeadArchvileXVILQ: FBD_DeadArchvile
{
	States
	{
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmarer respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			XVIL Q 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
			XVIL Q 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			XVIL Q -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}	 
	   
	   
actor FBD_DeadArchvileVIGIJ: FBD_DeadArchvile
{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VIGI J 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
			VIGI J 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VIGI J -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}	 
	   




actor FatalizedArchVile1: FBD_DeadArchvile //FBD_CurbstompedMarine
{
    Radius 20 //***Che otherwise raising failures
	States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			AVF1 Z 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
			AVF1 Z 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			AVF1 Z -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}
	   
	   
	   
actor ArchvileStabbedTheFuckOut: FBD_DeadArchvile //FBD_CurbstompedMarine
{
    Radius 20 //***Che otherwise raising failures
	States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			AVF2 T 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
			AVF2 T 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			AVF2 T -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}
	   	   
		   
		   
		   
actor FBD_DeadArchvileVID3Q: FBD_DeadArchvile 17790 // used in some EDAY maps as a prop
	// invoked from: 
	// DyingArchvileNoArm.{Death.Head,Death.HeadStun,Death.HeadPlasma,Death.Decaptate}@ArchVile.txt


{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VID3 Q 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
			VID3 Q 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VID3 Q -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		Death:	
		Death.ExplosiveImpact:
		Death.FriendlyExplosion:

			// This corpse has no head and so it must not spawn the "torso with head" piece

			TNT1 A 0
			TNT1 A 0 A_SpawnItem("Gibz")
			TNT1 A 0 A_NoBlocking
			// more meat chunks instead
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 5, 0, random (0, 360), 2, random (0, 160))
			
			// This corpse has no head!
			//TNT1 A 0 A_SpawnItemEx ("XDeathArchvile", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvileArm", 0,0,52, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 AA 0 A_SpawnItemEx ("XDeathArchvileLeg", 0,0,32, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)
			TNT1 AAAAAAAA 0 A_CustomMissile ("SmallSuperGore", 10, 0, random (0, 360), 2, random (10, 170))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistSmall", 35, 0, random (0, 360), 2, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("BloodMistBig", 15, 0, random (0, 360), 2, random (0, 60))
			TNT1 A 3 A_SpawnItem("MediumBLoodSpot", 0, 10)
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop
			
			
	}
}
	   
	   

actor FBD_DeadArchvileVID2G: FBD_DeadArchvileVID3Q //FBD_DeadArchvile // head split like a melon

	// invoked from: TehArchvile.{Death.Head,Death.HeadStun}@ArchVile.txt

{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VID2 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
			VID2 G 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VID2 G -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop   
	}
}
	   
actor FBD_DeadArchvileVYD2G: FBD_DeadArchvileVID3Q //FBD_DeadArchvile 
	// beheaded -- new sprites frankensteined from VID2 by Chebmaster
	// invoked from: TehArchvile.Death.Decaptate@ArchVile.txt
{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
			TNT1 A 0 A_RearrangePointers (AAPTR_NULL, AAPTR_DEFAULT, AAPTR_DEFAULT, 0)
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VYD2 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
			VYD2 G 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VYD2 G -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop			
	}
}

	   
	   
actor FBD_DeadArchvileVID2O: FBD_DeadArchvile
	
	// invoked from: 

{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VID2 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
			VID2 O 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VID2 O -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
	}
}		   
	   
	   
actor FBD_DeadArchvileVID3L: FBD_DeadArchvile
{
    States
    {
		//***Che // this is a descendant of FBD_CurbstompedMarine, which is neither a missile nor a monster
		Spawn:
			TNT1 A 0 NODELAY A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0  
			TNT1 A 0 A_GiveInventory("EnemyIsArchvile") // the nightmare respawn ACS scripts require this for vile corpses
			// become autonomous from our spawner by eraseing our target pointer
			TNT1 A 0 A_RearrangePointers (AAPTR_NULL, AAPTR_DEFAULT, AAPTR_DEFAULT, 0)
		Stay: // ancestor's Pain.Kick, Pain.ExplosiveImpact and Pain.Trample redirect here after z-thrusting the actor
			VID3 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
			VID3 L 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: do NOT play with flags here -- see Spawn
			VID3 L -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
			
		
		
		Death:	
		Death.ExplosiveImpact:
		Death.FriendlyExplosion:

			//***Che: this corpse is little else that two legs connected by a small amount of meat.
			// it should NOT spawn guts nor arms!

			TNT1 A 0
			TNT1 A 0 A_NoBlocking
		
			TNT1 AA 0 A_SpawnItemEx ("XDeathArchvileLeg", 0,0,32, random(-5,5),random(-5,5),random(2,4), 0,SXF_TRANSFERTRANSLATION,0)
			TNT1 AAA 0 A_CustomMissile ("SmallSuperGore", 10, 0, random (0, 360), 2, random (10, 170))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistSmall", 35, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("BloodMistBig", 15, 0, random (0, 360), 2, random (0, 60))
			TNT1 A 0 A_SpawnItem("MediumBLoodSpot", 0, 10)
			
			//***Che: do NOT play with flags here -- see Spawn
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)		
			Stop		
	}
}	   

ACTOR DyingArchvileNoArm: Fbd_ArchVile //TehArchvile
{
    Radius 12
    Height 52
    Speed 9
	Health 50
	-COUNTKILL
	+GHOST
	+THRUGHOST
	+THRUACTORS
	-ISMONSTER // allows us receiving the spawner as our target,
		// vital for checking his inventory
		// will set this flag later
	Mass 500
	DeathHeight 4
	BurnHeight 0
    States
    {
	
		Spawn:
			TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 12)  // dying guy headbox, now the same as default headbox //ignores the SOLID snd CORPSE flags
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
		AfterSpawn:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInTargetInventory("IAmRaiseable", 1, 1)
			Goto AfterSpawn2
			TNT1 A 0 A_GiveInventory("IAmRaiseable", 1) 
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
		AfterSpawn2:
			TNT1 A 0 
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 1) // required for headbox
			
			TNT1 A 0 A_FaceTarget
			//TNT1 A 0 ACS_NamedExecuteAlways("FrankenHeadForceCreate", 0, 0, 4, 45) 
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 4, 45, 1) // force create
			// CMF_TRACKOWNER here is a cheap way to make the blood itself slaughter-aware (by checking the monster's inventory)
			VID2 KKKLLL 2 A_CustomMissile ("Brutal_LiquidBlood", 24, 0, random (0, 360), 2, random (0, 45))
			VID2 KKKLLL 2 A_CustomMissile ("Brutal_LiquidBlood", 24, 0, random (0, 360), 2, random (0, 45))
			VID2 KKKLLL 2 A_CustomMissile ("Brutal_LiquidBlood", 24, 0, random (0, 360), 2, random (0, 45))
			VID2 KKKLLL 2 A_CustomMissile ("Brutal_LiquidBlood", 24, 0, random (0, 360), 2, random (0, 45))
			VID2 KKKLLL 2 A_CustomMissile ("Brutal_LiquidBlood", 24, 0, random (0, 360), 2, random (0, 45))
			
		Death: 
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			VID2 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			VID2 MN 6
			TNT1 A 0 A_SpawnItemEx("FBD_DeadArchvileVID2O",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without a *large* margin scripts run ownerless
			Stop
			 
		Death.Desintegrate:
		Death.HeadPlasma:
			TNT1 A 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))
		
		Death.HeadStun:
		Death.Head:
		Death.Decaptate:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_PlaySound("misc/xdeath4")
			TNT1 AAAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAAAA 0 A_CustomMissile ("FBD_FlyingBlood", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 A 0 A_CustomMissile ("Brains2", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("Brains3", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("SmallBrainPieceFast", random (45, 55), random (5, -5), random (170, 190), 2, random (-10, 10))
			TNT1 AAAAA 0 A_CustomMissile ("SmallBrainPiece", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("Teeth", 40, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_CustomMissile ("XDeath3b", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 A 0 A_XScream
			TNT1 A 0 A_NoBlocking
			VID3 MNOP 4
			TNT1 A 0 A_SpawnItemEx("FBD_DeadArchvileVID3Q",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without a *large* margin scripts run ownerless
			Stop
		
		BrutalDeath:
		Death.Saw:
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun:
		Death.Shotgun:
		Death.SSG:
		Death.Blast:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_SpawnItem("SplatteredLarge")
			TNT1 A 0 A_XScream
			//TNT1 A 0 A_CustomMissile ("XDeathArchvile", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_SpawnItemEx ("XDeathArchvile", 0,0,52, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION,0)	
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 32, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath2b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 AA 0 A_CustomMissile ("XDeath3b", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (60, 120))
			TNT1 A 0 A_CustomMissile ("XDeath2", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeath3", 52, 0, random (0, 360), CMF_AIMDIRECTION, random (30, 120))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2", 24, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 40, 0, random (0, 360), 2, random (0, 160))//A_SpawnItem("MuchBlood2", 0, 40)
			TNT1 AAAA 0 A_CustomMissile ("SuperWallRedBlood", 32, 0, random (170, 190), 2, random (0, 40))
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 40, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Guts", 32, 0, random (0, 360), 2, random (60, 120))
			TNT1 A 0 A_NoBlocking
			VID3 A 3
			VID3 AAAAAAAAAAAAAAAAAAAAA 2 A_CustomMissile ("Brutal_LiquidBlood", 46, 0, random (0, 360), 2, random (0, 45))
			VID3 BCDEFGHIJK 3
			TNT1 A 0 A_SpawnItem ("GrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx("FBD_DeadArchvileVID3L" ,0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without a *large* margin scripts run ownerless
			Stop
	
	}
}		   


//***Che: used by super archviles, 
// but also by this upgraded archvile to summon a lost soul in reaction to you aiming your SSG at his head

ACTOR SummoningFlash_1: FastProjectile {
	/* short-lived effects (5 tics nominal) that move forward a set distance
		(since A_CustomMissile doesn't support forward offset)
	   before doing their fireworks
	*/
	+DONTSPLASH
	-FORCEYBILLBOARD
	+FORCEXYBILLBOARD
	+NOINTERACTION
	+NOBLOCKMAP
	+CLIENTSIDEONLY
	+BRIGHT
	Damage 0
	Speed 30
	Scale 0.7
	Renderstyle Add
	// bfg flash recolored red
	Translation "112:122=173:191", "168:172=172:176", "123:127=191:191", "4:4=171:171", "224:231=171:177", "160:167=173:191", "80:80=173:173", "48:52=171:173", "128:143=179:191", "144:151=186:191", "56:79=179:191"
	States {
		Spawn:
			TNT1 A 1 // basically teleports to its destination
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BFE2 DCBDCB 1
			Stop
		Flare2:
			BFE2 DCDCDC 1
			Stop
		Flare3:
			BFE2 CBCBCC 1
			Stop
		Flare4:
			BFE2 DCBCD 1
			Stop
	}
}

ACTOR SummoningFlash_2: SummoningFlash_1 {
	States {
		Flare1:
			BFE2 CBACA 1
			Stop
		Flare2:
			BFE2 ABABC 1
			Stop
		Flare3:
			BFE2 CBCBCB 1
			Stop
		Flare4:
			BFE2 BACBC 1
			Stop	
	}
}

ACTOR SummoningFlash_3: SummoningFlash_2 {
	States {
		Flare1:
			BFE1 ADADA 1
			Stop
		Flare2:
			BFE1 ABABA 1
			Stop
		Flare3:
			BFE1 DEBED 1
			Stop
		Flare4:
			BFE1 ADBDA 1
			Stop	
	}
}

#include SuperArchvile.txt