#library "EnemyScouterThing"
#include "zcommon.acs"

str enemyname;
int enemyhealthmax;
int enemyhealth;
int monstercount;

script "EnemyScouterThing" ENTER
{
	monstercount = GetLevelInfo (LEVELINFO_KILLED_MONSTERS);

	while(TRUE)
	{
	
		//NOTE:	PickActor requires careful handling. See the zdoom wiki about that!
		//		Actor's old TID needs to be saved, assigned a new TID, then restored back to old TID to keep things operational.
		int old_tid = PickActor(0, GetActorAngle(0), GetActorPitch(0), 2048.0, 0, MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL |!MF_CORPSE, ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN, PICKAF_RETURNTID);
		
		int new_tid = UniqueTID();
	
		if(PickActor(0, GetActorAngle(0), GetActorPitch(0), 2048.0, new_tid, MF_SOLID | MF_SHOOTABLE | MF_COUNTKILL |!MF_CORPSE, ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN, PICKAF_FORCETID))
		{	
		
			//GET ACTOR INFO
			enemyname = GetActorProperty(new_tid, APROP_NameTag);			//name
			enemyhealthmax = GetActorProperty(new_tid, APROP_SpawnHealth);	//max hp
			enemyhealth = GetActorProperty(new_tid, APROP_HEALTH); 			//current hp
			
			//ACTOR HEALTH DISPLAY
			{
			if(CheckFlag(new_tid, "COUNTKILL") == FALSE)
			{
			}
			else
			{
			if (enemyhealth >= 1)
			{
			//ACTOR NAME DISPLAY
			{
			if(CheckFlag(new_tid, "COUNTKILL") == FALSE)
			{
			}
			else
			{
				HudMessage(	s:"", 
					s:enemyname;
					HUDMSG_FADEOUT, 112223, CR_DARKRED, 0.5, 0.02, 0.6, 0.2);
			
			}
			}
				int pc = enemyhealth * 100 / enemyhealthmax;
				if(pc>100)
				{
					HudMessage(	s:"\n",
					d:enemyhealth,
					s:"/",
					d:enemyhealthmax;
					HUDMSG_FADEOUT, 112224, CR_PURPLE, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=75)
				{
					HudMessage(	s:"\n",
					d:enemyhealth,
					s:"/",
					d:enemyhealthmax;
					HUDMSG_FADEOUT, 112224, CR_BLUE, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=50)
				{
					HudMessage(	s:"\n",
					d:enemyhealth,
					s:"/",
					d:enemyhealthmax;
					HUDMSG_FADEOUT, 112224, CR_GREEN, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=25)
				{
					HudMessage(	s:"\n",
					d:enemyhealth,
					s:"/",
					d:enemyhealthmax;
					HUDMSG_FADEOUT, 112224, CR_YELLOW, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=0)
				{
					HudMessage(	s:"\n",
					d:enemyhealth,
					s:"/",
					d:enemyhealthmax;
					HUDMSG_FADEOUT, 112224, CR_RED, 0.5, 0.02, 0.6, 0.2);	
				}
				
				//ACTOR INVULNERABLE INDICATOR
				if(GetActorProperty(new_tid, APROP_Invulnerable) == TRUE)
				{
					HudMessage(	s:"\n\n-Invulnerable-";
					HUDMSG_FADEOUT, 112225, CR_GOLD, 0.5, 0.02, 0.6, 0.2);
				}
				
				//ACTOR FRIENDLY NAME DISPLAY	
				if(GetActorProperty(new_tid, APROP_Friendly) == TRUE)
				{
					HudMessage(	s:"", 
					s:enemyname;
					HUDMSG_FADEOUT, 112223, CR_DARKGREEN, 0.5, 0.02, 0.6, 0.2);
				}
			}
			}
			}
			
			/*			
			//ACTOR DEAD MESSAGE - Disabled due to popular demand. They found it annoying.
			if(enemyhealth <= 0)
			{
			//ACTOR NAME DISPLAY (Again)
			HudMessage(	s:"", 
				s:enemyname;
				HUDMSG_FADEOUT, 112223, CR_DARKRED, 0.5, 0.02, 0.6, 0.2);
			
			HudMessage(	s:"\n",
				d:enemyhealth,
				s:"/",
				d:enemyhealthmax,
				s:" (Dead)";
				HUDMSG_FADEOUT, 112224, CR_DARKGRAY, 0.5, 0.02, 0.6, 0.2); 		
			}
			*/
			
			Thing_ChangeTID(new_tid, old_tid);
		}
		
		/*
		//Extra feature: Kill confirmer. Turned off, since I think it might be too obnoxious.
		if(monstercount != GetLevelInfo (LEVELINFO_KILLED_MONSTERS))
		{
			monstercount = GetLevelInfo (LEVELINFO_KILLED_MONSTERS);
			HudMessage(	s:"\n\n\n-Kill-";
						HUDMSG_FADEINOUT, 0, CR_OLIVE, 0.5, 0.02, 0.5, 0.1, 0.5);
			
			//for lulz
			
			//HudMessage(	s:"\n\nOscar Mike Tango Down";
			//			HUDMSG_FADEINOUT, 0, CR_OLIVE, 0.5, 0.02, 0.5, 0.1, 0.5);
			
		}	
		*/
		
		Delay(1);
	}
}
