


ACTOR MightyMastermind: FBD_Mastermind 17686 {

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

	// projectile origin shifted to 52,10 from the original 42,0 (up and to his right)
	// because his sprites, turns out, have the gun noticeably off-center

	//$Sprite SPYDA1D1
	
	var int user_beam_org_x;
	var int user_beam_org_y;
	var int user_beam_org_z;
	var int user_beam_org_set;
	var int user_firing_mah_lazor;
	var int user_i_am_mighty; // set by descendant class, increases BFG9000 usage
	

	Species "EvilBosses" // for his own BFG and for damaging fires spawned by his lazer, should never harm self
	+DONTHARMSPECIES 
	
	Tag "$UNMAKER_MASTERMIND" // "Unmaker Mastermind" / "Зачинщик - изничтожитель" // I adapt "Unmaker" as "Изничтожитель" (not translateable literally, Russian just doesn't work that way)
	Obituary "$UNMAKER_MASTERMIND_O" // "%o was unmade by a Mastermind." / "%o был изничтожен Зачинщиком."
	
	PainChance "Taunt", 255 

	damagefactor "Killme", 1.0 // AOE inflicted by captured marines
	PainChance "Killme", 255
	
	PainChance "Avoid", 255
	PainChance "Railgun", 255
	PainChance "Extreme", 255
	DamageFactor "Avoid", 1.0
	
	States {
		Spawn:
			SPYD A 1 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			TNT1 A 0 A_GiveInventory("TargetIsAMastermind")
			TNT1 A 0 A_GiveInventory("TargetIsAGreatTerribleBoss")
			TNT1 A 0 A_GiveInventory("TargetIsABoss")
			Goto Stand
/* //***Che fuck vanilla bent over an anchor		
		ReplaceVanilla:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunMonster")
			Goto Stand // fuck vanilla
*/			

		Stand:	
			SPYD A 10 A_Look
			Loop
			
		Idle: // without this, ancestor's method is used resulting in wrong sprites 
				//-- and that wrecks havok with the init scripts!
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_sleeping", 1)
		LookingForPlayer:	
			SPYD AAA 10 A_Look
			TNT1 A 0 A_Jump(64, "LookingForPlayer2")
			Loop
		LookingForPlayer2:
			TNT1 A 0 A_SetAngle(angle + Random(-50,50))
			SPYD A 2 A_PlaySound("spider/walk", CHAN_BODY) 
				// don't use A_Metal, you stoopid Cheb! It performs A_Chase and jumps to Idle immediately!
			SPYD A 4 A_Wander
			SPYD B 4 A_Wander
			SPYD B 2 A_Look
			SPYD C 6 A_Wander
			SPYD D 2 A_PlaySound("spider/walk", CHAN_BODY)
			SPYD D 4 A_Wander			
			SPYD E 2 A_Look
			SPYD E 4 A_Wander
			SPYD F 6 A_Wander
			TNT1 A 0 A_Jump(32, "LookingForPlayer")
			Loop			
			
		See:
		
			//***Che
			// 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, 4)	// we count as 4		
			TNT1 A 0 A_SetUserVar("user_serverside_sfchk", 1) // reply that we did the deed			
			
			SPYD A 2 A_Metal
			SPYD A 2 A_Chase
			SPYD B 2 A_Chase
			SPYD B 2 A_Chase
			SPYD C 2 A_Chase
			SPYD C 2 A_Chase
			SPYD D 2 A_Chase
			SPYD D 2 A_Metal
			SPYD E 2 A_Chase
			SPYD E 2 A_Chase
			SPYD F 2 A_Chase
			Loop	
			
		Pain.Killme:
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, 2)
			TNT1 A 0 A_PlaySound("spider/sight", CHAN_VOICE)
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor, "ImmaFiringMahLazor") // just keep at it
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileBfg9000OhNoes")
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			Goto Missile

		IosChastises: // required by Chebskies-EDAY map 313
			"----" A 0 A_ClearTarget
			"----" A 0 HealThing(500)
			"----" A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 40, 100, 50)	
			Goto Pain
		Pain:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor <= 0, 3)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_sto", CHAN_WEAPON)
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0)
			
			SPYD I 4 A_Pain
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			Goto See
		Pain.Stomp:
			TNT1 A 0		
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil(10)
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor <= 0, 3)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_sto", CHAN_WEAPON)
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0)
			
			SPYD I 2 A_Pain
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			Goto See			
		Pain.Explosive: // cloning because Goto Avoid is not inheritance-aware
		Pain.Bfg10k: //***Che changed damage type from extreme to custom
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_Recoil(10)

			TNT1 A 0 A_JumpIf(user_firing_mah_lazor <= 0, 3)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_sto", CHAN_WEAPON)
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0)

			SPYD I 2 A_Pain
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			Goto Avoid
		Avoid:
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 1)
			NULL A 0 A_FaceTarget
			TNT1 A 0 A_PlaySound("spider/walk", 7)
			SPYD ABCD 1 A_FastChase
			NULL A 0 A_FaceTarget
			TNT1 A 0 A_PlaySound("spider/walk", 6)
			SPYD ABCD 1 A_FastChase
			NULL A 0 A_FaceTarget
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			Goto Missile+6
		Pain.Railgun: //d'uh
		Pain.Extreme: // bfg 10k
		Pain.Avoid: // rocket alerter tracer
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor <= 0, "Avoid")
			
			// This is him dancing without interrupting his fire!
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 1)
			TNT1 A 0 A_Jump(256, "DodgeLeftWhileFiringLazor", "DodgeRightWhileFiringLazor") 
			SPYD I 1 //Zandronum client skips the jump and loops this frame waiting for server's word
			Wait

		Pain.Argent: // inflicted by ghost souls spammed by super archviles
		
			TNT1 A 0
			TNT1 A 0 HealThing(500)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 40, 100, 50)			
		
			// results in furious spraying in a random direction if target is out of sight:
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, 2)
			TNT1 A 0 A_PlaySound("spider/sight", CHAN_VOICE)
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor, "ImmaFiringMahLazor") // just keep at it
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileBfg9000OhNoes")
			TNT1 A 0 A_GiveInventory("Enraged", 1)
			Goto Missile
			
		DodgeRightWhileFiringLazor:
			TNT1 A 0 ThrustThingZ(0, 20, 0, 1)
			TNT1 A 0 ThrustThing(angle*256/360+192, 15, 0, 0)
			SPYD E 4 A_PlaySound("spider/walk", 7) // otherwise checkfloor fires before he lifts off
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)
			SPYD EEEEEEEEEEEEEE 2 A_CheckFloor("LandAndContinueFiringZazor") 
			Goto ImmaFiringMahLazorLoop
		DodgeLeftWhileFiringLazor:
			TNT1 A 0 ThrustThingZ(0, 20, 0, 1)
			TNT1 A 0 ThrustThing(angle*256/360+64, 15, 0, 0)
			SPYD B 4 A_PlaySound("spider/walk", 7) // otherwise checkfloor fires before he lifts off
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)			
			SPYD BBBBBBBBBBBBBB 2 A_CheckFloor("LandAndContinueFiringZazor") 
			Goto ImmaFiringMahLazorLoop
		LandAndContinueFiringZazor:
			TNT1 A 0
			TNT1 A 0 A_PlaySound("spider/walk", 6)
			Goto ImmaFiringMahLazorLoop
		MissileAtInvisible:
			TNT1 A 0
			Goto Missile
		StopFiring:
			TNT1 A 0
			Goto See
		MissileEnraged:
			TNT1 A 0 
			TNT1 A 0 A_Jump(128, "MissileBfg9000OhNoes") // 50%, regardless of range!
			Goto ImmaChargingMahLazor
		Missile:
			TNT1 A 0 A_TakeInventory ("BrutalCounter2", 500)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			SPYD A 4 A_FaceTarget 
			SPYD A 4 A_FaceTarget 
			SPYD A 4 A_FaceTarget 
			SPYD G 4 A_FaceTarget
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsAMastermind", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")			
			
			//***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
			
			SPYD G 3 //A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileEnraged")
			TNT1 A 0 A_JumpIfCloser(800, "ImmaChargingMahLazor") // only fire bfg 9000 if the player is sniping from afar
		MissileLongRange:		
			TNT1 A 0 
			TNT1 A 0 A_Jump(96, "MissileBfg9000OhNoes") // 38%
		ImmaChargingMahLazor:	
			TNT1 A 0 
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_StopSound(CHAN_WEAPON)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_sta", CHAN_WEAPON) // unmaker sounds with laaaarge roloff
			
			// charging time 1 s (35 tics)
			
				//***Che: do NOT adjust aim if target goes out of sight or is invisible
				TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), 3)
				TNT1 A 0 A_JumpIfTargetInLOS(3)
				TNT1 A 0 A_Jump(256, 3) // jumps to the next frame after a_facetarget
				TNT1 A 0 A_Jump(192, 2) // 1/4th chance to readjust aim (jumps here if target is invisible)
				TNT1 A 0 A_FaceTarget // jumps here if target in LOS
				
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_1", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_1", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_EnergySuck", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_1", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_2", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "ImmaFiringMahLazor") // ohshi, he's fast!
			
			
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_EnergySuck", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_2", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)			
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_3", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_EnergySuck", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)			
				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
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahLazor_3", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
		
		ImmaFiringMahLazor:
			TNT1 A 0	
			
			// fixed 6 - shots bursts, 2 seconds long (12 tics per shot)
			
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 6) // burst length
			
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_lop", CHAN_WEAPON)
			
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)
			
		ImmaFiringMahLazorLoop:	
		
			//***Che: please note that player's Unmaker fires *every* tic inflicting 50 damage per tic
			//  The mastermind's Unmaker is thus nerfed *horribly* 
			//    firing every 12 tics (8 for the mighty one)
			//  Thus, even considering the convention that monsters only inflict 
			//    50% of player's nominally (on UV), it is nerfed x6 (x4 for the mighty one)
					
			TNT1 A 0
				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
			SPYD G 2 BRIGHT A_CustomMissile("ImmaChargingMahLazor_2", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, 2) // arrgh, not the fire rate! (12 tics between shots => 8, i.e. rof 2.9 => 4.3)
			SPYD G 4 BRIGHT
			SPYD H 1 BRIGHT A_CustomMissile("ImmaChargingMahLazor_1", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			"----" A 0 A_JumpIf(user_i_am_mighty, 2) // higher fire rate!
			SPYD H 4 
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_pew", CHAN_BODY)
			TNT1 A 0 A_SetUserVar("user_beam_org_set", 0)
			// because frakkin' projectile cannot tell its point of origin to an ACS script:
			// even if we fire the script on its spawn frame,
			// by the time the script begins executing the projectile had already hit!
			//P.S. OBSOLETED
			//TNT1 A 0 BRIGHT A_CustomMissile("BeamOriginSetter", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, 0)
			
				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
			
			SPYD H 4 BRIGHT A_CustomMissile("SpiderLazer", 52, 10, random(-1, 1)+ angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, random(-1, 1))
			// and again - he may have been interrupted by a pain.avoid and leaped far and wide!
			//TNT1 A 0 BRIGHT A_CustomMissile("BeamOriginSetter", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH, 0)
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0) // Always fires at least one shot, can only flinch after firing the shot
			
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", user_firing_mah_lazor - 1)
			
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTarget"), "StopFiringLazor") // if target no longer exists he'd make pew sounds but no beam would come out!
			
			TNT1 A 0 A_JumpIf( user_firing_mah_lazor <= 0 , "LazorAfterBurst")
			
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "ImmaFiringMahLazorLoop")
			TNT1 A 0 A_JumpIf(user_i_am_mighty, "TryCircleStrafing") // 100% for the mighty one
			TNT1 A 0 A_Jump(32, "TryCircleStrafing") // 12.5% for the regular one
			
			Loop
			
		TryCircleStrafing:
			TNT1 A 0 
			TNT1 A 0 A_JumpIfTargetInLOS("NoCircleStrafing")
			
			// doesnt work :(((((
			//TNT1 A 0 A_CheckLOF("DodgeRightWhileFiringLazor", CLOFF_SKIPOBSTACLES, 10000,0,0,0,0, 64, AAPTR_TARGET)
			//TNT1 A 0 A_CheckLOF("DodgeLeftWhileFiringLazor", CLOFF_SKIPOBSTACLES, 10000,0,0,0,0, -64, AAPTR_TARGET)
			//TNT1 A 0 A_CheckLOF("DodgeRightWhileFiringLazor", CLOFF_SKIPOBSTACLES, 10000,0,0,0,0, 128, AAPTR_TARGET)
			//TNT1 A 0 A_CheckLOF("DodgeLeftWhileFiringLazor", CLOFF_SKIPOBSTACLES, 10000,0,0,0,0, -128, AAPTR_TARGET)
			
			TNT1 A 0 A_JumpIfInventory("CircleStrafeLeft", 1, "DodgeLeftWhileFiringLazor")
			TNT1 A 0 A_JumpIfInventory("CircleStrafeRight", 1, "DodgeRightWhileFiringLazor")
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerRight64", 52, 0, angle - 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerLeft64", 52, 0, angle + 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			
			Goto ImmaFiringMahLazorLoop
			
		NoCircleStrafing:
			TNT1 A 0
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)
			Goto ImmaFiringMahLazorLoop
			
		LazorAfterBurst:	
			// refire
			TNT1 A 0 A_JumpIfTargetInLOS(4, 0, JLOSF_DEADNOJUMP)
			TNT1 A 0 A_Jump(96, "StopFiringLazor")
			TNT1 A 0 A_JumpIf(user_i_am_mighty, "MaybeSwitchToBfg") // the ascendant annihilator mastermind sets this
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MaybeSwitchToBfg")
			TNT1 A 0 // an obligatory stub frame to jump to -- otherwise, script breaks 
				// (the parser assumes you meant the next state's first frame)
				// The game engine only aborts its startup with an error if this frame is missing in the *last* state in the list			

		CheckIfFiredLazorEnough:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "StopFiringLazor")
			TNT1 A 0 A_GiveInventory ("BrutalCounter2", 1)
			TNT1 A 0 A_JumpIfInventory ("BrutalCounter2", 4, "StopFiringLazor")
			Goto ImmaFiringMahLazor
		StopFiringLazor:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0)
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_sto", CHAN_WEAPON)
			Goto See
		MaybeSwitchToBfg:	
			TNT1 A 0
			TNT1 A 0 A_Jump(170, "CheckIfFiredLazorEnough") // 66%
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0) // the sound is replaced by bfg charging sound anyway
			Goto MissileBfg9000OhNoes + 4 // skip the face target
		MissileBfg9000OhNoes:	
			
			SPYD G 1 
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1) // not. interruptable.
						
			SPYD G 1 BRIGHT A_FaceTarget // does this once, then only adjusts aim during the entire charging and firing process if the circle-strafing check passes
			TNT1 A 0
			TNT1 A 0 A_PlaySound("misc/supermaster_bfg_cha", CHAN_WEAPON)
			TNT1 A 0 A_SetUserVar("user_firing_mah_lazor", 0)
			
			// two seconds charging time (75 tics)
			
			SPYD GGG 5 A_CustomMissile("ImmaChargingMahBFG_1", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD GH 5 BRIGHT A_CustomMissile("ImmaChargingMahBFG_2", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerRight64", 52, 0, angle - 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_CustomMissile("CircleStrafeCheckerLeft64", 52, 0, angle + 90, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			
			// give them a few tics to bear fruit
			
			SPYD G 5 BRIGHT A_CustomMissile("ImmaChargingMahBFG_2", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			TNT1 A 0 A_JumpIf (user_i_am_mighty, 2) // 100% for the mighty one
			TNT1 A 0 A_Jump(32, "ContinueChargingBFG") // 12.5% for the regular one
			TNT1 A 0 A_JumpIfTargetInLOS("ContinueChargingBFG")	
			TNT1 A 0 A_JumpIfInventory("CircleStrafeLeft", 1, "StrafeLeftWhileChargingBFG")
			TNT1 A 0 A_JumpIfInventory("CircleStrafeRight", 1, "StrafeRightWhileChargingBFG")
			
			
		ContinueChargingBFG:
			TNT1 A 0
			SPYD HGH 5 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			// Fires it! You are gonna die! (considering I modded the bfg ball to act like q2's one, 
			// meaning it spams homing insta-shred lightning with a horrible rape radius)
			// You and that ball in the same country, you die.
			
			TNT1 A 0 A_PlaySound("misc/supermaster_bfg_fir", CHAN_WEAPON)
			
			SPYD H 10 BRIGHT A_CustomMissile("EnemyBFGBall", 52, 10, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)			
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MaybeBFGRefire")
			TNT1 A 0 A_JumpIf(user_i_am_mighty, "MaybeBFGRefire") 
			
			SPYD G 15
			
			Goto See
		MaybeBFGRefire:
			TNT1 A 0
			TNT1 A 0 A_Jump(128, "See")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "See")
			TNT1 A 0 A_JumpIfTargetInLOS("MissileBfg9000OhNoes", 0, JLOSF_DEADNOJUMP)
			SPYD G 15
			Goto See
		StrafeRightWhileChargingBFG:
			TNT1 A 0 ThrustThingZ(0, 20, 0, 1)
			TNT1 A 0 ThrustThing(angle*256/360+192, 15, 0, 0)
			SPYD E 5 A_PlaySound("spider/walk", 7) // otherwise checkfloor fires before he lifts off
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)
			
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD E 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			Goto ContinueChargingBFG
		StrafeLeftWhileChargingBFG:
			TNT1 A 0 ThrustThingZ(0, 20, 0, 1)
			TNT1 A 0 ThrustThing(angle*256/360+64, 15, 0, 0)
			SPYD B 4 A_PlaySound("spider/walk", 7) // otherwise checkfloor fires before he lifts off
			TNT1 A 0 A_TakeInventory("CircleStrafeLeft", 1)
			TNT1 A 0 A_TakeInventory("CircleStrafeRight", 1)			
			
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			SPYD B 5 A_CheckFloor("LandAndContinueChargingBFG") 
			TNT1 A 0 BRIGHT A_CustomMissile("ImmaChargingMahBFG_3", 66, 0, angle, CMF_ABSOLUTEANGLE | CMF_OFFSETPITCH | CMF_SAVEPITCH)
			
			Goto ContinueChargingBFG
		LandAndContinueChargingBFG:
			TNT1 A 0
			TNT1 A 0 A_PlaySound("spider/walk", 6)
			TNT1 A 0 A_JumpIfTargetInLOS(1)
			Goto ContinueChargingBFG		
			TNT1 A 0 A_FaceTarget
			Goto ContinueChargingBFG


		//***Che: Since I'm using a recolored mastermind,
		// the unique cut animation and the fatality won't work 
		// (in part, due to palette-shifting the supreme mastermind into gold and purple)
		// Replacing them with a *simpler* unique animation that is more palette shift friendly:
		// He explodes into gore but the empty platform keeps standing,
		//   then keels over and asplodes.
		// The stomp death, too. Incompatible with the palette swap.
			
		Death:
		Death.Stomp:
		Death.Telefrag:
		Death.Massacre:
			SPYD J 1
			SPYD J 20 A_Scream
			tnt1 a 0 A_FaceTarget
			SPYD K 10 A_NoBlocking
			TNT1 A 0 A_CustomMissile ("RidiculousExplosionSpawner", 30, 0, random (0, 360), 2, 90)
			SPYD LM 5
			EXPL A 0 Radius_Quake (8, 100, 0, 22, 0)
			TNT1 A 0 A_Explode(150, 300)
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("PEPart2SuperFast", 32, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAAAAA 0 A_CustomMissile ("BloodMistXXBig", 40, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("BloodMistXXBig", 100, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAAA 0 A_CustomMissile ("UltraGoreSPawner", 80, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			//TNT1 AAA 0 A_CustomMissile ("MastermindLeg", 40, 0, random (0, 360), 2, random (40, 90))
			TNT1 AA 0 A_SpawnItemEx("SupremeMastermindLeg", 40,random(-30, 30),random(-30, 30), random(-24,24),random(-24,24),random(12,24), Random(0,360), SXF_TRANSFERTRANSLATION,0)
			TNT1 A 0 A_SpawnItem ("GiantBloodSpot")
			
			TNT1 A 0 A_ChangeFlag("NOTARGET", 1)
			SPYD NOPQR 5
			SPYD S 300
			SPYD S 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.Fatality:
			TNT1 A 0
			TNT1 A 0 A_GiveToTarget("SoulAmmo", 1)
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_JumpIfIntargetInventory("IsPlayer", 1, 1)
			Goto Death
			TNT1 A 0 A_GiveToTarget("GoFatality", 1)
			TNT1 A 0 A_GiveToTarget("ErsatzFatalityEpic", 1)
			SPYD C 5 A_FaceTarget
			SPYD C 5 A_PlaySound("SPIPAIN1", CHAN_VOICE)
			SPYD C 5 A_FaceTarget
			TNT1 A 0 ACS_NamedExecuteAlways("DropFatalityBonuses", 0, 25, 25, 0) // 0, health, armor, 0 -- rounded down to nearest 2
		Death.Cut:
		Death.Saw:
		Death.decaptate:	
			TNT1 A 0
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("PEPart2SuperFast", 82, 0, random (0, 360), 2, random (0, 160))
			TNT1 AAAAAAA 0 A_CustomMissile ("BloodMistXXBig", 90, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAAAAAAAAA 0 A_CustomMissile ("BloodMistXXBig", 150, 0, random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			TNT1 AAAA 0 A_CustomMissile ("MuchMeatDeath", 55, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 160))
			
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_ChangeFlag("NOTARGET", 1)
			
			// it has no mastermind, but the metal to gold translation of the supreme mastermind has still to apply:
			TNT1 A 0 A_SpawnItemEx("MastermindlessPlatform",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION | SXF_TRANSFERTRANSLATION,0)
			
			TNT1 AAAA 17 A_CustomMissile ("UltraGoreSPawner", 80, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 180))
			
			TNT1 A 300
			TNT1 A 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						
			
	}
}


ACTOR SupremeMastermind: MightyMastermind 17687 { // much more bfg happy
	Health 7000
	//$Sprite SPYDH1
	
	Tag "$ANNIHILATOR_MASTERMIND" // = "Annihilator Mastermind";
	Obituary "$ANNIHILATOR_MASTERMIND_O" // = "%o was annihilated by a Mastermind.";
	
	// red-purple body and gold legs
	Translation "168:191=250:254", "16:47=171:191", "128:143=160:167", "80:95=224:231", "96:103=160:167", "104:108=185:191", "109:109=5:8", "110:111=0:0", "48:79=16:47", "144:151=163:167", "152:159=165:167"
	
	States {
		Missile:
			TNT1 A 0 A_TakeInventory ("BrutalCounter2", 500)
			TNT1 A 0 A_SetUserVar("user_i_am_mighty", 1) //don't want to give him a separate spawn state
			TNT1 A 0 A_TakeInventory("TargetIsABoss")
			TNT1 A 0 A_GiveInventory("TargetIsAGreatTerribleBoss")
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			TNT1 A 0 A_ChangeFlag("NODROPOFF", 0)
			SPYD A 4 A_FaceTarget 
			SPYD A 4 A_FaceTarget 
			SPYD A 4 A_FaceTarget 
			SPYD G 4 A_FaceTarget
			
			// Kinslayer check:	
			TNT1 A 0 A_JumpIfInTargetInventory("TargetIsAMastermind", 1, 2)
			TNT1 A 0 A_JumpIf(true, 2)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_InfightFriendlyFireOn")			
			
			//***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
			
			SPYD G 3 //A_FaceTarget
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, "MissileEnraged")
			TNT1 A 0 A_JumpIfCloser(500, "ImmaChargingMahLazor")
		MissileLongRange:		
			TNT1 A 0 
			TNT1 A 0 A_Jump(144, "MissileBfg9000OhNoes") // 56%
			Goto ImmaChargingMahLazor
		MissileEnraged:
			TNT1 A 0 
			TNT1 A 0 A_Jump(160, "MissileBfg9000OhNoes") // 62%
			Goto ImmaChargingMahLazor
		MaybeBFGRefire:
			TNT1 A 0
			TNT1 A 0 A_Jump(64, "See")
			TNT1 A 0 A_JumpIfTargetInLOS("MissileBfg9000OhNoes", 0, JLOSF_DEADNOJUMP)
			SPYD G 15
			Goto See
		Pain.Taunt:
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIfInventory("Enraged", 1, 2)
			TNT1 A 0 A_PlaySound("spider/sight", CHAN_VOICE)
			TNT1 A 0 A_JumpIf(user_firing_mah_lazor > 0, "ImmaFiringMahLazorLoop") // just keep at it
			Goto MissileBfg9000OhNoes	
	}
}


ACTOR MastermindlessPlatform {
	+FLOORCLIP
    +DONTRIP
	+BOSSDEATH
	+SOLID
	+SHOOTABLE
	+NOBLOODDECALS
	-BLOODSPLATTER	
	Health 500
	Radius 60
	Height 38
	Scale 1.1
	BloodType "TankBlood", "TankBlood", "TankBlood"
	States {
		Spawn:
			SPID W 1 
			SPID W 60
			SPID X 10
			SPID Y 10
			SPID Y 60
			// Its gonna blow. Get away, ya idjit!
			SPID YYYYYY 10 A_SpawnItemEx("DetectFloorCrater", Random(-25,25),Random(-25,25),0, 0,0,0, 0,SXF_NOCHECKPOSITION,0)
		Death:
			TNT1 A 0
			TNT1 A 0 A_NoBlocking
			TNT1 A 0 A_SetDamageType("ExplosiveImpact")
			TNT1 A 0 A_Explode(150, 300)
			TNT1 A 0 A_CustomMissile ("RidiculousExplosionSpawner", 30, 0, random (0, 360), CMF_AIMDIRECTION, 90)
			TNT1 AAAAAA 0 A_CustomMissile ("ExplosionSpawner", 10, 0, random (0, 360), CMF_AIMDIRECTION, random (0, 360))
			TNT1 AAAA 0 A_SpawnItemEx("SupremeMastermindLeg", 30,random(-30, 30),random(-30, 30), random(-24,24),random(-24,24),random(12,24), 0, SXF_TRANSFERTRANSLATION,0)
			EXPL A 0 Radius_Quake (8, 100, 0, 22, 0)
			TNT1 A 30
			Stop
	}
}

ACTOR SupremeMastermindLeg: MastermindLeg {
	-MISSILE
	States {
		Spawn:
			SPP4 A 5
			TNT1 A 0 A_ChangeFlag("MISSILE", 1)
		Fly:
			TNT1 A 0 A_JumpIf(waterlevel > 1, "Underwater")
			SPP4 BCDEFGHA 5
			Loop
	}
}


ACTOR ImmaChargingMahLazor_Abstract: FastProjectile {
	// short-lived effects (5 tics nominal) because what if the boss is interrupted by pain?
	+DONTSPLASH
	-FORCEYBILLBOARD
	+FORCEXYBILLBOARD
	+NOINTERACTION
	+NOBLOCKMAP
	+CLIENTSIDEONLY
	+BRIGHT
	Damage 0
	Speed 30
	Renderstyle Add
	States {
		Spawn:
			TNT1 A 1 // basically teleports to its destination
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 1 // insert your dramatic charging animation here
			Stop
	}
}

ACTOR ImmaChargingMahBFG_Abstract: ImmaChargingMahLazor_Abstract {
	Scale 0.7
}


ACTOR ImmaChargingMahLazor_EnergySuck: ImmaChargingMahLazor_Abstract {
	// the "particles being sucked in" anime effect - a must for any wave motion gun
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			SPKS IHGFEDCBA 2 
			TNT1 A 1
			Stop
	}
}

ACTOR ImmaChargingMahLazor_1: ImmaChargingMahLazor_Abstract {
	// flashing red flare, small
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BAL1 AABB 1 
			SPRK s 1 
			TNT1 A 1
			Stop
		Flare2:
			BAL1 ABABAB 1
			Stop
		Flare3:
			LEYS R 1 
			BAL1 ABAB 1
			Stop
		Flare4:
			BAL1 AB 1
			LEYS R 1 
			BAL1 AB 1 
			SPRK s 1 
			TNT1 A 1
			Stop
	}
}

