
/*
//***Che a weapon made using Project Brutality's Demon Tech rifle
	but the functionality is very different.
	
	First, there is no actual reloading. The reloading animation
	is used for switching between elements (reload = up, weapon special = down)
	
	Second, the weapon uses souls as ammo (the same as Unmaker, the same as the most recent PB's does)
	
	Third, it behaves not like a plasma gun but like a shotgun, meaning it's elemental hitscan!
	
	Fourth, the elements themselves differ in their effect on monsters:
		fire - lingering hazards on alt fire
		ice - stuns because FBD monsters are all designed to have 20-tick long Pain.Ice states. Also, alt fire is like the flamethrower.
		poison - inflicts double damage but over 6..9 seconds and directly provokes infighting, even among the same species.
		lightning - damage scales with the number of nearby monsters, like Chain Lightning. Alt fire is a special case.
		
	Also, primary fire uses sub-ammo to achieve 3 shots per one soul.

	To match the Unmaker, one soul results in roughly 300 damage (but the Unmaker has a *much* higher fire rate and so DPS).
	
	
	YHRL X..Z - dark (no color) inserting the magazine back
	YHR4 A..N - blue (electric) pull magazine out
	YHR4 P..U - blue (electric) big skull puff after inserting the magazine
	YHS4 A..E - blue (electric) ready
	YHS4 F..H - blue (electric) fire
	YHS4 V..Z - blue (electric) lower
	
	YHR/S1 - red (fire)
	YHR/S2 - green (poison)
	YHR/S3 - white (ice)
	
	
	P.S. Default reload action is switching to the next element -- BUT if you reload again before firing you switch to the next element immediately without playing this lenghty animation!
	
	Token_DemonTechElement (max 4)
	0 - fire
	1 - ice
	2 - poison
	3 - lightning
	4 - cycle back to 0!
	
	NOTE: does not use "BRIGHT" frames because am planning to add a full set of brightmaps (possibly at a later date)
	
*/ 

