abstract class AISignalSenderTask extends AIbehaviortaskScript
{
	mutable editable var tags : array< CName >;
	mutable editable var flags : array< EAIGateSignalFlags >;
	editable var priority : Float;
	private var m_signalId : Uint32;

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

	protected export override function Deactivate( context : ScriptExecutionContext )
	{
		GetPuppet( context ).GetSignalHandlerComponent().RemoveSignal( m_signalId );
	}

	protected final function QueueGateSignal( context : ScriptExecutionContext )
	{
		var signal : AIGateSignal;
		var i : Int32;
		signal.priority = priority;
		signal.lifeTime = GetSignalLifeTime();
		for( i = 0; i < tags.Size(); i += 1 )
		{
			AIGateSignal.AddTag( signal, tags[ i ] );
		}
		for( i = 0; i < flags.Size(); i += 1 )
		{
			AIGateSignal.AddFlag( signal, flags[ i ] );
		}
		m_signalId = GetPuppet( context ).GetSignalHandlerComponent().AddSignal( signal );
	}

	public virtual function GetSignalLifeTime() : Float
	{
		return 0.0;
	}

	protected final function GetSignalTable( context : ScriptExecutionContext ) : gameBoolSignalTable
	{
		return GetPuppet( context ).GetAIControllerComponent().GetSignals();
	}

}

class CustomEventSender extends AISignalSenderTask
{

	public function GetEditorSubCaption() : String
	{
		var result : String;
		var i : Int32;
		for( i = 0; i < tags.Size(); i += 1 )
		{
			if( i > 0 )
			{
				result += ".";
			}
			result += NameToString( tags[ i ] );
		}
		result += ( ( " (" + priority ) + ")" );
		return result;
	}

	public override function GetSignalLifeTime() : Float
	{
		return 0.5;
	}

}

class ReactiveEventSender extends AISignalSenderTask
{
	editable var m_behaviorArgumentNameTag : CName;
	editable var m_behaviorArgumentFloatPriority : CName;
	editable var m_behaviorArgumentNameFlag : CName;
	editable var m_reactiveType : CName;

	protected export override function Activate( context : ScriptExecutionContext )
	{
		tags.Resize( 3 );
		tags[ 0 ] = 'reactive';
		tags[ 1 ] = m_reactiveType;
		tags[ 2 ] = ScriptExecutionContext.GetArgumentName( context, m_behaviorArgumentNameTag );
		priority = ScriptExecutionContext.GetArgumentFloat( context, m_behaviorArgumentFloatPriority );
		flags.Resize( 1 );
		flags[ 0 ] = GateSignalFlagsNameToEnum( ScriptExecutionContext.GetArgumentName( context, m_behaviorArgumentNameFlag ) );
		super.Activate( context );
	}

	public override function GetSignalLifeTime() : Float
	{
		return 1.0;
	}

	private function GateSignalFlagsNameToEnum( FlagName : CName ) : EAIGateSignalFlags
	{
		switch( FlagName )
		{
			case 'AIGSF_Undefined':
				return EAIGateSignalFlags.AIGSF_Undefined;
			case 'AIGSF_OverridesSelf':
				return EAIGateSignalFlags.AIGSF_OverridesSelf;
			case 'AIGSF_InterruptsSamePriorityTask':
				return EAIGateSignalFlags.AIGSF_InterruptsSamePriorityTask;
			case 'AIGSF_InterruptsForcedBehavior':
				return EAIGateSignalFlags.AIGSF_InterruptsForcedBehavior;
			case 'AIGSF_AcceptsAdditives':
				return EAIGateSignalFlags.AIGSF_AcceptsAdditives;
			default:
				return EAIGateSignalFlags.AIGSF_Undefined;
		}
	}

}

class CerberusCustomEventSender extends AISignalSenderTask
{

	public function GetEditorSubCaption() : String
	{
		var result : String;
		var i : Int32;
		for( i = 0; i < tags.Size(); i += 1 )
		{
			if( i > 0 )
			{
				result += ".";
			}
			result += NameToString( tags[ i ] );
		}
		result += ( ( " (" + priority ) + ")" );
		return result;
	}

	public override function GetSignalLifeTime() : Float
	{
		return 0.0;
	}

}