ACTOR ImmaChargingMahLazor_2: ImmaChargingMahLazor_Abstract {
	// flashing red flare, medium
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BLHD ABA 1
			FLAR B 1 		
			BHLD B 1
			Stop
		Flare2:
			SPRK O 1
			L2NR A 1 
			BLHD B 1
			FLAR B 1
			L2NR A 1
			Stop
		Flare3:
			BLHD A 1
			BLHD B 1
			L2NR A 1 
			SPRK s 1
			SPKO A 1 
			Stop
		Flare4:
			SPRK OA 1 
			SPKO A 1 
			L2NR A 1  
			TNT1 A 1
			Stop
	}
}

ACTOR ImmaChargingMahLazor_3: ImmaChargingMahLazor_Abstract {
	// flashing red flare, big
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BLHD D 1
			SPRK AOAO 1
			Stop
		Flare2:
			BLHD CDCD 1
			SPRK O 1
			Stop
		Flare3:
			SPRK AO 1
			SPKO A 1
			SPRK AO 1
			Stop
		Flare4:
			BLHD C 1
			BLHD D 1
			SPKO A 1
			SPRK A 1
			SPRK O 1
			Stop
	}
}

ACTOR ImmaChargingMahBFG_1: ImmaChargingMahBFG_Abstract {
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BFE2 DCBDCB 1
			Stop
		Flare2:
			BFE2 DCDCDC 1
			Stop
		Flare3:
			BFE2 CBCBCC 1
			Stop
		Flare4:
			BFE2 DCBCD 1
			Stop
	}
}