ACTOR DemonEleTech : BrutalWeapon 17944
{
	Game Doom

	//Weapon.SelectionOrder 1300
	
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 15
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "SoulAmmo"
	Weapon.AmmoType2 "DemonTechVirtualAmmo"	// see Script "VirtualAmmoCountersManage" ENTER in FBD_CORE.acs
	

	Inventory.PickupMessage "$GOTELETECH"
    Inventory.PickupSound "eletech/ready"
	//Obituary "$OB_MPELETECH" // FBD is not viable for deathmatch
    AttackSound "None"
    +WEAPON.NOALERT
    +WEAPON.NOAUTOAIM
	+WEAPON.NOAUTOFIRE
	+FORCEXYBILLBOARD
	+WEAPON.CHEATNOTWEAPON	
	Scale 0.9
	Tag "DemonEleTech"
	States
	{
		Spawn: // does not rely on weapon spawners
			YHRL V 1
			YHRL V -1
			Stop		
		
		//***Che disabling player weapons for cutscenes and for the evacuation center
		HoldFire:
			
			/* 
				A reminder: the *ONLY* jump specials working clientside are player inventory checks!
				No user variables, no A_JumpIf(), no A_Jump(256,...).
				You only have crap and sticks and sheer grit.
			*/
			
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 1)
			
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "HoldFire3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "HoldFire2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "HoldFire1")
			YHS1 Z 0 A_JumpIfInventory("Taunting",1,"Taunt")
			YHS1 Z 0 A_JumpIfInventory("Salute1", 1, "Salute")
			YHS1 Z 0 A_JumpIfInventory("Salute2", 1, "Salute")
			YHS1 Z 0 A_JumpIfInventory("Reloading",1,"Reload")
			YHS1 Z 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			YHS1 Z 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			YHS1 Z 1 offset(-32,32) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE | WRF_ALLOWRELOAD)
			YHS1 Z 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready
		HoldFire1:
			YHS3 Z 0 A_JumpIfInventory("Taunting",1,"Taunt")
			YHS3 Z 0 A_JumpIfInventory("Salute1", 1, "Salute")
			YHS3 Z 0 A_JumpIfInventory("Salute2", 1, "Salute")
			YHS3 Z 0 A_JumpIfInventory("Reloading",1,"Reload")
			YHS3 Z 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			YHS3 Z 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			YHS3 Z 1 offset(-32,32) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE | WRF_ALLOWRELOAD)
			YHS3 Z 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready
		HoldFire2:
			YHS2 Z 0 A_JumpIfInventory("Taunting",1,"Taunt")
			YHS2 Z 0 A_JumpIfInventory("Salute1", 1, "Salute")
			YHS2 Z 0 A_JumpIfInventory("Salute2", 1, "Salute")
			YHS2 Z 0 A_JumpIfInventory("Reloading",1,"Reload")
			YHS2 Z 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			YHS2 Z 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			YHS2 Z 1 offset(-32,32) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE | WRF_ALLOWRELOAD)
			YHS2 Z 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready	
		HoldFire2:
			YHS4 Z 0 A_JumpIfInventory("Taunting",1,"Taunt")
			YHS4 Z 0 A_JumpIfInventory("Salute1", 1, "Salute")
			YHS4 Z 0 A_JumpIfInventory("Salute2", 1, "Salute")
			YHS4 Z 0 A_JumpIfInventory("Reloading",1,"Reload")
			YHS4 Z 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			YHS4 Z 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			YHS4 Z 1 offset(-32,32) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE | WRF_ALLOWRELOAD)
			YHS4 Z 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready

		Select:
			YHS1 Z 0 A_Takeinventory("StartDualWield",1)
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 999)
			YHS1 Z 0 A_Giveinventory("GoSpecial",1)
			YHS1 Z 0 A_Takeinventory("FistsSelected",1)
			YHS1 Z 0 A_Takeinventory("sawSelected",1)
			YHS1 Z 0 A_Takeinventory("ShotgunSelected",1)
			YHS1 Z 0 A_Takeinventory("SSGSelected",1)
			YHS1 Z 0 A_Takeinventory("MinigunSelected",1)
			YHS1 Z 0 A_Takeinventory("PlasmaGunSelected",1)
			YHS1 Z 0 A_Takeinventory("RocketLauncherSelected",1)
			YHS1 Z 0 A_Takeinventory("GrenadeLauncherSelected",1)
			YHS1 Z 0 A_Takeinventory("BFGSelected",1)
			YHS1 Z 0 A_Takeinventory("BFG10kSelected",1)
			
			// For now, registers for the mob AI and player look as the unmaker,
			// will add proper demon tech support later.
			// As a consequeance, maradeur will respond by switching to Unmaker.
			"----" A 0 A_Giveinventory("UnmakerSelected",1) //***Che
			
			"----" A 0 A_Takeinventory("MG42Selected",1)
			"----" A 0 A_Takeinventory("AxeSelected",1)
			"----" A 0 A_Takeinventory("DragonslayerSelected",1)
			"----" A 0 A_Takeinventory("SniperRifleSelected",1)
			"----" A 0 A_Takeinventory("ShotolverSelected",1)
			"----" A 0 A_Takeinventory("Shotolver2Selected",1)
			YHS1 Z 0 A_Takeinventory("RailGunSelected",1)
			YHS1 Z 0 A_Takeinventory("SubMachineGunSelected",1)
			YHS1 Z 0 A_Takeinventory("RevenantLauncherSelected",1)
			YHS1 Z 0 A_Takeinventory("LostSoulSelected",1)
			YHS1 Z 0 A_Takeinventory("FlameCannonSelected",1)
			YHS1 Z 0 A_Takeinventory("HasBarrel",1)
			YHS1 Z 0 A_TakeInventory("TossGrenade", 1)
			TNT1 AAAAAAAAA 0 A_Raise
			TNT1 AAAA 1 A_Raise

		SelectAnimation:
			TNT1 AAAA 0 A_JumpIfInventory("GoFatality", 1, "Steady")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "SelectAnimation3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "SelectAnimation2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "SelectAnimation1")
			YHS1 ZYXWV 1 A_JumpIfInventory("GoFatality", 1, "Steady")
			"----" A 0 A_PlaySound("eletech/ready")
			"----" A 0 A_GunFlash // launches the parallel process that manages flashlight, pressing Use etc.
			Goto Ready 
		SelectAnimation1:
			TNT1 AAAA 0 A_JumpIfInventory("GoFatality", 1, "Steady")
			YHS3 ZYXWV 1 A_JumpIfInventory("GoFatality", 1, "Steady")
			"----" A 0 A_PlaySound("eletech/ready")
			"----" A 0 A_GunFlash // launches the parallel process that manages flashlight, pressing Use etc.
			Goto Ready 
		SelectAnimation2:
			TNT1 AAAA 0 A_JumpIfInventory("GoFatality", 1, "Steady")
			YHS2 ZYXWV 1 A_JumpIfInventory("GoFatality", 1, "Steady")
			"----" A 0 A_PlaySound("eletech/ready")
			"----" A 0 A_GunFlash // launches the parallel process that manages flashlight, pressing Use etc.
			Goto Ready
		SelectAnimation3:
			TNT1 AAAA 0 A_JumpIfInventory("GoFatality", 1, "Steady")
			YHS4 ZYXWV 1 A_JumpIfInventory("GoFatality", 1, "Steady")
			"----" A 0 A_PlaySound("eletech/ready")
			"----" A 0 A_GunFlash // launches the parallel process that manages flashlight, pressing Use etc.
			Goto Ready

		NoAmmo:
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "NoAmmo3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "NoAmmo2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "NoAmmo1")
			YHS1 A 1 offset(0,33) A_PlaySound("weapons/empty", 4)
			YHS1 A 1 offset(0,32)
			Goto Ready
			
		NoAmmo1:
			YHS3 A 1 offset(0,33) A_PlaySound("weapons/empty", 4)
			YHS3 A 1 offset(0,32)
			Goto Ready
		NoAmmo2:
			YHS2 A 1 offset(0,33) A_PlaySound("weapons/empty", 4)
			YHS2 A 1 offset(0,32)
			Goto Ready
		NoAmmo3:
			YHS4 A 1 offset(0,33) A_PlaySound("weapons/empty", 4)
			YHS4 A 1 offset(0,32)
			Goto Ready
				
		Ready2:
		Ready3:	
		Ready:
			// Starting the Ready state from "----" makes the weapon invalid and the game engine pretends it doesn't exist but never tells you WHY. Totally undocumented.
			// MUST jumpt to an appropriate element's sprite set state before using any non-zero length states
			YHS1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 1)
			"----" A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			"----" A 0 A_JumpIfInventory("Taunting",1,"Taunt")
			"----" A 0 A_JumpIfInventory("Reloading",1,"Reload")
			"----" A 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			"----" A 0 A_JumpIfInventory("Salute1", 1, "Salute")
			"----" A 0 A_JumpIfInventory("Salute2", 1, "Salute")
			"----" A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			
		OkToFire:
			"----" A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire") //***Che
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "OkToFire3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "OkToFire2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "OkToFire1")			
			YHS1 A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			"----" A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			"----" A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			Goto Ready
		OkToFire1:
			YHS3 A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			"----" A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			"----" A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			Goto Ready
		OkToFire2:
			YHS2 A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			"----" A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			"----" A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			Goto Ready
		OkToFire3:
			YHS4 A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			"----" A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			"----" A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			Goto Ready	
			
		Deselect:
			YHS1 A 0
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 999)
			YHS1 A 0 A_TakeInventory("TossGrenade", 1)
			YHS1 A 0 A_Takeinventory("UseShotgunStrap",1)
			YHS1 A 0 A_ZoomFactor(1.0)
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "Deselect3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "Deselect2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "Deselect1")				
			
			YHS1 VWXYZ 1
			TNT1 AAAAAAAAAAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Wait

		Deselect1:
			YHS3 VWXYZ 1
			TNT1 AAAAAAAAAAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Wait
		Deselect2:
			YHS2 VWXYZ 1
			TNT1 AAAAAAAAAAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Wait
		Deselect3:
			YHS4 VWXYZ 1
			TNT1 AAAAAAAAAAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Wait			
			
			
		Fire:
			"----" A 0 A_Takeinventory("Reloading",1)
			"----" A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
				"----" A 0 A_JumpIfInventory("Token_DemonTechSubAmmo", 1, 4)
				"----" A 0 A_JumpIfInventory("SoulAmmo",1,1)
				Goto NoAmmo
				"----" A 0 A_TakeInventory("SoulAmmo",1) // currency exchange: 3 shots for the price of one soul
				"----" A 0 A_GiveInventory("Token_DemonTechSubAmmo",3)
			
			"----" A 0 A_GiveInventory("Token_DemonTechFiredOnce",1)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat",25,"Cooldown")
			"----" A 0 A_ZoomFactor(0.96)
			
				"----" A 0 A_JumpIfInventory("QPowerQuadDamage", 1, 2)
				"----" A 0 A_JumpIfInventory("IsPlayer", 1, 2)
				"----" A 0 A_PlaySound("quaddamage/echo", CHAN_7)
				"----" A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire
			
			"----" A 0 A_AlertMonsters
			"----" A 0 A_PlaySound("eletech/fire", 1)
			"----" A 0 A_FireCustomMissile("DistantFireSoundShotgun", random(-1,1), 0, 0, -12, 0, random(-1,1))
			"----" A 0
			"----" A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
			
			"----" A 0 A_Takeinventory("Token_DemonTechSubAmmo",1)
			"----" A 0 A_GiveInventory("Token_DemonTechOverheat",12) // 2 shots give 24 = less than 25 that triggers the puff - so 3 shot bursts on a fully cooled down gun
			
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "Fire3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "Fire2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "Fire1")	
			
			"----" A 0 A_FireBullets (5, 1, 4, 13, "FirePuff", FBF_NORANDOM)
			"----" A 0 A_FireBullets (2.5, 2.5, 5, 13, "FirePuff", FBF_NORANDOM)
			YHS1 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-2.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS1 H 1 A_SetPitch(+0.3 + pitch)
			YHS1 ED 1 A_SetPitch(+0.3 + pitch)
			YHS1 C 1 A_SetPitch(+0.8 + pitch)
			YHS1 BAEDCB 1 A_SetPitch(+0.1 + pitch)
			"----" A 0 A_JumpIfInventory("PressedPrimary", 1, "Fire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Ready
			
		Fire1:
			"----" A 0 A_FireBullets (5, 1, 4, 13, "IcePuff", FBF_NORANDOM)
			"----" A 0 A_FireBullets (2.5, 2.5, 5, 13, "IcePuff", FBF_NORANDOM)
			YHS3 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-2.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS3 H 1 A_SetPitch(+0.3 + pitch)
			YHS3 ED 1 A_SetPitch(+0.3 + pitch)
			YHS3 C 1 A_SetPitch(+0.8+ pitch)
			YHS3 BAEDCB 1 A_SetPitch(pitch+0.1)
			"----" A 0 A_JumpIfInventory("PressedPrimary", 1, "Fire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Ready
			
		Fire2:
			"----" A 0 A_FireBullets (5, 1, 4, 1, "ToxicPuff", FBF_NORANDOM)
			"----" A 0 A_FireBullets (2.5, 2.5, 5, 1, "ToxicPuff", FBF_NORANDOM)
			YHS2 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-2.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS2 H 1 A_SetPitch(+0.3 + pitch)
			YHS2 ED 1 A_SetPitch(+0.3 + pitch)
			YHS2 C 1 A_SetPitch(+0.8 + pitch)
			YHS2 BAEDCB 1 A_SetPitch(pitch+0.1)
			"----" A 0 A_JumpIfInventory("PressedPrimary", 1, "Fire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Ready

		Fire3:
			"----" A 0 A_FireBullets (5, 1, 4, 1, "SparkPuff", FBF_NORANDOM)
			"----" A 0 A_FireBullets (2.5, 2.5, 5, 1, "SparkPuff", FBF_NORANDOM)
			YHS4 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-2.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS4 H 1 A_SetPitch(+0.3 + pitch)
			YHS4 ED 1 A_SetPitch(+0.3 + pitch)
			YHS4 C 1 A_SetPitch(+0.8 + pitch)
			YHS4 BAEDCB 1 A_SetPitch(pitch+0.1)
			"----" A 0 A_JumpIfInventory("PressedPrimary", 1, "Fire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Ready				
			
			
		AltFire:
			"----" A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire") //***Che
			"----" A 0 A_JumpIfInventory("Reloading",1,"Reload")
			"----" A 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			"----" A 0 A_JumpIfInventory("SoulAmmo",1,1)
			Goto NoAmmo	
			
			"----" A 0 A_GiveInventory("Token_DemonTechFiredOnce",1)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat",25,"Cooldown")
			
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "AltFire3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "AltFire2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "AltFire1")				
			
			"----" A 0 A_GiveInventory("Token_DemonTechOverheat",40)
			"----" A 0 A_Takeinventory("SoulAmmo",1)
			"----" A 0 A_PlaySound("eletech/charge")
			// 15 tics
			YHS1 CBCBC 1
			YHS1 DEFDEFDEF 1
			
				"----" A 0 A_JumpIfInventory("QPowerQuadDamage", 1, 2)
				"----" A 0 A_JumpIfInventory("IsPlayer", 1, 2) 
				"----" A 0 A_PlaySound("quaddamage/echo", CHAN_7)
				"----" A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire

			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("PLSALTFR")
			"----" A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)			
			
			// three clumped fireballs then de-clump automatically as per revenant fireball protocols
			// different speeds not just for declumping but also to allow the slower ones retargeting in the fastest one kills a weak monster in one hit
			"----" A 0 A_FireCustomMissile("PlayersImmolantBall", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersImmolantBall25", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersImmolantBall35", 0, 0, 0, 0, 0, 0)
			
			
			YHS1 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-6.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS1 H 1 A_SetPitch(+1.0 + pitch)
			YHS1 ED 1 A_SetPitch(+1.0 + pitch)
			YHS1 C 1 A_SetPitch(+3.0 + pitch)
			YHS1 BAEDCB 1 
			//"----" A 0 A_JumpIfInventory("PressedAlt", "AltFire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Cooldown
			
		AltFire1:
	
			
			"----" A 0 BRIGHT A_FireCustomMissile("BlizzardMissile", 0, 0, 0, -12, 0, 8)
			"----" A 0 A_PlaySound("eletech/blizzard", CHAN_WEAPON, 1, 1)

		AltFire1Loop:	

			"----" A 0 A_Takeinventory("SoulAmmo",1)
			"----" A 0 A_GiveInventory("Token_DemonTechOverheat",13) // up to 3 "shots", the highest bust damage of all elements!
			
			YHS3 FG 2 BRIGHT A_SetAngle(random(1, -1) + angle)
			"----" A 0 BRIGHT A_SetPitch(random(1, -1) + pitch)
			
			"----" A 0 BRIGHT A_FireCustomMissile("BlizzardMissileProper", 0, 1, 0, -12, 0, 8)
			"----" A 0 A_PlaySound("eletech/blizzard", CHAN_WEAPON, 1, 1)
			YHS3 FG 2 BRIGHT
			
			"----" A 0 BRIGHT A_FireCustomMissile("BlizzardMissileProper", 0, 1, 0, -12, 0, 8)
			"----" A 0 A_PlaySound("eletech/blizzard", CHAN_WEAPON, 1, 1)
			
			YHS3 FG 2 BRIGHT
			
			"----" A 0 BRIGHT A_FireCustomMissile("BlizzardMissileProper", 0, 1, 0, -12, 0, 8)
			"----" A 0 A_PlaySound("eletech/blizzard", CHAN_WEAPON, 1, 1)
		
			
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat",37,"AltFire1End")
			
			"----" A 0 A_JumpIfInventory("PressedAlt", 1, "AltFire1Loop") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
		
		AltFire1End:	
			YHS3 GG 2 BRIGHT
			YHS3 G 1 A_PlaySound("FLAMSTOP", CHAN_WEAPON)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat",25,"Cooldown")
			Goto Ready
		
		AltFire2:
			"----" A 0 A_PlaySound("eletech/charge")
			"----" A 0 A_GiveInventory("Token_DemonTechOverheat",40)
			"----" A 0 A_Takeinventory("SoulAmmo",1)
			// 15 tics
			YHS2 CBCBC 1
			YHS2 DEFDEFDEF 1
			
				"----" A 0 A_JumpIfInventory("QPowerQuadDamage", 1, 2)
				"----" A 0 A_JumpIfInventory("IsPlayer", 1, 2) 
				"----" A 0 A_PlaySound("quaddamage/echo", CHAN_7)
				"----" A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire

			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("PLSALTFR")
			"----" A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
			
			// six clumped fireballs then de-clump automatically as per revenant fireball protocols
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall24", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall27", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall33", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall36", 0, 0, 0, 0, 0, 0)
			"----" A 0 A_FireCustomMissile("PlayersNoxinantBall39", 0, 0, 0, 0, 0, 0)
			
			YHS2 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-6.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS2 H 1 A_SetPitch(+1.0 + pitch)
			YHS2 ED 1 A_SetPitch(+1.0 + pitch)
			YHS2 C 1 A_SetPitch(+3.0 + pitch)
			YHS2 BAEDCB 1 
			//"----" A 0 A_JumpIfInventory("PressedAlt", "AltFire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Cooldown
		
		AltFire3:
			// NO charging delay: this mode only has meaning it it allows *immediate* defensive action!
			"----" A 0 A_GiveInventory("Token_DemonTechOverheat",40)
			//"----" A 0 A_PlaySound("eletech/charge")
			"----" A 0 A_Takeinventory("SoulAmmo",1)
			/*
			// 15 tics
			YHS4 CBCBC 1
			YHS4 DEFDEFDEF 1
			*/
			
				"----" A 0 A_JumpIfInventory("QPowerQuadDamage", 1, 2)
				"----" A 0 A_JumpIfInventory("IsPlayer", 1, 2) 
				"----" A 0 A_PlaySound("quaddamage/echo", CHAN_7)
				"----" A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire

			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("eletech/shortcircuit")
			"----" A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
			
			"----" A 0 A_FireCustomMissile("ShortCircuitBall", 0, 0, 0, 0, 0, 0) // see RevElemenants.txt

			YHS4 FG 1 //BRIGHT
			"----" A 0 A_SetPitch(-6.0 + pitch)
			"----" A 0 A_ZoomFactor(1.00)
			YHS4 H 1 A_SetPitch(+1.0 + pitch)
			YHS4 ED 1 A_SetPitch(+1.0 + pitch)
			YHS4 C 1 A_SetPitch(+3.0 + pitch)
			YHS4 BAEDCB 1 
			//"----" A 0 A_JumpIfInventory("PressedAlt", "AltFire") //***Che ChebMaster's addition to BD tokens, auto-removed by the same ACS script when the button is released
			//"----" A_Refire // cannot because it is not a single state anymore
			Goto Cooldown				
		
			
		Cooldown:
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "Cooldown3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "Cooldown2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "Cooldown1")				
		Cooldown0:
			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("eletech/vent", 6)
			// 36 tics if repeated thrice
			YHR1 PQRSTU 2 
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 13)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat", 7, "Cooldown0")
			Goto CooldownEnd
			
		Cooldown1:
			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("eletech/vent", 6)
			YHR3 PQRSTU 2 
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 13)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat", 7, "Cooldown1")
			Goto CooldownEnd
			
		Cooldown2:
			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("eletech/vent", 6)
			YHR2 PQRSTU 2 
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 13)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat", 7, "Cooldown2")
			Goto CooldownEnd
			
		Cooldown3:
			"----" A 0 A_StopSound(6)
			"----" A 0 A_PlaySound("eletech/vent", 6)
			YHR4 PQRSTU 2 
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 13)
			"----" A 0 A_JumpIfInventory("Token_DemonTechOverheat", 7, "Cooldown3")
			Goto CooldownEnd			
			
		CooldownEnd:	
			"----" A 0 //A_StopSound(6)
			Goto Ready	
			
			
		DualWield: // cycling elements backwards
			"----" A 0
			"----" A 0 A_TakeInventory("StartDualWield",1)
			"----" A 0 A_GiveInventory("Token_DemonTechReverseCycle", 1) // we are scrolling elements backwards
			"----" A 0 A_JumpIfInventory("Token_DemonTechFiredOnce", 1, "PullOut")
			Goto JustTouch
			
		Reload:
			"----" A 0
			"----" A 0 A_TakeInventory("Reloading", 1)	
			"----" A 0 A_TakeInventory("Token_DemonTechReverseCycle", 1) // we are scrolling elements forward
			"----" A 0 A_JumpIfInventory("Token_DemonTechFiredOnce", 1, "PullOut")
			Goto JustTouch
			
		
		SwapElement:
			"----" A 0 A_JumpIfInventory("Token_DemonTechReverseCycle", 1, "SwapElementBackwards")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "SwapToFirstElement")
			"----" A 0 A_GiveInventory("Token_DemonTechElement", 1)
			Goto SwapElementEnd
			
		SwapElementBackwards:
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, 1)
			Goto SwapToLastElement
			"----" A 0 A_TakeInventory("Token_DemonTechElement", 1)
			Goto SwapElementEnd	
		
		SwapToFirstElement:
			"----" A 0 A_TakeInventory("Token_DemonTechElement", 999)
			Goto SwapElementEnd

		SwapToLastElement:
			"----" A 0 A_TakeInventory("Token_DemonTechElement", 999)
			"----" A 0 A_GiveInventory("Token_DemonTechElement", 3)
			Goto SwapElementEnd
			
		SwapElementEnd:
			"----" A 0 A_TakeInventory("Token_DemonTechOverheat", 999)
			"----" A 0 A_JumpIfInventory("Token_DemonTechFiredOnce", 1, "SwapElementWail")
			Goto Ready

		SwapElementWail:
			"----" A 0 A_TakeInventory("Token_DemonTechFiredOnce", 999)
			"----" A 0 A_JumpIfInventory("Token_DemonTechSubAmmo", 1, 2)
			"----" A 0 A_JumpIfInventory("SoulAmmo", 1, 1)
			Goto NoAmmo // make a weapon empty click instead of the wail if out of ammo
			"----" A 0 A_StopSound(6) 
			"----" A 0 A_PlaySound("eletech/ready", 6) // wail
			Goto Ready
			
		JustTouch:
			// grab the magazine but do not pull out
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "JustTouch3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "JustTouch2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "JustTouch1")			
			
			YHR1 ABCDE 1
			YHRL Y 5 A_PlaySound("eletech/clipin", 7)
			YHRL Z 2
			Goto SwapElement
		
		JustTouch1:	
			YHR3 ABCDE 1
			YHRL Y 5 A_PlaySound("eletech/clipin", 7)
			YHRL Z 2
			Goto SwapElement
			
		JustTouch2:	
			YHR2 ABCDE 1
			YHRL Y 5 A_PlaySound("eletech/clipin", 7)
			YHRL Z 2
			Goto SwapElement

		JustTouch3:	
			YHR4 ABCDE 1
			YHRL Y 5 A_PlaySound("eletech/clipin", 7)
			YHRL Z 2
			Goto SwapElement			
		
		PullOut:
			
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "PullOut3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "PullOut2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "PullOut1")
			
			YHR1 ABCDE 1 // 6 tics
			"----" A 10 A_PlaySound("eletech/clipout", CHAN_WEAPON)
			YHR1 FGHIJKLMN 2 // +18 tics = 24 tics
			Goto PullOutEnd
			
		PullOut1:
			YHR3 ABCDE 1
			"----" A 10 A_PlaySound("eletech/clipout", CHAN_WEAPON)
			YHR3 FGHIJKLMN 2
			Goto PullOutEnd
			
		PullOut2:
			YHR2 ABCDE 1
			"----" A 10 A_PlaySound("eletech/clipout", CHAN_WEAPON)
			YHR2 FGHIJKLMN 2
			Goto PullOutEnd
			
		PullOut3:
			YHR4 ABCDE 1
			"----" A 10 A_PlaySound("eletech/clipout", CHAN_WEAPON)
			YHR4 FGHIJKLMN 2
			Goto PullOutEnd			
			
		PullOutEnd:	
			YHRL X 5
			YHRL Y 3 A_PlaySound("eletech/clipin", 7)
			YHRL Z 3 // +11 tics = 35 tics
			Goto SwapElement
			
		CheckSprint:
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 3, "CheckSprint3")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 2, "CheckSprint2")
			"----" A 0 A_JumpIfInventory("Token_DemonTechElement", 1, "CheckSprint1")
			YHS1 A 1 A_WeaponReady(WRF_NOFIRE)
			Goto CheckSprintContinue
			
		CheckSprint1:
			YHS3 A 1 A_WeaponReady(WRF_NOFIRE)
			Goto CheckSprintContinue
			
		CheckSprint2:
			YHS2 A 1 A_WeaponReady(WRF_NOFIRE)
			Goto CheckSprintContinue
			
		CheckSprint3:
			YHS4 A 1 A_WeaponReady(WRF_NOFIRE)
			Goto CheckSprintContinue
			
		CheckSprintContinue:	
			"----" A 0 A_Takeinventory("Zoomed",1)
			"----" A 0 A_ZoomFactor(1.0)
			"----" A 0 A_Takeinventory("ADSmode",1)
			"----" A 0 A_Giveinventory("GoSpecial",1)
			"----" A 0 A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			"----" A 0 A_JumpIfInventory("IsTacticalClass", 1, "StartSprint")
			Goto Ready
			
		StartSprint:
			"----" A 1 A_WeaponReady(WRF_NOFIRE)
			"----" A 0 A_Takeinventory("Zoomed",1)
			"----" A 0 A_Takeinventory("ADSmode",1)
			"----" A 0 A_ZoomFactor(1.0)
			"----" A 0 A_JumpIfInventory("UsedStamina", 40, "StopSprintTired")
			
		Sprinting:	
			"----" A 0 offset(-9,32) 
			"----" A 0 offset(-9,32) A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			"----" A 0 offset(-9,32) A_JumpIfInventory("UsedStamina", 100, "StopSprintTired")
			"----" A 0 offset(-9,32) ACS_ExecuteAlways(852, 0, 0, 0, 0)//Makes player faster.
			"----" A 0 offset(-9,32) A_JumpIfInventory("PowerStrength", 1, 2)
			"----" A 0 offset(-9,32) A_GiveInventory("UsedStamina", 5)
			"----" A 0 offset(-9,32)
			"----" A 1 offset(-9,34) A_SetPitch(pitch -0.5)
			"----" A 1 offset(-6,36) A_SetPitch(pitch -0.5)
			"----" A 1 offset(-3,38) A_SetPitch(pitch -0.5)
			"----" A 1 offset(0,38) A_SetPitch(pitch -0.5)
			"----" A 1 offset(3,36) A_SetPitch(pitch -0.5)
			"----" A 1 offset(6,34) A_SetPitch(pitch -0.5)
			"----" A 1 offset(9,32) A_SetPitch(pitch -0.5)
			"----" A 0 offset(9,32) A_WeaponReady(WRF_NOBOB)
			"----" A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			"----" A 0 A_JumpIfInventory("Taunting",1,"Taunt")
			"----" A 0 A_JumpIfInventory("Reloading",1,"Reload")
			"----" A 0 A_JumpIfInventory("StartDualWield",1,"DualWield")
			"----" A 0 offset(-9,32) A_GiveInventory("UsedStamina", 5)
			"----" A 0 offset(9,33) A_SpawnItemEx("FootStep", 0, 0, 2, 0, 0, -4)
			"----" A 1 offset(9,34) A_SetPitch(pitch +0.5)
			"----" A 1 offset(6,36) A_SetPitch(pitch +0.5)
			"----" A 1 offset(3,38) A_SetPitch(pitch +0.5)
			"----" A 1 offset(0,38) A_SetPitch(pitch +0.5)
			"----" A 1 offset(-3,36) A_SetPitch(pitch +0.5)
			"----" A 1 offset(-6,34) A_SetPitch(pitch +0.5)
			"----" A 1 offset(-9,32) A_SetPitch(pitch +0.5)
			"----" A 0 offset(-9,32) A_WeaponReady(WRF_NOBOB)
			"----" A 0 offset(-9,32) A_JumpIfInventory("IsRunning", 1, "Sprinting")
			
			Goto StopSprint
		StopSprintTired:
			"----" A 1
			"----" A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			"----" A 0 A_PlaySound("Tired", 2)
			"----" A 0 A_TakeInventory("UsedStamina", 2)
			"----" A 5 A_WeaponReady
			"----" A 0 A_TakeInventory("UsedStamina", 2)
			"----" A 5 A_WeaponReady
			"----" A 0 A_TakeInventory("UsedStamina", 2)
			"----" A 5 A_WeaponReady
			"----" A 0 A_TakeInventory("UsedStamina", 2)
			"----" A 5 A_WeaponReady
			"----" A 0 A_TakeInventory("UsedStamina", 2)
			"----" A 5 A_WeaponReady
			Goto Ready
		StopSprint:
			"----" A 1
			"----" A 0 A_JumpIfInventory("UsedStamina", 60, "StopSprintTired")
			"----" A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			Goto Ready			
	}
}	
			
		
			
			
ACTOR ShortCircuitBall
// Aped after https://wiki.teamfortress.com/wiki/Short_Circuit 's secondary fire
// A slow moving ball that inflicts little damage but destroys projectiles
//  (by radius-giving them an item that spawns short lived colliders inside them)
{
	PROJECTILE
	+NOBLOCKMAP
	Speed 10
	FastSpeed 10
	Damage (random(15,15))
	DamageType "Electric"
	Radius 16
	Height 2
	+THRUGHOST
	+THRUACTORS
	Translation "168:191=192:207", "48:79=80:111", "16:47=194:207"	
	var int user_phase;
	Scale 3.0
	RenderStyle Add
	Alpha 0.35
	
	var int user_vfx_angle;
	States 
	{
		
		Spawn:
			TNT1 A 1
		Fly:
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Underwater")
			TNT1 A 0 A_SetUserVar("user_phase", user_phase > 0 ? user_phase - 1 : 0)
			TNT1 A 0 A_JumpIf(!user_phase, "InflictAOE")
			Goto KeepFlying
		InflictAOE:
			TNT1 A 0 A_RadiusGive("ShockAOEGiver15", 60, RGF_OBJECTS | RGF_MONSTERS | RGF_NOSIGHT) //RGF_OBJECTS | RGF_MISSILES | RGF_MONSTERS | RGF_NOSIGHT
			TNT1 A 0 A_SetUserVar("user_phase", 16)
		KeepFlying:
			TNT1 A 0 A_RadiusGive("MissileDestroyAOE", 60, RGF_OBJECTS | RGF_MISSILES | RGF_NOSIGHT) // RGF_OBJECTS | RGF_MISSILES | RGF_MONSTERS | RGF_NOSIGHT
			TNT1 A 0 A_SetScale(random(0,1) ? 1.0 : -1.0, random(0,1) ? 1.0 : -1.0)
			
			TNT1 A 0 A_SetUserVar("user_vfx_angle", Random(0,360))
			TNT1 A 0 A_SpawnItemEx("FBD_SmallSparkWSound", 0,60.0 * Sin(user_vfx_angle),60.0 * Cos(user_vfx_angle), 0,0,0, 0,SXF_NOCHECKPOSITION)
			
			TNT1 A 0 A_SetUserVar("user_vfx_angle", Random(0,360))
			TNT1 A 0 A_SpawnItemEx("FBD_SmallSparkWSound", 0,60.0 * Sin(user_vfx_angle),60.0 * Cos(user_vfx_angle), 0,0,0, 0,SXF_NOCHECKPOSITION)
			
			TNT1 A 0 A_Jump(256, "Var1", "Var2", "Var3", "Var4", "Var5")
		Var1:
			LFX1 S 1
			Goto Fly
		Var2:
			LFX1 T 1
			Goto Fly
		Var3:
			LFX1 U 1
			Goto Fly
		Var4:
			LFX1 V 1
			Goto Fly
		Var5:
			LFX1 W 1
			Goto Fly
		
		Underwater:
			TNT1 A 0 A_Stop
			Goto Death
		Death:
		XDeath:
		Crash:
			TNT1 A 0
			TNT1 A 0 A_RadiusGive("ShockAOEGiver15", 40, RGF_PLAYERS | RGF_MONSTERS)
			
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
			TNT1 AAAAA 0 A_CustomMissile ("BluePlasmaParticle", 0, 0, random (0, 360), 2, random (0, 360))			
			TNT1 A 30
			Stop
	}				
}
	
