示例#1
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;
        }
示例#2
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;
        }
示例#3
0
        public int TickCounter { get; private set; } // 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;
        }