/*
	--------------------------------------------------------------
	Condition_ActorHealth_SE
	--------------------------------------------------------------

    A Condition which tracks the health state of specified Actor(s)
    and is marked complete when it drops below a specified threshold.
	
	Enhancements and fixes:
	- bSearchOnlyOnce

	Author :  			PooSH
	Original Author :  	Alex Quick

	--------------------------------------------------------------
*/

class ObjCondition_ActorHealth_SE extends ObjCondition_ActorHealth
editinlinenew;

var ()		   							bool				bSearchOnlyOnce;
var			   transient 				bool				bSearchCompleted;


function Reset()
{
    Super.Reset();
    HealthMax = 100;
}

function ConditionActivated(pawn ActivatingPlayer)
{
	local Actor MyHealthActor;
	
    Super.ConditionActivated(ActivatingPlayer);
	
	MyHealthActor = GetTargetActor(HealthActorName);

    if(MyHealthActor != none && !MyHealthActor.bPendingDelete)
		bSearchCompleted = true;
}



function ConditionTick(float DeltaTime)
{
	if ( bSearchOnlyOnce && bSearchCompleted && GetTargetActor(HealthActorName) == none ) {
		// if bSearchOnlyOnce=true and TargetActor was searchen for and not found, 
		// then count it as dead 
		HealthMax		= 100;
		CurrentHealth	= 0;
		super(KF_ObjectiveCondition).ConditionTick(DeltaTime);
	}	
	else {
		super.ConditionTick(DeltaTime);
		if ( HealthMax <= 0 )
			HealthMax = 100; // prevents 0/0 showing as 100%
	}
}


function UpdatePawnList()
{
	if( bSearchOnlyOnce && bSearchCompleted )
        return;
		
	super.UpdatePawnList();
	bSearchCompleted = true;
}

defaultproperties
{
}
