예제 #1
0
        /// <summary>
        /// Создает новую ноду описывающую конкретное действие из плана ИИ.
        /// </summary>
        private AntAIDebuggerNode CreatePlanNode(AntAIAction aAction, AntAICondition aConditions,
                                                 AntAICondition aPrevConditions, ref Vector2 aNodePosition)
        {
            AntAICondition condCopy = aConditions.Clone();

            condCopy.name = aAction.name;

            int    numLines;
            string desc = DescribePlanAction(condCopy, aPrevConditions, out numLines);

            GUIStyle style;

            if (_currentPlan.isSuccess)
            {
                style = (aAction.name.Equals(_agent.currentPlan[0])) ? _activePlanStyle : _planStyle;
            }
            else
            {
                style = (aAction.name.Equals(_agent.currentPlan[0])) ? _activeFailedPlanStyle : _failedPlanStyle;
            }

            var node = AddNode(desc, 220.0f, CalcHeight(numLines), style, style, ref aNodePosition, false);

            node.value = aAction.state;
            node.SetOutput(node.rect.width - 10.0f, node.rect.height * 0.5f);
            node.SetInput(10.0f, node.rect.height * 0.5f);

            if (_genericNodes.Count > 0)
            {
                _genericNodes[_genericNodes.Count - 1].LinkTo(node, new Color(0.3f, 0.7f, 0.4f));
            }

            _genericNodes.Add(node);
            return(node);
        }
        /// <summary>
        /// Gets action by name.
        /// </summary>
        /// <param name="aActionName">Action name.</param>
        /// <returns>Returns action by name. If action not found, will be created new one.</returns>
        public AntAIAction GetAction(string aActionName)
        {
            var action = FindAction(aActionName);

            if (action == null && actions.Count < MAX_ACTIONS)
            {
                action = new AntAIAction(aActionName);
                actions.Add(action);
            }
            return(action);
        }
예제 #3
0
        public bool Post(string aActionName, string aAtomName, bool aValue)
        {
            AntAIAction action = GetAction(aActionName);
            int         atomId = GetAtomIndex(aAtomName);

            if (action == null || atomId == -1)
            {
                return(false);
            }
            return(action.post.Set(atomId, aValue));
        }
예제 #4
0
        public bool SetCost(string aActionName, int aCost)
        {
            AntAIAction action = GetAction(aActionName);

            if (action != null)
            {
                action.cost = aCost;
                return(true);
            }
            return(false);
        }
예제 #5
0
        private AntAIDebuggerNode CreateActionNode(AntAIAction aAction, ref Vector2 aNodePosition)
        {
            bool value = false;
            var  desc  = new List <string>();

            desc.Add(string.Format("<b><color={2}>ACTION</color> '<color={3}>{0}</color>'</b> [{1}]",
                                   aAction.name, aAction.cost, _titleColor, _nameColor));
            desc.Add("   <b>Pre Conditions</b>");

            for (int i = 0; i < AntAIPlanner.MAX_ATOMS; i++)
            {
                if (aAction.pre.GetMask(i))
                {
                    value = aAction.pre.GetValue(i);
                    desc.Add(string.Format("      '<color={2}>{0}</color>' = <color={2}>{1}</color>",
                                           _agent.planner.atoms[i], value, (value) ? _trueColor : _falseColor));
                }
            }

            desc.Add("   <b>Post Conditions</b>");
            for (int i = 0; i < AntAIPlanner.MAX_ATOMS; i++)
            {
                if (aAction.post.GetMask(i))
                {
                    value = aAction.post.GetValue(i);
                    desc.Add(string.Format("      '<color={2}>{0}</color>' = <color={2}>{1}</color>",
                                           _agent.planner.atoms[i], value, (value) ? _trueColor : _falseColor));
                }
            }

            StringBuilder text = new StringBuilder();

            for (int i = 0, n = desc.Count; i < n; i++)
            {
                text.AppendLine(desc[i]);
            }

            return(AddNode(text.ToString(), 220.0f, CalcHeight(desc.Count), _nodeStyle, _nodeStyle, ref aNodePosition));
        }
예제 #6
0
        /// <summary>
        /// Обновляет ноду описывающую конкретное действие из плана ИИ.
        /// </summary>
        private void UpdatePlanNode(AntAIAction aAction, AntAICondition aConditions,
                                    AntAICondition aPrevConditions, AntAIDebuggerNode aNode)
        {
            AntAICondition condCopy = aConditions.Clone();

            condCopy.name = aAction.name;
            aNode.value   = aAction.state;

            int numLines;

            aNode.title       = DescribePlanAction(condCopy, aPrevConditions, out numLines);
            aNode.rect.height = CalcHeight(numLines);

            if (_currentPlan.isSuccess)
            {
                aNode.defaultNodeStyle = (aAction.name.Equals(_agent.currentPlan[0])) ? _activePlanStyle : _planStyle;
            }
            else
            {
                aNode.defaultNodeStyle = (aAction.name.Equals(_agent.currentPlan[0])) ? _activeFailedPlanStyle : _failedPlanStyle;
            }
        }