// Fancy halo code by yholl


// New halo base actor by that dread thingy known as yholl
// fear me for I am powered by dark decorate shenanigans

ACTOR HaloBase
{
	+NOINTERACTION
	+NOGRAVITY
	+FLOATBOB

	var int user_haloalpha;
	var int user_halofadespeed;
	
	var int user_halophase;
	var int user_haloheight;
	
	var int user_halohealth75;
	var int user_halohealth50;
	var int user_halohealth25;
States
	{
	Spawn:
		TNT1 A 0
		HALO A 0 A_Die
        Stop
// 		Loop
// 		TNT1 A 0 A_Jump(256, "SpawnSetHealthPercentages") // These jumps are required for inheritance to work nice.
// 		Goto SpawnSetHealthPercentages // This technically doesn't need to be here, but it looks pretty and complete.
		// Gotos are static jumps, A_Jump is dynamic.
		// What this means is, this Goto will always go to the SpawnSetHealthPercentages that's defined in this actor.
		// If you inherited from this and made a new SpawnSetHealthPercentages, that Goto would still go to the old one.
		// But the A_Jump will always go to the new one, so make sure you've got them all over when doing heavy inheritance!
		
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05)
		TNT1 A 0 A_SetUserVar (user_haloheight, 28)
		TNT1 A 0 A_SetUserVar (user_halohealth75, 75)
		TNT1 A 0 A_SetUserVar (user_halohealth50, 50)
		TNT1 A 0 A_SetUserVar (user_halohealth25, 25)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	SpawnHealthCheck:
		TNT1 A 0 A_JumpIfHealthLower (1, "HaloDestroyed" ) // It's a lower check, so it has to be 1, not 0.
		TNT1 A 0 A_JumpIfHealthLower (user_halohealth25, "Halo25Health" )
		TNT1 A 0 A_JumpIfHealthLower (user_halohealth50, "Halo50Health" )
		TNT1 A 0 A_JumpIfHealthLower (user_halohealth75, "Halo75Health" )
		TNT1 A 0 A_Jump(256, "SpawnExistanceCheck")
		Goto SpawnExistanceCheck
	SpawnExistanceCheck:
		// If it's health is higher than those values, then check that it at least exists.
		TNT1 A 0 A_CheckFlag ("ISMONSTER", "Halo100Health", AAPTR_MASTER)
		// If it hasn't jumped from anything by now, the angel must not exist, so destroy the halo.
		TNT1 A 0 A_Jump(256, "HaloDestroyed")
		Goto HaloDestroyed
		
		// hmm yes float var, the ultimate power
		// This sets the current level of transparency wanted for the halo.
		// The alpha then fades smoothly to the new level while animating.
		
	Halo100Health:
		TNT1 A 0 A_SetUserVar (user_haloalpha, 1.0)
		TNT1 A 0 A_Jump(256, "AnimationLoopCheck")
		Goto AnimationLoopCheck
	Halo75Health:
		TNT1 A 0 A_SetUserVar (user_haloalpha, 0.75)
		TNT1 A 0 A_Jump(256, "AnimationLoopCheck")
		Goto AnimationLoopCheck
	Halo50Health:
		TNT1 A 0 A_SetUserVar (user_haloalpha, 0.55)
		TNT1 A 0 A_Jump(256, "AnimationLoopCheck")
		Goto AnimationLoopCheck
	Halo25Health:
		TNT1 A 0 A_SetUserVar (user_haloalpha, 0.10)
		TNT1 A 0 A_Jump(256, "AnimationLoopCheck")
		Goto AnimationLoopCheck
		
		// Main animation loops are here.
		// user_halophase keeps track of which part of the animation it should play next, so it only needs one set of health checks.
		
	AnimationLoopCheck:
		TNT1 A 0 A_JumpIf (user_halophase == 1, "AnimationLoop2")
		TNT1 A 0 A_JumpIf (user_halophase == 2, "AnimationLoop3")
		TNT1 A 0 A_JumpIf (user_halophase == 3, "AnimationLoop3") // Loops this part twice.
		TNT1 A 0 A_Jump(256, "AnimationLoop1")
		Goto AnimationLoop1
		
	AnimationLoop1:
        HALQ A 1 Bright A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
        HALQ B 1 Bright A_FadeTo(user_haloalpha, user_halofadespeed, 0)
        HALQ C 1 Bright //... repeat for C, D, E, etc., if needed
        // ... more sprites
        TNT1 A 0 A_SetUserVar(user_halophase, 1)
        TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
        Goto SpawnHealthCheck
	AnimationLoop2:
		HALQ M 1 Bright A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
		HALQ N 1 Bright A_FadeTo(user_haloalpha, user_halofadespeed, 0)
		HALQ O 1 Bright //... repeat for O, P, Q, etc., if needed
		// ... more sprites
		TNT1 A 0 A_SetUserVar(user_halophase, 2)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck

	AnimationLoop3:
        // This random jump is here simply to desync the halo animations across the angels.
        // If you don't want that, simply delete the jump here to remove it.
        TNT1 A 0 A_Jump(256, "Label1", "Label2", "Label3")

    Label1:
        HALQ A 1 Bright A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
        TNT1 A 0 A_FadeTo(user_haloalpha, user_halofadespeed, 0)
        Goto AfterLabel

    Label2:
        HALQ A 1 Bright A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
        TNT1 A 0 A_FadeTo(user_haloalpha, user_halofadespeed, 0)
        Goto AfterLabel

    Label3:
        HALQ A 1 Bright A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
        TNT1 A 0 A_FadeTo(user_haloalpha, user_halofadespeed, 0)
  
    AfterLabel:
        TNT1 A 0 A_SetUserVar(user_halophase, user_halophase+1)
        TNT1 A 0 A_JumpIf(user_halophase == 4, "AnimationEnd") // Time to reset the animation.
        TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
        Goto SpawnHealthCheck
		
	AnimationEnd:
		TNT1 A 0 A_SetUserVar (user_halophase, 0) // Reset the animation loops.
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
		
	Death.Ice: // I don't think you need this for something that can't be hurt, but I'll leave it here just in case you use it.
	HaloDestroyed:
		HALQ AAAAA 1 A_Warp(AAPTR_MASTER, 0, 0, user_haloheight, 0, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION)
		TNT1 A 0 A_FadeTo (0, user_halofadespeed, 1)
		Loop
	}
}