ACTOR ImmaChargingMahBFG_2: ImmaChargingMahBFG_Abstract {
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BFE2 CBACA 1
			Stop
		Flare2:
			BFE2 ABABC 1
			Stop
		Flare3:
			BFE2 CBCBCB 1
			Stop
		Flare4:
			BFE2 BACBC 1
			Stop
	}
}

ACTOR ImmaChargingMahBFG_3: ImmaChargingMahBFG_Abstract {
	States {
		Spawn:
			TNT1 A 1
			Goto Death
		Death:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 A_Jump(256, "Flare1", "Flare2", "Flare3", "Flare4")
		Flare1:
			BFE1 ADADA 1
			Stop
		Flare2:
			BFE1 ABABA 1
			Stop
		Flare3:
			BFE1 DEBED 1
			Stop
		Flare4:
			BFE1 ADBDA 1
			Stop
	}
}




ACTOR EnemyBFGBall: Quake2AndDoom2016LikeBFGBall {
	Species "EvilBosses" // because it is otherwise designed not to hurt player
	
	// half the player's
	Damage (random(150, 150)) //Damage (random(300, 300))
	
	States
	{
		Spawn:
			BFGN A 0
			BFGN A 0 A_GiveInventory("BfgBallRaysCount", 20)
			BFGN A 0 A_SpawnItemEx("BFGFOG", 0, 0)
			BFS1 ABABABABAB 1 BRIGHT // first 10 tics, no spam
		FlyOnwards:
			// after that, start spamming lightning
			BFS1 AB 1 BRIGHT A_CustomMissile("EnemyBFGBallLazerProjectile", 0.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH, Random(-70,70))
			
			// continued hugging the floor, annoyingly, if fired at very shallow angles
			// (e.g. always when the mastermind is concerned -- his firing origin
			//  is above Doomguy's head
			TNT1 A 0 A_JumpIf((z - floorz) < 20, "Death")
			Loop
		 
		Death:
			BFGN A 0
			BFGN A 0 A_Stop // in case we are "died" manually
			BFGN A 0 Radius_Quake(4,34,0,12,0)
			BFGN A 0 Radius_Quake(1,34,0,32,0)
			BFGN A 0 A_SpawnItemEx ("ExplosionSplashSpawner", 0, 0, -20)
			BFGN A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AA 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			BFGN A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_PlaySOund("BFGEXPL2", 1)
			BFGN A 0 Bright A_SpawnItem("GreenShockWave",0,0,0)
			//BFE1 A 0 A_SpawnItemEx("BFGDeathParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
			//BFE1 A 0 A_SpawnItemEx("BFGSuperParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 0, 0, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 50, 0, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", -50, 0, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 0, 50, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 0, -50, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 50, 50, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", 50, -50, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", -50, 50, 0)
			EXPL A 0 A_SpawnItemEx("BFGBigFlare", -50, -50, 0)
			EXPL AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("BFGDeathParticleFast", 0, 0, random (0, 360), 2, random (0, 360))
			EXPL AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("BFGDeathParticleSuperFast", 0, 0, random (0, 360), 2, random (0, 360))
			EXPL AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("BFGDeathParticleFast", 0, 0, random (0, 360), 2, random (0, 360))
			EXPL AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("BFGDeathParticleFast", 0, 0, random (0, 360), 2, random (0, 360))

			BFGN A 0 A_Explode(200,400,0)
			
			//TNT1 A 0 A_JumpIfInventory("BfgBallRaysCount", 1, "DeathAdvanced")
			//Goto DeathPointBlank
		
		DeathAdvanced:
			
			// The flash is a separate entity, purely cosmetic. 
			BFGN A 0 A_SPawnItemEx("SuperBFGExtraGiantChe", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION, 0, 0)
			
			// We go invisibal and spam beams!
			TNT1 A 0 A_CheckFloor("DeathFloor")
			TNT1 A 0 A_JumpIf((z - floorz) < 21, "DeathFloor")
			TNT1 A 0 A_CheckCeiling("DeathCeiling")
		
		DeathSpam:
			// projectiles are launched *backwards*, so they curve back towards the target
			TNT1 A 0
			TNT1 A 1 A_CustomMissile("EnemyBFGBallLongReachFastTurning", 0.0, 0.0, Random(135,225), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, - pitch + Random(-45,45)) // angle = 180 +/-45
			TNT1 A 0 A_TakeInventory("BfgBallRaysCount", 1)
			TNT1 A 0 A_JumpIfInventory("BfgBallRaysCount", 1, "DeathSpam")
			TNT1 A 12
			Stop
		DeathFloor:
			TNT1 A 0
			TNT1 A 1 A_CustomMissile("EnemyBFGBallLongReachFastTurning", 24.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, Random(5, 70))
			TNT1 A 0 A_TakeInventory("BfgBallRaysCount", 1)
			TNT1 A 0 A_JumpIfInventory("BfgBallRaysCount", 1, "DeathFloor")
			TNT1 A 12
			Stop
		DeathCeiling:
			TNT1 A 0
			TNT1 A 0 A_Stop
			TNT1 A 1 A_CustomMissile("EnemyBFGBallLongReachFastTurning", -24.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, Random(-70,-5))
			TNT1 A 0 A_TakeInventory("BfgBallRaysCount", 1)
			TNT1 A 0 A_JumpIfInventory("BfgBallRaysCount", 1, "DeathCeiling")
			TNT1 A 12
			Stop
		DeathPointBlank:
			TNT1 A 0
			Goto DeathAdvanced
	}	
}

