Example #1
0
        /// <summary>
        /// perform the behavior
        /// </summary>
        public BehaviorReturnCode Behave(TreeContext context)
        {
            try
            {
                switch (_Root.Behave(context))
                {
                case BehaviorReturnCode.Failure:
                    ReturnCode = BehaviorReturnCode.Failure;
                    break;

                case BehaviorReturnCode.Success:
                    ReturnCode = BehaviorReturnCode.Success;
                    break;

                case BehaviorReturnCode.Running:
                    ReturnCode = BehaviorReturnCode.Running;
                    break;

                default:
                    ReturnCode = BehaviorReturnCode.Running;
                    break;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Console.Error.WriteLine(e.ToString());
#endif
                ReturnCode = BehaviorReturnCode.Failure;
            }

            return(this.ReturnCode);
        }
Example #2
0
        /// <summary>
        /// performs the given behavior
        /// </summary>
        /// <returns>the behaviors return code</returns>
        public override BehaviorReturnCode OnBehave(TreeContext context)
        {
            for (; _LastBehavior < _Behaviors.Length; _LastBehavior++)
            {
                try{
                    switch (_Behaviors[_LastBehavior].Behave(context))
                    {
                    case BehaviorReturnCode.Failure:
                        continue;

                    case BehaviorReturnCode.Success:
                        _LastBehavior = 0;
                        ReturnCode    = BehaviorReturnCode.Success;
                        return(ReturnCode);

                    case BehaviorReturnCode.Running:
                        ReturnCode = BehaviorReturnCode.Running;
                        return(ReturnCode);

                    default:
                        continue;
                    }
                }
                catch (Exception e) {
#if DEBUG
                    Console.Error.WriteLine(e.ToString());
#endif
                    continue;
                }
            }

            _LastBehavior = 0;
            ReturnCode    = BehaviorReturnCode.Failure;
            return(ReturnCode);
        }
Example #3
0
 public TreeContext(TreeContext oldContext) : this()
 {
     this.OldContext = oldContext;
 }