

Actor FBD_BelphegorAttack: FBD_KnightAttack {
	damage 40
}

ACTOR BelphegorPotpourriChecker: AbstractPotpourriChecker
{
	Height 88
	Radius 32
}

Actor BelphegorBossCubeSpawner: AbstractBossCubeSpawner
{
	Height 88
	Radius 32
	States
	{
		DoSummon:	
			TNT1 A 0 A_GiveInventory("SummonsCount", 1, AAPTR_TRACER)
			TNT1 A 0 A_SpawnItemEx("BossSizedTeleportFog")
			TNT1 A 1 A_SpawnItemEx("Belphegor2",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0,user_stid)
			Stop
	}
}

ACTOR FBD_Belphegor 2544 //: BaronofHell2 2544

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

// Do mot mistake with Lord Belphegor (doomed num 8362). 
// They are mostly the same but Lord's scale is 1.5 (while the hitbox size is the same!)

{
	Game Doom
	
	PainChance 50
	Monster
	+FLOORCLIP
	+BOSSDEATH
	SeeSound "baron/sight"
	PainSound "baron/pain"
	DeathSound "baron/death"
	ActiveSound "baron/active"

	Mass 1000	
	
	//$category "FBD Monsters"
	
	//$Sprite BOS3A1
	Tag "$BELPHEGOR" // "Belphegor";
	Obituary "$BELPHEGOR_OB" // "%o was no match for a Belphegor.";
	
	// disabling the baron-only behavior
	DamageFactor "CallingTheBaronAFaggot", 0.0
	DamageFactor "Avoid", 0.0
	
	var int user_head_tid;
	var int user_head_type; // 2, noble headbox
	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_sleeping;
	var int user_item_no;
	var int user_serverside_sfchk;
	
	var int user_bleeding_angle;
	var int user_angle;
	
	
	
    Scale 1.2

    GibHealth 25
	+NOICEDEATH
	PainChance "Saw", 100
	PainChance "Cut", 100
	PainChance "Kick", 255
	PainChance "LowKick", 200
	PainChance "HangingHook", 0	
	
	PainChance "Bullet792", 64 // machineguns and snip[er rifles not aimed
	PainChance "SniperBullet", 70 // sniper rifle aimed	
	
	damagefactor "Avoid", 0.0
	damagefactor "Head", 1.0 //***Che must be *awful* old code! //2.0
	damagefactor "GibRemoving", 0.0
	damagefactor "MINORHead", 1.0
	DamageFactor "CauseSplash", 0.0 DamageFactor "CauseObjectsToSplashSlime", 0.0 DamageFactor "CauseObjectsToSplashNukage", 0.0
	DamageFactor "CauseObjectsToSplashBlood", 0.0 DamageFactor "CauseObjectsToSplashLava", 0.0
	damagefactor "TeleportRemover", 0.0
    Health 2000
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0
	damagefactor "Explosive", 1.7
	
	BloodType "Green_Blood", "GreenFBD_SawBlood", "GreenFBD_SawBlood"
	BloodColor "DarkGreen"
	MaxStepHeight 24
	MaxDropOffHeight 32
	
	//***Che:
	//+DONTHURTSPECIES
	// https://zdoom.org/wiki/Actor_flags#DONTHARMCLASS
	// This flag was previously named DONTHURTSPECIES, which was a misleading name that could lead to believe its effect was that of DONTHARMSPECIES.
	+DONTHARMSPECIES // Prevents monsters with this flag from dealing explosion damage to other monsters that have the same species.
	
	+MISSILEMORE
	DeathHeight 4
	BurnHeight 0
    Speed 8
	FastSpeed 12
	//Species "Belphegor" //***Che this was causing infighting with barons
	Height 88
	Radius 32

	
	PainChance "HeadStun", 255 // compensated by him gaining +NOPAIN with 50% probability
	PainChance "Decaptate", 96
	
	PainChance "Argent", 255
	DamageFactor "Argent", 1.0
	
	damagefactor "Killme", 1.0 // AOE inflicted by captured marines
	PainChance "Killme", 255	
	
	Species "Bruisers"
	
	PainChance "Ice", 96
	
	States
	{
		
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See

		
		Spawn:
			BOS3 A 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 2) // noble headbox
			//TNT1 A 0 A_SetUserVar("user_head_type", 2) // noble headbox
			TNT1 A 0 A_GiveInventory("TargetIsAMiniBoss", 1)
			TNT1 A 0 A_GiveInventory("TargetIsABruiser")
			BOS3 B 7 // slaughtermap init takes 5 tics
			Goto Stand
			
		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("StandaloneGreenRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			BOS3 O 8
			BOS3 NMLKJI  8
			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", 2008) // see _mob_list.xlsx
			Stop
			
		FallbackRezSuccess:
			TNT1 A 0 A_SpawnItemEx("StandaloneRezSfx",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
			TNT1 A 30
			Stop			
			
		Death.Fatality:
			// ersatz fatality: doomguy punches, we asplode, doomguy flexes
			TNT1 A 0 
			TNT1 A 0 A_NoBlocking
			
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("ErsatzFatalityGreen", 1)	// this does nothing in BD22, obviously
			
			// after exactly 15 tics, asplode
			BOS3 P 9 A_FaceTarget
			BOS3 Q 6
			
			TNT1 A 0 ACS_NamedExecuteAlways("DropFatalityBonuses", 0, 15, 20, 0) // 0, health, armor, 0 -- rounded down to nearest 2
			
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			Goto XDeath				
		
		Stand:	
			TNT1 A 0
			//TNT1 A 0 A_JumpIf(user_serverside_sfchk >= 4, "StandSlow") // extreme slaughtermap optimization
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)			
			
			BOS3 BD 10 A_Look
			"----" A 0 A_JumpIf(!user_head_tid, "StandSlow")
			Loop
		StandSlow:
			BOS3 B 13 A_Look
			BOS3 D 13
			Goto Stand
		See:
			TNT1 A 0
			
			// slaughtermap manage
			//TNT1 A 0 A_JumpIf(!user_sleeping, 3) // forgo the expensive sight check if already awake
			//TNT1 A 0 A_CheckSight(2) // 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, 2) // count us as two		
			//TNT1 A 0 A_SetUserVar("user_serverside_sfchk", 1) // reply that we did the deed	
		
				
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, -3, 67)
			BOS3 AAAA 2 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 BBBB 2 A_Chase("","")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 67)
			BOS3 CCCC 2 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 BBBB 2 A_Chase
			
			// a copy-paste to slaughtercheck less often:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, -3, 67)
			BOS3 AAAA 2 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 BBBB 2 A_Chase("","")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 67)
			BOS3 CCCC 2 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 BBBB 2 A_Chase
			
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "See2") // only start running after a 2 second walk
			
			Loop
		
		
		See2:
			// pay attention: b0s3 (as in zero), not bos3 (as in oh)
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_angle", angle)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 5, 62)
			B0S3 PPP 1 A_Chase("","", CHF_NIGHTMAREFAST)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 6, 59)
			B0S3 QQQ 1 A_Chase("","", CHF_NIGHTMAREFAST)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 4, 56)
			B0S3 RRR 1 A_Chase
			
			// slow down to a walk if turned for more than 30 degrees per leap (means hit an obstacle)
			TNT1 A 0 A_SetUserVar("user_angle", angle - user_angle)
			TNT1 A 0 A_JumpIf (user_angle > 180, "Math1")
			TNT1 A 0 A_JumpIf (user_angle < -180, "Math2")
			TNT1 A 0 A_JumpIf(user_angle > 30 || user_angle < -30, "See")
			Loop
		Math1:
			TNT1 A 0 A_JumpIf((user_angle - 360) > 30 || (user_angle - 360) < -30, "See")
			Goto See2
		Math2:
			TNT1 A 0 A_JumpIf((user_angle + 360) > 30 || (user_angle + 360) < -30, "See")
			Goto See2
		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 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, 1, 60)
			TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, "Stand")
		LookingForPlayer:
			TNT1 A 0
			//TNT1 A 0 A_JumpIfInventory("IAmClassicMonster", 1, "VanillaSee")
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 BBB 10 A_Look
			TNT1 A 0 A_SetAngle(angle - 40)
			BOS3 BBB 10 A_Look
			TNT1 A 0 A_SetAngle(angle + 40)
			BOS3 BBB 10 A_Look
		
		LookingForPlayerContinue:
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, -3, 67)
			BOS3 A 0 A_Wander
			BOS3 AA 3 A_Look
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 B 0 A_Wander
			BOS3 BB 3 A_Look
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 67)
			BOS3 C 0 A_Wander
			BOS3 CC 3 A_Look
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62)
			BOS3 B 0 A_Wander
			BOS3 BB 3 A_Look

			TNT1 A 0 A_jump(128, "LookingForPlayer")
			Loop
		
		
		QuickRage:	// does NOT make immune to pain
			TNT1 A 0 A_CHangeFlag("FASTER", 1)
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			TNT1 A 0 A_PlaySound("baron/see")
			Goto See			
		
		Pain:
		
		//***Che without this, baron frames!
		Pain.Kick:
		Pain.Explosive:
		Pain.Bfg10k:
		Pain.Head:
		Pain.HeadPlasma:
		
		
			TNT1 A 0 A_JumpIfInventory("Curbstomp_Marine", 1, "CurbstompMarine")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, -4, 65)
			TNT1 A 0 A_JumpIfHealthLower(1000, "Pain.Taunt")
			BOS3 E 3
			
			BOS3 E 3 A_Pain
			TNT1 A 0 A_Jump(32, "Pain.Taunt")
			Goto See

		Pain.Argent:
			TNT1 A 0
			
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 28, 60, 0)
			//TNT1 A 0 A_ClearTarget
			TNT1 A 0 HealThing(200,5000)
			
			TNT1 A 0 A_CHangeFlag("FASTER", 1)
			//TNT1 A 0 A_CHangeFlag("NOPAIN", 1)
			TNT1 A 0 A_GiveInventory("Enraged", 1)		
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, -4, 65)
			BOS3 EE 8 A_Pain
			Goto Missile // results in furious spraying in a random direction if target is out of sight
			
		Pain.Decaptate:
		Pain.HeadStun: //you get ONE stun, which enrages him. Congratulations.
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_bleeding_angle", random(-50, 50))
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 16, -4, 65)
			BOS3 E 3
			
			BOS3 E 1 A_Pain  
			BOS3 EEEEEE 3 A_CustomMissile ("Green_LiquidBlood2", 70, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (25, 45))
			
			BOS3 E 1 A_Pain  
			BOS3 EEEE 4  A_CustomMissile ("Green_LiquidBlood2", 70, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (0, 25))
			
			// one second or two seconds stun with 50% probability 
			TNT1 A 0 A_Jump(128, "QuickRage")
			
			BOS3 E 1 A_Pain  
			BOS3 EEEE 5  A_CustomMissile ("Green_LiquidBlood2", 70, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (-25, 0))

			BOS3 E 1 A_Pain  
			BOS3 EEE 6  A_CustomMissile ("Green_LiquidBlood2", 70, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (-45, -25))			
			
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 A_CHangeFlag("FASTER", 1)
			TNT1 A 0 A_CHangeFlag("NOPAIN", 1)
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileAngry")
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 62)
			B0S3 IJ 3
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 5, 61)
			B0S3 KL 3
			TNT1 A 0 A_PlaySound("baron/see")
			B0S3 MNONMNOMN 3
			B0S3 LKJ 3
			Goto See2
		Death.KillMe:
		Death.Taunt:
			// rage, then have a heart attack
			TNT1 A 0
			TNT1 A 0 A_CHangeFlag("NOPAIN", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			B0S3 IJKL 3
			TNT1 A 0 A_PlaySound("baron/see")
			B0S3 MNONMNOMNLKJ 3			
			Goto Death
		Melee:
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsABruiser", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")
			
			BOS3 F 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 8, 68)
			TNT1 A 0 A_PlaySound("weapons/gswing")
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 18, 7, 61)
			BOS3 G 8 A_FaceTarget
			
			//TNT1 AAAA 0 A_CustomMissile("KnightAttack",10,0,0,0)
			TNT1 A 0 A_CustomMissile("FBD_BelphegorAttack",10,0,0,0)
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 30, 7, 54)
			BOS3 H 8 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("Curbstomp_Marine", 1, "CurbstompMarine")
			Goto See
			
		Melee2:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 30, 7, 54)
			//TNT1 AAAA 0 A_CustomMissile("KnightAttack",10,0,0,0)
			TNT1 A 0 A_CustomMissile("FBD_BelphegorAttack",10,0,0,0)
			TNT1 A 0 A_PlaySound("weapons/gswing")
			BOS3 H 8 A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("Curbstomp_Marine", 1, "CurbstompMarine")
			Goto See
			
			
		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)

			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsABruiser", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")			
			
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileAngry")
			TNT1 A 0 A_JumpIfInventory("Curbstomp_Marine", 1, "CurbstompMarine")
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 8, 68)
			BOS3 F 8 A_FaceTarget
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 18, 7, 61)
			
			//***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			
			
			BOS3 G 8 //A_FaceTarget
			
			TNT1 A 0 A_JumpIfCloser(150, "Melee2")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 30, 7, 54)
			
			// since we fire NOT autoaimed, we need another A_FaceTarget right before firing!
			//***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 A_JumpIfInventory("IAmSfestMonster", 1, "FireSfest")
			BOS3 H 8 A_CustomMissile("BelphegorGreenPlasmaBall", 50, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			Goto See
/*			
		FireSfest:
			BOS3 H 8 A_CustomMissile("BelphegorGreenPlasmaBallSfest", 50, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			Goto See
*/		
		MissileAngry:
			TNT1 A 0 A_JumpIfInventory("Curbstomp_Marine", 1, "CurbstompMarine")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, 8, 68)
			TNT1 A 0 A_FaceTarget
			
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "MissileAngryAtInvisible")
			
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			BOS3 F 4
			TNT1 A 0 A_Jump(256, 6)
			TNT1 A 0 A_FaceTarget
			BOS3 FFFF 1 A_Chase("","")
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 18, 7, 61)
			
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			BOS3 G 4 
			TNT1 A 0 A_Jump(256, 6)
			TNT1 A 0 A_FaceTarget
			BOS3 GGGG 1 A_Chase("","")
			
			TNT1 A 0 A_JumpIfCloser(150, "Melee2")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 30, 7, 54)
			
			
			//***Che: this is embarrassing: A_Chase resulted in him turning 45 degrees instead of keeping his heading... And firing left or right!
			// adding facetarget here:
			
			TNT1 A 0 A_JumpIfTargetInLOS(2)
			TNT1 A 0 A_Jump(256, 4)
			
			TNT1 A 0 A_FaceTarget
			//TNT1 A 0 A_JumpIfInventory("IAmSfestMonster", 1, "FireSfestAngry")
			BOS3 H 0 A_CustomMissile("BelphegorGreenPlasmaBall", 70, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			BOS3 H 4
			TNT1 A 0 A_Jump(256, 6)
			TNT1 A 0 A_FaceTarget
			BOS3 HHHH 1 A_Chase("","")
			Goto See2
/*			
		FireSfestAngry:
			BOS3 H 0 A_CustomMissile("BelphegorGreenPlasmaBallSfest", 70, 0, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			TNT1 A 0 A_JumpIfTargetInLOS(6)
			BOS3 H 4
			TNT1 A 0 A_Jump(256, 6)
			TNT1 A 0 A_FaceTarget
			BOS3 HHHH 1 A_Chase("","")
			TNT1 A 0 // an empty frame to jump to
			Goto See2
*/			
		MissileAngryAtInvisible:
		
			BOS3 G 0 A_FaceTarget
			BOS3 FFFF 1 A_Wander
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 18, 7, 61)
			
			BOS3 GGGG 1 A_Wander
			
			TNT1 A 0 A_JumpIfCloser(150, "Melee2")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 30, 7, 54)
			//TNT1 A 0 A_JumpIfInventory("IAmSfestMonster", 1, "FireSfestAngryAtInvisible")
			BOS3 H 0 A_CustomMissile("BelphegorGreenPlasmaBall", 70, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			BOS3 HHHH 1 A_Wander
			Goto See2	
/*			
		FireSfestAngryAtInvisible:
			BOS3 H 0 A_CustomMissile("BelphegorGreenPlasmaBallSfest", 70, 0, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			BOS3 G 0 A_FaceTarget
			BOS3 HHHH 1 A_Wander
			Goto See2
*/	

		//***Che: other nobles' melee attacks (now possible in FBD)
		Death.HKFT: // belphegors themselves inflict hell knight melee attack damage type
		Death.BHFT:
		Death.DHFT:
		Death.CCFT:
		
		Death.SSG:
		XDeath:
		Death.Railgun:
		Death.Desintegrate:
		Death.Saw:
		XDeath.ExplosiveImpact:
		XDeath.FriendlyExplosion:
		XDeath.Desintegrate:
		XDeath.Saw:	
		Death.SniperBullet:
		Death.Bullet792:		
		Death.Minigun: //***Che: without this, baron frames
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 AA 0 A_CustomMissile ("XDeath2bGreen", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath3bGreen", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath2Green", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath3Green", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath4Green", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath5Green", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath6Green", 55, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_SpawnItem("MuchBlood2Green", 0, 55)
			TNT1 AAAA 0 A_CustomMissile ("GreenGuts", 52, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeathHellKnightArm", 52, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1Green", 55, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2Green", 55, 0, random (0, 360), 2, random (0, 160))
			BXDE B  0 A_Scream
			BXDE C  0 A_bossdeath
			BXDE D  0 A_NoBlocking
			BO3G ABCD 8
			TNT1 A 0 A_SpawnItem ("GreenGrowingBloodPool")
			TNT1 A 0 A_SpawnItemEx("DeadBelphegorXDeath",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERSCALE,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop

		Death:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")		
			BOS3 I 8 A_Scream
			BOS3 J 8 A_bossdeath
			BOS3 K 8 A_NoBlocking
			BOS3 L 8
			TNT1 A 0 A_SpawnItemEx("DeadBelphegor",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERSCALE,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0) // without at least 8 tics delay, scripts runs ownerless
			Stop


		Death.head:
		Death.HeadStun:
		Death.HeadPlasma:
		Death.Decaptate:
		XDeath.HeadPlasma:
		XDeath.Head:
		XDeath.HeadStun:
		XDeath.Decaptate:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")		
			TNT1 AAAAAA 0 A_CustomMissile ("Xdeath1Green", 82, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("SmallGreenBrainPiece", 82, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("GreenBrainPiece", 82, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAA 0 A_CustomMissile ("SmallGreenBrainPieceFast", 82, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_bossdeath
			TNT1 A 0 A_NoBlocking
			BOS3 MNOPQR 8
			TNT1 A 0 A_SpawnItemEx("DeadBelphegorNoHead",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERSCALE,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			//BOS3 R -1
			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 -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:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			Goto Missile
			
		Death.Eat:
			TNT1 A 0 A_GiveToTarget("EatMe", 1)
			//Goto Death+3
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_bossdeath
			TNT1 A 0 A_NoBlocking			
			BOS3 L 8
			TNT1 A 0 A_SpawnItemEx("DeadBelphegor",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERSCALE,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)			
			Stop	

		CurbstompMarine:
			TNT1 A 0
			TNT1 A 0 A_SetInvulnerable
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			BS3F AB 10
			BS3F CDEF 2
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			BS3F GF 4
			BS3F HHIII 2
			BS3F J 15
			BS3F K 6
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			TNT1 AAA 0 A_CustomMissile ("XDeath2", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeath3", 5, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("MuchBlood2", 50, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("XDeath1", 1, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAAA 0 A_CustomMissile ("PlayerFlyingBlood", 50, 0, random (0, 360), 2, random (0, 160))
			BS3F L 15
			BS3F NM 4
			BS3F N 1
			TNT1 AAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Blood", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), 2, random (30, 90))
			BS3F NOPPP 3
	   
			BS3F NM 4
			BS3F N 1
			TNT1 AAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Blood", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), 2, random (30, 90))
			BS3F NOPPP 3
	   
			BS3F NM 4
			BS3F N 1
			TNT1 AAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Blood", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), 2, random (30, 90))
			BS3F NOPPP 3
	   
			BS3F NM 4
			BS3F N 1
			TNT1 AAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Blood", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), 2, random (30, 90))
			BS3F NOPPP 3
	   
			BS3F NM 4
			BS3F N 1
			TNT1 AAAA 0 bright A_CustomMissile ("SuperGoreSpawner", 5, 0, random (0, 360), 2, random (30, 180))
			EXPL A 0 Radius_Quake (2, 24, 0, 15, 0)
			TNT1 AAAA 0 A_CustomMissile ("BloodMistBig", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("Blood", 10, 0, random (0, 360), 2, random (30, 90))
			TNT1 AAA 0 A_CustomMissile ("XDeath1", 10, 0, random (0, 360), 2, random (30, 90))
			BS3F NOPPP 3
	   
			TNT1 A 0 A_TakeInventory("Curbstomp_Marine")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 29, 0, 62, 1) // force create
			TNT1 A 0 A_UnSetInvulnerable
			Goto See
	}
} 



Actor BelphegorRaisedByVile: FBD_Belphegor {
	States {
		Spawn:
			BOS3 O 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 2) // noble headbox
			
			//TNT1 A 0 A_SetUserVar("user_head_type", 2) // noble headbox
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_GiveInventory("TargetIsAMiniBoss", 1)
			TNT1 A 0 A_GiveInventory("TargetIsABruiser")			
			BOS3 O 8
			BOS3 NMLKJI  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 BelphegorGreenPlasmaBall: GreenPlasmaBall//BaronBall
{
	Radius 10
	Height 16
	Speed 30
	FastSpeed 30
	Projectile 
	+RANDOMIZE
	+FORCEXYBILLBOARD
    +THRUGHOST
    Damage (random(60,60))
	RenderStyle Add
	Alpha 0.9
	Scale 1.6
	SeeSound "baron/attack"
	DeathSound "FAREXPL"
	Decal "Scorch"
	DamageType "ExplosiveImpact"
	States
	{
		Spawn:
			TNT1 A 0
		Fly:		
			TNT1 A 0 A_SpawnItem("GreenFlare22",0,0)
			FRPG K 1 BRIGHT A_SpawnItemEx("FBD_GreenTinyFlameTrail", 0,0,0, 0.4 * momx, 0.4 * momy, 0.4 * momz, 0, SXF_CLIENTSIDE | SXF_ABSOLUTEMOMENTUM) 
			Loop
		
		Death:
			BFE1 A 0 Bright
			EXPL A 0 Radius_Quake (2, 54, 0, 15, 0)
			BFE1 A 0 Bright A_Explode(32, 96, 1)
			TNT1 AAAA 0 A_CustomMissile ("GreenExplosionFire", 2, 0, random (0, 360), 2, random (0, 360))
			EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 BCDEF 2 Bright
			TNT1 AAAA 2 A_CustomMissile ("BigNeoSmoke", 2, 0, random (0, 360), 2, random (0, 360))
			Stop
	}
}


ACTOR BelphegorGreenPlasmaBallSfest: BelphegorGreenPlasmaBall {
	Scale 1.8
	+NODECAL
	States
	{
		Spawn:
			TNT1 A 0
		Fly:
			FRPG K 4 BRIGHT A_SpawnItemEx("FBD_GreenTinyFlameTrail", 0,0,0, 0.6 * momx, 0.6 * momy, 0.6 * momz, 0, SXF_CLIENTSIDE | SXF_ABSOLUTEMOMENTUM) 
			Loop
		
		Death:
			TNT1 A 0 Bright
			TNT1 A 0 Radius_Quake (2, 54, 0, 15, 0)
			TNT1 A 0 Bright A_Explode(32, 96, 1)
			FIR6 ABCDEFGHIJKLMNOP 1 BRIGHT
			Stop
	}

}

		

Actor DeadBelphegor: FBD_DeadBaron //FBD_CurbstompedMarine
{
    Radius 32 //***Che otherwise raising failures //12
    Height 18
    Scale 1.2
    Mass 8000
    Health 1000
	
	BloodType "Green_Blood", "GreenFBD_SawBlood", "GreenFBD_SawBlood"
	BloodColor "DarkGreen"
	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
			BOS3 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
			BOS3 L 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			BOS3 L -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)	
			Stop
		Raise:
			// note: the frame letter of the "----" (keep previous) sprite is ignored
			"----" A 0
			"----" A 0 A_ChangeFlag("CORPSE", 0)
			"----" A 0 A_GiveInventory("RezzingNow")
			"----" A 0 A_NoBlocking // the raising code deep in C++ makes it solid
			"----" A 0 A_JumpIf(!CallAcs("EnoughSpaceToRezNormally", 2008), "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 ("BelphegorRaisedByVile",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, 5, 25, 0)//"BelphegorRaisedByVile"
			"----" A -1 ACS_NamedExecuteWithResult("FallbackRez", 2008) // see _mob_list.xlsx
			Stop
		Death:
		Death.Bfg10k: //***Che changed damage type from extreme to custom
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 AA 0 A_CustomMissile ("XDeath2bGreen", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath3bGreen", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath4Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath5Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath6Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AAA 0 A_SpawnItem("MuchBlood2Green", 0, 25)
			TNT1 A 0 A_SpawnItem("MuchBlood3Green", 0, 25)
			TNT1 AAAA 0 A_CustomMissile ("GreenGuts", 32, 0, random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("XDeathHellKnightArm", 32, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan1Green", 15, 0, random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeathOrgan2Green", 15, 0, random (0, 360), 2, random (0, 160))
			
			TNT1 A 0 A_SpawnItemEx("DeadBelphegorXDeath",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION|SXF_TRANSFERTRANSLATION|SXF_TRANSFERSCALE,0)
			TNT1 A 30 A_ChangeFlag("CORPSE", 0)
			Stop	
		LandOnLava:
		Death.Plasma: 
		Death.Plasma2:
		Death.Electric:
		Death.Flames:
		Death.Burn:
		
			TNT1 A 0
			TNT1 A 0 A_Scream
			TNT1 A 0 A_NoBlocking
			EXPL AAAAA 0 A_CustomMissile ("ExplosionSmoke", 32, 0, random (0, 360), 2, random (0, 360))
			BOSB ABCDE 9 A_CustomMissile ("PlasmaSmoke", 24, 0, random (0, 180), 2, random (0, 180))
			BOSB EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 8 A_CustomMissile ("PlasmaSmoke", 16, 0, random (0, 180), 2, random (0, 180))

			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			BOSB E -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)	
			Stop
			
		Death.CrushedBodies:
			TNT1 A 0 A_SetAngle(0)
			TNT1 A 0 bright A_CustomMissile ("GreenSuperGoreSpawner", 1, -40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 bright A_CustomMissile ("GreenSuperGoreSpawner", 1, 40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 A_CustomMissile ("XDeath1Green", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2bGreen", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3bGreen", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("GreenBloodMistBig", 1, -40, random (0, 360), 2, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("GreenBloodMistBig", 1, 40, random (0, 360), 2, random (30, 90))
			TNT1 A 0 A_SetAngle(90)
			TNT1 A 0 bright A_CustomMissile ("GreenSuperGoreSpawner", 1, -40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 bright A_CustomMissile ("GreenSuperGoreSpawner", 1, 40, random (0, 360), 2, random (25, 45))
			TNT1 A 0 A_CustomMissile ("XDeath1Green", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath2bGreen", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 A 0 A_CustomMissile ("XDeath3bGreen", 1, random (-30, 30), random (0, 360), 2, random (0, 160))
			TNT1 AA 0 A_CustomMissile ("GreenBloodMistBig", 1, -40, random (0, 360), 2, random (30, 90))
			TNT1 AA 0 A_CustomMissile ("GreenBloodMistBig", 1, 40, random (0, 360), 2, random (30, 90))
			TNT1 A 0 A_NoBlocking
			GIBS Y 1
			
			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			GIBS Y -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop
		
	}
}


ACTOR DeadBelphegorNoHead: DeadBelphegor {
	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
			BOS3 R 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
			BOS3 R 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			BOS3 R -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop	
	}
}

Actor FBD_DeadBelphegor: DeadBelphegor {

}

Actor FBD_DeadBelphegorNoHead: DeadBelphegorNoHead {

}


Actor DeadBelphegorXDeath: DeadBelphegor
{
	Health 5000
	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
			BO3G E 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
			BO3G E 30
			TNT1 A 0 A_JumpIf(user_floor_is_lava, "LandOnLava")	
			
			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			BO3G E -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)	
			Stop
		Death:
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 AA 0 A_CustomMissile ("XDeath2bGreen", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath3bGreen", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath4Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath5Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AA 0 A_CustomMissile ("XDeath6Green", 25, 0, random (0, 360), 2, random (20, 90))
			TNT1 AAA 0 A_SpawnItem("MuchBlood2Green", 0, 25)
			TNT1 A 0 A_SpawnItem("MuchBlood3Green", 0, 25)
			
			//***Che: prevent the game engine from auto-respawning this gibbed corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			TNT1 A -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)
			Stop	
	}
}

Actor FBD_DeadBelphegorXDeath: DeadBelphegorXDeath {

}

Actor FatalizedBelphegor: DeadBelphegor
{
	States
	{
		Raise:
			Stop // fatalized bodies are not raiseable
		Spawn:
			TNT1 AAAAAA 0 A_CustomMissile ("GreenBloodMistBig", 50, 0, random (0, 360), 2, random (0, 160))
			BS4F JK 7
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("MuchBloodGreen", 50, 0, random (0, 360), 2, random (0, 160))
			
			//***Che: prevent the game engine from auto-respawning this corpse on nightmare as a corpse
			// while allowiing archviles raising it (they only check for the CORPSE flag)
			// and respawning via script on nightmare
			TNT1 A 0 A_ChangeFlag("CORPSE", 1)
			TNT1 A 0 A_ChangeFlag("ISMONSTER", 0)
			BS4F L -1 ACS_NamedExecuteAlways("RespawnCorpseAfter60sIfNightmare", 0, 0, 0, 0)	
			Stop
    }
}