Actor EnemyBfgBallLazerProjectile: BfgBallLazerProjectile
{
	Species "EvilBosses"
	// half the player's
	Damage (Random(40,40)) //Damage (Random(80,80))
	States	{
		Spawn:
			TNT1 AAAAA 1 A_SeekerMissile(32, 64, SMF_LOOK | SMF_PRECISE, 256, 3)
			TNT1 A 1 A_Jump (256, "Airburst")
			Wait
		Airburst: // no flash
			TNT1 AAA 0 A_CustomMissile("EnemyBfgBallAirExpiration", 0.0, 0.0, Random(-90,90), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH, pitch + Random(-45,45))
			TNT1 A 0
			Stop
		Death:
		XDeath:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("BFGBallFlash", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION, 0,0)
			TNT1 A 0 A_CheckFloor("DeathFloor")
			TNT1 A 0 A_CheckCeiling("DeathCeiling")
			TNT1 AAA 0 A_CustomMissile("EnemyBfgBallRipper", 0.0, 0.0, Random(-45,45), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH, pitch + Random(-35,35))
			TNT1 A 0
			Stop
		DeathFloor:
			TNT1 AAA 0 A_CustomMissile("EnemyBfgBallAirExpiration", 33.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, Random(-70,-15))
			TNT1 A 0
			Stop
		DeathCeiling:	
			TNT1 AAA 0 A_CustomMissile("EnemyBfgBallAirExpiration", -33.0, 0.0, Random(-180,180), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_SAVEPITCH, Random(15,70))
			TNT1 A 0
			Stop
	}
}