ACTOR MissileDestroyAOE: CustomInventory  // for radiusgive effects
{
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	inventory.maxamount 1
    States
    {
		Pickup:
			// inventory item's states executes in the context of the actor that item is in inventory of
			TNT1 A 0 NODELAY A_CheckFlag("NOBLOCKMAP", "Nope", AAPTR_DEFAULT) // GZDoom gives to *all* missiles including blood particles and bubbles since it iterates over *all* thinkers on the map in A_RadiusGive disregaring the blockmap
			TNT1 A 0 A_CheckFlag("MISSILE", "Blockit", AAPTR_DEFAULT)
		Nope:	
			TNT1 A 1 A_RailWait // without this, pickup fails to register and GZDoom hangs up then crashes
			Stop
		Blockit:
			//TNT1 A 0 A_SpawnItemEx("TransientHitbox2x1",0,0,0, velx,vely,velz, 0,SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION,0)
			// а вот ХУЙ >:(
			
			//Why does this cause a CRASH in GZDoom?
			//TNT1 A 0 ACS_NamedExecuteWithResult("FBD_DebugLogActorClass", 1)	
			// prints out "FBD_SmallSparkWSound". 
			// Visualization shows us it's only those that hit the ground OR if you aim straight up.
			// Conclusion? Non-standard behavior of A_RadiusGive in GZDoom, it ignores the NOBLOCKMAP flag of missiles!
			// Of course that causes a runaway recursion since every blocker spawns 3 more of these

			TNT1 A 0 A_JumpIf(CallAcs("FBD_IsASmallSparkWSound"), "Nope") // excluding those manually!

			// Some missiles (like cyberdemon's) have speed much higher than radius.
			TNT1 A 0 A_SpawnItemEx("MissileDestroyHitbox",velx, vely, velz - 2.0, 0,0,0, 0,SXF_ABSOLUTEPOSITION | SXF_ABSOLUTEVELOCITY | SXF_NOCHECKPOSITION,0)
			TNT1 A 1 A_RailWait
			
			Stop
    }
}

