/*
	//***Che
	
	By ChebMaster, using Project Brutality's sprites.
	
	NOTE: PB's sprites were shifted down by 24 to achieve a more compact monster!
	
	I am burned out at this point, so a very very basic monster.
	No brightmaps, he's always fullbright, no fatalities, 
	he explodes on death as any elemental-enhanced monster.
	
	Powerlevel-wise, a flying knight equavalent with flame attacks.
	Unlike lost souls, 100% immune to flamethrower.

*/

ACTOR Yfreet 17943
{
	Monster
	Health 500
	
	//$category "FBD Monsters"
	//$Sprite YFRTB1
	
	// must fit inside cacodemon's hitbox because he can be used as an escalation replacement
	Radius 18
	Height 40 // 56 - 22 of the headbox
	Mass 100
	Speed 8
	PainChance 128
	+FLOAT 
	+NOGRAVITY
	+FLOORCLIP
	+SPECIALFLOORCLIP /*An actor with this flag is considered to use the floor clipping feature to achieve special effects, such as the buried reiver raising from the ground; so its floorclip is not adjusted by the engine depending on which terrain type it is standing.*/
	+FORCEXYBILLBOARD
	+BRIGHT
	SeeSound "knight/sight"
	ActiveSound "knight/active"
	PainSound "knight/pain"
	DeathSound None // the explosion takes care of that
	Tag "$YFREET"
	Obituary "$YFREET_O"
	
	Game Doom
	BloodType "FieryBlood", "FieryBloodSaw", "FieryBlood"
	bloodcolor None
    GibHealth 25
    
	damagefactor "Crush", 10.0
	damagefactor "Flames", 0.0
	damagefactor "Fire", 0.1
	damagefactor "Burn", 0.3 // imp fireball
	
	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;	
	
	PainChance "Argent", 255
	DamageFactor "Argent", 1.0
	
	PainChance "Bullet792", 160 // machineguns and snip[er rifles not aimed
	PainChance "SniperBullet", 255 // sniper rifle aimed
	
	damagefactor "Killme", 1.0 // AOE broadcasted by captured marines
	PainChance "Killme", 255	
	
	PainChance "Ice", 255
	
	PainChance "Kick", 255
	PainChance "Avoid", 90
	damagefactor "Avoid", 1.0 // subscribe to rocket alerters
	PainChance "Saw", 255
	// flying monsters vulnerable to splash:
	damagefactor "ExplosiveImpact", 3.0 DamageFactor "FriendlyExplosion", 3.0 damagefactor "Shrapnel", 3.0
	damagefactor "GibRemoving", 0.0 damagefactor "HangingHook", 0
	
	
	States {
		
		Spawn:
			YFRT B 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 18) // yfrit headbox
			YFRT B 0 A_GiveInventory("TargetIsABruiser")
			"----" A 1 A_SetUserVar("user_sleeping", 1)
			
		Stand:
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT ABCDABCD 5 A_Look
			Loop
			
			
		Missile:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "MissileCheckFatality")
			
			Goto MissileContinue
			
		MissileCheckFatality:
			TNT1 A 0 A_JumpIfCloser(200, "WaitTargetsFatalityOut")
			Goto MissileContinue
		
		MissileContinue:
			TNT1 A 0 A_Jump(64, "Missile2")	
			
		Missile1: // red analogue of the baron ball, leaves lingering flames
			TNT1 A 0
			
			// no kinslayer check because they are immune to their own damage anyway.
			
			TNT1 A 0 A_TakeInventory("EnemyMemory", 30)
			TNT1 A 0 A_JumpIfCloser(140, "Missile2")
			

			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "MissileAfterAvoid")
			TNT1 A 0 A_Jump (198, "MissileAfterAvoid") // only 23% probability to side-dash before attacking. BUT in case of our target being a player, we already perform aggressive side-dashing in our Dance state, into which we get if in player's 30-degree frontal segment (those checks don't give a flying crap about *vertical* aim, purely 2d!)
			
			TNT1 A 0 A_JumpIfInventory("CacoStamina", 15, 1) // max two such dodges, then cooldown
			Goto MissileAfterAvoid // no dodging if out of juice
			
			// the Hexen boss dodging only works closer than 640 anyway (hardcoded in C++)
			TNT1 A 0 A_JumpIfCloser(700, "Avoid")
			
			Goto MissileAfterAvoid
			
		Avoid:

			TNT1 A 0 A_TakeInventory("CacoStamina", 15)
			
			TNT1 A 0 A_JumpIfInTargetInventory("IsPlayer", 1, "AvoidPlayer")
			
			YFRT A 2 A_Chase ("","", CHF_FASTCHASE) // hexen boss dodging //A_FastChase
			YFRT BC 2
			NULL A 0 A_FaceTarget
			YFRT D 2 A_Chase ("","", CHF_FASTCHASE) // hexen boss dodging //A_FastChase
			YFRT AB 2
			NULL A 0 A_FaceTarget
			YFRT C 2 A_Chase ("","", CHF_FASTCHASE) // hexen boss dodging //A_FastChase
			YFRT DA 2
			NULL A 0 A_FaceTarget
			YFRT B 2 A_Chase ("","", CHF_FASTCHASE) // hexen boss dodging //A_FastChase
			YFRT CD 2

			Goto MissileAfterAvoid
			
		AvoidPlayer:
			
			TNT1 A 0 A_JumpIfInTargetLOS("DanceThenMissile", 30, JLOSF_DEADNOJUMP | JLOSF_CLOSENOSIGHT, 700, 180)
			Goto ChasePlayer		

		MissileAfterAvoid:	// not autoaimed
			
			YFRT S 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 8, 7, 39)
			YFRT T 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 9, 3, 39)
			
			//***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
			
			// not autoaimed
			YFRT U 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 13, -2, 39)
			YFRT U 4 BRIGHT A_CustomMissile("YfreetBall", 32, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			Goto See			

		Missile2: // mancubus fireball
			
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")			
			
			TNT1 A 0 A_FaceTarget
			
			YFRT E 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 9, 5, 36)
			YFRT F 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 11, 3, 37)
			YFRT G 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 15, 0, 35)
			
			//***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
			
			YFRT G 0 A_CustomMissile("BigFireBall", 16, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH) 
			
			TNT1 A 0 A_JumpIfCloser(120, "BackpedalAfterMissile2")
			
			YFRT G 8
			Goto See
		
		BackpedalAfterMissile2:
		
			YFRT G 8 A_Recoil(6)
			Goto See
			
		Pain:
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 3 A_Pain
			TNT1 A 0 A_JumpIfInventory("CacoStamina", 15, "MaybeAvoidAfterPain")
			YFRT C 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT D 3
			Goto See
			
		MaybeAvoidAfterPain:
			TNT1 A 0 A_Jump (128, "Avoid")
			YFRT C 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT D 3
			Goto See
			
			
		Pain.Ice:
			"----" A 8 A_Pain
			YFRT A 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT BC 4
			Goto See
			
		Pain.Argent:
			
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 HealThing(50)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 10, 30, 0)	
			
			YFRT H 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 3 A_Pain
			YFRT C 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT D 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			TNT1 A 0 A_Pain
			YFRT ABC 3 
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT D 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			TNT1 A 0 A_Pain
			YFRT ABC 3 
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT D 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			TNT1 A 0 A_Pain
			YFRT ABC 3 
			Goto See			

		Pain.Kick:
		Pain.HeavyImpact:
			TNT1 A 0 A_FaceTarget
			YFRT H 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 6 A_Recoil(5)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 3 A_Pain
			YFRT BCD 3
			Goto See
			
		Pain.Cut:
		Pain.Saw:
			TNT1 A 0 A_Stop
			YFRT H 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 3 A_Pain
			YFRT A 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT C 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT H 3 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			Goto See			
		
		WaitTargetsFatalityOut:
			YFRT A 1 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 1 A_PlaySound("knight/sight", CHAN_VOICE)
			YFRT A 1 A_FaceTarget
			YFRT B 1 A_Recoil(1)
			YFRT BBCCC 1
			TNT1 A 0 A_Recoil(1)
		WTF2:
			YFRT DA 3
			YFRT A 1 A_Jump(256, "AvoidLeft", "AvoidRight", "See")
			Wait

		Pain.Avoid: // inflicted by the tracer "Alerter" fired by: the vanilla bfg9000; the revenant launcher; the minigun when beginning to spin up; the rocket launcher. 
			"----" A 0
			"----" A 0 HealThing(1)
			"----" A 0 A_JumpIf(user_sleeping, "Flatfooted") // dont dodge if unaware
			
			"----" A 0 A_JumpIfInventory("CacoStamina", 15, 1) // max two such dodges, then cooldown
			Goto Flatfooted // no dodging if out of juice
			
			"----" A 0 A_TakeInventory("CacoStamina", 15)
			
			"----" A 0 ACS_NamedExecuteWithResult("JumpAvoidLeftOrRight")  // uses *pseudo* random pattern rather than random!
			"----" A 1
			Wait
		  
		AvoidLeft:
			YFRT H 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 1 A_FaceTarget
			TNT1 A 0 ThrustThing(angle*256/360+192, 10, 0, 0)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT BCDAB 1 
			Goto Missile
		AvoidRight:
			YFRT H 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, -3, 39)
			YFRT H 1 A_FaceTarget
			TNT1 A 0 ThrustThing(angle*256/360+64, 10, 0, 0)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT BADCB 1 
			Goto Missile
		Flatfooted:
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			TNT1 A 0 A_PlaySound("knight/sight", CHAN_VOICE)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT ABCDA 4 
			Goto See
			
		Idle: // without this, the game engine puts him into his Spawn state when he loses target 
				//-- and that wrecks havok with the init scripts!
			YFRT A 1 A_ClearTarget
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
			
		SearchPlayer:
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 1, 2) // this causes to clear target on the second loop
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 A_TakeInventory("EnemyMemory", 40)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 0 A_Look
			YFRT ABCD 3
			TNT1 A 0 A_SetAngle(angle - 30)
			YFRT A 0 A_Look
			YFRT ABCD 3
			TNT1 A 0 A_SetAngle(angle + 30)
			YFRT A 0 A_Look
			YFRT ABCD 3
			TNT1 A 0 A_SetAngle(angle + 30)
			YFRT A 0 A_Look
			YFRT ABCD 3
			TNT1 A 0 A_SetAngle(angle - 30)
			
			
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			TNT1 A 0 A_GiveInventory("CacoStamina", 10)
			
			TNT1 A 0 A_Jump(128, "SearchPlayer")
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT A 0 A_Wander
			YFRT A 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT B 0 A_Wander
			YFRT B 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT C 0 A_Wander
			YFRT C 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			YFRT D 0 A_Wander
			YFRT D 2 A_Look
			TNT1 A 0 A_GiveInventory("CacoStamina", 10)
			Goto SearchPlayer	

		See:
			TNT1 A 0
	
			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_JumpIfInTargetInventory("IsPlayer", 1, "ChasePlayer")
			TNT1 A 0 A_JumpIfInTargetLOS("SeeContinue", 0, JLOSF_DEADNOJUMP)
			TNT1 A 0 A_CheckSight("See2")
			
		SeeContinue:	
			//***Che cloning this to decrease slaughterchecks frequency to ~1/second
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 2 A_Chase
			YFRT AB 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)
			
			TNT1 A 0 A_CheckSight("See2")
			YFRT B 2 A_Chase
			YFRT CC 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)

			TNT1 A 0 A_CheckSight("See2")
			YFRT D 2 A_Chase
			YFRT DA 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)

			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)

			TNT1 A 0 A_CheckSight("See2")
			YFRT A 2 A_Chase
			YFRT BB 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)

			TNT1 A 0 A_CheckSight("See2")
			YFRT C 2 A_Chase
			YFRT CD 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)

			TNT1 A 0 A_CheckSight("See2")
			YFRT D 2 A_Chase
			YFRT DA 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 1)
			TNT1 A 0 A_GiveInventory("CacoStamina", 1)
			
			Loop
			
		See2:
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT AABBCCDD 2 A_Chase
			TNT1 A 0 A_GiveInventory("CacoStamina", 5)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 25, "Idle")//"SearchPlayer")
			TNT1 A 0 A_GiveInventory("EnemyMemory", 1)
			Goto See
		ForgetQuicker:
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT AABBCCDD 2 A_Chase
			TNT1 A 0 A_GiveInventory("CacoStamina", 5)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 25, "Idle")//"SearchPlayer")
			TNT1 A 0 A_GiveInventory("EnemyMemory", 4)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT AABBCCDD 2 A_Wander
			TNT1 A 0 A_GiveInventory("CacoStamina", 5)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 25, "Idle")//"SearchPlayer")
			TNT1 A 0 A_GiveInventory("EnemyMemory", 4)
			Goto See

		ChasePlayer:
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 2 A_Chase("", "")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "ForgetQuicker")
			// the Hexen boss dodging only works closer than 640 anyway(hardcoded in C++)
			TNT1 A 0 A_JumpIfInTargetLOS("Dance", 30, JLOSF_DEADNOJUMP | JLOSF_CLOSENOSIGHT, 400, 180)
			YFRT A 2 A_Chase
			YFRT BB 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 5)	
			TNT1 A 0 A_GiveInventory("CacoStamina", 1)
			
			YFRT C 2 A_Chase("", "")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "ForgetQuicker")
			// the Hexen boss dodging only works closer than 640 anyway(hardcoded in C++)
			TNT1 A 0 A_JumpIfInTargetLOS("Dance", 30, JLOSF_DEADNOJUMP | JLOSF_CLOSENOSIGHT, 400, 180)
			YFRT C 2 A_Chase
			YFRT DD 2 A_Chase ("","")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 5)	
			TNT1 A 0 A_GiveInventory("CacoStamina", 1)			
			TNT1 A 0 A_JumpIfTargetInLOS("ChasePlayer")
			Goto See2

		Dance:
			TNT1 A 0 A_JumpIfInventory("CacoStamina", 6, 1) // skip the goto
			Goto SeeContinue // out of juice
			TNT1 A 0 A_TakeInventory("CacoStamina", 6)
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 2 A_Chase
			YFRT BC 2 A_Chase ("","", CHF_FASTCHASE) // hexen boss dodging
			YFRT D 2
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 10)
			TNT1 A 0 A_JumpIfTargetInLOS("ChasePlayer")
			Goto See2
			
		DanceThenMissile:
			YFRT A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 6, 0, 39)
			YFRT A 2 A_FaceTarget
			YFRT AB 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			YFRT B 2 A_Recoil(2)
			YFRT CC 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			YFRT D 2 A_Recoil(3)
			YFRT DA 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			YFRT A 2 A_FaceTarget
			YFRT BB 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			YFRT C 2 A_Recoil(1)
			YFRT CD 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			YFRT D 2 A_Recoil(1)
			YFRT A 2 A_Chase ("","MissileAfterAvoid", CHF_FASTCHASE) // hexen boss dodging
			TNT1 A 0 A_JumpIfTargetInLOS("Missile2", 190, JLOSF_DEADNOJUMP, 99, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 10)
			TNT1 A 0 A_JumpIfTargetInLOS("MissileAfterAvoid")
			Goto ChasePlayer				
		
		Death:
		XDeath:
			TNT1 A 0 
			TNT1 A 0 A_NoBlocking // clears the nogravity flag
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", 1) // re-set it
			
			// do a helluvalot of damage
			TNT1 A 0 A_CustomMissile ("FireEnhancedDeathExplosion", 0, 40, random (0, 360), 2, 90)
			
			FRIT IJKLMNOPQR 3
			
			TNT1 A 0 A_ChangeFlag("NOGRAVITY", 0)
			TNT1 A -1 // raiseable by vile but NOT via AOE raise!
		Raise:
			FRIT RQPONMLKJI 5
			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", 605) // see _mob_list.xlsx
			Stop
			
		FallbackRezSuccess:
			TNT1 A 0
			TNT1 AA 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles3", 10, 0, random (0, 360), 2, random (40, 90))
			EXPL A 0 A_CustomMissile ("FlamethrowerFireParticles", 6, 0, random (0, 360), 2, random (0, 90))
			TNT1 A 30
			Stop			
			
	}
}