Actor EnemyBfgBallLongReachProjectile: EnemyBfgBallLazerProjectile
{
	States	{
		Spawn:
			TNT1 AA 1 A_SeekerMissile(16, 32, SMF_LOOK | SMF_PRECISE, 256, 4)
			TNT1 AAAAAAAA 1 A_SeekerMissile(32, 64, SMF_LOOK | SMF_PRECISE, 256, 4)
			TNT1 A 1 A_Jump (256, "Airburst")
			Wait
	}
}

Actor EnemyBfgBallLongReachFastTurning: EnemyBfgBallLazerProjectile
{
	States	{
		Spawn:
			TNT1 AAAAAAAA 1 A_SeekerMissile(32, 64, SMF_LOOK | SMF_PRECISE, 256, 3)
			TNT1 A 1 A_Jump (256, "Airburst")
			Wait
	}
}



Actor EnemyBfgBallAirExpiration: EnemyBfgBallLazerProjectile
{
	//-RIPPER
	+RIPPER
	+BLOODLESSIMPACT // without this, framerate dies a horrible stuttering death every time you hit a big crowd
	+NOBOSSRIP // only tickle the bosses
	Missiletype "BFGBallLazerTrailSecondary"
	// half the player's
	Damage (Random(1,1)) //Damage (Random(2,2))
	// ripper rips 8 times per tic (i.e. 8..11 times per imp or baron (if horizontally).
	Radius 3
	Height 3	
	//Speed 25
	Speed 32
	States {
		Spawn:
			TNT1 A 1 BRIGHT
			TNT1 AA 1 BRIGHT A_SeekerMissile(64, 90, SMF_LOOK | SMF_PRECISE, 256, 2)
			TNT1 A 0 A_Jump (256, "Airburst")
			Stop
		Airburst:
			TNT1 A 0 // no flash
			Stop
		Death:
		XDeath:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("BFGBallFlash", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION, 0,0) //"BFGBallFlashNoScream"
			Stop			
	}
}

