//=============================================================================
// HumanBot.
//=============================================================================
class HumanBot expands Bots;

var(Sounds) sound 	drown;
var(Sounds) sound	breathagain;
var(Sounds) sound	WoodFootstep;
var(Sounds) sound	StoneFootstep;
var(Sounds) sound	MetalFootstep;
var(Sounds) sound	HitSound3;
var(Sounds) sound	HitSound4;
var(Sounds) sound	Die2;
var(Sounds) sound	Die3;
var(Sounds) sound	Die4;

#exec AUDIO IMPORT FILE="Sounds\female\wdwalk1.WAV" NAME="wdwalk1" GROUP="Female"
#exec AUDIO IMPORT FILE="Sounds\female\stone02.WAV" NAME="stwalk1" GROUP="Female"
#exec AUDIO IMPORT FILE="Sounds\female\mtwalk1.WAV" NAME="mtwalk1" GROUP="Female"

//-----------------------------------------------------------------------------
// Sound functions 
function PlayFootStep()
{
	if ( FootRegion.Zone.bWaterZone )
	{
		PlaySound(sound 'LSplash', SLOT_Interact, 0.5);
		return;
	}
	//FIXME - choose sound based on texture we are standing on
	if ( bIsWalking )
		PlaySound(StoneFootstep, SLOT_Interact, 0.1);
	else 
		PlaySound(StoneFootstep, SLOT_Interact);
}

function PlayDyingSound()
	{
		local float rnd;
		rnd = FRand();
		if (rnd < 0.25)
			PlaySound(Die, SLOT_Talk);
		else if (rnd < 0.5)
			PlaySound(Die2, SLOT_Talk);
		else if (rnd < 0.75)
			PlaySound(Die3, SLOT_Talk);
		else 
			PlaySound(Die4, SLOT_Talk);
	}


function PlayTakeHitSound(int damage, name damageType)
	{
		if (damage < 10) PlaySound(HitSound1, SLOT_Pain,,,,Frand()*0.4+0.8);
		else if (damage < 20)
		{
			if (FRand() < 0.5) PlaySound(HitSound2, SLOT_Pain,,,,Frand()*0.4+0.8);			
			else PlaySound(HitSound3, SLOT_Pain,,,,Frand()*0.4+0.8);
		}
		else PlaySound(HitSound4, SLOT_Pain,,,,Frand()*0.4+0.8);			
	}


//-----------------------------------------------------------------------------
// Animation functions

	
function SetFall()
{
	if (Enemy != None)
	{
		NextState = 'Attacking'; //default
		NextLabel = 'Begin';
		TweenToWaiting(0.2);
		NextAnim = AnimSequence;
		GotoState('Falling');
	}
}


function TweenToWalking(float tweentime)
	{
		if ( Physics == PHYS_Swimming )
		{
			if ( (vector(Rotation) Dot Acceleration) > 0 )
				TweenToSwimming(tweentime);
			else
				TweenToWaiting(tweentime);
		}
		
		BaseEyeHeight = Default.BaseEyeHeight;
		if (Weapon == None)
			TweenAnim('Walk', tweentime);
		else if ( Weapon.bPointing ) 
		{
			if (Weapon.Mass < 20)
				TweenAnim('WalkSMFR', tweentime);
			else
				TweenAnim('WalkLGFR', tweentime);
		}
		else
		{
			if (Weapon.Mass < 20)
				TweenAnim('WalkSM', tweentime);
			else
				TweenAnim('WalkLG', tweentime);
		} 
	}

function TweenToRunning(float tweentime)
	{
		if ( Physics == PHYS_Swimming )
		{
			if ( (vector(Rotation) Dot Acceleration) > 0 )
				TweenToSwimming(tweentime);
			else
				TweenToWaiting(tweentime);
			return;
		}

		BaseEyeHeight = Default.BaseEyeHeight;

		if (Weapon == None)
			TweenAnim('RunSM', tweentime);
		else if ( Weapon.bPointing ) 
		{
			if (Weapon.Mass < 20)
				TweenAnim('RunSMFR', tweentime);
			else
				TweenAnim('RunLGFR', tweentime);
		}
		else
		{
			if (Weapon.Mass < 20)
				TweenAnim('RunSM', tweentime);
			else
				TweenAnim('RunLG', tweentime);
		} 
	}