ACTOR MissileDestroyHitbox
{
	+NOGRAVITY
	-MISSILE
	+NOTELEPORT
	+NOCLIP
	+SOLID
	-SHOOTABLE
	+SERVERSIDEONLY
	+SPECTRAL // A monster with this flag can only be hurt by a missile or puff (bullet attacks only; not rail attacks) that also has this flag set.
		// Idk why the ancestor class of all enemy rockets (including cyberdemon's) has this flag set
	
	// with radius 1 it FAILS against imp fireballs (radius 4)
	Radius 8
	Height 4
	
	// red to blue-white
	Translation "176:191=192:198", "16:26=4:4", "27:47=192:199", "168:175=4:4"
	RenderStyle Add
	Alpha 0.7	
	
	States {
		Spawn:
			TNT1 A 0 NODELAY A_PlaySound("lightning/snap")
			// Nope nope nope, runaway recursion iss scary! Draw the effect ourselves!
			//TNT1 AAA 0 A_SpawnItemEx("FBD_LightningTrail", Random(-16,16),Random(-16,16),Random(-16,16), 0,0,0, 0,SXF_NOCHECKPOSITION)
			//TNT1 A 2
			HEFX CDEFGHI 1 BRIGHT A_SetScale(random(0,1) ? 1.0 : -1.0, random(0,1) ? 1.0 : -1.0)
			//KYDB G 2
			Stop
	}
}