Actor EnemyBfgBallRipper:  EnemyBfgBallAirExpiration
{
	+RIPPER
	+BLOODLESSIMPACT // without this, framerate dies a horrible stuttering death every time you hit a big crowd
	+NOBOSSRIP // only tickle the bosses
	Speed 64
	// half the player's
	Damage (Random(2,2)) //Damage (Random(4,4))
	// ripper rips 8 times per tic (i.e. 8 times per 64 -- i.e. 4..5 times per imp or baron (if horizontally). Must splatter any imp.
	
	States {
		Airburst:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("BFGBallFlashNoScream", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION, 0,0) //"BFGBallFlashNoScream"
			Stop
		Death:
		XDeath:
			TNT1 A 0 // no flash
			Stop			
	}
}

//	SPRK Z 0 is 23x23, would form a line with a step of 8. Scale is 1.6 meaning a step of 13
// fast projectiles leave exactly 8 trail actors per movement (the same code that handles fast ripping projectiles ripping)
// so fast projectile's speed should be 13 x 8 = 104
// the next stage's speed should be 104 x 8 = 832.
// then actual lazor's speed should be that 832 x 8 = 6656

/*
Actor BeamOriginSetter {
	// the hardest task was to feed the beam drawing script the coordinates the projectile was launched from!
	PROJECTILE
	radius 3
	height 3
	Speed 3
	damage 0
	+CLIENTSIDEONLY
	+NOBLOCKMAP // as far as collision detection is concerned, we do not exist
	+NOGRAVITY
	+NOINTERACTION // we are a spherical projectile in vacuum, map geometry doesn't exist for us nor does collision
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	states	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteAlways("SetBeamOrigin", 0, 0, 0, 0)
			TNT1 A 40 // let the script time to run: we disappear, it gets terminated
			// P.S. Addendum: not terminated but *disconnected* losing it access to actors it is tasked with notifying
			Stop
	}
}
*/