function PlayWalking()
	{
		if ( Physics == PHYS_Swimming )
		{
			if ( (vector(Rotation) Dot Acceleration) > 0 )
				PlaySwimming();
			else
				PlayWaiting();
			return;
		}

		BaseEyeHeight = Default.BaseEyeHeight;
		if (Weapon == None)
			LoopAnim('Walk');
		else if ( Weapon.bPointing ) 
		{
			if (Weapon.Mass < 20)
				LoopAnim('WalkSMFR');
			else
				LoopAnim('WalkLGFR');
		}
		else
		{
			if (Weapon.Mass < 20)
				LoopAnim('WalkSM');
			else
				LoopAnim('WalkLG');
		}
	}


function PlayRunning()
	{
		if ( Physics == PHYS_Swimming )
		{
			if ( (vector(Rotation) Dot Acceleration) > 0 )
				PlaySwimming();
			else
				PlayWaiting();
			return;
		}

		BaseEyeHeight = Default.BaseEyeHeight;
		if (Weapon == None)
			LoopAnim('RunSM');
		else if ( Weapon.bPointing ) 
		{
			if (Weapon.Mass < 20)
				LoopAnim('RunSMFR');
			else
				LoopAnim('RunLGFR');
		}
		else
		{
			if (Weapon.Mass < 20)
				LoopAnim('RunSM');
			else
				LoopAnim('RunLG');
		}
	}

function PlayDying(name DamageType, vector HitLocation)
	{
		BaseEyeHeight = Default.BaseEyeHeight;
		PlayAnim('Death', 0.5, 0.1);
		PlayDyingSound();
	}

function PlayTakeHit(float tweentime, vector HitLoc, int Damage)
	{
	BaseEyeHeight = Default.BaseEyeHeight;
	if ( (Weapon != None) && Weapon.bPointing )
		return;
	if (AnimSequence != 'TakeHit')
		tweenanim('TakeHit', tweentime);
	}	
	
function PlayLanded(float impactVel)
	{	
		impactVel = impactVel/JumpZ;
		impactVel = 0.1 * impactVel * impactVel;
		BaseEyeHeight = Default.BaseEyeHeight;

		if (impactVel > 0.17)
			PlaySound(Land, SLOT_Talk, FMin(5, 5 * impactVel),,,FRand()*0.4+0.8);
		if ( !FootRegion.Zone.bWaterZone )
			PlaySound(sound'Land1', SLOT_Interact, impactVel);
		if ( (Weapon == None) || (Weapon.Mass < 20) )
			//TweenAnim('JumpSMFR', 0.05); //FIXME - play the full kneebend or part kneebend when I get it
			TweenAnim('RunSMFR', 0.15);
		else
			//TweenAnim('JumpLGFR', 0.05);
			TweenAnim('RunLGFR', 0.15);
	}
	
function PlayInAir()
	{
	BaseEyeHeight =  0.4 * Default.BaseEyeHeight;
	if ( (Weapon == None) || (Weapon.Mass < 20) )
		TweenAnim('JumpSMFR', 0.8);
	else
		TweenAnim('JumpLGFR', 0.8); 
	}

function PlayDuck()
	{
	BaseEyeHeight = 0.1 * Default.BaseEyeHeight;
	if ( (Weapon == None) || (Weapon.Mass < 20) )
		TweenAnim('JumpSMFR', 0.25);
	else
		TweenAnim('JumpLGFR', 0.25);
	}

function PlayCrawling()
	{
		//log("Play duck");
		BaseEyeHeight = 0.1 * Default.BaseEyeHeight;
		if ( (Weapon == None) || (Weapon.Mass < 20) )
		{
			if (AnimSequence == 'JumpSMFR') //FIXME - temp crawl placeholder
				TweenAnim('TreadSM', 0.2);
			else
				TweenAnim('JumpSMFR', 0.2);
		}
		else
		{
			if (AnimSequence == 'JumpLGFR') //FIXME - temp crawl placeholder
				TweenAnim('TreadLG', 0.2);
			else
				TweenAnim('JumpLGFR', 0.2);
		}	
	}

