public override void Construct(MyObjectBuilder_BehaviorTreeNode nodeDefinition, MyBehaviorTree.MyBehaviorTreeDesc treeDesc)
        {
            base.Construct(nodeDefinition, treeDesc);

            m_child = MyBehaviorTreeNodeFactory.CreateBTNode(nodeDefinition);
            m_child.Construct(nodeDefinition, treeDesc);
        }
        public override void Construct(MyObjectBuilder_BehaviorTreeNode nodeDefinition, MyBehaviorTree.MyBehaviorTreeDesc treeDesc)
        {
            base.Construct(nodeDefinition, treeDesc);

            var ob = (MyObjectBuilder_BehaviorTreeActionNode)nodeDefinition;
            Debug.Assert(!string.IsNullOrEmpty(ob.ActionName), "Action name was not provided");
            if (!string.IsNullOrEmpty(ob.ActionName))
            {
                m_actionName = MyStringId.GetOrCompute(ob.ActionName);
                treeDesc.ActionIds.Add(m_actionName);
            }

            if (ob.Parameters != null)
            {
                var obParameters = ob.Parameters;
                m_parameters = new object[obParameters.Length];
                for (int i = 0; i < m_parameters.Length; i++)
                {
                    var obParam = obParameters[i];
                    if (obParam is MyObjectBuilder_BehaviorTreeActionNode.MemType)
                    {
                        string value = (string)obParam.GetValue();
                        m_parameters[i] = (Boxed<MyStringId>)MyStringId.GetOrCompute(value);
                    }
                    else
                    {
                        m_parameters[i] = obParam.GetValue();
                    }
                }
            }
        }
        public override void Construct(MyObjectBuilder_BehaviorTreeNode nodeDefinition, MyBehaviorTree.MyBehaviorTreeDesc treeDesc)
        {
            base.Construct(nodeDefinition, treeDesc);

            var controlBaseNode = (MyObjectBuilder_BehaviorControlBaseNode)nodeDefinition;

            m_children = new List<MyBehaviorTreeNode>(controlBaseNode.BTNodes.Length);
            m_isMemorable = controlBaseNode.IsMemorable;
            foreach (var ob in controlBaseNode.BTNodes)
            {
                var childInst = MyBehaviorTreeNodeFactory.CreateBTNode(ob);
                childInst.Construct(ob, treeDesc);
                m_children.Add(childInst);
            }
        }
        public override void Construct(MyObjectBuilder_BehaviorTreeNode nodeDefinition, MyBehaviorTree.MyBehaviorTreeDesc treeDesc)
        {
            base.Construct(nodeDefinition, treeDesc);
            var ob = nodeDefinition as MyObjectBuilder_BehaviorTreeDecoratorNode;

            m_defaultReturnValue = (MyBehaviorTreeState)((byte)ob.DefaultReturnValue);
            m_decoratorLogicName = ob.DecoratorLogic.GetType().Name;

            m_decoratorLogic = GetDecoratorLogic(ob.DecoratorLogic);
            m_decoratorLogic.Construct(ob.DecoratorLogic);

            if (ob.BTNode != null)
            {
                m_child = MyBehaviorTreeNodeFactory.CreateBTNode(ob.BTNode);
                m_child.Construct(ob.BTNode, treeDesc);
            }
        }
Exemple #5
0
 public void Update()
 {
     foreach (BTData local1 in this.m_BTDataByName.Values)
     {
         MyBehaviorTree behaviorTree = local1.BehaviorTree;
         foreach (BotData data in local1.BotsData)
         {
             IMyBot bot = data.Bot;
             if (bot.IsValidForUpdate)
             {
                 int num = data.UpdateCounter + 1;
                 data.UpdateCounter = num;
                 if (num > 10)
                 {
                     if (MyFakes.DEBUG_BEHAVIOR_TREE)
                     {
                         if (!MyFakes.DEBUG_BEHAVIOR_TREE_ONE_STEP)
                         {
                             continue;
                         }
                         MyFakes.DEBUG_BEHAVIOR_TREE_ONE_STEP = false;
                     }
                     data.UpdateCounter = 0;
                     bot.BotMemory.PreTickClear();
                     behaviorTree.Tick(bot);
                     if ((MyFakes.ENABLE_BEHAVIOR_TREE_TOOL_COMMUNICATION && (ReferenceEquals(this.DebugBot, data.Bot) && (!this.DebugBreakDebugging && MyDebugDrawSettings.DEBUG_DRAW_BOTS))) && this.TryGetValidToolWindow(out this.m_toolWindowHandle))
                     {
                         if ((!this.DebugSelectedTreeHashSent || (this.m_toolWindowHandle != this.DebugLastWindowHandle)) || (this.DebugCurrentBehaviorTree != this.m_botBehaviorIds[this.DebugBot].String))
                         {
                             this.SendSelectedTreeForDebug(behaviorTree);
                         }
                         this.SendDataToTool(data.Bot, data.Bot.BotMemory.CurrentTreeBotMemory);
                     }
                 }
             }
         }
     }
 }
