


ACTOR IconOfSinBossChe 17543
{
	//$category "EDAY map-dependent bosses"
	Tag "$IOSBOSS" // Icon of Sin
	Obituary "$IOSBOSS_O" // %o fell in the Final Battle
	
	// https://zdoom.org/wiki/Editor_keys
	//$Arg1 Cooldowns (0 ITYTD 1 HMP 2 UV)
	//$Arg1Type 0
	//$Arg2 LastStand HP threshold
	//$Arg2Type 0
	//$Arg3 Summons (0 trash 1 norm 2 bosses)
	//$Arg3Type 0
	//$Arg4 Summons for LastStand
	//$Arg4Type 0
	
	// Cooldown is measured in "heartbeat cycles" 
	//    (one cycle of the "Ready" state pause OR one attack OR one flinch)
	// Each attack is a combo of attack + maybe summon, both counting as one cycle:
	//   cannot summon without attacking so can only summon as often as attacks.
	//   When summon cooldown is 0 but all attacks are on cooldown, waits
	
	//Scale 10.0 // the original has 9.0, but his mouth is misaligned with projectiles during fire-breathing
	// I felt that easiest way to fix it, without touching the gameplay, was making the boss larger
	
	// P.S. Enlarges from 8.0 to 10.0 by the script he calls from his See state. 
	//   Reason: clipping through map edges when you looked around in his "rising from under the ground" phase
	Scale 8.0
	
	Species "FinalBoss"
	
	Health 30000
	Radius 300
	Height 2000
	Mass 99999
	Speed 0
	PainChance 20
	Monster
	+BOSS 
	+FLOORCLIP
	+NORADIUSDMG
	+DONTMORPH
	+BOSSDEATH
	+NOBLOOD
	+NOTARGET
	+FORCEXYBILLBOARD
	+NOICEDEATH
	
	+MISSILEMORE
	+MISSILEEVENMORE

	DeathSound "cyber/death"
	damagefactor "Normal", 1.0
	
	//***Che instead of him being bullet-spongey 
	// I balanced this by him going apeshit in response to this damage type.
	// You use BFG, you die.

	damagefactor "Desintegrate", 1.0 // 0.6 // as with spider mastermind, otherwise he could be cheesed using both the 9K and the Unmaker
	
	var int user_cubelevel;
	var int user_cubelevel_default;
	var int user_cubelevel_laststand;
	var int user_cooldowns_set;
	var int user_laststand_threshold;
	
	States {
		Spawn:
			ICOS A 5
			
			// unnecessary for us because our dated code still refers to the args directly
			// but required for the map transform script to copy these to the third stage actor
			// (I don't know how to access actor's args from ACS, all right?)
			TNT1 A 0 A_SetUserVar("user_cooldowns_set", args[1])
			TNT1 A 0 A_SetUserVar("user_laststand_threshold", args[2])	
			TNT1 A 0 A_SetUserVar("user_cubelevel_default", args[3])
			TNT1 A 0 A_SetUserVar("user_cubelevel_laststand", args[4])
			
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 20) // he mostly begins using it in response to pain (clears cooldowns)
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 7)
			
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 30) // on UV, he *will* spamming eventually
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 20)
			
			//TNT1 A 0 A_GiveInventory("IosSummonCooldown", 5) // No, let him summon MOAR at the start
			//TNT1 A 0 A_GiveInventory("IosFlameCooldown", 14) // No, let him open with the flame breath
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 5) // because I radically shortened his initial roar stage
			
			// disable regular use if below UV, only use in last stand:
			TNT1 A 0 A_JumpIf(args[1] >= 2, 3)
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 9999)
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 9999)
			TNT1 A 0 A_GiveInventory("TargetIsAGreatTerribleBoss")

			Goto Backstage
		
		Backstage:
			ICOS ABCCB 5 A_Look
			Loop
			
		See:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("HasSpotedThePlayerAlready", 1, "See2")
			TNT1 A 0 A_GiveInventory("HasSpotedThePlayerAlready", 1)
			
			// The grand entrance
			//TNT1 A 0 ACS_ExecuteAlways(33, 0, 0, 0, 0)
			//TNT1 A 0 ACS_NamedExecuteAlways("DisplayBossHealth", 0, 0, 0, 0)
			TNT1 A 0 ACS_NamedExecuteWithResult("FBD_DisplayBossHealth", 12) // IOSBOSS"; // Icon of Sin / Лик греха
			TNT1 A 0 ACS_NamedExecute("ScaleTheBossUp", 0, 0, 0, 0) // scales him smoothly from 8.0 to 10.0
			
			TNT1 A 0
			ICOS ABCCBA 5 
			
			TNT1 A 0 A_PLaySoundEx("brain/sight", CHAN_VOICE, 0, 2)
			TNT1 A 0 ACS_Execute(56)
			
			TNT1 A 0 Floor_LowerByValue(32, 2, 128) // make the gigasphere secret available
			
			// ain't need this long-winded shit			
			//ICOH ABCBABCBABCBABCBAABCBABCBABCBABCBA 6
			//ICOS AB 5
			//TNT1 A 0 A_PLaySoundEx("ICOBREAT", 4, 0, 2)
			//ICOS CCB 5

						
			Goto Summon	
		See2:
			TNT1 A 0
			Goto TryAttacking				
		
		// each attack performs its "go cooldown after" and those redirect 
		// to "trysummoning" which redirects to summon if not on cooldown
		// so summoning is a part of any attack, but has its own cooldown
		
		NukeGoCooldown:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(args[1] == 2, "NukeGoCooldownUV")	
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 15)
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 2)
			Goto TrySummoning
		NukeGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 5) // very dedli 
			Goto TrySummoning
		NukeSpamGoCooldown:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(args[1] == 0, "NukeSpamGoCooldownITYTD")
			TNT1 A 0 A_JumpIf(args[1] == 2, "NukeSpamGoCooldownUV")
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 15)
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 3) // prevent chaining them
			Goto TrySummoning
		NukeSpamGoCooldownITYTD:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 40)
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 5)
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 13)
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 15) // cross-blocking of spam
			Goto TrySummoning
		NukeSpamGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 12)
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 5)
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 5) // cross-blocking of spam
			TNT1 A 0
			Goto TrySummoning
		FlameGoCooldown:
			TNT1 A 0 
			TNT1 A 0 A_JumpIf(args[1] < 1, "FlameGoCooldownITYTD")
			TNT1 A 0 A_JumpIf(args[1] == 2, "FlameGoCooldownUV")
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 5)
			Goto TrySummoning
		FlameGoCooldownITYTD:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 12)
			Goto TrySummoning
		FlameGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 2)
			Goto TrySummoning
		FlameSpamGoCooldown:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(args[1] == 0, "FlameSpamGoCooldownITYTD")
			TNT1 A 0 A_JumpIf(args[1] == 2, "FlameSpamGoCooldownUV")			
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 15)
			Goto TrySummoning
		FlameSpamGoCooldownITYTD:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 40)
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 15) // cross-blocking of spam
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 5)
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 13)
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 5)
			Goto TrySummoning
		FlameSpamGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 10)
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 5)
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 5) // cross-blocking of spam
			TNT1 A 0
			Goto TrySummoning
		ThunderGoCooldown:
			TNT1 A 0 
			TNT1 A 0 A_JumpIf(args[1] == 0, "ThunderGoCooldownITYTD")
			TNT1 A 0 A_JumpIf(args[1] == 2, "ThunderGoCooldownUV")			
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 13)
			Goto TrySummoning
		ThunderGoCooldownITYTD:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 6) // *MORE lightning on ITYTD - trying to make it his main attack
			Goto TrySummoning
		ThunderGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 2)
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 2)
			TNT1 A 0 A_GiveInventory("IosThunderCooldown", 2) // skipped if last stand, otherwise total 4
			TNT1 A 0
			Goto TrySummoning			
		SummonGoCooldown:
			TNT1 A 0 
			TNT1 A 0 A_JumpIf(args[1] == 2, "SummonGoCooldownUV")
			TNT1 A 0 A_GiveInventory("IosSummonCooldown", 10)
			Goto TryAttacking
		SummonGoCooldownUV:
			TNT1 A 0 
			TNT1 A 0 A_GiveInventory("IosSummonCooldown", 5)
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 2)
			TNT1 A 0 A_GiveInventory("IosSummonCooldown", 2) // skipped if last stand, otherwise total 7
			TNT1 A 0
			Goto TryAttacking			
		Pain:
			ICOA C 10 A_BrainPain
			
			// no, you cannot stunlock him. Every ~4 flinches = retaliation
			TNT1 A 0 A_TakeInventory("IosRetaliateCooldown", 1)
			TNT1 A 0 A_JumpIfInventory("IosRetaliateCooldown", 1, "Ready")
			
			// one flinch counts as one attack/idle cycle:
			//TNT1 A 0 A_TakeInventory("IosNukeCooldown", 1)
			//TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 1)
			//TNT1 A 0 A_TakeInventory("IosFlameCooldown", 1)
			//TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 1)
			
			TNT1 A 0 A_JumpIf(args[1] == 0, "PainITYTD")
			TNT1 A 0 A_JumpIf(args[1] == 2, "PainUV")
			TNT1 A 0 A_GiveInventory("IosRetaliateCooldown", 6) // otherwise, using minigun has... consequence
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 4)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 8)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 2)
			//TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, "ClearSpamCooldowns") // too much, retaliates like an agry god :(
			Goto TryAttacking
		PainITYTD:
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("IosRetaliateCooldown", 10)
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 2)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 1)
			Goto Ready
		PainUV:
			// goes full rampage on each pain
			TNT1 A 0
			TNT1 A 0 A_GiveInventory("IosRetaliateCooldown", 4)
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 3)
			Goto TryAttacking
		
		// in response to BFG9000 and Unmaker - the only two weapons inflicting this damage type
		Pain.Desintegrate:
			ICOA C 10 A_BrainPain
			TNT1 A 0 A_JumpIf(args[1] == 2, "PainUVDesint")
			
			// no, you cannot stunlock him. Every ~4 flinches = retaliation
			TNT1 A 0 A_TakeInventory("IosRetaliateCooldown", 2)
			TNT1 A 0 A_JumpIfInventory("IosRetaliateCooldown", 1, "Ready")
			TNT1 A 0 A_GiveInventory("IosRetaliateCooldown", 6)
			
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 3)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 3)
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 4)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 8)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 6)
			Goto TryAttacking		
		PainUVDesint:	
			// die, mortal!
			// *no* flinch
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 10)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 999)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 10)			
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 999)
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, "ClearSpamCooldowns") // retaliate like an agry god		
			Goto TryAttacking		
			
		ClearSpamCooldowns:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(args[1] < 1, "TryAttacking") // ITYTD version should never use spam attacks
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 9999)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 9999)
			Goto TryAttacking
		
		LastStand: // perform "turns red" https://tvtropes.org/pmwiki/pmwiki.php/Main/TurnsRed
			TNT1 A 0
			
			// clear cooldowns on power attacks
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 4)
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 9999)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 9999)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 9999)
			
			TNT1 A 0 A_TakeInventory("IosRetaliateCooldown", 10)
			
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 5)
			TNT1 A 0 A_StopSound(CHAN_VOICE)
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("CLOVERFI", CHAN_VOICE, 0, 2)
			TNT1 A 0 ACS_NamedExecute("PaintBossRed", 0, 0, 0, 0) // performs pallette swap
			TNT1 A 0 A_GiveInventory("IosLastStand", 1)
			TNT1 A 0
			// eyes glowing
			ICOH ABCBABCBABCBABCBAABCBABCBABCBABC 1
			ICOH CBA 8
			//ICOS  5
			//Goto AttackPattern
			Goto RagingThunder // reason: too sudden! There must be a pause of ~1.5s between turning red and raining spammy death!
			// edit: raging thunder is now interruptable by pain... Resulting in a furious retaliation
