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





// moved to FBD_nomonon.txt and FBD_Monstersonly.txt
//ACTOR SuperBlurSphereNoCount: SuperBlurSphere 

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

//***Che: cross-mod hardening: see ACTOR Spectro: FBD_BullDemon Replaces Spectre {} in Doom_Replacements.txt

ACTOR FBD_Spectro: FBD_BullDemon 17847
{
	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!
	
	Mass 400
    -FASTER
	DropItem "DemonStrengthRune" 2
	
	//***Che
	//DropItem "SuperBlurSphere" 12
	DropItem "SuperBlurSphereNoCount" 12
	
	RenderStyle Add
    Alpha 0.45
	speed 8
	
	//***Che The bit about see frames duration halved on nightmare forgets to mention the fact 
	//  that that only applies to frames *longer* than 3 tics and cannot bring frame duration below 3.
	// This monster uses 1-tic frames. Nuff said.
	fastspeed 11 //6
	
	Obituary "%o has been sodomized by a Spectre."
	Tag "$SPECTRO" // "Spectre"
	States
	{
		Pain.Ice:
			SARG H 20 A_Pain
			Goto See
	
		WaitTargetsFatalityOut:
			WaitTargetsFatalityOut:
			TNT1 A 0 A_PlaySound("demon/sight", CHAN_VOICE)
			SPEC A 1 A_Jump(256, "WTF1", "WTFWander", "WTFWander")
			Wait
		WTF1:	
			SPEC AAAAAA 6 BRIGHT A_SetAngle(angle + Random(-15, 15))
			Goto See
		WTFWander:
			SPEC AABBCCDDAABBCCDDAABBCCDD 2 BRIGHT A_Wander
			Goto See
		
/*	
		ReplaceVanilla:
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_SpawnItemEx ("VanillaSpectre",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION | SXF_TRANSFERAMBUSHFLAG ,0)
			Stop
*/			
		Spawn:
			SPEC A 1 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			//TNT1 A 0 ACS_NamedExecuteAlways("BDCHeckClassicMonsters", 0, 0, 0, 0)//Check if Vanilla Mode is activated
		Spawned:
			SPEC AAAAAAAAAAAAAAAAAA 10 BRIGHT A_Look
			Loop
		SpawnVisible:
			
			SARG A 10
			Goto Spawned
			
		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_JumpIf(user_serverside_sfchk != -1, 3) // -1 means ACS commands us to do the radiusgive
			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 A_SpawnItemEx("FootStep", 0, 0, 30, 0, 0)
			TNT1 A 0 A_JumpIfInTargetInventory("HasInfrared", 1, "SeeVisible")
			SPEC AAABBBAAABBB 1 BRIGHT A_Chase
			TNT1 A 0 A_JumpIfInTargetInventory("HasInfrared", 1, "SeeVisible")
			SPEC AAABBBAAABBB 1 BRIGHT A_Chase
			Loop
		
		SeeVisible:
			SARG AAABBBCCCDDD 1 A_Chase
			Goto See
		
		Pain:
			SARG H 2
			SARG H 2 A_Pain
			Goto See
			
		Pain.Argent:

			TNT1 A 0
		
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 HealThing(30,300)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 20, 48, 0)	
			
			TNT1 A 0 A_GiveInventory("ComeEatMeDemon", 1)
			TNT1 A 0 A_ChangeFlag("QUICKTORETALIATE", 1)
			TNT1 A 0 A_ChangeFlag("ALWAYSFAST", 1) // turbo boost, switch to FastSpeed
			
			SARG HHHH 8 A_Pain
			Goto SeeContinue			
			
		Pain.Shotgun:
			TNT1 A 0 A_Pain
			TNT1 A 0
			//TNT1 A 0 ThrustThingZ(0,30,0,1)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil (2)
			SARG H 2
			//DEMP A 4
			SARG H 2
			Goto See	

		Pain.Kick:
		Pain.HeavyImpact:
			TNT1 A 0 A_Pain
			TNT1 A 0
			//TNT1 A 0 ThrustThingZ(0,30,0,1)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil (9)
			SARG H 4
			//DEMP B 6
			SARG H 4
			Goto See
			 
		Missile:
			TNT1 A 0
			TNT1 A 0 A_JumpIFCloser(100, "Melee")
			Goto See
			 
		Melee:
			TNT1 A 0
			
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			
			TNT1 A 0 A_TakeInventory("EnemyMemory", 100)
			TNT1 A 0 A_JumpIfInTargetInventory("ComeEatMeDemon", 1, "MeleeDown")
			SARG E 1 A_FaceTarget
			TNT1 A 0 A_Recoil(-5)
			SARG E 6 A_FaceTarget
			SARG F 6 A_FaceTarget
			TNT1 A 0 A_CustomMissile("DemonAttack",40,0,0,0)
			SARG G 12 A_CustomMissile("DemonAttack",5,0,0,0)

			TNT1 A 0 A_JumpIfInventory("ZombieManFatality", 1, "FatalityZombieman")
			TNT1 A 0 A_JumpIfInventory("SergeantFatality", 1, "FatalitySergeant")
			TNT1 A 0 A_JumpIfInventory("ImpFatality", 1, "FatalityImp")
			TNT1 A 0 A_JumpIfInventory("ComandoFatality", 1, "FatalityComando")	

			TNT1 A 0 A_JumpIfInventory("EatMe", 1, "Eat")
			Goto See	
	}
}