//=============================================================================
// KilltheCowGame.
//=============================================================================
class KilltheCowGame expands TeamGame
	config;

var() config float ReturnHeadScore;
var() config float CaptureHeadScore;
var	  int   GrowTimer;

function PostBeginPlay()
{
	local int i;
	
	for (i=0;i<MaxTeams;i++)
		AddTeamCow(i);
	
	CallParent.PostBeginPlay();
}

function Timer()
{
	local SacredCow aCow;
	// boost all cows
	GrowTimer++;
	if ( GrowTimer > 6 )
	{
		GrowTimer = 0;
		foreach AllActors( class 'SacredCow', aCow)
			aCow.Grow();
	}
			
	CallParent.Timer();
}

function AddTeamCow(int TeamNumber)
{
	local CowShrine aShrine;
	local SacredCow aCow;
	foreach AllActors( class 'CowShrine', aShrine )
	{
		if (aShrine.Team == TeamNumber)
		{
			aCow = Spawn(class 'SacredCow',,,aShrine.Location, aShrine.Rotation);
			aCow.Team = TeamNumber;
			break;
		}	
	}
}

function Killed(pawn killer, pawn Other, name damageType)
{
	local SacredCowHead aHead;

	if ( (SacredCow(Other) != None) && (Killer.Team != Other.Team) )
	{
		Teams[killer.Team].Score += 5.0;
		killer.Score += 1.0;
	}
	else if ( Other.bIsPlayer )
		foreach AllActors( class 'SacredCowHead', aHead )
			if ( aHead.Holder == Other )
				aHead.Drop(Other.Velocity);	
						
	CallParent.Killed(killer, Other, damageType);
}

function ScoreOffering(Pawn Scorer, SacredCowHead theHead, CowShrine theShrine)
{
	local pawn TeamMate;
	
	if (Scorer.Team != theShrine.Team)
	{
		Scorer.Score -= 0.5 * ReturnHeadScore;
		Teams[Scorer.Team].Score -= 0.5 * ReturnHeadScore;
		BroadcastMessage(Scorer.PlayerName$" offers a head to the wrong shrine!");
		return;
	}
	
	if (Scorer.Team == theHead.Team)
	{
		Scorer.Score += ReturnHeadScore;
		Teams[Scorer.Team].Score += ReturnHeadScore;
		ForEach AllActors( class 'Pawn', TeamMate)
			if (TeamMate.Team == Scorer.Team) TeamMate.Score += 0.5 * ReturnHeadScore;
		BroadcastMessage(Scorer.PlayerName$" saves the "$Teams[Scorer.Team].TeamName$" cow's soul");
	}
	else
	{
		Scorer.Score += CaptureHeadScore;
		Teams[Scorer.Team].Score += CaptureHeadScore;
		ForEach AllActors( class 'Pawn', TeamMate)
			if (TeamMate.Team == Scorer.Team) TeamMate.Score += 0.5 * CaptureHeadScore;
		BroadcastMessage(Scorer.PlayerName$" damns the "$Teams[Scorer.Team].TeamName$" cow's soul");
		theShrine.SignalScore();
	}
}


