internal QualifierVisualizer(IQualifier q, SelectorVisualizer parent)
        {
            this._qualifier = q;
            this._parent    = parent;
            SelectorAction      selectorAction     = q.action as SelectorAction;
            AILinkAction        aILinkAction       = q.action as AILinkAction;
            CompositeAction     compositeAction    = q.action as CompositeAction;
            IRequireTermination requireTermination = q.action as IRequireTermination;

            if (selectorAction != null)
            {
                this._action = new SelectorActionVisualizer(selectorAction, this);
                return;
            }
            if (aILinkAction != null)
            {
                this._action = new AILinkActionVisualizer(aILinkAction, this);
                return;
            }
            if (compositeAction != null)
            {
                this._action = new CompositeActionVisualizer(compositeAction, this);
                return;
            }
            if (requireTermination != null)
            {
                this._action = new ActionRequiresTerminationVisualizer(q.action, this);
                return;
            }
            if (q.action != null)
            {
                this._action = new ActionVisualizer(q.action, this);
            }
        }
        public void Terminate(IAIContext context)
        {
            IRequireTermination requireTermination = base.action as IRequireTermination;

            if (requireTermination != null)
            {
                requireTermination.Terminate(context);
            }
        }
Пример #3
0
        /// <summary>
        /// Executes the AI. Typically this is called by whatever manager controls the AI execution cycle.
        /// </summary>
        public void Execute()
        {
            IAIContext context = _contextProvider.GetContext(_ai.id);

            var action = _ai.Select(context);

            bool finalActionFound = false;

            while (!finalActionFound)
            {
                //While we could treat all connectors the same, most connectors will not have anything to execute, so this way we save the call to Execute.
                var composite = action as ICompositeAction;
                if (composite == null)
                {
                    var connector = action as IConnectorAction;
                    if (connector == null)
                    {
                        finalActionFound = true;
                    }
                    else
                    {
                        action = connector.Select(context);
                    }
                }
                else
                {
                    //For composites that also connect, we execute the child actions before moving on.
                    //So action is executed and then reassigned to the selected action if one exists.
                    if (composite.isConnector)
                    {
                        action.Execute(context);
                        action = composite.Select(context);
                    }
                    else
                    {
                        finalActionFound = true;
                    }
                }
            }

            if (_activeAction != null && !object.ReferenceEquals(_activeAction, action))
            {
                _activeAction.Terminate(context);
                _activeAction = action as IRequireTermination;
            }
            else if (_activeAction == null)
            {
                _activeAction = action as IRequireTermination;
            }

            if (action != null)
            {
                action.Execute(context);
            }
        }
        public void Terminate(IAIContext context)
        {
            int count = this._actions.Count;

            for (int i = 0; i < count; i++)
            {
                IRequireTermination item = this._actions[i] as IRequireTermination;
                if (item != null)
                {
                    item.Terminate(context);
                }
            }
        }
        public void Execute()
        {
            IAIContext context = this._contextProvider.GetContext(this._ai.id);
            IAction    action  = this._ai.Select(context);
            bool       flag    = false;

            while (!flag)
            {
                ICompositeAction compositeAction = action as ICompositeAction;
                if (compositeAction == null)
                {
                    IConnectorAction connectorAction = action as IConnectorAction;
                    if (connectorAction != null)
                    {
                        action = connectorAction.Select(context);
                    }
                    else
                    {
                        flag = true;
                    }
                }
                else if (!compositeAction.isConnector)
                {
                    flag = true;
                }
                else
                {
                    action.Execute(context);
                    action = compositeAction.Select(context);
                }
            }
            if (this._activeAction != null && this._activeAction != action)
            {
                this._activeAction.Terminate(context);
                this._activeAction = action as IRequireTermination;
            }
            else if (this._activeAction == null)
            {
                this._activeAction = action as IRequireTermination;
            }
            if (action != null)
            {
                action.Execute(context);
            }
        }
Пример #6
0
 internal ActionRequiresTerminationVisualizer(IAction action, IQualifierVisualizer parent) : base(action, parent)
 {
     this._action = (IRequireTermination)action;
 }