//=============================================================================
// SacredCowHead.
//=============================================================================
class SacredCowHead expands CreatureChunks;

#exec MESH IMPORT MESH=CowHead ANIVFILE=MODELS\g_cowh_a.3D DATAFILE=MODELS\g_cowh_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=CowHead X=0 Y=0 Z=0 YAW=64
#exec MESH SEQUENCE MESH=CowHead SEQ=All    STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=CowHead SEQ=Still  STARTFRAME=0   NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JGCow2  FILE=MODELS\Nc_2.PCX FAMILY=Skins 
#exec MESHMAP SCALE MESHMAP=CowHead X=0.09 Y=0.09 Z=0.18
#exec MESHMAP SETTEXTURE MESHMAP=CowHead NUM=1 TEXTURE=JGCow2

#exec AUDIO IMPORT FILE="Sounds\Cow\cMoo1a.WAV" NAME="cMoo1c" GROUP="Cow"
#exec AUDIO IMPORT FILE="Sounds\Cow\cMoo2a.WAV" NAME="cMoo2c" GROUP="Cow"

var byte	 	 Team;      	
var Pawn		Holder;

function Destroyed()
{
	if ( Level.Game.IsA('KilltheCowGame') )
		KilltheCowGame(Level.Game).AddTeamCow(Team);
	CallParent.Destroyed();
}

function InitFor(Actor Other)
{
	CallParent.InitFor(Other);
	Bugs = Spawn(class 'SacredHeadSwarm');
	if (Bugs != None)
		Bugs.SetBase(Self);
	SetTimer(1.0, false);
}

function Touch(Actor Other)
{
	local vector X,Y,Z;
	
	if ( Other.IsA('Pawn') && Pawn(Other).bIsPlayer )
	{
		Holder = Pawn(Other);
		if ( Level.Game.IsA('KilltheCowGame') )
			BroadCastMessage(Holder.PlayerName$" has the "$KilltheCowGame(Level.Game).Teams[Team].TeamName$" cow head");
		bCollideWorld = false;
		SetCollision(false, false, false);
		Bugs.bCollideWorld =false;
		Bugs.SetLocation(Holder.Location);
		Bugs.SetBase(Holder);
		LifeSpan = 0.0;
		GetAxes(Holder.Rotation, X,Y,Z);
		SetLocation(Holder.Location - 0.5 * Holder.CollisionRadius * X);
		SetBase(Holder);
	}
}

function BaseChange()
{
}

function Drop(vector newVel)
{
	if ( Level.Game.IsA('KilltheCowGame') )
		BroadCastMessage(Holder.PlayerName$" dropped the "$KilltheCowGame(Level.Game).Teams[Team].TeamName$" cow head");
	Holder = None;
	RotationRate.Yaw = Rand(200000) - 100000;
	RotationRate.Pitch = Rand(200000 - Abs(RotationRate.Yaw)) - 0.5 * (200000 - Abs(RotationRate.Yaw));
	Velocity = (0.2 + FRand()) * (newVel + 400 * FRand() * VRand());
	If (Region.Zone.bWaterZone)
		Velocity *= 0.5;
	LifeSpan = 20.0;
	bCollideWorld = true;
	SetCollision(true, false, false);
	bHidden = false;
	SetPhysics(PHYS_Falling);
}

function Damage( int Damage, Pawn instigatedBy, Vector hitlocation, 
						Vector momentum, name damageType)
{
	if ( instigatedBy == None )
		Destroy();
	else
	{
		SetPhysics(PHYS_Falling);
		Velocity += momentum/Mass;
	}
}

function Timer()
{
	if ( FRand() < 0.5 )
		PlaySound(sound'cMoo1c');
	else 
		PlaySound(sound'cMoo2c');
	SetTimer(2 + 3 * FRand(), false);
}

state Dead 
{
	function Timer()
	{
		CallGlobal.Timer();
	}

	function BeginState()
	{
	}
}