Exemple #6
0
        public bool ChangeBehaviorTree(string behaviorTreeName, IMyBot bot)
        {
            bool           assign       = false;
            MyBehaviorTree behaviorTree = null;

            if (!TryGetBehaviorTreeByName(behaviorTreeName, out behaviorTree))
            {
                return(false);
            }
            if (!behaviorTree.IsCompatibleWithBot(bot.ActionCollection))
            {
                return(false);
            }
            var tree = TryGetBehaviorTreeForBot(bot);

            if (tree != null)
            {
                if (tree.BehaviorTreeId == behaviorTree.BehaviorTreeId)
                {
                    assign = false;
                }
                else
                {
                    UnassignBotBehaviorTree(bot);
                    assign = true;
                }
            }
            else
            {
                assign = true;
            }

            if (assign)
            {
                AssignBotBehaviorTreeInternal(behaviorTree, bot);
            }
            return(assign);
        }
 public virtual void Construct(MyObjectBuilder_BehaviorTreeNode nodeDefinition, MyBehaviorTree.MyBehaviorTreeDesc treeDesc)
 {
     MemoryIndex = treeDesc.MemorableNodesCounter++;
     treeDesc.Nodes.Add(this);
 }
Exemple #8
0
 public void AssignBehaviorTree(MyBehaviorTree behaviorTree)
 {
     if (CurrentBehaviorTree == null || behaviorTree.BehaviorTreeId == CurrentBehaviorTree.BehaviorTreeId)
     {
         CurrentTreeBotMemory = CreateBehaviorTreeMemory(behaviorTree);
     }
     else
     {
         bool isValid = ValidateMemoryForBehavior(behaviorTree);
         if (!isValid)
         {
             CurrentTreeBotMemory.Clear();
             ClearPathMemory(false);
             ResetMemoryInternal(behaviorTree, CurrentTreeBotMemory);
         }
     }
 }
Exemple #9
0
 private void ResetMemoryInternal(MyBehaviorTree behaviorTree, MyPerTreeBotMemory treeMemory)
 {
     for (int i = 0; i < behaviorTree.TotalNodeCount; i++)
     {
         treeMemory.AddNodeMemory(behaviorTree.GetNodeByIndex(i).GetNewMemoryObject());
     }
 }
Exemple #10
0
        public void ResetMemory(MyBehaviorTree behaviorTree, bool clearMemory = false)
        {
            if (clearMemory)
                ClearPathMemory(true);

            if (CurrentBehaviorTree.BehaviorTreeId == behaviorTree.BehaviorTreeId)
                CurrentTreeBotMemory.Clear();
            else
                CurrentTreeBotMemory = new MyPerTreeBotMemory();

            ResetMemoryInternal(behaviorTree, CurrentTreeBotMemory);
        }
Exemple #11
0
 public bool ValidateMemoryForBehavior(MyBehaviorTree behaviorTree)
 {
     bool isValid = true;
     if (CurrentTreeBotMemory.NodesMemoryCount != behaviorTree.TotalNodeCount)
         isValid = false;
     else
     {
         for (int i = 0; i < CurrentTreeBotMemory.NodesMemoryCount; i++)
         {
             var nodeMemory = CurrentTreeBotMemory.GetNodeMemoryByIndex(i);
             if (nodeMemory.GetType() != behaviorTree.GetNodeByIndex(i).MemoryType)
             {
                 isValid = false;
                 break;
             }
         }
     }
     return isValid;
 }
Exemple #12
0
 private MyPerTreeBotMemory CreateBehaviorTreeMemory(MyBehaviorTree behaviorTree)
 {
     var treeMemory = new MyPerTreeBotMemory(); 
     ResetMemoryInternal(behaviorTree, treeMemory);
     return treeMemory;
 }
 public BTData(MyBehaviorTree behaviorTree)
 {
     BehaviorTree = behaviorTree;
     BotsData     = new HashSet <BotData>(this);
 }
 private void AssignBotBehaviorTreeInternal(MyBehaviorTree behaviorTree, IMyBot bot)
 {
     bot.BehaviorTree = behaviorTree;
     bot.BotMemory.AssignBehaviorTree(behaviorTree);
     m_BTDataByName[behaviorTree.BehaviorTreeId].BotsData.Add(new BotData(bot));
 }
Exemple #15
0
 public void UnassignCurrentBehaviorTree()
 {
     ClearPathMemory(true);
     CurrentTreeBotMemory = null;
     m_behaviorTree = null;
 }