function TweenToWaiting(float tweentime)
{
	if ( Physics == PHYS_Swimming )
	{
		BaseEyeHeight = 0.5 * Default.BaseEyeHeight;
		if ( (Weapon == None) || (Weapon.Mass < 20) )
			TweenAnim('TreadSM', tweentime);
		else
			TweenAnim('TreadLG', tweentime);
	}
	else
	{
		BaseEyeHeight = Default.BaseEyeHeight;
		if ( (Weapon == None) || (Weapon.Mass < 20) )
			TweenAnim('StillSMFR', tweentime);
		else
			TweenAnim('StillFRRP', tweentime);
	}
}

function TweenToFighter(float tweentime)
{
	TweenToWaiting(tweentime);
}
	
function PlayChallenge()
{
	TweenToWaiting(0.15);
}	
	
function PlayWaiting()
{
	if ( Physics == PHYS_Swimming )
	{
		BaseEyeHeight = 0.5 * Default.BaseEyeHeight;
		if ( (Weapon == None) || (Weapon.Mass < 20) )
			LoopAnim('TreadSM');
		else
			LoopAnim('TreadLG');
	}
	else
	{	
		BaseEyeHeight = Default.BaseEyeHeight;
		TweenToWaiting(0.2);
	}
}	

function PlayFiring()
{
	// switch animation sequence mid-stream if needed
	if (AnimSequence == 'RunLG')
		AnimSequence = 'RunLGFR';
	else if (AnimSequence == 'RunSM')
		AnimSequence = 'RunSMFR';
	else if (AnimSequence == 'WalkLG')
		AnimSequence = 'WalkLGFR';
	else if (AnimSequence == 'WalkSM')
		AnimSequence = 'WalkSMFR';
}

function ClientPlayWeaponSwitch(Weapon NewWeapon)
{
	if ( (Weapon == None) || (Weapon.Mass < 20) )
	{
		if ( (NewWeapon != None) && (NewWeapon.Mass > 20) )
		{
			if ( (AnimSequence == 'RunSM') || (AnimSequence == 'RunSMFR') )
				AnimSequence = 'RunLG';
			else if ( (AnimSequence == 'Walk') || (AnimSequence == 'WalkSM') || (AnimSequence == 'WalkSMFR') )
				AnimSequence = 'WalkLG';	
		 	else if (AnimSequence == 'JumpSMFR')
		 		AnimSequence = 'JumpLGFR';
		 	else if (AnimSequence == 'StillSMFR')
		 		AnimSequence = 'StillFRRP';
		 }	
	}
	else if ( (NewWeapon == None) || (NewWeapon.Mass < 20) )
	{		
		if ( (AnimSequence == 'RunLG') || (AnimSequence == 'RunLGFR') )
			AnimSequence = 'RunSM';
		else if ( (AnimSequence == 'WalkLG') || (AnimSequence == 'WalkLGFR') )
		{
			if (NewWeapon == None)
				AnimSequence = 'Walk';
			else
				AnimSequence = 'WalkSM';
		}	
	 	else if (AnimSequence == 'JumpLGFR')
	 		AnimSequence = 'JumpSMFR';
	 	else if (AnimSequence == 'StillFRRP')
	 		AnimSequence = 'StillSMFR';
	}
}

function PlayTurning()
{
	TweenToWaiting(0.1);
}

function PlaySwimming()
{
	BaseEyeHeight = 0.5 * Default.BaseEyeHeight;
	if ((Weapon == None) || (Weapon.Mass < 20) )
		LoopAnim('SwimSM');
	else
		LoopAnim('SwimLG');
}

function TweenToSwimming(float tweentime)
{
	BaseEyeHeight = 0.5 * Default.BaseEyeHeight;
	if ((Weapon == None) || (Weapon.Mass < 20) )
		TweenAnim('SwimSM',tweentime);
	else
		TweenAnim('SwimLG',tweentime);
}

