abstract class AITimeCondition extends AIbehaviorconditionScript
{
}

abstract class AITimeoutCondition extends AITimeCondition
{
	protected var m_timestamp : Float;

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		if( m_timestamp < 0.0 )
		{
			return true;
		}
		return EngineTime.ToFloat( ScriptExecutionContext.GetAITime( context ) ) < m_timestamp;
	}

	protected export override function Activate( context : ScriptExecutionContext )
	{
		UpdateTimeStamp( context );
	}

	protected function UpdateTimeStamp( context : ScriptExecutionContext )
	{
		var timeoutValue : Float;
		timeoutValue = GetTimeoutValue( context );
		if( timeoutValue >= 0.0 )
		{
			m_timestamp = EngineTime.ToFloat( ScriptExecutionContext.GetAITime( context ) ) + timeoutValue;
		}
		else
		{
			m_timestamp = -1.0;
		}
	}

	protected virtual function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		return 0.0;
	}

}

class SelectorTimeout extends AITimeoutCondition
{

	protected override function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		return 0.1;
	}

}

class MappingTimeout extends AITimeoutCondition
{
	editable inlined var m_timeoutMapping : AIArgumentMapping;
	protected var m_timeoutValue : Float;

	protected override function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		if( m_timeoutMapping )
		{
			m_timeoutValue = ( ( Float )( ScriptExecutionContext.GetMappingValue( context, m_timeoutMapping ) ) );
		}
		return m_timeoutValue;
	}

}

class CustomValueTimeout extends AITimeoutCondition
{
	editable var m_timeoutValue : Float;

	protected override function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		return m_timeoutValue;
	}

}

class CustomValueFromMappingTimeout extends AITimeoutCondition
{
	editable inlined var m_actionTweakIDMapping : AIArgumentMapping;

	protected override function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		return ( ( Float )( ScriptExecutionContext.GetMappingValue( context, m_actionTweakIDMapping ) ) );
	}

}

class CharParamTimeout extends AITimeoutCondition
{
	editable var m_timeoutParamName : String;

	protected override function GetTimeoutValue( context : ScriptExecutionContext ) : Float
	{
		return GetPuppet( context ).GetFloatFromCharacterTweak( m_timeoutParamName );
	}

}

abstract class AICooldown extends AITimeCondition
{
	editable var m_cooldown : Float;
	protected var m_timestamp : Float;

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		return EngineTime.ToFloat( ScriptExecutionContext.GetAITime( context ) ) > m_timestamp;
	}

	protected function UpdateTimeStamp( context : ScriptExecutionContext )
	{
		if( m_cooldown > 0.0 )
		{
			m_timestamp = EngineTime.ToFloat( ScriptExecutionContext.GetAITime( context ) ) + m_cooldown;
		}
	}

}

class CooldownOnActivation extends AICooldown
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		UpdateTimeStamp( context );
	}

}

class CooldownOnDeactivation extends AICooldown
{

	protected override function Deactivate( context : ScriptExecutionContext )
	{
		if( EngineTime.ToFloat( ScriptExecutionContext.GetAITime( context ) ) > m_timestamp )
		{
			UpdateTimeStamp( context );
		}
	}

}