ACTOR YfreetBall: ZandronumBaronBall
{
	Radius 10
	Height 16
	Speed 20
	FastSpeed 30
	DamageType Flames
	Projectile 
	+RANDOMIZE
	+FORCEXYBILLBOARD
    +THRUGHOST
    Damage (random(30,30))
	RenderStyle Add
	Alpha 0.95
	Scale 0.25
	SeeSound "baron/attack"
	DeathSound "baron/shotx"
	Decal "Scorch"
	
	//***Che
	-NOBLOCKMAP // without this, A_RadiusGive does not see them 
	 // and so projectile-destroying effects do not work
	 // see Demon EleTech gun's ligtning element alt fire. 		
	
	States
	{
		Spawn:
			TNT1 A 0 NODELAY ACS_NamedExecuteWithResult("YfreetBallTrails") // a load-balanced clientside script
		Fly:				
			PBAL W 1 BRIGHT A_JumpIf(waterlevel > 0, "Death")
			Loop

			
		Crash: // hit someone who cannot bleed
		Death: // hit a wall
		XDeath: // hit someone who can bleed
			TNT1 A 0

			TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("BDExplosionparticles3", 10, 0, random (0, 360), 2, random (40, 90))
			TNT1 A 0 A_CustomMissile ("FlamethrowerFireParticles", 6, 0, random (0, 360), 2, random (0, 90))			
			
			TNT1 A 0 A_CustomMissile("ImmolantBurningStuff", random (-32, 0), random (-32, 32), random (-32, 32), 2 | CMF_TRACKOWNER, random (-32, 32))

			TNT1 AA 0 A_SpawnItem("RedFlare",0,0)
			TNT1 A 0 A_SetScale(0.7)
			TNT1 A 0 A_FadeOut(0.2)
			FRPR ABCDEFGH 2 BRIGHT
			Stop
	}
}


ACTOR SmallRedFlameTrailsPT: FlameTrails
{

    Scale 0.3
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_Jump(192, "Spawn2", "Spawn3", "Spawn4")
			Goto Fly
		Spawn2:
			TNT1 A 0
			TNT1 A 0 A_SetScale(0.3, -0.3)
			Goto Fly
		Spawn3:
			TNT1 A 0
			TNT1 A 0 A_SetScale(-0.3, 0.3)
			Goto Fly
		Spawn4:
			TNT1 A 0
			TNT1 A 0 A_SetScale(-0.3, -0.3)
			Goto Fly
		Fly:
			TNT1 A 1 // otherwise they outrun the fireball!
			FRPR BCDEFGH 1 BRIGHT
			Stop
	}
}