Actor FirePuff: HitPuff
{
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	+HITMASTER // to get the monster we hit in our master pointer
	+PUFFGETSOWNER // otherwise our target pointer is null
	+PUFFONACTORS // otherwise the engine spawns a blood puff instead, as declared by the victim, as it only applies damage type and sounds cherry-picked from this actor class -- not what we need.
	
	DamageType Fire
	//Decal "Scorch"
	+BRIGHT
	States
	{
		XDeath: // hit a bleeding actor
			//NOTE, the puff is switched to corresponding state inside the native C++ code right after spawn!
			TNT1 A 0 // this one does nothing beside simple damage
			Goto VFX

		Crash: // hit map geometry. 
		Spawn: // used in all other cases (hit a non-bleeding actor?)
		Melee: // I *think* this one should never happen, I'm 99% sure.
			TNT1 A 0
			TNT1 A 0 A_SetDamageType("Flames") 
			TNT1 A 0 A_Explode(4, 32, XF_HURTSOURCE, 0, 30) 
			
			TNT1 A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			
			TNT1 A 0 A_Jump(256, "WallHit1", "WallHit2", "WallHit3")

		WallHit1:
			TNT1 A 0 A_SpawnItemEx ("FireBallExplosionFlames",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 1
			Stop
			
		WallHit2:
			TNT1 A 0 A_SpawnItemEx ("BDExplosionparticlesSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 1
			Stop
			
		WallHit3:
			TNT1 A 0 A_SpawnItemEx ("TinyBurningPiece3",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 1
			Stop			
			
		WallHit3:	
		
		VFX:
			TNT1 A 0 A_Jump(192, "Vfx2", "Vfx3", "Vfx4")
		Vfx1:	
			EXPL C 1 BRIGHT A_SetScale(0.15, 0.15)
			EXPL D 1 BRIGHT A_SetScale(0.2, 0.2)
			EXPL E 1 BRIGHT A_SetScale(0.3, 0.3)
			EXPL F 1 BRIGHT A_SetScale(0.4, 0.4)
			EXPL G 1 BRIGHT A_SetScale(0.5, 0.5)
			Stop
		Vfx2:	
			EXPL C 1 BRIGHT A_SetScale(-0.15, 0.15)
			EXPL D 1 BRIGHT A_SetScale(-0.2, 0.2)
			EXPL E 1 BRIGHT A_SetScale(-0.3, 0.3)
			EXPL F 1 BRIGHT A_SetScale(-0.4, 0.4)
			EXPL G 1 BRIGHT A_SetScale(-0.5, 0.5)
			Stop
		Vfx3:	
			EXPL C 1 BRIGHT A_SetScale(0.15, -0.15)
			EXPL D 1 BRIGHT A_SetScale(0.2, -0.2)
			EXPL E 1 BRIGHT A_SetScale(0.3, -0.3)
			EXPL F 1 BRIGHT A_SetScale(0.4, -0.4)
			EXPL G 1 BRIGHT A_SetScale(0.5, -0.5)
			Stop
		Vfx4:	
			EXPL C 1 BRIGHT A_SetScale(-0.15, -0.15)
			EXPL D 1 BRIGHT A_SetScale(-0.2, -0.2)
			EXPL E 1 BRIGHT A_SetScale(-0.3, -0.3)
			EXPL F 1 BRIGHT A_SetScale(-0.4, -0.4)
			EXPL G 1 BRIGHT A_SetScale(-0.5, -0.5)
			Stop
	}
}

Actor ToxicPuff: HitPuff // 26 damage rather than 32 -- 200%, just spread over time...
{
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	+HITMASTER
	+PUFFGETSOWNER
	+PUFFONACTORS 
	
	DamageType Slime
	//Decal "Scorch"
	States
	{
		XDeath: // hit a bleeding actor
			//NOTE, the puff is switched to corresponding state inside the native C++ code right after spawn!
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("FBD_GetMasterHasIronFeet"), 3)
			TNT1 A 0 A_PlaySound("burn")
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunToxicDOTOnMaster", 25, -3) // negative means "add to current"
			Goto VFX

		Crash: // hit map geometry. 
		Spawn: // used in all other cases (hit a non-bleeding actor?)
		Melee: // I *think* this one should never happen, I'm 99% sure.
			TNT1 A 0
			TNT1 A 0 A_RadiusGive("ToxicDOT1", 70, RGF_PLAYERS | RGF_MONSTERS | RGF_OBJECTS)
			Goto VFX
			
		VFX:	
			TNT1 A 0 A_Jump(192, "Vfx2", "Vfx3", "Vfx4")
		Vfx1:	
			TNT1 A 0 
			EXPG C 1 BRIGHT A_SetScale(0.15, 0.15)
			EXPG D 1 BRIGHT A_SetScale(0.2, 0.2)
			EXPG E 1 BRIGHT A_SetScale(0.3, 0.3)
			EXPG F 1 BRIGHT A_SetScale(0.4, 0.4)
			EXPG G 1 BRIGHT A_SetScale(0.5, 0.5)
			Stop
		Vfx2:	
			TNT1 A 0
			EXPG C 1 BRIGHT A_SetScale(-0.15, 0.15)
			EXPG D 1 BRIGHT A_SetScale(-0.2, 0.2)
			EXPG E 1 BRIGHT A_SetScale(-0.3, 0.3)
			EXPG F 1 BRIGHT A_SetScale(-0.4, 0.4)
			EXPG G 1 BRIGHT A_SetScale(-0.5, 0.5)
			Stop
		Vfx3:	
			TNT1 A 0
			EXPG C 1 BRIGHT A_SetScale(0.15, -0.15)
			EXPG D 1 BRIGHT A_SetScale(0.2, -0.2)
			EXPG E 1 BRIGHT A_SetScale(0.3, -0.3)
			EXPG F 1 BRIGHT A_SetScale(0.4, -0.4)
			EXPG G 1 BRIGHT A_SetScale(0.5, -0.5)
			Stop
		Vfx4:	
			TNT1 A 0
			EXPG C 1 BRIGHT A_SetScale(-0.15, -0.15)
			EXPG D 1 BRIGHT A_SetScale(-0.2, -0.2)
			EXPG E 1 BRIGHT A_SetScale(-0.3, -0.3)
			EXPG F 1 BRIGHT A_SetScale(-0.4, -0.4)
			EXPG G 1 BRIGHT A_SetScale(-0.5, -0.5)
			Stop
		
	}
}

Actor IcePuff: HitPuff
{
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	+PUFFONACTORS
	+HITMASTER
	+PUFFGETSOWNER
	
	DamageType Ice
	Decal None
	RenderStyle Add
	States
	{
		// this one is most *boring*, it literally does nothing
		XDeath: // hit a bleeding actor
			//NOTE, the puff is switched to corresponding state inside the native C++ code right after spawn!
			TNT1 A 0 // this one does nothing beside simple damage
			Goto VFX

		Crash: // hit map geometry. 
		Spawn: // used in all other cases (hit a non-bleeding actor?)
		Melee: // I *think* this one should never happen, I'm 99% sure.
			TNT1 A 0 // this one does nothing beside simple damage
			Goto VFX
		
		VFX:
			TNT1 A 0 A_PlaySound("ice/crackle/short")
			
			TNT1 AA 0 A_CustomMissile ("XIceChunk1", 0, 0, random (140, 220), 2, random (-60,35))
			TNT1 A 0 A_CustomMissile ("XIceChunk2", 0, 0, random (140, 220), 2, random (-60,35))
			
			TNT1 A 0 A_Jump(192, "Vfx2", "Vfx3", "Vfx4")
		Vfx1:	
			SM6K A 1 A_SetScale(0.15, 0.15)
			SM6K B 1 A_SetScale(0.2, 0.2)
			SM6K C 1 A_SetScale(0.3, 0.3)
			SM6K D 1 A_SetScale(0.4, 0.4)
			SM6K E 1 A_SetScale(0.5, 0.5)
			SM6K F 1 A_SetScale(0.5, 0.5)
			SM6K G 1 A_SetScale(0.5, 0.5)
			Stop
		Vfx2:	
			SM6K A 1 A_SetScale(-0.15, 0.15)
			SM6K B 1 A_SetScale(-0.2, 0.2)
			SM6K C 1 A_SetScale(-0.3, 0.3)
			SM6K D 1 A_SetScale(-0.4, 0.4)
			SM6K E 1 A_SetScale(-0.5, 0.5)
			SM6K F 1 A_SetScale(-0.5, 0.5)
			SM6K G 1 A_SetScale(-0.5, 0.5)
			Stop
		Vfx3:	
			SM6K A 1 A_SetScale(0.15, -0.15)
			SM6K B 1 A_SetScale(0.2, -0.2)
			SM6K C 1 A_SetScale(0.3, -0.3)
			SM6K D 1 A_SetScale(0.4, -0.4)
			SM6K E 1 A_SetScale(0.5, -0.5)
			SM6K F 1 A_SetScale(0.5, -0.5)
			SM6K G 1 A_SetScale(0.5, -0.5)
			Stop
		Vfx4:	
			SM6K A 1 A_SetScale(-0.15, -0.15)
			SM6K B 1 A_SetScale(-0.2, -0.2)
			SM6K C 1 A_SetScale(-0.3, -0.3)
			SM6K D 1 A_SetScale(-0.4, -0.4)
			SM6K E 1 A_SetScale(-0.5, -0.5)
			SM6K F 1 A_SetScale(-0.5, -0.5)
			SM6K G 1 A_SetScale(-0.5, -0.5)
			Stop
	}
}


/* 
	//***Che 
	ALAS, yet *another* Zandronum limitation shot this cool idea down.
	Fast projectiles fired by the *player* have a pitch of zero and there is no way around that :(
	As a result, the beam is rendered wrong (horizontally from the point of impact).
	A workaround would be doable BUT I am laser-guided towards releasing 2.0 ASAP, no time!
	

ACTOR EleTechLightning: FastProjectile
{
	Species "Marines"
	Speed 2000
	FastSpeed 2000
	Radius 8
	Height 4
	missiletype "none" 
	missileheight 8
	SeeSound "lightning/snap/low"
	+SKYEXPLODE
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	DamageType "Plasma"
	Damage (random(10, 10)) //x5 = 50
	+HITMASTER
	var int user_z;
	States {
		Spawn:
			TNT1 A 1 // limit range to 500
			TNT1 A 0 A_Stop
			
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5", 1) // a serverside script that calls a clientside script to actually draw
			
			TNT1 A 60
			Stop				
			
		Death:
		Crash:
			TNT1 A 0 
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5", 1) // a serverside script that calls a clientside script to actually draw
			TNT1 A 0 A_Stop
			TNT1 A 0 A_PlaySound("lightning/hit", 6)
			TNT1 A 0 A_SetDamageType("Electric")
			TNT1 A 0 A_Explode(50, 10, 0)
			
			
			TNT1 A 0 A_CustomMissile ("ShoqueAzul", 3, 0, random (0, 360), 2, random (0, 360))
			EXPL A 0 A_CustomMissile ("BluePlasmaFire", 1, 0, random (0, 360), 2, random (0, 360))
			TNT1 AAA 1 A_SpawnItem("BlueFlare")
			TNT1 A 30
			Stop

		XDeath:
			// hit a bleeding actor
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5", 1)
			TNT1 A 0 A_Stop
			
			
			TNT1 A 0 A_CheckFlag("CORPSE", "DoNothing", AAPTR_MASTER)
			TNT1 A 0 A_CheckFlag("FRIENDLY", "DoNothing", AAPTR_MASTER)
			TNT1 A 0 A_JumpIf(CallAcs("FBD_GetMastersIsPlayer"), "DoNothing")
			TNT1 A 0 A_CheckFlag("ISMONSTER", "ActuallyChain", AAPTR_MASTER)
			Goto DoNothing

			
		DoNothing:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5", 1)
			// keep existing in case script starts delayed - it is CLIENTSIDE after all
			TNT1 A 30
			Stop

		ActuallyChain:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_z", CallAcs("GetZDeltaToMaster"))
			TNT1 A 0 A_PlaySound("lightning/hit", 6)
			TNT1 A 0 A_CustomMissile ("ShoqueAzul", 3, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 1, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_DamageMaster(10, "Electric") // this IGNORES ARMOR!!! (also, Zandronum doesn't support the Flags parameter so can't turn that feature off)
				// Because of that, can only be used for projectiles fired by player, *NOT* monsters.
			
			
			// random delay to make lightning chains more dramatic	
			TNT1 A Random(0,4) A_Warp(AAPTR_MASTER,0,0,user_z,0,WARPF_STOP|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE,"WarpedOk")
			
			TNT1 A 1 A_Jump(256, "TheRest") // a goto replacement that honors descendant classes redefining states but does not work clientside
			Wait
			
		WarpedOk:	
			TNT1 A 0 A_CustomMissile("EleTech2ndLightningFirer", 0, 0, angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, Random(-30, 30))
			Goto TheRest
			
		TheRest:
			TNT1 AAAAAAAA Random(5,15) A_DamageMaster(10, "Electric") // +8x10, total 100
			TNT1 A 30
			Stop
	}
}

ACTOR FakeLightningBoltVfx: FastProjectile
//***Che since the player remains the originator of all secondary chain discharges,
// we cannot use our beam drawing script because it's get the length wrong (distance to player)
// so any secondary bolt fires a VFX projectile *backwards* at the first monster
// while pointers are swindled twice in the process to make that monster the originator.
// Hoping that the first monster is still solid.

{
	-THRUGHOST
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	damage 0
	Radius 8
	Height 4
	Speed 200
	FastSpeed 200
	States
	{
		Spawn:
			TNT1 A 1
			TNT1 A 0
			Stop
		Death:
		Crash:
			TNT1 A 1
			Stop
		XDeath:
			TNT1 A 0 A_Stop
			TNT1 A 0 ACS_NamedExecuteWithResult("DrawLazorBeamMk5", 1)
			TNT1 A 30
			Stop
	}
}

ACTOR EleTech2ndLightning: EleTechLightning
{
	Speed 50
	FastSpeed 50
	+THRUACTORS // initial, clears after traveling 50
	SeeSound None
	Damage 0
	States {
		Spawn:
			TNT1 A 1 // limit range to 200
			TNT1 A 1 A_ChangeFlag("THRUACTORS", 0)
			TNT1 AA 1
			Stop // nope nothing to see here
		
		Death:
		Crash:
			TNT1 A 0 // Did not happen, no bolt nope 
			TNT1 A 1
			Stop	
			
		XDeath:
			// hit a bleeding actor
			TNT1 A 0
			TNT1 A 0 A_Stop
			
			TNT1 A 0 A_CheckFlag("CORPSE", "DoNothing", AAPTR_MASTER)
			TNT1 A 0 A_CheckFlag("FRIENDLY", "DoNothing", AAPTR_MASTER)
			TNT1 A 0 A_JumpIf(CallAcs("FBD_GetMastersIsPlayer"), "DoNothing")
			TNT1 A 0 A_CheckFlag("ISMONSTER", "ActuallyChain", AAPTR_MASTER)
			Goto DoNothing
			
		DoNothing:
			TNT1 A 0
			TNT1 A 1
			Stop		
			
		ActuallyChain:
		
			//Swindle pointers swapping target and master to make the monster we hit (the master) temporarily into target
			TNT1 A 0 A_RearrangePointers(AAPTR_MASTER, AAPTR_TARGET)
			// fire a visual lightning backwards
			TNT1 A 0 A_CustomMissile("FakeLightningBoltVfx", 0, 0, 180.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 - pitch) //***Che fun fact: if you simply write "-pitch" it doesn't work. No error message, nothing - just doesn't work. You *have* to have a value to subtract from -- hence "0.0-pitch".
			// swap the pointers back
			TNT1 A 0 A_RearrangePointers(AAPTR_MASTER, AAPTR_TARGET)			
		
			TNT1 A 0 A_PlaySound("lightning/snap", 1)
			TNT1 A 0 A_PlaySound("lightning/hit", 6)
			TNT1 A 0 A_CustomMissile ("ShoqueAzul", 3, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_CustomMissile ("BluePlasmaFire", 1, 0, random (0, 360), 2, random (0, 360))
			TNT1 A 0 A_SpawnItem("BlueFlare")
			
			TNT1 A 0 A_DamageMaster(10, "Electric") // this IGNORES ARMOR!!! (also, Zandronum doesn't support the Flags parameter so can't turn that feature off)
				// Because of that, can only be used for projectiles fired by player, *NOT* monsters.
			
			// random delay to make lightning chains more dramatic	
			TNT1 A Random(0,4) A_Warp(AAPTR_MASTER,0,0,user_z,0,WARPF_STOP|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE,"WarpedOk")
			
			TNT1 A 1 A_Jump(256, "TheRest") // a goto replacement that honors descendant classes redefining states but does not work clientside
			Wait
	
		WarpedOk:	
			TNT1 A 0 A_CustomMissile("EleTech3rdLightningFirer", 0, 0, angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, Random(-30, 30))
			Goto TheRest
		TheRest:
			TNT1 AAAAAA Random(5,15) A_DamageMaster(10, "Electric") // +6x10, total 80
			TNT1 A 30
			Stop	
	}
}

ACTOR EleTech3rdLightning: EleTech2ndLightning
{
	States {
		WarpedOk:	
			TNT1 A 0 A_CustomMissile("EleTech4thLightningFirer", 0, 0, angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, Random(-30, 30))
			Goto TheRest
		TheRest:
			TNT1 AAAA Random(5,15) A_DamageMaster(10, "Electric") // +4x10, total 60
			TNT1 A 30
			Stop	
	}
}

ACTOR EleTech4thLightning: EleTech3rdLightning
{
	States {
		WarpedOk:	
			TNT1 A 0 A_CustomMissile("EleTech5thLightningFirer", 0, 0, angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, Random(-30, 30))
			Goto TheRest
		TheRest:
			TNT1 AA Random(5,15) A_DamageMaster(10, "Electric") // +2x10, total 40
			TNT1 A 30
			Stop	
	}
}

ACTOR EleTech5thLightning: EleTech4thLightning
{
	States {
		WarpedOk:	
			TNT1 A 0 A_CustomMissile("EleTech6thLightningFirer", 0, 0, angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, Random(-30, 30))
			Goto TheRest
		TheRest:
			TNT1 A Random(5,15) A_DamageMaster(10, "Electric") // +1x10, total 30
			TNT1 A 30
			Stop	
	}
}

ACTOR EleTech6thLightning: EleTech5thLightning
{
	States {
		WarpedOk:	
			TNT1 A 0 // the chain ends here
			Goto TheRest
		TheRest:
			TNT1 A Random(5,15) A_DamageMaster(10, "Electric") // +1x10, total 30
			TNT1 A 30
			Stop	
	}
}

ACTOR EleTech2ndLightningFirer {
	PROJECTILE
	+SEEKERMISSILE
	+BLOODLESSIMPACT
	SeeSound None 
	Damage 0
	Radius 1
	Height 1
	Speed 1
	FastSpeed 1
	States {
		Spawn:
			// here the missile is still counted as fired by the player so the seeker seeks hostile monsters
			TNT1 A 1 NODELAY A_SeekerMissile(170, 170, SMF_LOOK, 256, 2) // acquire target with 100% probability in a range of two blockmap blocks (2x128 = 256)
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTracer"), "DoNothing")
			TNT1 A 0 A_CustomMissile("EleTech2ndLightning", 0, 0, 0.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 + pitch)
			TNT1 A 30 // keep existing because network lag & stuff
			Stop 
		Crash:
		Death:
		DoNothing:
		XDeath:
			TNT1 A 1
			Stop // if we hit map geometry or a static decoration, nothing happened.
	}
}

ACTOR EleTech3rdLightningFirer: EleTech2ndLightningFirer {
	States {
		Spawn:
			TNT1 A 1 NODELAY A_SeekerMissile(150, 150, SMF_LOOK, 256, 2)
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTracer"), "DoNothing")
			TNT1 A 0 A_CustomMissile("EleTech3rdLightning", 0, 0, 0.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 + pitch)
			TNT1 A 30
			Stop 	
	}
}

ACTOR EleTech4thLightningFirer: EleTech3rdLightningFirer {
	States {
		Spawn:
			TNT1 A 1 NODELAY A_SeekerMissile(130, 130, SMF_LOOK, 256, 2)
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTracer"), "DoNothing")
			TNT1 A 0 A_CustomMissile("EleTech4thLightning", 0, 0, 0.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 + pitch)
			TNT1 A 30
			Stop 	
	}
}

ACTOR EleTech5thLightningFirer: EleTech4thLightningFirer {
	States {
		Spawn:
			TNT1 A 1 NODELAY A_SeekerMissile(110, 110, SMF_LOOK, 256, 2)
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTracer"), "DoNothing")
			TNT1 A 0 A_CustomMissile("EleTech5thLightning", 0, 0, 0.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 + pitch)
			TNT1 A 30
			Stop 	
	}
}

ACTOR EleTech6thLightningFirer: EleTech5thLightningFirer {
	States {
		Spawn:
			TNT1 A 1 NODELAY A_SeekerMissile(90, 90, SMF_LOOK, 256, 2)
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTracer"), "DoNothing")
			TNT1 A 0 A_CustomMissile("EleTech6thLightning", 0, 0, 0.0 + angle, CMF_AIMDIRECTION | CMF_SAVEPITCH, 0.0 + pitch)
			TNT1 A 30
			Stop 	
	}
}

*/

Actor SparkPuff: HitPuff // designed for 0 damage, all damage is accumulated and inflicted the next tic -- to have proper XDeaths
{
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	+HITMASTER
	+PUFFGETSOWNER
	+PUFFONACTORS 
	
	// red to blue-white
	Translation "176:191=192:198", "16:26=4:4", "27:47=192:199", "168:175=4:4"
	RenderStyle Add
	Alpha 0.8
	+BRIGHT
	
	DamageType Electric
	//Decal "Scorch"
	States
	{
		XDeath: // hit a bleeding actor
			//NOTE, the puff is switched to corresponding state inside the native C++ code right after spawn!
			TNT1 A 0
			TNT1 A 0 A_JumpIf(waterlevel >= 1, "HitSomeoneUnderwater")
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_RunElectricDmg", 13, 1), "Crash") // the master may be immune or may be gone for some reason
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			Goto VFX

		Crash: // hit map geometry. 
		Spawn: // used in all other cases (hit a non-bleeding actor?)
		Melee: // I *think* this one should never happen, I'm 99% sure.
			TNT1 A 0
			TNT1 A 0 A_JumpIf(waterlevel >= 1, "HitMapGeometryUnderwater")
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			TNT1 A 0 A_Explode(2, 90)
			TNT1 A 0 A_RadiusGive("ElectricAOE", 90, RGF_MONSTERS | RGF_PLAYERS) 
			

			Goto VFX
			
		VFX:	
			HEFX C Random(1,2)
			HEFX D Random(1,2)
			HEFX E Random(1,2)
			HEFX F Random(1,2)
			HEFX G Random(1,2)
			HEFX H Random(1,2)
			HEFX I Random(1,2)
			Stop
		
		HitSomeoneUnderwater:
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunElectricDmg", 5, 1)		
		
		HitMapGeometryUnderwater:
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			TNT1 AAAA 0 A_CustomMissile("BUBULZ",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 A 0 A_CustomMissile("ExplosionBubulz",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 A 0 A_RadiusGive("ElectricShock", 120, RGF_MONSTERS | RGF_PLAYERS) 
			Stop
		
	}
}

ACTOR ChainLightningAOEGiver: CustomInventory 
{
	+INVENTORY.AUTOACTIVATE
	+INVENTORY.ALWAYSPICKUP
	inventory.maxamount 1
    States
    {
		Pickup:
			// inventory item's states execute in the context of the actor that item is in the inventory of
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("IsPlayer",1,"OnPlayer")
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunElectricDmg", 55, 0)	
			TNT1 A 0 A_RailWait // set the internal action result variable to true, otherwise fails if FBD_RunElectricDmg returns false
			Stop
			
		OnPlayer:
			TNT1 A 0
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_RunElectricDmg", 18, 0)
			TNT1 A 0 A_RailWait // set the internal action result variable to true, otherwise fails if FBD_RunElectricDmg returns false
			Stop
    }
}

ACTOR ChainlikeLightning
{
	+THRUACTORS
	+MISSILE
	+THRUGHOST
	+NOCLIP
	-SHOOTABLE
	-SOLID
	+NOGRAVITY
	Radius 1
	Height 1
	States {
		Spawn:
			TNT1 A 0 
			TNT1 A 0 A_JumpIf(waterlevel >= 1, "Underwater")
			TNT1 A 0 A_RadiusGive("ChainLightningAOEGiver", 128, RGF_MONSTERS) 
			TNT1 A 1
			Stop
			
		Underwater:
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			TNT1 AAAAAA 0 A_CustomMissile("BUBULZ",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 AAA 0 A_CustomMissile("ExplosionBubulz",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 A 0 A_RadiusGive("ElectricShock", 90, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 120, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 160, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 255, RGF_MONSTERS | RGF_PLAYERS) 
			Stop		
	
	}
}

ACTOR FBD_SecondaryDischarge: FastProjectile 
{
	Speed 128
	FastSpeed 128
	Radius 8
	Height 4
	
	missiletype "FBD_SmallSpark"
	missileheight 8 // zero, for historical reasons
	+HITMASTER
	
	Translation "176:191=192:198", "16:26=4:4", "27:47=192:199", "168:175=4:4"
	RenderStyle Add
	Alpha 0.8
	
	States {
		Spawn:
			TNT1 A 1
			Stop
			
		XDeath:
			TNT1 A 0 A_JumpIf(waterlevel >= 1, "Underwater")
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_RunElectricDmg", 55, 1), "Crash") // the master may be immune or may be gone for some reason
			
			
		Death:
		Crash:
			TNT1 A 1 A_SetScale(random(0,1) ? 1.0 : -1.0, random(0,1) ? 1.0 : -1.0)
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			HEFX CDEFGHI 1 BRIGHT
			Stop
			
		Underwater:
			TNT1 A 0 A_PlaySound("KYBFGSPR")
			TNT1 AAAAAA 0 A_CustomMissile("BUBULZ",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 AAA 0 A_CustomMissile("ExplosionBubulz",0,0,Random(0,360), CMF_AIMDIRECTION,Random(0,90))
			TNT1 A 0 A_RadiusGive("ElectricShock", 90, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 120, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 160, RGF_MONSTERS | RGF_PLAYERS) 
			TNT1 A 0 A_RadiusGive("ElectricShock", 255, RGF_MONSTERS | RGF_PLAYERS) 
			Stop
	}
}





ACTOR FBD_SmallSpark: FlameTrails //AbstractParticle // Script error, "chebskies-EDAY-2.pk3:demoneletech.txt" line 1489: Parent type 'AbstractParticle' not found in FBD_SmallSpark
// wtf bro

{
	// red to blue-white
	Translation "176:191=192:198", "16:26=4:4", "27:47=192:199", "168:175=4:4"
	RenderStyle Add
	Alpha 0.8
	+NOGRAVITY
	+NOBLOCKMAP
	-SHOOTABLE
	
	States
	{
		Spawn:
			TNT1 A 1 NODELAY A_SetScale(random(0,1) ? 0.35 : -0.35, random(0,1) ? 0.35 : -0.35)
			TNT1 A 1 A_JumpIf(waterlevel > 1, "Bubble")
			HEFX CDEFGHI 1 BRIGHT
			Stop
	}
}

ACTOR FBD_SmallSparkWSound: FBD_SmallSpark
{
	SeeSound "KYBFGSPR"
}


ACTOR BlizzardMissile
{
	Game Doom
	Radius 8
	Height 8
	Speed 35
	Damage (random (12, 12)) 
    +NOBLOCKMAP
    +NOTELEPORT
    +DONTSPLASH
	+MISSILE
	+FORCEXYBILLBOARD
	+NOBLOOD
	+NOBLOODDECALS
	+BLOODLESSIMPACT
	-BLOODSPLATTER
	+NODAMAGETHRUST
	-NOGRAVITY
	+BOUNCEONWALLS
	+BOUNCEONFLOORS
	+BOUNCEONCEILINGS
	//+THRUACTORS
	RenderStyle Translucent
    DamageType Ice
	Decal None
    Scale 1.5
	Alpha 0.2
	Gravity 1.0
	BounceCount 2
	WallBounceFactor 0.25
	States
	{
		Spawn:
			TNT1 A 1
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 AB 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(16, 32, 0, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 CD 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(16, 64, 0, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 EFGHIJ 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(21, 128, 1, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 KLMNOP 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(24, 196, 1, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 QRSTUV 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(24, 196, 1, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF2 WXYZ 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			PUF3 AB 1 BRIGHT A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			TNT1 A 0 A_Explode(24, 196, 1, 0, 1)
			TNT1 A 0 A_JumpIf(waterlevel > 0, "Death")
			PUF3 C 1 BRIGHT
			TNT1 AAAA 0 A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			Stop
		Death:
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("FORCERADIUSDMG", 1)
			TNT1 A 0 A_Explode(32, 128, 1, 0, 1)
			TNT1 AAAAA 0 A_CustomMissile ("FBD_BlizzardParticle", 15, 0, random (0, 360), 2, random (-90, -45))
			Stop
	}
}

ACTOR BlizzardMissileProper: BlizzardMissile
{
	-BOUNCEONWALLS
	-BOUNCEONFLOORS
	-BOUNCEONCEILINGS
	Speed 40
}

//SM6K A..G
//SMOK A..Q

ACTOR FBD_BlizzardParticle: FlameTrails //AbstractParticle 
{
	+NOINTERACTION
	+NOCLIP
	+NOGRAVITY
	+BRIGHT
	Radius 12
	Height 1
	Speed 0
	RenderStyle Translucent
	Alpha 0.4
	States
	{
		Spawn: 
			//***Che: variability in flipping
			TNT1 A 0 NODELAY A_SetScale(random(0,1) ? 3 : -3, random(0,1) ? 3 : -3)
			TNT1 A 0 A_Jump(128, "Spawn2")
			SM6K A Random(1,2)
			SM6K B Random(1,2)
			SM6K C Random(1,2)
			SM6K D Random(1,2)
			SM6K E Random(1,2)
			SM6K F Random(1,2)
			SM6K G Random(1,2)
			Stop
		
		Spawn2:
			SMOK A Random(1,2)
			SMOK B Random(1,2)
			SMOK C Random(1,2)
			SMOK D Random(1,2)
			SMOK E Random(1,2)
			SMOK F Random(1,2)
			SMOK G Random(1,2)
			SMOK H Random(1,2)
			SMOK I Random(1,2)
			SMOK J Random(1,2)
			SMOK K Random(1,2)
			SMOK L Random(1,2)
			SMOK M Random(1,2)
			SMOK N Random(1,2)
			SMOK O Random(1,2)
			SMOK P Random(1,2)
			SMOK Q Random(1,2)
			Stop
			
	}
}

// player elemenant balls are defined in HellishMissile.txt due to load order