Actor SpiderLazer: UnmakerLaser // also replacing flames with custom flames that do not hurt the boss himself
{
	
	//var int user_stopped;
	//var int user_x;
	//var int user_y;
	//var int user_z;
	
	//Speed 5120 // 8 trails with spacing of 640
	Speed 5000
	FastSpeed 5000
	//Speed 500
	Radius 12
	Height 8
	missiletype "none" //"SpiderLazerTrail"
	missileheight 8
	Species "EvilBosses"
	+SKYEXPLODE
	damage (random(35, 35)) // relegating 15 damage to the persisting afterbeams
	States {
		Spawn:

			TNT1 A 0 NODELAY A_CustomMissile("SpiderLazerAfterbeamer", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			
			//TNT1 A 0

			// ACS scripts being asynchronous we cannot rely on the ACS script getting the initial position!
			// jumping through so many hoops just to pass that innocious information to the beam drawing script...
			//TNT1 A 0 A_CustomMissile("BeamOriginSetter", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_pew", 0)
			

			// waits 2 tics, then fires SpiderLazerAfterBeam three times with 1 tic intervals (damage 5 each, total 35)
			
			// fire *both* intermediary projectile types to avoid a HUGE gap in the beginning.
		
			
			//TNT1 A 0 BRIGHT A_CustomMissile("SpiderLazerTrail4", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			//TNT1 A 1 BRIGHT A_CustomMissile("SpiderLazerTrail2", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
				// CMF_AIMDIRECTION does not need a target, but the angle is relative to the calling actor's angle
				// with CMF_ABSOLUTEANGLE the angle is really absolute but the projectile fails to spawn if there is no target
		Fly:	
			TNT1 AAA 1 // limit range to 15000
			TNT1 A 0 A_Stop
		Death:
		XDeath:
			UNHG A 0
			TNT1 A 0 A_Stop
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5") // a serverside script that calls a clientside script to actually draw
			//TNT1 A 0 ACS_NamedExecuteAlways("DrawLazorBeam", 0, "SpiderLazerTrail5", 10, 0)
			UNHG A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			EXPL A 0 A_SpawnItem("ExplosionParticleSpawner")
			EXPL A 0 A_CustomMissile ("FlamethrowerFireParticles", 6, 0, random (0, 360), 2, random (0, 90))
			
			//UNHG A 0 A_CustomMissile("FlamethrowerBurningStuff", random (-32, 0), random (-32, 32), random (-32, 32), 2, random (-32, 32))
			UNHG A 0 A_CustomMissile("SpidersLazersFlames", random (-32, 0), random (-32, 32), random (-32, 32), 2| CMF_TRACKOWNER, random (-32, 32))
			
			UNHG A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_explode(14, 100) //(20, 100)
			TNT1 A 0 A_CustomMissile ("BigBlackSmoke", 0, 0, random (0, 360), 2, random (40, 160))
			//TNT1 A 10 // give the beam drawing ACS sctipt time to run
			//TNT1 A 30 A_SetUserVar("user_stopped", 1)
			//Stop
/*
			TNT1 A 0 A_SetUserVar("user_x", x)
			TNT1 A 0 A_SetUserVar("user_y", y)
			TNT1 A 0 A_SetUserVar("user_z", z)
			// NOTE: this is optimized for looking from the front when he is firing at you 
			//  -- so the forward offset is zero, to match the beam with a flat sprite
			//  aligned to camera!
			// If we cared how this looks from the side, we'd set the forward offset
			//   to wherever his muzzle is (at 40, AFAIR)
			// P.S. WARPF_USECALLERANGLE is vital to preserve missile's angle because that is used
			//  by the clientside script (which is only passed one parameter: beam length)
			TNT1 A 1 A_Warp(AAPTR_TARGET,0,10,52,0,WARPF_STOP|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE,"WarpedOk")
			Stop
		WarpedOk:
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk4") // a serverside script that calls a clientside script to actually draw
*/			
			// keep existing in case script starts delayed - it is CLIENTSIDE after all
			TNT1 A 30
			Stop
	}
}




Actor SpiderLazer2: UnmakerLaser2 // this one does not spawn flames
{
	
	//var int user_stopped;
	var int user_x;
	var int user_y;
	var int user_z;	
	
	//Speed 500
	Speed 5000
	FastSpeed 5000
	Radius 12
	Height 8
	missiletype "none" //"SpiderLazerTrail"
	missileheight 8
	Species "EvilBosses"
	+SKYEXPLODE
	damage (random(35, 35)) // relegating 15 damage to the persisting afterbeams
	States {
		Spawn: 
			TNT1 A 0
			
			// ACS scripts being asynchronous we cannot rely on the drawing ACS script getting the initial position!
			// in fact it is guaranteed to start too late for that, when the projectile had already hit
			//TNT1 A 0 BRIGHT A_CustomMissile("BeamOriginSetter", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			
		
			TNT1 A 0 A_PlaySound("misc/supermaster_laz_pew", 0)
						
			
			TNT1 A 0 BRIGHT A_CustomMissile("SpiderLazerAfterbeamer", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			//TNT1 A 0 BRIGHT A_CustomMissile("SpiderLazerTrail4", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			//TNT1 A 1 BRIGHT A_CustomMissile("SpiderLazerTrail2", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
		Fly:	
			TNT1 AAA 1 // limit range to 15000
			TNT1 A 0 A_Stop
		Death:
		XDeath:
			UNHG A 0
			
			TNT1 A 0 A_Stop
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5") // a serverside script that calls a clientside script to actually draw			
			
			//TNT1 A 0 ACS_NamedExecuteAlways("DrawLazorBeam", 0, "SpiderLazerTrail5", 10, 0)
			UNHG A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			EXPL A 0 A_SpawnItem("ExplosionParticleSpawner")
			EXPL A 0 A_CustomMissile ("FlamethrowerFireParticles", 6, 0, random (0, 360), 2| CMF_TRACKOWNER, random (0, 90))
			UNHG A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_explode(14, 100) //(20, 100)
			//TNT1 A 10 // give the beam drawing ACS sctipt time to run
			//TNT1 A 30 A_SetUserVar("user_stopped", 1)
			//Stop
/*
			TNT1 A 0 A_SetUserVar("user_x", x)
			TNT1 A 0 A_SetUserVar("user_y", y)
			TNT1 A 0 A_SetUserVar("user_z", z)
			// NOTE: this is optimized for looking from the front when he is firing at you 
			//  -- so the forward offset is zero, to match the beam with a flat sprite
			//  aligned to camera!
			// If we cared how this looks from the side, we'd set the forward offset
			//   to wherever his muzzle is (at 40, AFAIR)
			// P.S. WARPF_USECALLERANGLE is vital to preserve missile's angle because that is used
			//  by the clientside script (which is only passed one parameter: beam length)
			TNT1 A 1 A_Warp(AAPTR_TARGET,0,10,52,0,WARPF_STOP|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE,"WarpedOk")
			Stop
		WarpedOk:
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk4") // a serverside script that calls a clientside script to actually draw
*/			
			// keep warping just in case script starts delayed
			TNT1 A 30
			Stop
	}
}	

// the visible beam lingers for 4 more tics. Let's make crossing it hazardous via afterbeams (5 dmg per tic for 3 tics)


Actor SpiderLazerAfterbeamer: SpiderLazer2 // in case you run into the beam after it was fired
{
	radius 3
	height 3
	+FORCEXYBILLBOARD
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	States {
		Spawn:
			TNT1 A 2
			TNT1 AAA 1 A_CustomMissile("SpiderLazerAfterBeam", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			Stop
			Loop	
	}	

}


Actor SpiderLazerAfterBeam: SpiderLazer2 // in case you run into the beam after it was fired
{
	damage (random(5, 5))
	missiletype "none"
	States {
		Spawn:
			TNT1 A 1
			Loop
		Death:
			TNT1 A 0
			TNT1 A 0 A_explode(2, 100) // one tenth of the total damage
			EXPL A 0 A_CustomMissile ("FireBallExplosionFlames", 1, 0, random (0, 360), 2, random (0, 360))
			Stop
		XDeath:
			TNT1 A 0
			Stop
	}

}




// A fucking 5-stage matroshka only to spawn *enough* sprites to form a solid beam. Fucking SOLID, I said!
/*
Alas, this worked perfectly in GZDoom but failed craptacularly in Zandronum 
because Zandronum does not assign fast projectile's pitch to its trails, only the angle.
Boooooo. :(

One more day wasted to figure how to do the same using ACS.

Actor SpiderLazer: UnmakerLaser // also replacing flames with custom flames that do not hurt the boss himself
{
	
	Speed 5120 // 8 trails with spacing of 640
	Radius 12
	Height 8
	missiletype "SpiderLazerTrail"
	missileheight 8
	Species "EvilBosses"
	+SKYEXPLODE
	...
	

Actor SpiderLazerTrail 
	// nope, cannot use another fast projectile for fast projectile's trails.
	// we need intermediaries!
	
	// A note: Zandronum ASSUMES the fast projectile's trails are for decorative purposes only
	//    so the engine effectively forces the CLIENTSIDEONLY flag on them
	// You cannot make them damaging -- well, you can, but then you will eat a bad case of multiplayer desync.
{
	radius 3
	height 3
	+FORCEXYBILLBOARD
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	states	{
		Spawn:
			TNT1 A 0
			TNT1 A 1 BRIGHT A_CustomMissile("SpiderLazerTrail2", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			Stop
	}
}	

Actor SpiderLazerTrail2: FastProjectile {
	radius 3
	height 3
	Speed 640 // 8 trails with spacing of 8
	Damage 0
	+FORCEXYBILLBOARD
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	missiletype "SpiderLazerTrail3"
	missileheight 8	
	states	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 BRIGHT //A_CustomMissile("SpiderLazerTrail4", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
			Stop
	}		
}


ACTOR SpiderLazerTrail3 {
	radius 3
	height 3
	+FORCEXYBILLBOARD
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	renderstyle ADD
	alpha 0.9
	scale 1.6
	states	{
		Spawn:
			TNT1 A 0
			TNT1 A 1 BRIGHT A_CustomMissile("SpiderLazerTrail4", 0, 0, 0, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch)
				//A_CustomMissile("SpiderLazerTrail4", 0, 0, angle, CMF_ABSOLUTEANGLE | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch) // works in gzdoom but fails in zandronum
				// conclusion: in zandronum fast projectile's trails do not inherit pointers.
				// CMF_AIMDIRECTION does not need a target, but the angle is relative to the calling actor's angle
				// with CMF_ABSOLUTEANGLE the angle is really absolute but the projectile fails to spawn if there is no target
			Stop
	}
}


ACTOR SpiderLazerTrail4: FastProjectile {
	Speed 80 // 8 trails with spacing of 10
	radius 3
	height 3
	Damage 0
	+FORCEXYBILLBOARD
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	missiletype "SpiderLazerTrail5"
	missileheight 8	
	alpha 0.9
	scale 1.6	
	states	{
		Spawn:
			TNT1 A 0
			SPRK Z 1 BRIGHT //just in case
			Stop
	}	
}
*/


Actor SpiderLazerTrail5 {
	radius 12
	height 3
	+FORCEXYBILLBOARD
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	+NOINTERACTION
	+NOTELEPORT
	+CANNOTPUSH
	+NODAMAGETHRUST
	renderstyle ADD
	//alpha 0.9
	scale 1.6
	states	{
		Spawn:
			SPRK Z 1 BRIGHT A_Stop
			SPRK ZZZZZ 1 BRIGHT A_FadeOut(0.2)
			Stop
	}
}


	
	
ACTOR SpidersLazersFlames: FlamethrowerBurningStuffNoSelfHarm {
	Species "EvilBosses"
	+DONTHARMSPECIES
	
	// no use, he sets every tree in sight on fire then takes damage from burning trees :(((
}






// moved from SpecialDoom1Bosses.txt

ACTOR E3M8Mastermind: SupremeMastermind 2547 {

	//$category "BD Bosses"
    Obituary "%o was destroyed by a Mastermind."
	Tag "Great Mastermind Invasion Leader"	
	
	//***Che: need I remind you masterminds have 60% damage resistance against BFG9000 and Unmaker?
	Health 10000
	Mass 500000
	Speed 40
	+NOTARGET
	MaxStepHeight 64
	MaxDropOffHeight 64

	States {
		CheckIfBoss:
			"####" "#" 1
			"####" "#" -1 A_BrainDie
			Stop	
	}
}


Actor MaradeurLazer: SpiderLazer //moved from MARINES_evil.txt
{
	// muzzle xyz are 42 6 34  but we use 15 6 34 because there is 99% chance he is firing at YOU.
	Species "EvilMarines"
	+THRUSPECIES
	+MTHRUSPECIES
	damage (random(50, 50)) // Unlike the super mastermind there are no afterbeamers: he moves too swiftly
	States
	{
		Death:
		XDeath:
			TNT1 A 0 A_Stop
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5") // a serverside script that calls a clientside script to actually draw
			
			UNHG A 0
			UNHG A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			EXPL A 0 A_SpawnItem("ExplosionParticleSpawner")
			EXPL A 0 A_CustomMissile ("FlamethrowerFireParticles", 6, 0, random (0, 360), 2, random (0, 90))

			UNHG A 0 A_CustomMissile("MaradeurLazersFlames", random (-32, 0), random (-32, 32), random (-32, 32), 2| CMF_TRACKOWNER, random (-32, 32))
			
			UNHG A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			UNHG A 0 A_explode(20, 100)
			TNT1 A 0 A_CustomMissile ("BigBlackSmoke", 0, 0, random (0, 360), 2, random (40, 160))
/*
			TNT1 A 0 A_SetUserVar("user_x", x)
			TNT1 A 0 A_SetUserVar("user_y", y)
			TNT1 A 0 A_SetUserVar("user_z", z)
			// P.S. WARPF_USECALLERANGLE is vital to preserve missile's angle because that is used
			//  by the clientside script (which is only passed one parameter: beam length)
			TNT1 A 1 A_Warp(AAPTR_TARGET,0,10,52,0,WARPF_STOP|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE,"WarpedOk")
			Stop
		WarpedOk:
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk4") // a serverside script that calls a clientside script to actually draw
*/			
			// keep warping just in case script starts delayed
			TNT1 A 30
			Stop
	}
}
