Ejemplo n.º 1
0
        public MyObjectBuilder_BotMemory GetObjectBuilder()
        {
            var builder = new MyObjectBuilder_BotMemory();

            builder.LastRunningNodeIndex = LastRunningNodeIndex;
            builder.NewPath = m_newNodePath.ToList();
            builder.OldPath = m_oldNodePath.ToList();

            // tree memory + blackboard
            var behaviorTreeMemory = new MyObjectBuilder_BotMemory.BehaviorTreeNodesMemory();

            behaviorTreeMemory.BehaviorName = m_behaviorTree.BehaviorTreeName;
            behaviorTreeMemory.Memory       = new List <MyObjectBuilder_BehaviorTreeNodeMemory>(CurrentTreeBotMemory.NodesMemoryCount);
            foreach (var nodeMemory in CurrentTreeBotMemory.NodesMemory)
            {
                behaviorTreeMemory.Memory.Add(nodeMemory.GetObjectBuilder());
            }
            behaviorTreeMemory.BlackboardMemory = new List <MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory>();
            foreach (var bbMemInstance in CurrentTreeBotMemory.BBMemory)
            {
                var bbMemoryBuilder = new MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory();
                bbMemoryBuilder.MemberName = bbMemInstance.Key.ToString();
                bbMemoryBuilder.Value      = bbMemInstance.Value;
                behaviorTreeMemory.BlackboardMemory.Add(bbMemoryBuilder);
            }
            builder.BehaviorTreeMemory = behaviorTreeMemory;

            return(builder);
        }
Ejemplo n.º 2
0
        public MyObjectBuilder_BotMemory GetObjectBuilder()
        {
            MyObjectBuilder_BotMemory memory = new MyObjectBuilder_BotMemory {
                LastRunningNodeIndex = this.LastRunningNodeIndex,
                NewPath = this.m_newNodePath.ToList <int>(),
                OldPath = this.m_oldNodePath.ToList <int>()
            };

            MyObjectBuilder_BotMemory.BehaviorTreeNodesMemory memory2 = new MyObjectBuilder_BotMemory.BehaviorTreeNodesMemory {
                BehaviorName = this.m_behaviorTree.BehaviorTreeName,
                Memory       = new List <MyObjectBuilder_BehaviorTreeNodeMemory>(this.CurrentTreeBotMemory.NodesMemoryCount)
            };
            foreach (MyBehaviorTreeNodeMemory memory3 in this.CurrentTreeBotMemory.NodesMemory)
            {
                memory2.Memory.Add(memory3.GetObjectBuilder());
            }
            memory2.BlackboardMemory = new List <MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory>();
            foreach (KeyValuePair <MyStringId, MyBBMemoryValue> pair in this.CurrentTreeBotMemory.BBMemory)
            {
                MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory item = new MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory();
                item.MemberName = pair.Key.ToString();
                item.Value      = pair.Value;
                memory2.BlackboardMemory.Add(item);
            }
            memory.BehaviorTreeMemory = memory2;
            return(memory);
        }
Ejemplo n.º 3
0
        public MyBotMemory Clone()
        {
            MyBotMemory memory1 = new MyBotMemory(this.m_memoryUser);

            memory1.m_behaviorTree = this.m_behaviorTree;
            MyObjectBuilder_BotMemory builder = new MyObjectBuilder_BotMemory();

            builder = this.GetObjectBuilder();
            memory1.Init(builder);
            return(memory1);
        }
Ejemplo n.º 4
0
        }                                            // Can be used by actions to check, whether something happened in the same frame

        public MyBotMemory Clone()
        {
            // creates copy of current memory state
            MyBotMemory copy = new MyBotMemory(m_memoryUser);

            copy.m_behaviorTree = m_behaviorTree;
            MyObjectBuilder_BotMemory memoryBuilder = new MyObjectBuilder_BotMemory();

            memoryBuilder = GetObjectBuilder();
            copy.Init(memoryBuilder);
            return(copy);
        }
Ejemplo n.º 5
0
        public void Init(MyObjectBuilder_BotMemory builder)
        {
            if (builder.BehaviorTreeMemory != null)
            {
                var treeBotMemory = new MyPerTreeBotMemory();
                foreach (var nodeMemoryBuilder in builder.BehaviorTreeMemory.Memory)
                {
                    var nodeMemoryObj = MyBehaviorTreeNodeMemoryFactory.CreateNodeMemory(nodeMemoryBuilder);
                    nodeMemoryObj.Init(nodeMemoryBuilder);
                    treeBotMemory.AddNodeMemory(nodeMemoryObj);
                }

                if (builder.BehaviorTreeMemory.BlackboardMemory != null)
                {
                    foreach (var bbMemInstance in builder.BehaviorTreeMemory.BlackboardMemory)
                    {
                        treeBotMemory.AddBlackboardMemoryInstance(bbMemInstance.MemberName, bbMemInstance.Value);
                    }
                }
                CurrentTreeBotMemory = treeBotMemory;
            }

            if (builder.OldPath != null)
            {
                for (int i = 0; i < builder.OldPath.Count; i++)
                {
                    m_oldNodePath.Add(i);
                }
            }
            if (builder.NewPath != null)
            {
                for (int i = 0; i < builder.NewPath.Count; i++)
                {
                    m_newNodePath.Push(builder.NewPath[i]);
                }
            }

            LastRunningNodeIndex = builder.LastRunningNodeIndex;
            TickCounter          = 0;
        }
Ejemplo n.º 6
0
 public void Init(MyObjectBuilder_BotMemory builder)
 {
     if (builder.BehaviorTreeMemory != null)
     {
         MyPerTreeBotMemory memory = new MyPerTreeBotMemory();
         foreach (MyObjectBuilder_BehaviorTreeNodeMemory memory2 in builder.BehaviorTreeMemory.Memory)
         {
             MyBehaviorTreeNodeMemory nodeMemory = MyBehaviorTreeNodeMemoryFactory.CreateNodeMemory(memory2);
             nodeMemory.Init(memory2);
             memory.AddNodeMemory(nodeMemory);
         }
         if (builder.BehaviorTreeMemory.BlackboardMemory != null)
         {
             foreach (MyObjectBuilder_BotMemory.BehaviorTreeBlackboardMemory memory4 in builder.BehaviorTreeMemory.BlackboardMemory)
             {
                 memory.AddBlackboardMemoryInstance(memory4.MemberName, memory4.Value);
             }
         }
         this.CurrentTreeBotMemory = memory;
     }
     if (builder.OldPath != null)
     {
         for (int i = 0; i < builder.OldPath.Count; i++)
         {
             this.m_oldNodePath.Add(i);
         }
     }
     if (builder.NewPath != null)
     {
         for (int i = 0; i < builder.NewPath.Count; i++)
         {
             this.m_newNodePath.Push(builder.NewPath[i]);
         }
     }
     this.LastRunningNodeIndex = builder.LastRunningNodeIndex;
     this.TickCounter          = 0;
 }