enum ECallbackExpressionActions
{
	SetTrue = 0,
	SetFalse = 1,
	Toggle = 2,
}

class AIBehaviorCallbackExpression extends AIbehaviorexpressionScript
{
	protected editable var m_callbackName : CName;
	hint m_callbackName = "Name of the behavior callback to listen to.";
	protected editable var m_initialValue : Bool;
	default m_initialValue = false;
	hint m_initialValue = "Value this expression is going to have after activation before the callback is called.";
	protected editable var m_callbackAction : ECallbackExpressionActions;
	default m_callbackAction = ECallbackExpressionActions.SetTrue;
	hint m_callbackAction = "What happens to the value when the behavior callback is invoked.";
	protected var m_callbackId : Uint32;
	protected var m_value : Bool;

	protected function Activate( context : ScriptExecutionContext )
	{
		m_callbackId = ScriptExecutionContext.AddBehaviorCallback( context, m_callbackName, this );
		m_value = m_initialValue;
	}

	protected function Deactivate( context : ScriptExecutionContext )
	{
		ScriptExecutionContext.RemoveBehaviorCallback( context, m_callbackId );
	}

	protected function CalculateValue( context : ScriptExecutionContext ) : Variant
	{
		return m_value;
	}

	protected override function OnBehaviorCallback( cbName : CName, context : ScriptExecutionContext ) : Bool
	{
		switch( m_callbackAction )
		{
			case ECallbackExpressionActions.SetTrue:
				m_value = true;
			break;
			default:
				m_value = true;
			break;
			case ECallbackExpressionActions.SetFalse:
				m_value = false;
			break;
			case ECallbackExpressionActions.Toggle:
				m_value = !( m_value );
			break;
		}
		MarkDirty( context );
		return true;
	}

}