/*
//***Che: was, in theory, a good idea, but no.
Just doesn't feel *right*. These cubes buzzing around you like flies,
depositing monsters randomly (including melee monsters stuck on cliffs)
just adds NOISE and chaos. We already have thunderbolts for that!
My finely-tuned flow of battle was already altered by removing cover for thunder.
So I reserve these cubes to the third form.
Plus, altering spawn scripts for the third form 
to exclude melee demons for z > -140
		Summon:
			TNT1 A 0
			
			ICOT ABCC 5
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			
			// look, kids, how a simple if..else.. looks in this brain-melting scripting language:
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 3) // if last stand, jump over the next two lines into script called with args[4]
			// map script, see the map
			//TNT1 A 0 ACS_NamedExecuteAlways("SpawnMinions", 0, args[3], 0, 0) // regular summon list (red cubes)
			TNT1 A 0 A_SetUserVar("user_cubelevel", args[3])
			TNT1 A 0 A_JumpIf(true, 2)
			//TNT1 A 0 ACS_NamedExecuteAlways("SpawnMinions", 0, args[4], 0, 0) // last stand summon list (golden cubes)
			TNT1 A 0 A_SetUserVar("user_cubelevel", args[4])
			
		//***Che this part has changed since Chebskies 1.0!	
			TNT1 A 0 A_JumpIf(user_cubelevel == 1, "Summon1")
			TNT1 A 0 A_JumpIf(user_cubelevel == 2, "Summon2")
			
		Summon0:
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube0", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube0", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube0", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube0", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			Goto SummonEnd		

		Summon1:
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube1", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube1", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube1", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube1", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			Goto SummonEnd
		
		Summon2:
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube2", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube2", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube2", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "SummonEnd")
			ICOJ A 5 BRIGHT
			ICOJ B 5 BRIGHT A_CustomMissile("IosBossCube2", 2250, 0, random(-30, 30), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, random(-16, 16))
			Goto SummonEnd
			
		SummonEnd:	
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOT CCBA 5
			Goto SummonGoCooldown
*/			
		Summon:
			TNT1 A 0
			
			ICOT ABCC 5
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			
			// look, kids, how a simple if..else.. looks in this brain-melting scripting language:
			//TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 3) // if last stand, jump over the next two lines into script called with args[4]
			// map script, see the map
			//TNT1 A 0 ACS_NamedExecuteAlways("SpawnMinions", 0, args[3], 0, 0) // regular summon list (red cubes)
			//TNT1 A 0 A_Jump(256, 2) // jump over the next line with 100% probability
			//TNT1 A 0 ACS_NamedExecuteAlways("SpawnMinions", 0, args[4], 0, 0) // last stand summon list (golden cubes)
			
			// this is pure animation, the actual deployment is now processed 
			//   via scripts and an advanced teleporting monster closet
			ICOJ AB 5 BRIGHT
			ICOJ AB 5 BRIGHT
			"----" A 1 ACS_NamedExecuteWithResult("IosLaunchesBossCubes")
			ICOJ AB 5 BRIGHT
			ICOJ AB 5 BRIGHT
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOT CCBA 5
			Goto SummonGoCooldown			


		ThunderAlsoClearCooldown:
			TNT1 A 0
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 9999)
			goto Thunder
		Missile: // we should never land here, added it just in case
			TNT1 A 0
			Goto TryAttacking
		TrySummoning: // all attacks redirect here
			TNT1 A 0 
			TNT1 A 0 A_JumpIfInventory("IosSummonCooldown", 1, "Ready")
			TNT1 A 0 A_JumpIfInventory("IosNumberOfCubesInFlight", 8, "Ready")
			Goto Summon
		Ready:
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOS ABCCCCB 3 // pause cycle
			TNT1 A 0 A_TakeInventory("IosIdleSoundCooldown", 1)
			TNT1 A 0 A_JumpIfInventory("IosIdleSoundCooldown", 1, 1)
			Goto MakeSound // not a frame so A_JumpIfInventory jumps over this line (such a perverted implementation of IF NOT )
			TNT1 A 0
			TNT1 A 0 A_CheckSight("LookForPlayers")
			TNT1 A 0 A_JumpIfInTargetInventory("PlayerIsDead", 1, "LookForPlayers")
			Goto TryAttacking
		MakeSound:
			TNT1 A 0
			TNT1 A 0 A_PLaySoundEx("ICOBREAT", 4, 0, 2)
			TNT1 A 0 A_GiveInventory("IosIdleSoundCooldown", 3)
			TNT1 A 0 A_CheckSight("LookForPlayers")
			TNT1 A 0 A_JumpIfInTargetInventory("PlayerIsDead", 1, "LookForPlayers")
			Goto TryAttacking
			
		LookForPlayers:
			TNT1 A 0
			TNT1 A 0 A_Look // jumps to See if sees any 
			Goto IdleThundering 
		
		IdleThundering: // when no target, keep spawning thunderbolts and summoning
			TNT1 A 0
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosRetaliateCooldown", 1)			
			
			TNT1 A 0 A_CheckSight("ThunderAlsoClearCooldown") // if you hide, spams thunderbolts nonstop
			TNT1 A 0 A_JumpIfInventory("IosThunderCooldown", 1, 1)
			goto Thunder // not a frame, gets jumped over
			TNT1 A 0
			goto TrySummoning // does not stop summoning if no target
			
		TryAttacking:
			TNT1 A 0 A_TakeInventory("IosNukeCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosNukeSpamCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosFlameCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosFlameSpamCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosThunderCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosSummonCooldown", 1)
			TNT1 A 0 A_TakeInventory("IosRetaliateCooldown", 1)
			Goto AttackPattern

		AttackPattern:	
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, 2) // skip the next line if already red,
				// otherwise it causes an infinite loop
				// causing the game engine to perform a beautiful crash-to-desktop
			TNT1 A 0 A_JumpIfHealthLower(args[2], "LastStand") // turn RED and go berserk
			
			TNT1 A 0 A_JumpIfInventory("IosNukeSpamCooldown", 1, 1)
			goto NukeSpam
			TNT1 A 0 A_JumpIfInventory("IosFlameSpamCooldown", 1, 1)
			goto FlameSpam
			TNT1 A 0			
			
			TNT1 A 0 A_CheckSight("ThunderAlsoClearCooldown") // if you hide, spams thunderbolts
			TNT1 A 0 A_JumpIfInTargetInventory("PlayerIsDead", 1, "LookForPlayers")
			
			TNT1 A 0 A_JumpIfInventory("IosNukeCooldown", 1, 1)
			goto Nuke
			TNT1 A 0 A_JumpIfInventory("IosFlameCooldown", 1, 1)
			goto Flames
			TNT1 A 0 A_JumpIfInventory("IosThunderCooldown", 1, 1)
			goto Thunder
			TNT1 A 0 // an empty frame to jump to
			Goto Ready // everything is on cooldown -- run the one-second pause cycle while looking for players	

			// TNT1 A 0 A_JumpIf(CallAcs("GetNoTraget"), "NoTargetSitThundering")
		NoTargetSitThundering:
			TNT1 A 0 A_GiveInventory("IosNukeCooldown", 1)
			TNT1 A 0 A_GiveInventory("IosNukeSpamCooldown", 1)
			TNT1 A 0 A_GiveInventory("IosFlameCooldown", 1)
			TNT1 A 0 A_GiveInventory("IosFlameSpamCooldown", 1)
			TNT1 A 0 A_GiveInventory("IosSummonCooldown", 1)
			Goto AttackPattern	
		
		// leftover stubs from him being a descendant class of EDAY IOS
		Flames:
			TNT1 A 0
			Goto TryAttacking
		Missile:
			TNT1 A 0
			Goto TryAttacking
			
			

			
