

class VirUIHandler : EventHandler
{
	override void RenderOverlay (RenderEvent e)
	{
		PlayerPawn PP = players[consoleplayer].mo;
		StatusBar.BeginHud();
		HUDFont Virfont = HUDFont.Create(smallfont);
		
		VirObjectiveControl VOC = VirObjectiveControl(pp.FindInventory("VirObjectiveControl"));
		if (VOC)
		{
			StatusBar.DrawString(Virfont, VOC.CurrentTask, (40,25), StatusBar.DI_SCREEN_LEFT_TOP | StatusBar.DI_TEXT_ALIGN_LEFT, Font.CR_RED);
		}
	}
	
}

Class virmarksmanzombie : Actor
{
	default
	{
		  OBITUARY "%o was shot by a Marksman Zombie.";
		  Health 110;
		  Radius 20;
		  Height 56;
		  Mass 100;
		  Speed 12;
		  PainChance 160;
			SeeSound "grunt/sight";
			PainSound "grunt/pain";;
			DeathSound "grunt/death";
			ActiveSound "grunt/active";

			DropItem "Clip";
			
		  MONSTER;
		  +MISSILEMORE;
		  Decal "Bulletchip";
	}
  states
  {
  Spawn:
    ZHRT AB 10 A_Look;
    Loop;
  See:
		ZHRT AABBCCDD 4 A_Chase;
		Loop;
  Missile:
		ZHRT E 15 A_FaceTarget;
		ZHRT F 0 Bright A_StartSound("MarksmanRifleFire", CHAN_WEAPON);
		ZHRT F 0 Bright A_CustomBulletAttack(2,2,1,9,"BulletPuff", 5000);
		ZHRT F 6 Bright;
    Goto See;
  Pain:
    ZHRT G 3;
    ZHRT G 0 A_Pain;
    ZHRT G 3;
    Goto Missile;
  Death:
    ZHRT H 2;
	ZHRT H 3;
    ZHRT I 5 A_Scream;
    ZHRT J 5 A_NoBlocking;
    ZHRT K 5;
    ZHRT L -1;
	Stop;
  XDeath:
    ZHRT O 2;
    ZHRT O 3;
    ZHRT P 5 A_XScream;
    ZHRT Q 5 A_NoBlocking;
    ZHRT RTUV 5;
    ZHRT W -1;
    Stop;
	Raise:
		ZHRT O 0;
		ZHRT KJIH 5;
		Goto See;
  }
}

Class VirChaingunTurret : Actor
{
	Default
	{
		Health 800;
		Speed 0;
		Painchance 0;
		Mass 10000000;
		Monster;
		-SOLID
		-CANPASS
		+SPAWNCEILING
		+NOGRAVITY
		+NOBLOOD
		+DONTFALL
		-COUNTKILL
		MinMissileChance 255;
		AttackSound "chainguy/attack";
		Obituary "%o was riddled by a Chaingun Turret";
		Tag "Chaingun Turret";
	}
	States
	{
	Spawn:
		TURT A 1;
		TURT A 0 A_LookEx(0,0,4096.0,0,360);
		TURT A 0 SwitchTarget("Missile");
		Loop;
	See:
		TURT A 1;
		TURT A 0 SwitchTarget("Missile");
		Goto Spawn;
	Missile:
	Pain:
		TURT B 4 A_FaceTarget;
	MissileFire:		
		TURT D 2 A_CPosAttack;
		TURT B 2 A_FaceTarget;
		TURT B 0 SwitchTarget("MissileFire");
		Loop;
	Death:
		TURT C 0 A_SpawnItemEx("VirExplosion");
		TURT C -1;
		Stop;
	}
	void SwitchTarget(statelabel Shoot)
	{
		if (target)
		{
			if (!CheckSight(target) || (target.health <= 0))
			{
				target = null;
				SetStateLabel("Spawn");
			}
			else
			{		
				SetStateLabel(Shoot);
			}
		}
	}
}

Class VirChainshotgunTurret : VirChaingunTurret
{
	Default
	{
		+Friendly;
		Obituary "%o was obliterated by a Chain shotgun Turret";
		Tag "Chainshotgungun Turret";
	}
	States
	{
	Missile:
	Pain:
		TURT B 4 A_FaceTarget;
	MissileFire:
		TURT D 2 A_SposAttackUseAtkSound;
		TURT B 2 A_FaceTarget;
		TURT B 0 SwitchTarget("MissileFire");
		Loop;
	}
}

