

//***Che this is #include'd from Cyberdemon.txt

//***Che the higher the cyberdemon tier, the larger his leap and more damaging the stomp
//  BUT also the shorter the stomp attack triggering distance
// Meaning it is much harder to pull him into a leap
//   and much harder to survive if you succeed

// see const float FIXED_TO_FLOAT = 0.0000152587890625; in Abstract.txt

Actor CyberDevastator: CyberdemonChad 17685 {
	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!
	
	//$Sprite ANNIF1
	Health 8500
	// dark gold annihilator with shiny golden guns
	Translation "16:31=160:167", "32:47=72:79", "80:88=224:231", "89:95=160:167", "96:111=74:79"
	Tag "$ANNIGRIZ"
	
	Radius 35
	Height 102
	Scale 1.2
	
	var int user_spread;
	
	States {
	
		Spawn:
			ANNI A 1 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 19, 120) // annihilator headbox, 120% headbox scale
			ANNI A 0 
			TNT1 A 0 A_SetUserVar("user_headshot_stun_limit", 8) // prevents permanent stunlock
			TNT1 A 0 A_GiveInventory("TargetIsACyberdemon")
			TNT1 A 0 A_GiveInventory("TargetIsABoss")
			TNT1 A 0 A_GiveInventory("TargetIsAGreatTerribleBoss")
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 
			Goto Stand

		Idle: // without this, the game engine puts him into his Spawn state when he loses target 
				//-- and that wrecks havok with the init scripts!
		Stand:	
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			ANNI AAAAAAAA 10 A_Look
			"----" A 0 A_JumpIf(!user_head_tid, "StandSfest")
			Loop
			
		StandSfest:
			"----" AA 10 A_Look
			Loop			
		
		See:
			
			TNT1 A 0 
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			
			

		ChaseTheTarget:		
			// 12 a_chase calls
			// 34 tics total length
			//TNT1 A 0 A_SpawnItem("HeavyFootSteps32")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			
			ANNI A 7 A_PlaySound("KYBHOOF1")// A_Hoof
			TNT1 A 0 A_JumpIfTargetInLOS("Missile", 60, JLOSF_DEADNOJUMP, 120)

			//TNT1 A 0 A_JumpIf(CallACS("GetCyberdemonCanStompTarget", 120), "Stomp")
			TNT1 A 0 A_Metal // spider mastermind walk sound
			
			ANNI AA 1 A_Chase
			//TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 120 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			//TNT1 A 0 A_JumpIf(CallACS("GetCyberdemonCanStompTarget", 120), "Stomp")
			//TNT1 A 0 A_SpawnItemEx("CyberStep",12,-30)
			ANNI BBBB 2 A_Chase
			
			ANNI C 7 A_PlaySound("KYBHOOF1")
			TNT1 A 0 A_JumpIfTargetInLOS("Missile", 60, JLOSF_DEADNOJUMP, 120)	//TNT1 A 0 A_JumpIf(CallACS("GetCyberdemonCanStompTarget", 120), "Stomp")
			TNT1 A 0 A_Metal // spider mastermind walk sound

			ANNI CC 1 A_Chase
			//TNT1 A 0 A_JumpIf(CallACS("GetCyberdemonCanStompTarget", 120), "Stomp")
			ANNI DDDD 2 A_Chase
			Loop	

			
			
		Missile:
			//TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 256 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")	
			TNT1 A 0 A_JumpIf(CallACS("GetCyberdemonCanStompTarget", 120), "Stomp")

			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsACyberdemon", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")	
		
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "SpecialAttack")
			TNT1 A 0 A_Jump(85, "SpecialAttack")	
			
			//TNT1 A 0 A_JumpIfCloser(2048, "MissileRegular")
			//MissileLongRange:
			// like regular attack but spread reduced from 7 to 4				
			
			TNT1 A 0 A_SetUserVar("user_spread", CallAcs("CalcBarrageSpreadFromDistanceToTarget", 700, 400, 768, 2048)) 
				// arc near, arc far, threshold near, threshold far
				// degree percent, degree percent, map units, map units
				// return value is fixed degrees
				
		
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			TNT1 A 0 A_JumpIfTargetInLOS(2)
			TNT1 A 0 A_JumpIf(user_dont_adjust_aim, 2)
			TNT1 A 0 A_FaceTarget
			ANNI E 8
			TNT1 A 0 A_SetUserVar("user_dont_adjust_aim", 0)

			

			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale, angle + FIXED_TO_FLOAT * user_spread, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale)

			TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 180 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			
			
				//***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
			
			ANNI E 7 //A_FaceTarget
			
			

			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale, angle + FIXED_TO_FLOAT * user_spread,angle - FIXED_TO_FLOAT * user_spread, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale, - FIXED_TO_FLOAT * user_spread)

			
			
				//***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
			
			ANNI E 7 //A_FaceTarget

			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale, angle + FIXED_TO_FLOAT * user_spread, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale, FIXED_TO_FLOAT * user_spread)		

			
			
				//***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
			
			ANNI E 7 //A_FaceTarget
			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale)
			
			
			
				//***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
			
			ANNI E 7 //A_FaceTarget
			
			ANNI E 12
			Goto See
			
		SpecialAttack:
			
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			TNT1 A 0 A_JumpIfTargetInLOS(2)
			TNT1 A 0 A_JumpIf(user_dont_adjust_aim, 2)
			TNT1 A 0 A_FaceTarget
			ANNI E 6
			TNT1 A 0 A_SetUserVar("user_dont_adjust_aim", 0)

			// special attack uses fixed spread for all ranges
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,0,0)
			
			TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 180 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			
			ANNI E 5 //A_FaceTarget
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
				TNT1 A 0 A_JumpIfTargetInLOS(2)
				TNT1 A 0 A_Jump(256, 2)
				TNT1 A 0 A_FaceTarget
			
			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,+20.0 * FIXED_TO_FLOAT * user_head_scale,angle - 7, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,+20.0 * FIXED_TO_FLOAT * user_head_scale,-7,0)
			

			TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 180 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			
			ANNI E 5 //A_FaceTarget
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
				TNT1 A 0 A_JumpIfTargetInLOS(2)
				TNT1 A 0 A_Jump(256, 2)
				TNT1 A 0 A_FaceTarget

			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,angle + 7, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,7,0)
			
			TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 180 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			
			ANNI E 5 //A_FaceTarget
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
				TNT1 A 0 A_JumpIfTargetInLOS(2)
				TNT1 A 0 A_Jump(256, 2)
				TNT1 A 0 A_FaceTarget
			
			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale,0,0)
			
			TNT1 A 0 A_JumpIf(CallACS("GetDistanceToTarget", 999) <= 180 && CallACS("GetIsZDeltaToTargetInRange", -40, 40) && !CallACS("GetIsTargetUnStompeable"), "Stomp")
			
			ANNI E 5 //A_FaceTarget
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
				TNT1 A 0 A_JumpIfTargetInLOS(2)
				TNT1 A 0 A_Jump(256, 2)
				TNT1 A 0 A_FaceTarget
			
			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,0,0)
			

			ANNI E 5 //A_FaceTarget
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 4)
				TNT1 A 0 A_JumpIfTargetInLOS(2)
				TNT1 A 0 A_Jump(256, 2)
				TNT1 A 0 A_FaceTarget
			
			
			
			// MUST use auto-aiming at visible targets, otherwise misses at close range due to projectile's origin offset
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 2)
			TNT1 A 0 A_JumpIfTargetInLOS(3)
			// the version with auto-aim disabled:		
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,20.0 * FIXED_TO_FLOAT * user_head_scale,angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_Jump(256, 2)
			// the auto-aimed version:
			ANNI F 3 BRIGHT A_CustomMissile("GoldenCyberBall",50.0 * FIXED_TO_FLOAT * user_head_scale,-20.0 * FIXED_TO_FLOAT * user_head_scale,0,0)
			TNT1 A 0 // a dummy frame for A_Jump

			Goto See
			
		Melee:
			TNT1 A 0 A_JumpIf(!CallACS("GetIsZDeltaToTargetInRange", -40, 40) || CallACS("GetIsTargetUnStompeable"), "Missile")
			
		Stomp:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInTargetInventory("IsInATank", 1, "SpecialAttack")
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsACyberdemon", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")	
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			
			//***Che adding a windup sound
			TNT1 A 0 A_PlaySound("KYBWHRR", CHAN_BODY)
			ANNI A 4 A_FaceTarget
			
			ANNI A 1
			
			TNT1 A 0 A_Recoil(-7) //versus chad's -5)
			
			
				//***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 ThrustThingZ(0,25,0,1)
			TNT1 A 0 A_Recoil(-12) // versus chad's -10)
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			ANSA H 7 //A_FaceTarget
			ANSA HHHHHHHHHHH 1 A_CheckFloor("StompLand")
			ANSA H 1 A_Jump(256, "StompLand")
			Wait
		StompLand:
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			TNT1 A 0 A_CustomMissile("CyberStompMedium",10,0,0,0)
			ANSA I 7
			
			ANSA I 7
			
			Goto See			

		Pain.Head:
		Pain.HeadPlasma:
		Pain.Decaptate:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_headshot_stun_limit", user_headshot_stun_limit - 1)
			TNT1 A 0 A_JumpIf(user_headshot_stun_limit < 0, "HeadStunAftermath") // *immediate* uniterruptable furious retaliation
			TNT1 A 0 A_JumpIf(user_headshot_stun_limit == 0, "Pain.HeadStun")
			// Just pain
			
		Pain:
			ANNI G 1 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -13, 0, 85)
			ANNI G 4 A_Pain
			ANNI G 4 A_Pain
			Goto See
			
		IosChastises: // required by boss in Chebskies-EDAY map 313
			"----" A 0 A_ClearTarget			
			"----" A 0 HealThing(500)
			"----" A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 40, 90, 0)	
			Goto Pain
			
		Pain.Argent: // inflicted by ghost souls spammed by super archviles
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_headshot_stun_limit", 0)
			TNT1 A 0 HealThing(500)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 40, 90, 0)	
			
			ANNI G 1 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -13, 0, 85)
			ANNI G 3 A_Pain
			
			Goto Pain.Taunt // results in furious spraying in a random direction if target is out of sight
			
			
		Pain.HeadStun:
		
			// 25% standard short pain
			// 37.5% one second stun followed by retaliation (33.3%) / furious retaliation(66.6%)
			// 37.5% two seconds stun followed by furious retaliation
		
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_JumpIf(user_headshot_stun_limit <= 0, "HeadStunAftermath") // *immediate* uniterruptable furious retaliation
			TNT1 A 0 A_SetUserVar("user_headshot_stun_limit", user_headshot_stun_limit - 2)
			TNT1 A 0 A_SetUserVar("user_bleeding_angle", random(-110,110))
			ANNI G 1 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", -13, 0, 85)
			TNT1 A 0 A_Pain
			
			TNT1 A 0 A_FaceTarget // *assuming* it was a railgun, we thus lock our firing angle at where the player was before retreating into cover
			
			ANNI GGGG 2 A_CustomMissile ("Brutal_LiquidBlood2", 110, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			TNT1 A 0 A_Jump(64, "See") // just a common short pain, no retaliation
			
			
			// +1 second stun
			TNT1 A 0 A_Pain
			ANNI GGGGGGGGGG 2 A_CustomMissile ("Brutal_LiquidBlood2", 115, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			TNT1 A 0 A_Pain
			ANNI GGGG 4 A_CustomMissile ("Brutal_LiquidBlood2", 115, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			TNT1 A 0 A_SetUserVar("user_dont_adjust_aim", 1)
			TNT1 A 0 A_Jump(127, "Missile", "SpecialAttack", "SpecialAttack")
			TNT1 A 0 A_SetUserVar("user_dont_adjust_aim", 0)
			
			
			// + one more second stun followed by furious retaliation
			TNT1 A 0 A_Pain
			ANNI GGGGGGGGGG 2 A_CustomMissile ("Brutal_LiquidBlood2", 115, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			TNT1 A 0 A_Pain
			ANNI GGGG 4 A_CustomMissile ("Brutal_LiquidBlood2", 115, 0, angle + user_bleeding_angle + random (-15, 15), CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH, random (15, 55))
			
		HeadStunAftermath:	
			TNT1 A 0
			TNT1 A 0 A_PlaySound("cyber/sight", CHAN_VOICE)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_SetUserVar("user_dont_adjust_aim", 1) // fire in the direction that caused pain, first. 
			// Will adjust aim during firing, if player in LOS. If no LOS, will keep laying down suppressive fire past player's cover.
			
			ANNI G 1 A_Jump(256, "SpecialAttack")
			Wait // Zandronum multiplayer client will repeat the last frame 
				// waiting for a state update from the server
				// Otherwise (GZDoom or singleplayer) this frame never shows because of action functions execute *before* the frame


		Death:
			ANNI H 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			ANNI H 0 A_Scream
			ANNI H 10
			ANNI I 4
			ANNI J 4
			TNT1 AAAAAA 0 A_CustomMissile ("HighExplosiveFlames2", random (40* FIXED_TO_FLOAT * user_head_scale, 90* FIXED_TO_FLOAT * user_head_scale), 0, random (0, 360), 2, random (0, 360))
			ANNI J 4
			//TNT1 A 0 A_CustomMissile ("XDeathCyberdemonHead", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			Goto Death_Explosion


		XDeath:
		Death.Telefrag:	
		XDeath.Telefrag:
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_Scream
			TNT1 A 0 A_CustomMissile("ExplosionSplashSpawner") // liquid splash causer
			TNT1 A 0 Radius_Quake (6, 100, 0, 22, 0)
			TNT1 AAAA 0 A_CustomMissile ("ExplosionSpawner", 90* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAAA 0 A_CustomMissile ("ExplosionSpawner", 90* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAA 0 A_CustomMissile ("UltraGoreSPawner", 90* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAAA 0 A_CustomMissile ("UltraGoreSpawner", 90* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_CustomMissile ("CyberXDeath", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			ANNI IJKLMNOP 1
			ANNI P 120
			ANNI P 1 A_Jump(256, "CheckIfBoss")
			Wait // Zandronum client will skip the jump and keep repeating the last frame until receives status change from the server

		Death_Explosion:
			EXPL A 0 Radius_Quake (6, 50, 0, 22, 0)
			TNT1 A 0 A_CustomMissile("ExplosionSplashSpawner") // liquid splash causer
			TNT1 AA 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			
			TNT1 A 0 A_NoBlocking

			TNT1 A 0 A_CustomMissile ("XDeathCyberdemonArm", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_CustomMissile ("XDeathCyberdemonGun", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_CustomMissile ("XDeathCyberdemonPiece", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_CustomMissile ("XDeathCyberdemonTorso", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAA 0 A_CustomMissile ("BDExplosionparticles3", 74 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAA 0 A_CustomMissile ("BDExplosionparticles4", 76 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AA 0 A_CustomMissile ("ExplosionSpawner", 40 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (10, 90))
			EXPL AA 0 A_CustomMissile ("BigBlackSmokeLarger", 40 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (10, 90))
			TNT1 A 0 A_CustomMissile ("CyberXDeath", 0, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			ANNI MNOP 5
			ANNI P 120
			ANNI P 1 A_Jump(256, "CheckIfBoss")
			Wait // Zandronum client will skip the jump and keep repeating the last frame until receives status update from the server		
			

		Death_Beheaded:	
			ANSA WWWWWWWW 3 A_SpawnItem("MuchBlood3", 0, 120.0 * FIXED_TO_FLOAT * user_head_scale)
			ANSA XXYYWWXXYYWW 4 A_SpawnItem("MuchBlood", 0, 120.0 * FIXED_TO_FLOAT * user_head_scale)
			Goto Death_Explosion				
				
		Death.Head:
			//***Che: Decaptate damage is now relayed directly by the headbox
		Death.HeadPlasma:
		Death.HeadStun:	
		Death.Decaptate:
			TNT1 A 0
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			//TNT1 AAA 0 A_CustomMissile ("Brains6Big", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			//TNT1 AAA 0 A_CustomMissile ("Brains7Big", 210, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			TNT1 A 0 A_CustomMissile ("UltraGoreSPawner", 210 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_CustomMissile ("UltraGoreSPawner", 120 * FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 AAAAA 0 A_CustomMissile ("XDeath3b", 120* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 AAAAA 0 A_CustomMissile ("XDeath2b", 120* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			TNT1 AAAAA 0 A_CustomMissile ("MeatDeath", 120* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (50, 90))
			Goto Death_Beheaded
/*
		Death.Decaptate:
			TNT1 A 0
			TNT1 A 0 A_StopSound(CHAN_VOICE) 
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			//***Che scalability and palette-swappability:
			//TNT1 A 0 A_CustomMissile ("XDeathCyberdemonHead", 120, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			TNT1 A 0 A_SpawnItemEx ("XDeathCyberdemonHead", 0,0,120.0* FIXED_TO_FLOAT * user_head_scale, random(-5,5),random(-5,5),random(3,5), 0,SXF_TRANSFERTRANSLATION | SXF_TRANSFERSCALE,0)
			TNT1 AAAAAAAAA 0 A_CustomMissile ("XDeath1", 120.0* FIXED_TO_FLOAT * user_head_scale, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			Goto Death_Beheaded
*/			

		CheckIfBoss:
			"----" A 1
			"----" A -1 A_BossDeath
			Stop
			
		Death.Fatality:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DeleteHeadboxMkII")
			TNT1 A 0 A_Pain
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_JumpIfIntargetInventory("IsPlayer", 1, 1)
			Goto Death
			TNT1 A 0
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("ErsatzFatalityEpic", 1)
			ANNI H 0 A_Scream
			ANNI H 12
			ANNI IJ 2
			TNT1 A 0 ACS_NamedExecuteAlways("DropFatalityBonuses", 0, 40, 40, 0) // 0, health, armor, 0 -- rounded down to nearest 2
			Goto Death_Explosion		
			
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "SpecialAttack")
			TNT1 A 0 A_Pain
			TNT1 A 0 A_ChangeFlag("FASTER", 1)
			TNT1 A 0 A_ChangeFlag("MISSILEMORE", 1)
			TNT1 A 0 A_ChangeFlag("MISSILEEVENMORE", 1)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_PlaySound("demon/pain", CHAN_VOICE)
			ANSA A 1 A_FaceTarget
			ANSA A 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, 0, 81)
			ANSA B 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, 0, 75)
			ANSA C 8 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 11, 0, 73) 
			TNT1 A 0 A_PlaySound("CYBTAT", 1)
			ANSA CDEFGFEDCDEFGFED 3
			ANSA B 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 10, 0, 75)
			ANSA A 4 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 5, 0, 81)
			"----" A 0 A_GiveInventory("Enraged", 1)
			//Goto Missile
			"----" A 1 A_Jump(256, "Missile")
			Wait			
	}
}	

























// moved from SpecialDoom1Bosses.txt

ACTOR CyberdemonE2M8Boss: CyberDevastator 2546 {
	Scale 2.4
	Radius 62
	Height 204
	Obituary "%o was destroyed by the Cyberdemon."
	Tag "Cyberdemon Lord of Deimos"
	Health 20000
    damagefactor "Crush", 20.0
	MaxStepHeight 64
	MaxDropOffHeight 64
	Speed 28
	FastSpeed 32
	painchance "kick", 0
	States {
		Spawn:
			ANNI A 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster", 20, 240) // e2m8boss headbox, 240% headbox scale
			ANNI A 0 
			TNT1 A 0 A_SetUserVar("user_headshot_stun_limit", 12) // prevents permanent stunlock
			TNT1 A 0 A_GiveInventory("TargetIsACyberdemon")
			TNT1 A 0 A_GiveInventory("TargetIsABoss")
			TNT1 A 0 A_GiveInventory("TargetIsAGreatTerribleBoss")
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 
			Goto Stand
/*
		Death:
			CYBR H 10
			EXPL A 0 Radius_Quake (6, 100, 0, 22, 0)
			TNT1 AAAA 0 A_CustomMissile ("ExplosionSpawner", 190, 0, random (0, 360), 2, random (0, 180))
			TNT1 AAAAAA 0 A_CustomMissile ("ExplosionSpawner", 190, 0, random (0, 360), 2, random (0, 180))
			TNT1 AAAA 0 A_CustomMissile ("UltraGoreSPawner", 190, 0, random (0, 360), 2, random (0, 180))
			TNT1 AAAAAA 0 A_CustomMissile ("UltraGoreSpawner", 190, 0, random (0, 360), 2, random (0, 180))
			TNT1 A 0 A_CustomMissile ("CyberXDeath", 100, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAA 0 A_CustomMissile ("MuchMeatDeath", 0, 0, random (0, 360), 2, random (0, 160))
			CYBR I 5 A_Scream
			TNT1 A 0 A_CustomMissile ("RidiculousExplosionSpawner", 150, 0, random (0, 360), 2, 90)
			CYBR JKL 5
			CYBR M 5 A_NoBlocking
			CYBR NOP 5
			CYBR P 200
			CYBR P 1 A_BossDeath
			TNT1 A 0 A_BrainDie
			CYBR P 1 A_Jump(256, "CheckIfBoss")
			Wait // Zandronum client will skip the jump and keep repeating the last frame until receives status change from the server
*/			
		CheckIfBoss:
			"----" A 1 A_BossDeath
			"----" A 500
			"----" A 0 A_BrainDie // end the map
			"----" A -1 
			Stop
		StompLand:
			
			TNT1 A 0 ACS_NamedExecuteWithResult("AdjustHeadboxMkII", 0, 0, 85)
			TNT1 A 0 A_CustomMissile("CyberStompBig",10,0,0,0) // 300 in a radius of 300. You go splat, puny manling!
			ANSA I 7
			
			ANSA I 7
			
			Goto See				
	}
}


//***Che: I am absolutely unsure what this was about, but BD21 had it
// Much smaller, mind you: the BD21 bosses had 2.5 scale -- but im NOT going to fiddle with headboxes
Actor GreatCyberdemon: CyberDevastator 15858 {
	Health 10000
    damagefactor "Crush", 20.0
	MaxStepHeight 64
	MaxDropOffHeight 64
	Speed 28
	FastSpeed 32
	painchance "kick", 0
}			