// Thanks to inheritance, this is all you need to define for each halo!
// Inheritance is very powerful, it will be your friend if you learn it well.

ACTOR CherubHalo : HaloBase
{
	Scale 0.5 // Set the scale of the actor here, no need to spam A_SetScale everywhere.
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 28) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 60) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 40) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 20) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR KissHalo : HaloBase
{
	Scale 0.8 // Set the scale of the actor here, no need to spam A_SetScale everywhere.
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 50) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 225) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 150) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 75) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR AphroditeHalo : HaloBase
{
	Scale 0.8 // Set the scale of the actor here, no need to spam A_SetScale everywhere.
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 50) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 300) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 200) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 100) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR CardinalHalo : HaloBase
{
	Scale 0.5
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 44) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 110) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 75) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 40) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR JayHalo : HaloBase
{
	Scale 0.6
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 46) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 225) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 150) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 75) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}


ACTOR SnowBallHalo : HaloBase
{
	Scale 0.6
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 40) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 45) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 30) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 15) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR IrisHalo : HaloBase
{
	Scale 0.7 // Set the scale of the actor here, no need to spam A_SetScale everywhere.
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 70) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 225) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 150) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 75) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR AuthorityHalo : HaloBase
{
	Scale 0.7
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) 
		TNT1 A 0 A_SetUserVar (user_haloheight, 60) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 300) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 200) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 100)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR VVHalo : HaloBase
{
	Scale 0.7
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) 
		TNT1 A 0 A_SetUserVar (user_haloheight, 60) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 750) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 500) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 250)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR OphanimHalo : HaloBase
{
	Scale 0.8
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) 
		TNT1 A 0 A_SetUserVar (user_haloheight, 60) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 600) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 400) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 200)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR PrincipalityHalo : HaloBase
{
	Scale 0.8
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) 
		TNT1 A 0 A_SetUserVar (user_haloheight, 63) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 450) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 300) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 150)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR DollmaykrHalo : HaloBase
{
	Scale 0.6
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) 
		TNT1 A 0 A_SetUserVar (user_haloheight, 55) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 525) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 350) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 175)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR JoyElementalHalo : HaloBase
{
	Scale 0.6 // Set the scale of the actor here, no need to spam A_SetScale everywhere.
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.05) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 60) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 300) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 200) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 100) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}

ACTOR SeraphHalo : HaloBase
{
	Scale 1.0
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.20) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 100) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 2225) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 1500) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 750) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
			}
}

ACTOR GreatSeraphHalo : HaloBase
{
	Scale 1.0
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 100) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 3750) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 2500) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 1250) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
			}
}

ACTOR QofQHalo : HaloBase
{
	Scale 1.0
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.07) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 100) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 5250) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 3500) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 1750) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
			}
}

ACTOR CQueenHalo : HaloBase
{
	Scale 0.8
	
States
	{
	SpawnSetHealthPercentages: // Just overwrite this state in any sub-type of halo for whatever health values it needs.
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.10) // how much the halo changes transparency per tick
		TNT1 A 0 A_SetUserVar (user_haloheight, 90) // height of halo above the angel.
		TNT1 A 0 A_SetUserVar (user_halohealth75, 1875) // 75% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth50, 1250) // 50% health threshold
		TNT1 A 0 A_SetUserVar (user_halohealth25, 625) // 25% health threshold
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
			}
}

ACTOR CQueen2Halo : HaloBase
{
	Scale 0.8
	
States
	{
	SpawnSetHealthPercentages: 
		TNT1 A 0 A_SetUserVar (user_halofadespeed, 0.10) 
		TNT1 A 0 A_SetUserVar (user_haloheight, -10) 
		TNT1 A 0 A_SetUserVar (user_halohealth75, 750) 
		TNT1 A 0 A_SetUserVar (user_halohealth50, 500) 
		TNT1 A 0 A_SetUserVar (user_halohealth25, 250)
		TNT1 A 0 A_Jump(256, "SpawnHealthCheck")
		Goto SpawnHealthCheck
	}
}