class VirExplosion : Rocket
{
	Default
	{
		Radius 11;
		Height 8;
		Speed 20;
		Damage 20;
		Projectile;
		+RANDOMIZE
		+DEHEXPLOSION
		+ROCKETTRAIL
		+ZDOOMTRANS
		SeeSound "weapons/rocklf";
		DeathSound "weapons/rocklx";
		Obituary "$OB_MPROCKET";
	}
	States
	{
	Spawn:
	Death:
		MISL B 0;
		MISL B 0 A_StartSound("weapons/rocklx");
		MISL B 8 Bright A_Explode;
		MISL C 6 Bright;
		MISL D 4 Bright;
		Stop;
	}
}

Class VirDoomGear : Inventory
{
	Default
	{
	Tag "Doom Gear";
	Inventory.Amount 1;
	Inventory.MaxAmount 1; 
	INVENTORY.InterHubAmount 1;
	Radius 16;
	Translation "64:79=96:111";
	}
	States
	{
	Spawn:
		BPAK A -1;
		Stop;
	}
	
	override bool TryPickup (in out Actor toucher)
	{
		toucher.GiveInventory("Pistol",1);
		toucher.GiveInventory("Shotgun",1);
		toucher.GiveInventory("ArmorBonus",50);
		toucher.GiveInventory("Shell",8);
		toucher.GiveInventory("Clip",30);
		toucher.GiveInventory("VirObjectiveControl",1);
		GoAwayAndDie();
		return true;
	}
	override String PickupMessage ()
	{
		return "Received emergency gear!";		
	}
}
class VirObjectiveControl : Inventory
{
	string CurrentTask;
	int LastTask;
	default 
	{
		health 2100;
		Inventory.MaxAmount 9; 
	}
	override void Tick()
	{
		Super.Tick();
		If (Owner && Owner.health > 0)
		{
			If (amount == 1) // Base Quest
			{
				LastTask = amount;
				CurrentTask = "Objective: Escape Imprisonment!";				
			}
			else If (amount == 2) // Escaped cell Quest
			{
				LastTask = amount;
				CurrentTask = "Objective: Find a way out of the prison";
			}
			else If (amount == 3) // Escaped the building
			{
				LastTask = amount;
				CurrentTask = "Objective: Extraction beacon is enroute. Find it.";
			}
			else If (amount == 4) // Attempted to use the beacon
			{
				LastTask = amount;
				CurrentTask = "Objective: Landing Zone is protected by anti-air defenses, disable it! (This will trigger a mission time limit)";
			}
			else If (amount == 5) // Disabled the defense
			{		
				LastTask = amount;
				CurrentTask = "Objective: Activate the extraction beacon! Time Left: " .. (health / 35);
				health--;
			}
			else If (amount == 6) // Defend 
			{
				if (LastTask != amount)
				{
					LastTask = amount;
					health = 4200;
				}

				CurrentTask = "Objective: Dropship enroute. Remain in the area! Time until arrival: " .. (health / 35);
				health--;
				if (health <= 0)
				{
					amount++;
					health =1;
				}
			}
			else If (amount == 7) // Dropship Landing 
			{
				if (LastTask != amount)
				{
					LastTask = amount;
					health = 4200;
					Owner.ACS_NamedExecuteAlways("Vir_LandingSequence");
				}

				CurrentTask = "Objective: Dropship landing!";
				health--;
				if (health <= 0)
				{
					amount++;
					health =1;
				}
			
			}
			else If (amount == 8) // Extract 
			{
				if (LastTask != amount)
				{
					LastTask = amount;
					health = 525;
				}
				CurrentTask = "Objective: Extract! Time to extract: " .. (health / 35);
				health--;
			}
			else If (amount == 9) // Ending Sequence 
			{
				LastTask = amount;
				CurrentTask = "Objective Complete!";
			}
			else
			{
				CurrentTask = "Error!";	
			}
			if (health <= 0 && Owner.Health > 0)
			{
				Owner.Die(Owner, Owner);
			}
		}	
	}
	

}