// --- actual attacks ----------------------------


		NukeSpam: //a clone of original SuperFireballs, absolutely devastating because those are now nukes
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTraget"), "NoTargetSitThundering")
			ICOA ABCDD 5
			TNT1 A 0 A_PLaySoundEx("ICOFIRE", 1, 0, 2)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			ICOA EFEFEF 3 BRIGHT A_CustomMissile("IOSNuke", 1586, 0, random(-16, 16), 0)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOA DDDDCBA 10 // pain here causes the cooldown not to apply -- resulting in him nuke-spamming again
			Goto NukeSpamGoCooldown	

		Nuke: // normally, ONE nuke is enough
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTraget"), "NoTargetSitThundering")
			TNT1 A 0 A_JumpIfInventory("IosLastStand", 1, "StrongNuke")			

			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			ICOA ABCD 3
			ICOA EF 2 BRIGHT
			TNT1 A 0 A_CustomMissile("IOSNuke", 1586, 0, 0, 0)
			ICOA DCBA 3
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOA A 37 // pain here results in no cooldown
			Goto NukeGoCooldown
		
		StrongNuke: // Three in a row
			
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			ICOA ABCD 3
			ICOA EF 2 BRIGHT
			TNT1 A 0 A_CustomMissile("IOSNuke", 1586, 0, 0, 0)
			ICOA DCBA 3
			ICOA A 7
			ICOA ABCD 3
			TNT1 A 0 A_CustomMissile("IOSNuke", 1586, 0, 0, 0)
			ICOA EF 2 BRIGHT
			ICOA DCBA 3
			ICOA A 7
			ICOA ABCD 3
			TNT1 A 0 A_CustomMissile("IOSNuke", 1586, 0, 0, 0)
			ICOA EF 2 BRIGHT 
			ICOA DCBA 3
			ICOA A 7
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			Goto NukeGoCooldown
		Thunder:
			ICOT A 5
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			// Mark-sensei's original frames were DE, with upper hands flashing,
			// Mine are KLM(W) - NOP(X) for the right side (arc between lower and middle arms,
			//   then between middle and upper arms), 
			// QRS(Y) - TUV(Z) for his left side and  DEF(B) - GHI(C) for akimbo (see EnragedThunder)
			
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("ICOTHUND", 4, 0, 2)
			ICOT K 1 BRIGHT
			ICOT W 3
			ICOT L 1 BRIGHT
			ICOT W 3
			ICOT M 1 BRIGHT
			ICOT W 3
			ICOT X 3
			ICOT N 1 BRIGHT
			ICOT X 3
			ICOT O 1 BRIGHT
			ICOT X 3
			ICOT P 1 BRIGHT
			ICOT X 3
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, 1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			ICOT W 8
			ICOT A 5
			
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("ICOTHUND", 4, 0, 2)
			ICOT Q 1 BRIGHT
			ICOT Y 3
			ICOT R 1 BRIGHT
			ICOT Y 3
			ICOT S 1 BRIGHT
			ICOT Y 3
			ICOT Z 3
			ICOT T 1 BRIGHT
			ICOT Z 3
			ICOT U 1 BRIGHT
			ICOT Z 3
			ICOT V 1 BRIGHT
			ICOT Z 3
			//human error
			//TNT1 A 0 A_SpawnItemEx("SeekingThunder", 350)
			//TNT1 A 0 A_SpawnItemEx("SeekingThunder", -350)
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, -1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			ICOT Y 8
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOT A 20
			Goto ThunderGoCooldown
			
		RagingThunder:
			// a copy of thunder but faster and akimbo! Six thunderbolts for the price of two!
			ICOT A 5
			//TNT1 A 0 A_ChangeFlag("NOPAIN", 1) // reason: too vulnerable to cheesing via Unmaker otherwise
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("ICOTHUND", 4, 0, 2)
			ICOT D 1 BRIGHT
			ICOT B 3
			ICOT E 1 BRIGHT
			ICOT B 3
			ICOT F 1 BRIGHT
			ICOT B 3
			ICOT C 3
			ICOT G 1 BRIGHT
			ICOT C 3
			ICOT H 1 BRIGHT
			ICOT C 3
			ICOT I 1 BRIGHT
			ICOT C 3
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, 1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, -1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			ICOT DEF 1 BRIGHT
			ICOT B 8
			ICOT A 5
			
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("ICOTHUND", 4, 0, 2)
			ICOT D 1 BRIGHT
			ICOT B 3
			ICOT E 1 BRIGHT
			ICOT B 3
			ICOT F 1 BRIGHT
			ICOT B 3
			ICOT C 3
			ICOT G 1 BRIGHT
			ICOT C 3
			ICOT H 1 BRIGHT
			ICOT C 3
			ICOT I 1 BRIGHT
			ICOT C 3
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, 1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, -1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			ICOT B 8
			ICOT A 5
			
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_PLaySoundEx("ICOTHUND", 4, 0, 2)
			ICOT D 1 BRIGHT
			ICOT B 3
			ICOT E 1 BRIGHT
			ICOT B 3
			ICOT F 1 BRIGHT
			ICOT B 3
			ICOT C 3
			ICOT G 1 BRIGHT
			ICOT C 3
			ICOT H 1 BRIGHT
			ICOT C 3
			ICOT I 1 BRIGHT
			ICOT C 3
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, 1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_CustomMissile("IOSThunderboltSeeker", 1300, -1000, 0, CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, 0)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOT B 8
			ICOT A 20
			Goto Summon //no cooldown check
			
		FlameSpam:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTraget"), "NoTargetSitThundering")
			//TNT1 A 0 A_JumpIfHealthLower(11000, "Meteors")
			ICOA ABCDD 5
			TNT1 A 0 A_PLaySoundEx("ICOFIRE", 1, 0, 2)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			ICOA EFEFEFEFEFEFEFEFEFEFEFEFEFEF 3 BRIGHT A_CustomMissile("IceCyberlordMissile2", 1586, 0, random(-22, 22), 11, random(-22, 22))
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOA DDCBA 5
			Goto FlameSpamGoCooldown			
		Flames:
			TNT1 A 0
			TNT1 A 0 A_JumpIf(CallAcs("GetNoTraget"), "NoTargetSitThundering")
			//TNT1 A 0 A_JumpIfHealthLower(11000, "Meteors")
			ICOA ABCDD 5
			TNT1 A 0 A_PLaySoundEx("ICOFIRE", 1, 0, 2)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 1)
			ICOA EFEFEFEFEFEFEF 3 BRIGHT A_CustomMissile("IceCyberlordMissile2", 1586, 0, random(-16, 16), 0)
			TNT1 A 0 A_ChangeFlag("NOPAIN", 0)
			ICOA DDCBA 5
			Goto FlameGoCooldown

	// ----- death -----------------------------------------
	
		Death:
			ICOD Z 1 ACS_NamedExecuteWithResult("BossIsDead") // map script
			TNT1 A 0 A_StopSound(4)
			TNT1 A 0 A_StopSound(3)
			TNT1 A 0 A_StopSound(1)
			TNT1 A 0 A_PLaySoundEx("brain/death", 4, 0, 2)
			TNT1 A 0 Radius_Quake (22, 140, 0, 64, 0)
			TNT1 A 0 Floor_LowerByValue(4, 100, 3500)
			TNT1 A 0 A_FaceTarget
			
			TNT1 A 0 ACS_NamedExecuteWithResult("StopMusic") // map script
			
			ICOD ZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))
			TNT1 A 0 Thing_Destroy(660, 1, 0)
			TNT1 A 0 Thing_Destroy(661, 1, 0)
			ICOD ZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))
			TNT1 A 0 Thing_Destroy(662, 1, 0)
			ICOD ZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))
			TNT1 A 0 Thing_Destroy(663, 1, 0)
			ICOD ZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))
			ICOD ZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))
			TNT1 A 0 Thing_Destroy(660, 1, 0)
			TNT1 A 0 Thing_Destroy(661, 1, 0)
			TNT1 A 0 Thing_Destroy(662, 1, 0)
			TNT1 A 0 Thing_Destroy(663, 1, 0)
			TNT1 A 0 A_StopSound(4)
			//TNT1 A 0 A_PLaySoundEx("NUKEEXPL", 4, 0, 2)
			//TNT1 A 0 A_SpawnItem("SuperNuclearExplosion", 0, 800)
			ICOD ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 5 A_CustomMissile ("BloodmistEpic", Random(1200,2700), Random(-900,900), random (-80, 80), CMF_AIMDIRECTION | CMF_ABSOLUTEPITCH, random (40, 90))

			TNT1 A 0 Thing_Damage(660, 9999, 0)
			TNT1 A 0 Thing_Destroy(661, 9999, 0)
			TNT1 A 0 Thing_Destroy(662, 9999, 0)
			TNT1 A 0 Thing_Destroy(663, 9999, 0)
		
			TNT1 A 0 ACS_NamedExecuteAlways("TransformMapForStage2") // map script
			// script waits for the floor to finish lowering us, then deletes us and begins its work
			
			ICOD ZZZZZZZZ 35 A_CustomMissile ("BloodmistEpic", Random(900,1200), Random(-300,600), random (0, 360), CMF_AIMDIRECTION, random (40, 90))
			
			ICOD Z -1 // will be removed by the ACS scropt "TransformMapForStage2" to free space for stage 2
			Stop	
			
	}

}


ACTOR IconOfSin25K: IconOfSinBossChe 17544 {
	// weaker
	Health 25000
}

ACTOR IconOfSin50K: IconOfSinBossChe 17545 {
	// stronger
	Health 50000
}

ACTOR IconOfSinCoop: IconOfSin50K 17679 {
	// dynamic scaling DOES NOT WORK in coop, have to set his scale right away
	Health 90000
	Scale 10.0 // normally begins at 8.0, then enlarges to 10.0 by the script he calls from his See state -- which only works in singleplayer. 
}
