#include "scripts/common.txt"
#include "scripts/BP_common.txt"

class BP_DeadGrunt : ScriptObject
{
    kActor @self;
	//------------------------------------------------------------------------------------------------------------------------
    BP_DeadGrunt(kActor @actor)
	{
        @self = actor;
    }
	//------------------------------------------------------------------------------------------------------------------------
	bool IsRobot()
	{
		return self.SpawnParams(7) > 0;
	}
	//------------------------------------------------------------------------------------------------------------------------
	void OnBeginLevel()
    {
		self.AnimState().Set(anim_aiDeathStand, 8.0f, ANF_ROOTMOTION);
		self.AnimState().SetLastFrame();
		
        kRenderModel @model = self.RenderModel();
		if (IsRobot())
		{
			if(model is null)
			{
				return;
			}

			switch(self.ModelVariation())
			{
			// commander
			case GV_COMMANDER_SPEAR:
			case GV_COMMANDER_RIFLE1:
			case GV_COMMANDER_RIFLE2:
			case GV_COMMANDER_RIFLE3:
			case GV_COMMANDER_RIFLE4:
				for(int i = 0; i < HUMAN_HEAD; i++)
				{
					model.SetTexture(i, 1);
				}
				break;
				
			// cyborg guard
			case GV_CYBORG_PULSE_RIFLE:
			// demon lord
			case GV_DEMON_LORD:
				for(int i = 0; i < HUMAN_MAXNODE; i++)
				{
					model.SetTexture(i, 1);
				}
				break;
			}
		}
		else
		{
			if(model is null)
			{
				return;
			}
						
			switch(self.ModelVariation())
			{
			// common soldier
			case GV_GENERIC:
			case GV_GENERIC_AXE:
			case GV_GENERIC_CLUB:
				// face
				model.SetTexture(19, Math::SysRand() % 12);
				break;
			
			// commander
			case GV_COMMANDER_SPEAR:
			case GV_COMMANDER_RIFLE1:
			case GV_COMMANDER_RIFLE2:
			case GV_COMMANDER_RIFLE3:
			case GV_COMMANDER_RIFLE4:
				// chest
				model.SetTexture(0, 1);
				model.SetTexture(9, 1);
				
				// arms
				model.SetTexture(10, 1);
				model.SetTexture(11, 1);
				model.SetTexture(12, 1);
				model.SetTexture(13, 1);
				model.SetTexture(14, 1);
				model.SetTexture(15, 1);
				model.SetTexture(16, 1);
				model.SetTexture(17, 1);
				
				// face
				model.SetTexture(19, Math::SysRand() % 12);
				break;
				
			// poacher
			case GV_POACHER_KNIFE:
			case GV_POACHER_PISTOL1:
			case GV_POACHER_PISTOL2:
			case GV_POACHER_RIFLE:
			case GV_POACHER_SHOTGUN:
				// chest
				model.SetTexture(0, 5);
				model.SetTexture(9, 5);
				
				// legs
				model.SetTexture(1, 2);
				model.SetTexture(3, 2);
				model.SetTexture(4, 2);
				model.SetTexture(5, 2);
				model.SetTexture(7, 2);
				model.SetTexture(8, 2);
				
				// shin
				model.SetTexture(2, 2);
				model.SetTexture(6, 2);
				
				// face
				model.SetTexture(19, Math::SysRand() % 12);
				break;
				
			// warrior
			case GV_WARRIOR_BONE:
			case GV_WARRIOR_DART:
			case GV_WARRIOR_SPEAR:
				// hands
				model.SetTexture(17, 2);
				
				// chest
				model.SetTexture(0, 2);
				model.SetTexture(9, 2);
				
				// arms
				model.SetTexture(10, 2);
				model.SetTexture(11, 2);
				model.SetTexture(12, 2);
				model.SetTexture(13, 2);
				model.SetTexture(14, 2);
				model.SetTexture(15, 2);
				model.SetTexture(16, 2);
				
				// neck
				model.SetTexture(18, 1);
				break;
				
			// shaman
			case GV_SHAMAN:
				// chest
				model.SetTexture(0, 3);
				model.SetTexture(9, 3);
				
				// neck
				model.SetTexture(18, 2);
				
				// legs
				model.SetTexture(1, 1);
				model.SetTexture(3, 1);
				model.SetTexture(4, 1);
				model.SetTexture(5, 1);
				model.SetTexture(7, 1);
				model.SetTexture(8, 1);
				
				// shin
				model.SetTexture(2, 1);
				model.SetTexture(6, 1);
				
				// hands
				model.SetTexture(17, 3);
				
				// arms
				model.SetTexture(10, 3);
				model.SetTexture(11, 3);
				model.SetTexture(12, 3);
				model.SetTexture(13, 3);
				model.SetTexture(14, 3);
				model.SetTexture(15, 3);
				model.SetTexture(16, 3);
				break;
				
			// cyborg guard
			case GV_CYBORG_PULSE_RIFLE:
				// legs
				model.SetTexture(1, 1);
				model.SetTexture(3, 1);
				model.SetTexture(4, 1);
				model.SetTexture(5, 1);
				model.SetTexture(7, 1);
				model.SetTexture(8, 1);
				
				// shin
				model.SetTexture(2, 1);
				model.SetTexture(6, 1);
				
				// chest
				model.SetTexture(0, 4);
				model.SetTexture(9, 4);
				
				// arms
				model.SetTexture(10, 4);
				model.SetTexture(11, 4);
				model.SetTexture(12, 4);
				model.SetTexture(13, 4);
				model.SetTexture(14, 4);
				model.SetTexture(15, 4);
				model.SetTexture(16, 4);
				
				// neck
				model.SetTexture(18, 3);
				break;
				
			// demon
			case GV_DEMON_AXE:
			case GV_DEMON_SPEAR:
			case GV_DEMON_HANDS:
				// hands
				model.SetTexture(17, 6);
				model.SetTexture(13, 6);
				
				// legs
				model.SetTexture(1, 2);
				model.SetTexture(3, 2);
				model.SetTexture(4, 2);
				model.SetTexture(5, 2);
				model.SetTexture(7, 2);
				model.SetTexture(8, 2);
				
				// shin
				model.SetTexture(2, 2);
				model.SetTexture(6, 2);
				
				// chest
				model.SetTexture(0, 6);
				model.SetTexture(9, 6);
				
				// arms
				model.SetTexture(10, 6);
				model.SetTexture(11, 6);
				model.SetTexture(12, 6);
				model.SetTexture(13, 6);
				model.SetTexture(14, 6);
				model.SetTexture(15, 6);
				model.SetTexture(16, 6);
				
				// neck
				model.SetTexture(18, 4);
				break;
				
			// demon lord
			case GV_DEMON_LORD:
				// hands
				model.SetTexture(17, 7);
				model.SetTexture(13, 7);
				
				// legs
				model.SetTexture(1, 3);
				model.SetTexture(3, 3);
				model.SetTexture(4, 3);
				model.SetTexture(5, 3);
				model.SetTexture(7, 3);
				model.SetTexture(8, 3);
				
				// shin
				model.SetTexture(2, 3);
				model.SetTexture(6, 3);
				
				// chest
				model.SetTexture(0, 7);
				model.SetTexture(9, 7);
				
				// arms
				model.SetTexture(10, 7);
				model.SetTexture(11, 7);
				model.SetTexture(12, 7);
				model.SetTexture(13, 7);
				model.SetTexture(14, 7);
				model.SetTexture(15, 7);
				model.SetTexture(16, 7);
				
				// neck
				model.SetTexture(18, 5);
				break;
			}
		}

	}
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick()
	{
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnSpawn()
	{
    }
	//------------------------------------------------------------------------------------------------------------------------
}
