// completes when pawn reaches player or on timer
class ACTION_MoveToPlayerTimed extends LatentScriptedAction;

var(Action) float TimeLimit;
// if distance between me and my player is lower that that, action is skipped.
// MinDistance doesn't include collision radiuses
var(Action) float MinDistance; 
var(Action) float Cooldown; // time to wait till next action, if player is closer than MinDistance

var bool bNeedToMode;

function bool MoveToGoal()
{
	return bNeedToMode;
}

function Actor GetMoveTargetFor(ScriptedController C)
{
	return C.GetMyPlayer();
}

function string GetActionString()
{
	return ActionString@TimeLimit;
}

function bool InitActionFor(ScriptedController C)
{
	local Pawn MyPlayer;
	
	C.CurrentAction = self;

	MyPlayer = C.GetMyPlayer();
	bNeedToMode = MyPlayer != none && (MinDistance <= 0 || vsize(C.Pawn.Location - MyPlayer.Location) >= MinDistance + C.Pawn.CollisionRadius + MyPlayer.CollisionRadius);
	if ( bNeedToMode )
		C.SetTimer(TimeLimit, false);
	else
		C.SetTimer(fmax(Cooldown, 0.01), false); // wait at least 1 tick
	return true;
}

function bool CompleteWhenTimer()
{
	return true;
}

defaultproperties
{
     Cooldown=0.500000
     ActionString="Move to player or wait for timer"
}
