Esempio n. 1
0
        public void TryRemoveBot(int botHandler)
        {
            IMyBot bot = null;

            this.m_allBots.TryGetValue(botHandler, out bot);
            if (bot != null)
            {
                string behaviorType = bot.BotDefinition.BehaviorType;
                bot.Cleanup();
                if (this.m_botIndex != -1)
                {
                    if (ReferenceEquals(this.m_behaviorTreeCollection.DebugBot, bot))
                    {
                        this.m_behaviorTreeCollection.DebugBot = null;
                    }
                    int index = this.m_botsQueue.IndexOf(botHandler);
                    if (index < this.m_botIndex)
                    {
                        this.m_botIndex--;
                    }
                    else if (index == this.m_botIndex)
                    {
                        this.m_botIndex = -1;
                    }
                }
                this.m_allBots.Remove(botHandler);
                this.m_botsQueue.Remove(botHandler);
                string str2 = behaviorType;
                this.m_botsCountPerBehavior[str2] -= 1;
            }
        }
Esempio n. 2
0
        private void RecordRunningNodeName(IMyBot bot, MyBehaviorTreeState state)
        {
            if (MyDebugDrawSettings.DEBUG_DRAW_BOTS && (bot is MyAgentBot))
            {
                switch (state)
                {
                case MyBehaviorTreeState.ERROR:
                    (bot as MyAgentBot).LastActions.AddLastAction("error");
                    return;

                case MyBehaviorTreeState.NOT_TICKED:
                    (bot as MyAgentBot).LastActions.AddLastAction("not ticked");
                    return;

                case MyBehaviorTreeState.SUCCESS:
                    (bot as MyAgentBot).LastActions.AddLastAction("failure");
                    return;

                case MyBehaviorTreeState.FAILURE:
                    (bot as MyAgentBot).LastActions.AddLastAction("failure");
                    return;

                case MyBehaviorTreeState.RUNNING:
                    (bot as MyAgentBot).LastActions.AddLastAction(this.m_child.m_runningActionName);
                    return;
                }
            }
        }
        public IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition)
        {
            MyObjectBuilderType obType = MyObjectBuilderType.Invalid;

            if (botBuilder == null)
            {
                obType     = botDefinition.Id.TypeId;
                botBuilder = m_objectFactory.CreateObjectBuilder <MyObjectBuilder_Bot>(m_objectFactory.GetProducedType(obType));
            }
            else
            {
                obType = botBuilder.TypeId;
                Debug.Assert(botDefinition.Id == botBuilder.BotDefId, "Bot builder type does not match bot definition type!");
            }

            Debug.Assert(m_botDataByBehaviorType.ContainsKey(botDefinition.BehaviorType), "Undefined behavior type. Bot is not going to be created");
            if (!m_botDataByBehaviorType.ContainsKey(botDefinition.BehaviorType))
            {
                return(null);
            }
            var    botData = m_botDataByBehaviorType[botDefinition.BehaviorType];
            IMyBot output  = CreateBot(m_objectFactory.GetProducedType(obType), player, botDefinition);

            CreateActions(output, botData.BotActionsType);
            CreateLogic(output, botData.LogicType, botDefinition.BehaviorSubtype);
            output.Init(botBuilder);
            return(output);
        }
Esempio n. 4
0
 public void CallPostTickOnPath(IMyBot bot, MyPerTreeBotMemory botTreeMemory, IEnumerable <int> postTickNodes)
 {
     foreach (int num in postTickNodes)
     {
         this.m_treeDesc.Nodes[num].PostTick(bot, botTreeMemory);
     }
 }
        public MyBehaviorTreeState PerformAction(IMyBot bot, MyStringId actionId, object[] args)
        {
            Debug.Assert(m_actions.ContainsKey(actionId), "Given bot action does not exist!");

            var action = m_actions[actionId];

            if (action == null)
            {
                return(MyBehaviorTreeState.ERROR);
            }

            var botMemory = bot.BotMemory.CurrentTreeBotMemory;

            if (action.ParametersDesc.Count == 0)
            {
                return(action.Action(bot, args));
            }
            else
            {
                Debug.Assert(args != null, "Args were not provided, aborting action");
                if (args == null)
                {
                    return(MyBehaviorTreeState.FAILURE);
                }

                LoadActionParams(action, args, botMemory);
                var state = action.Action(bot, action.ActionParams);
                SaveActionParams(action, args, botMemory);
                return(state);
            }
        }
Esempio n. 6
0
 public MyBotMemory(IMyBot bot)
 {
     LastRunningNodeIndex = -1;
     m_memoryUser         = bot;
     m_newNodePath        = new Stack <int>(20);
     m_oldNodePath        = new HashSet <int>();
 }
Esempio n. 7
0
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            MyBehaviorTreeDecoratorNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory;

            if (this.m_child != null)
            {
                if (nodeMemoryByIndex.ChildState == MyBehaviorTreeState.RUNNING)
                {
                    return(this.TickChild(bot, botTreeMemory, nodeMemoryByIndex));
                }
                this.m_decoratorLogic.Update(nodeMemoryByIndex.DecoratorLogicMemory);
                if (this.m_decoratorLogic.CanRun(nodeMemoryByIndex.DecoratorLogicMemory))
                {
                    return(this.TickChild(bot, botTreeMemory, nodeMemoryByIndex));
                }
                if (this.IsRunningStateSource)
                {
                    bot.BotMemory.ProcessLastRunningNode(this);
                }
                botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex).NodeState = this.m_defaultReturnValue;
                if (MyDebugDrawSettings.DEBUG_DRAW_BOTS && (this.m_defaultReturnValue == MyBehaviorTreeState.RUNNING))
                {
                    base.m_runningActionName = "Par_N" + this.m_decoratorLogicName;
                }
            }
            return(this.m_defaultReturnValue);
        }
        void RecordRunningNodeName(IMyBot bot, MyBehaviorTreeState state)
        {
            if (!Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS || !(bot is MyAgentBot))
            {
                return;
            }

            switch (state)
            {
            case MyBehaviorTreeState.RUNNING:
                (bot as MyAgentBot).LastActions.AddLastAction(m_child.m_runningActionName);
                break;

            case MyBehaviorTreeState.ERROR:
                (bot as MyAgentBot).LastActions.AddLastAction("error");
                break;

            case MyBehaviorTreeState.FAILURE:
                (bot as MyAgentBot).LastActions.AddLastAction("failure");
                break;

            case MyBehaviorTreeState.SUCCESS:
                (bot as MyAgentBot).LastActions.AddLastAction("failure");
                break;

            case MyBehaviorTreeState.NOT_TICKED:
                (bot as MyAgentBot).LastActions.AddLastAction("not ticked");
                break;
            }
        }
Esempio n. 9
0
 public MyAgentLogic(IMyBot bot)
     : base(bot)
 {
     m_entityBot = m_bot as IMyEntityBot;
     AiTarget    = MyAIComponent.BotFactory.CreateTargetForBot(AgentBot);
     Debug.Assert(AiTarget != null, "Ai target was not created in CreateTargetForBot()!");
 }
Esempio n. 10
0
 public void CallPostTickOnPath(IMyBot bot, MyPerTreeBotMemory botTreeMemory, IEnumerable <int> postTickNodes)
 {
     foreach (var nodeIdx in postTickNodes)
     {
         m_treeDesc.Nodes[nodeIdx].PostTick(bot, botTreeMemory);
     }
 }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory;

            if (m_child == null)
                return m_defaultReturnValue;

            if (decoratorMemory.ChildState != MyBehaviorTreeState.RUNNING)
            {
                m_decoratorLogic.Update(decoratorMemory.DecoratorLogicMemory);
                if (m_decoratorLogic.CanRun(decoratorMemory.DecoratorLogicMemory))
                {
                    return TickChild(bot, botTreeMemory, decoratorMemory);
                }
                else
                {
                    if (IsRunningStateSource)
                        bot.BotMemory.ProcessLastRunningNode(this);

                    botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = m_defaultReturnValue;
                    return m_defaultReturnValue;
                }
            }
            else
            {
                return TickChild(bot, botTreeMemory, decoratorMemory);
            }
        }
Esempio n. 12
0
        public MyBehaviorTree TryGetBehaviorTreeForBot(IMyBot bot)
        {
            BTData data = null;

            this.m_BTDataByName.TryGetValue(this.m_botBehaviorIds[bot], out data);
            return((data == null) ? null : data.BehaviorTree);
        }
Esempio n. 13
0
        public string GetBehaviorName(IMyBot bot)
        {
            MyStringHash hash;

            this.m_botBehaviorIds.TryGetValue(bot, out hash);
            return(hash.String);
        }
Esempio n. 14
0
 public MyBotMemory(IMyBot bot)
 {
     LastRunningNodeIndex = -1;
     m_memoryUser = bot;
     m_newNodePath = new Stack<int>(20);
     m_oldNodePath = new HashSet<int>();
 }
Esempio n. 15
0
        public IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition)
        {
            MyObjectBuilderType invalid = MyObjectBuilderType.Invalid;

            if (botBuilder != null)
            {
                invalid = botBuilder.TypeId;
            }
            else
            {
                invalid    = botDefinition.Id.TypeId;
                botBuilder = m_objectFactory.CreateObjectBuilder <MyObjectBuilder_Bot>(m_objectFactory.GetProducedType(invalid));
            }
            if (!this.m_botDataByBehaviorType.ContainsKey(botDefinition.BehaviorType))
            {
                return(null);
            }
            BehaviorData data = this.m_botDataByBehaviorType[botDefinition.BehaviorType];
            IMyBot       bot  = this.CreateBot(m_objectFactory.GetProducedType(invalid), player, botDefinition);

            this.CreateActions(bot, data.BotActionsType);
            this.CreateLogic(bot, data.LogicType, botDefinition.BehaviorSubtype);
            bot.Init(botBuilder);
            return(bot);
        }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeControlNodeMemory;
            for (int i = nodeMemory.InitialIndex; i < m_children.Count; i++)
            {
                bot.BotMemory.RememberNode(m_children[i].MemoryIndex);
                var state = m_children[i].Tick(bot, botTreeMemory);
                if (state == SearchedValue || state == FinalValue)
                    m_children[i].PostTick(bot, botTreeMemory);
                if (state == MyBehaviorTreeState.RUNNING || state == SearchedValue)
                {
                    nodeMemory.NodeState = state;
                    if (state == MyBehaviorTreeState.RUNNING)
                    {
                        if (m_isMemorable)
                            nodeMemory.InitialIndex = i;
                    }
                    else
                    {
                        bot.BotMemory.ForgetNode();
                    }
                    return state;
                }
                bot.BotMemory.ForgetNode();
            }

            nodeMemory.NodeState = FinalValue;
            return FinalValue;
        }
Esempio n. 17
0
        private void GetBotActions(IMyBot bot, ActionCollection actions)
        {
            var methodInfos = bot.BotActions.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);

            foreach (var methodInfo in methodInfos)
            {
                var attrs = methodInfo.GetCustomAttributes(true);
                for (int i = 0; i < attrs.Length; i++)
                {
                    if (attrs[i] is MyBehaviorTreeActionAttribute)
                    {
                        MyBehaviorTreeActionAttribute btActionAttribute = (MyBehaviorTreeActionAttribute)attrs[i];

                        switch (btActionAttribute.ActionType)
                        {
                        case MyBehaviorTreeActionType.INIT:
                            actions.AddInitAction(btActionAttribute.ActionName, (x) => methodInfo.Invoke(x.BotActions, null));
                            break;

                        case MyBehaviorTreeActionType.BODY:
                            actions.AddAction(btActionAttribute.ActionName, methodInfo, btActionAttribute.ReturnsRunning, (x, y) => (MyBehaviorTreeState)methodInfo.Invoke(x.BotActions, y));
                            break;

                        case MyBehaviorTreeActionType.POST:
                            actions.AddPostAction(btActionAttribute.ActionName, (x) => methodInfo.Invoke(x.BotActions, null));
                            break;
                        }

                        break;
                    }
                }
            }
        }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeControlNodeMemory;

            for (int i = nodeMemory.InitialIndex; i < m_children.Count; i++)
            {
                bot.BotMemory.RememberNode(m_children[i].MemoryIndex);
                var state = m_children[i].Tick(bot, botTreeMemory);
                if (state == SearchedValue || state == FinalValue)
                {
                    m_children[i].PostTick(bot, botTreeMemory);
                }
                if (state == MyBehaviorTreeState.RUNNING || state == SearchedValue)
                {
                    nodeMemory.NodeState = state;
                    if (state == MyBehaviorTreeState.RUNNING)
                    {
                        if (m_isMemorable)
                        {
                            nodeMemory.InitialIndex = i;
                        }
                    }
                    else
                    {
                        bot.BotMemory.ForgetNode();
                    }
                    return(state);
                }
                bot.BotMemory.ForgetNode();
            }

            nodeMemory.NodeState = FinalValue;
            return(FinalValue);
        }
Esempio n. 19
0
 public void CallPostTickOnPath(IMyBot bot, MyPerTreeBotMemory botTreeMemory, IEnumerable<int> postTickNodes)
 {
     foreach (var nodeIdx in postTickNodes)
     {
         m_treeDesc.Nodes[nodeIdx].PostTick(bot, botTreeMemory);
     }
 }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory;

            if (m_child == null)
            {
                return(m_defaultReturnValue);
            }

            if (decoratorMemory.ChildState != MyBehaviorTreeState.RUNNING)
            {
                m_decoratorLogic.Update(decoratorMemory.DecoratorLogicMemory);
                if (m_decoratorLogic.CanRun(decoratorMemory.DecoratorLogicMemory))
                {
                    return(TickChild(bot, botTreeMemory, decoratorMemory));
                }
                else
                {
                    if (IsRunningStateSource)
                    {
                        bot.BotMemory.ProcessLastRunningNode(this);
                    }

                    botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = m_defaultReturnValue;
                    return(m_defaultReturnValue);
                }
            }
            else
            {
                return(TickChild(bot, botTreeMemory, decoratorMemory));
            }
        }
Esempio n. 21
0
 public MyAgentLogic(IMyBot bot)
     : base(bot)
 {
     m_entityBot = m_bot as IMyEntityBot;
     AiTarget = MyAIComponent.BotFactory.CreateTargetForBot(AgentBot);
     Debug.Assert(AiTarget != null, "Ai target was not created in CreateTargetForBot()!");
 }
Esempio n. 22
0
        public bool ChangeBehaviorTree(string behaviorTreeName, IMyBot bot)
        {
            bool           flag         = false;
            MyBehaviorTree behaviorTree = null;

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

            if (tree2 == null)
            {
                flag = true;
            }
            else if (tree2.BehaviorTreeId == behaviorTree.BehaviorTreeId)
            {
                flag = false;
            }
            else
            {
                this.UnassignBotBehaviorTree(bot);
                flag = true;
            }
            if (flag)
            {
                this.AssignBotBehaviorTreeInternal(behaviorTree, bot);
            }
            return(flag);
        }
 public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
 {
     botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).PostTickMemory();
     foreach (var child in m_children)
     {
         child.PostTick(bot, botTreeMemory);
     }
 }
 public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
 {
     botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).PostTickMemory();
     foreach (var child in m_children)
     {
         child.PostTick(bot, botTreeMemory);
     }
 }
Esempio n. 25
0
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            MyBehaviorTreeState             state;
            MyBehaviorTreeControlNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex) as MyBehaviorTreeControlNodeMemory;
            int initialIndex = nodeMemoryByIndex.InitialIndex;

            while (true)
            {
                if (initialIndex >= this.m_children.Count)
                {
                    nodeMemoryByIndex.NodeState    = this.FinalValue;
                    nodeMemoryByIndex.InitialIndex = 0;
                    return(this.FinalValue);
                }
                bot.BotMemory.RememberNode(this.m_children[initialIndex].MemoryIndex);
                if (MyDebugDrawSettings.DEBUG_DRAW_BOTS)
                {
                    if (this.m_children[initialIndex] is MyBehaviorTreeControlBaseNode)
                    {
                        string name = (this.m_children[initialIndex] as MyBehaviorTreeControlBaseNode).m_name;
                    }
                    else if (this.m_children[initialIndex] is MyBehaviorTreeActionNode)
                    {
                        (this.m_children[initialIndex] as MyBehaviorTreeActionNode).GetActionName();
                    }
                    else if (this.m_children[initialIndex] is MyBehaviorTreeDecoratorNode)
                    {
                        (this.m_children[initialIndex] as MyBehaviorTreeDecoratorNode).GetName();
                    }
                    base.m_runningActionName = "";
                }
                state = this.m_children[initialIndex].Tick(bot, botTreeMemory);
                if ((state == this.SearchedValue) || (state == this.FinalValue))
                {
                    this.m_children[initialIndex].PostTick(bot, botTreeMemory);
                }
                if (state == MyBehaviorTreeState.RUNNING)
                {
                    break;
                }
                if (state == this.SearchedValue)
                {
                    break;
                }
                bot.BotMemory.ForgetNode();
                initialIndex++;
            }
            nodeMemoryByIndex.NodeState = state;
            if (state != MyBehaviorTreeState.RUNNING)
            {
                bot.BotMemory.ForgetNode();
            }
            else if (this.m_isMemorable)
            {
                nodeMemoryByIndex.InitialIndex = initialIndex;
            }
            return(state);
        }
Esempio n. 26
0
 public bool AssignBotToBehaviorTree(MyBehaviorTree behaviorTree, IMyBot bot)
 {
     if (!behaviorTree.IsCompatibleWithBot(bot.ActionCollection))
     {
         return(false);
     }
     this.AssignBotBehaviorTreeInternal(behaviorTree, bot);
     return(true);
 }
Esempio n. 27
0
        public void PerformPostAction(IMyBot bot, MyStringId actionId)
        {
            BotActionDesc desc = this.m_actions[actionId];

            if (desc != null)
            {
                desc.PostAction(bot);
            }
        }
Esempio n. 28
0
        public static ActionCollection CreateActionCollection(IMyBot bot)
        {
            ActionCollection actions = new ActionCollection();

            foreach (MethodInfo info in bot.BotActions.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                ExtractAction(actions, info);
            }
            return(actions);
        }
Esempio n. 29
0
        public BotType TryGetBot <BotType>(int botHandler) where BotType : class, IMyBot
        {
            IMyBot bot = null;

            this.m_allBots.TryGetValue(botHandler, out bot);
            if (bot != null)
            {
                return(bot as BotType);
            }
            return(default(BotType));
        }
        public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex);
            if (nodeMemory.InitCalled)
            {
                if (bot.ActionCollection.ContainsPostAction(m_actionName))
                    bot.ActionCollection.PerformPostAction(bot, m_actionName);

                nodeMemory.InitCalled = false;
            }
        }
 public bool AssignBotToBehaviorTree(MyBehaviorTree behaviorTree, IMyBot bot)
 {
     Debug.Assert(!m_BTDataByName[behaviorTree.BehaviorTreeId].ContainsBot(bot), "Bot has already been added.");
     Debug.Assert(behaviorTree.IsCompatibleWithBot(bot.ActionCollection), "Bot is not compatible with the behavior tree.");
     if (!behaviorTree.IsCompatibleWithBot(bot.ActionCollection))
     {
         return(false);
     }
     AssignBotBehaviorTreeInternal(behaviorTree, bot);
     return(true);
 }
Esempio n. 32
0
        public void AddBot(int botHandler, IMyBot newBot)
        {
            Debug.Assert(!m_allBots.ContainsKey(botHandler), "Bot with the given handler already exists!");
            if (m_allBots.ContainsKey(botHandler)) return;

            ActionCollection botActions = new ActionCollection();
            newBot.GetAvailableActions(botActions);

            m_botActions.Add(botHandler, botActions);
            m_allBots.Add(botHandler, newBot);
        }
Esempio n. 33
0
 public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
 {
     botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex).PostTickMemory();
     using (List <MyBehaviorTreeNode> .Enumerator enumerator = this.m_children.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             enumerator.Current.PostTick(bot, botTreeMemory);
         }
     }
 }
        public static ActionCollection CreateActionCollection(IMyBot bot)
        {
            var actions     = new ActionCollection();
            var methodInfos = bot.BotActions.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);

            foreach (var methodInfo in methodInfos)
            {
                ExtractAction(actions, methodInfo);
            }
            return(actions);
        }
 internal void SelectBotForDebugging(IMyBot bot)
 {
     m_behaviorTreeCollection.DebugBot = bot;
     for (int i = 0; i < m_botsQueue.Count; i++)
     {
         if (m_allBots[m_botsQueue[i]] == bot)
         {
             m_botIndex = i;
             break;
         }
     }
 }
 private MyBehaviorTreeState TickChild(IMyBot bot, MyPerTreeBotMemory botTreeMemory, MyBehaviorTreeDecoratorNodeMemory thisMemory)
 {
     bot.BotMemory.RememberNode(m_child.MemoryIndex);
     var state = m_child.Tick(bot, botTreeMemory);
     thisMemory.NodeState = state;
     thisMemory.ChildState = state;
     if (state != MyBehaviorTreeState.RUNNING)
     {
         bot.BotMemory.ForgetNode();
     }
     return state;
 }
        public BotType TryGetBot <BotType>(int botHandler) where BotType : class, IMyBot
        {
            IMyBot bot = null;

            m_allBots.TryGetValue(botHandler, out bot);
            if (bot == null)
            {
                return((BotType)null);
            }

            return(bot as BotType);
        }
Esempio n. 38
0
 internal void SelectBotForDebugging(IMyBot bot)
 {
     this.m_behaviorTreeCollection.DebugBot = bot;
     for (int i = 0; i < this.m_botsQueue.Count; i++)
     {
         if (this.m_allBots[this.m_botsQueue[i]] == bot)
         {
             this.m_botIndex = i;
             return;
         }
     }
 }
Esempio n. 39
0
        public MyBehaviorTree TryGetBehaviorTreeForBot(IMyBot bot)
        {
            BTData data = null;

            m_BTDataByName.TryGetValue(m_botBehaviorIds[bot], out data);
            if (data != null)
            {
                return(data.BehaviorTree);
            }
            Debug.Assert(false, "Behavior not found");
            return(null);
        }
Esempio n. 40
0
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            bot.BotMemory.RememberNode(m_child.MemoryIndex);

            var state = m_child.Tick(bot, botTreeMemory);
            botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = state;

            if (state != MyBehaviorTreeState.RUNNING)
                bot.BotMemory.ForgetNode();

            return state;
        }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            if (bot.ActionCollection.ReturnsRunning(m_actionName))
                bot.BotMemory.ProcessLastRunningNode(this);

            var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex);
            if (!nodeMemory.InitCalled)
            {
                nodeMemory.InitCalled = true;
                if (bot.ActionCollection.ContainsInitAction(m_actionName))
                    bot.ActionCollection.PerformInitAction(bot, m_actionName);
            }

            var state = bot.ActionCollection.PerformAction(bot, m_actionName, m_parameters);
            nodeMemory.NodeState = state;
            return state;
        }
Esempio n. 42
0
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            bot.BotMemory.RememberNode(m_child.MemoryIndex);

            if ( Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS )
            {
                // store this old memory
                bot.LastBotMemory = bot.BotMemory.Clone();
            }

            var state = m_child.Tick(bot, botTreeMemory);
            botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = state;
            RecordRunningNodeName(bot, state);

            if (state != MyBehaviorTreeState.RUNNING)
                bot.BotMemory.ForgetNode();

            return state;
        }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeControlNodeMemory;
            for (int i = nodeMemory.InitialIndex; i < m_children.Count; i++)
            {
                bot.BotMemory.RememberNode(m_children[i].MemoryIndex);
                if (Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS)
                {
                    string childName = (m_children[i] is MyBehaviorTreeControlBaseNode) ? ((m_children[i] as MyBehaviorTreeControlBaseNode)).m_name : 
                        (m_children[i] is MyBehaviorTreeActionNode)? (m_children[i] as MyBehaviorTreeActionNode).GetActionName(): 
                        (m_children[i] is MyBehaviorTreeDecoratorNode)? (m_children[i] as MyBehaviorTreeDecoratorNode).GetName():
                        "";                     // just variable for conditional debugging
                    m_runningActionName = "";   // this line is good candidate for breakpoint is you want to debug special part of behavior tree
                }
                var state = m_children[i].Tick(bot, botTreeMemory);
                if (state == SearchedValue || state == FinalValue)
                    m_children[i].PostTick(bot, botTreeMemory);
                if (state == MyBehaviorTreeState.RUNNING || state == SearchedValue)
                {
                    nodeMemory.NodeState = state;
                    if (state == MyBehaviorTreeState.RUNNING)
                    {
                        if (m_isMemorable)
                            nodeMemory.InitialIndex = i;
                    }
                    else
                    {
                        bot.BotMemory.ForgetNode();
                    }
                    RecordRunningNodeName(state, m_children[i]);
                    return state;
                }
                bot.BotMemory.ForgetNode();
            }

            nodeMemory.NodeState = FinalValue;
            nodeMemory.InitialIndex = 0;
            return FinalValue;
        }
        public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
        {
            var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory;

            if (m_child == null)
                return m_defaultReturnValue;

            if (decoratorMemory.ChildState != MyBehaviorTreeState.RUNNING)
            {
                m_decoratorLogic.Update(decoratorMemory.DecoratorLogicMemory);
                if (m_decoratorLogic.CanRun(decoratorMemory.DecoratorLogicMemory))
                {
                    MyBehaviorTreeState state = TickChild(bot, botTreeMemory, decoratorMemory);
                    RecordRunningNodeName(state);
                    return state;
                }
                else
                {
                    if (IsRunningStateSource)
                        bot.BotMemory.ProcessLastRunningNode(this);

                    botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = m_defaultReturnValue;
                    if (Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS && m_defaultReturnValue == MyBehaviorTreeState.RUNNING)
                    {
                        m_runningActionName = ParentName + m_decoratorLogicName;
                    }
                        
                    return m_defaultReturnValue;
                }
            }
            else
            {
                MyBehaviorTreeState state = TickChild(bot, botTreeMemory, decoratorMemory);
                RecordRunningNodeName(state);
                return state;
                //return TickChild(bot, botTreeMemory, decoratorMemory);
            }
        }
Esempio n. 45
0
        void RecordRunningNodeName(IMyBot bot, MyBehaviorTreeState state)
        {
            if (!Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS || !(bot is MyAgentBot))
                return;

            switch(state)
            {
                case MyBehaviorTreeState.RUNNING:
                    (bot as MyAgentBot).LastActions.AddLastAction(m_child.m_runningActionName);
                    break;
                case MyBehaviorTreeState.ERROR:
                    (bot as MyAgentBot).LastActions.AddLastAction("error");
                    break;
                case MyBehaviorTreeState.FAILURE:
                    (bot as MyAgentBot).LastActions.AddLastAction("failure");
                    break;
                case MyBehaviorTreeState.SUCCESS:
                    (bot as MyAgentBot).LastActions.AddLastAction("failure");
                    break;
                case MyBehaviorTreeState.NOT_TICKED:
                    (bot as MyAgentBot).LastActions.AddLastAction("not ticked");
                    break;
            }
        }
        public void PerformPostAction(IMyBot bot, MyStringId actionId)
        {
            Debug.Assert(m_actions.ContainsKey(actionId), "Given bot action does not exist!");

            var action = m_actions[actionId];
            if (action == null) return;

            action.PostAction(bot);
        }
 public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory)
 {
     base.PostTick(bot, botTreeMemory);
     var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory;
     if (decoratorMemory.ChildState != MyBehaviorTreeState.NOT_TICKED)
     {
         decoratorMemory.PostTickMemory();
         if (m_child != null)
             m_child.PostTick(bot, botTreeMemory);
     }
     else
     {
         if (IsRunningStateSource)
             decoratorMemory.PostTickMemory();
     }
 }
Esempio n. 48
0
 public virtual void PostTick(IMyBot bot, MyPerTreeBotMemory nodesMemory) { }
Esempio n. 49
0
 public abstract MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory nodesMemory);
Esempio n. 50
0
 private void CreateActions(IMyBot bot, Type actionImplType)
 {
     var constructor = actionImplType.GetConstructor(new Type[] { bot.GetType() });
     if (constructor == null)
         bot.BotActions = Activator.CreateInstance(actionImplType) as MyBotActionsBase;
     else
         bot.BotActions = Activator.CreateInstance(actionImplType, bot) as MyBotActionsBase;
 }
Esempio n. 51
0
        private void CreateLogic(IMyBot output, Type defaultLogicType, string definitionLogicType)
        {
            Type logicType = null;
            if (m_logicDataByBehaviorSubtype.ContainsKey(definitionLogicType))
            {
                logicType = m_logicDataByBehaviorSubtype[definitionLogicType].LogicType;
                if (!logicType.IsSubclassOf(defaultLogicType) && logicType != defaultLogicType)
                {
                    logicType = defaultLogicType;
                }
            }
            else
            {
                logicType = defaultLogicType;
            }

            var logic = Activator.CreateInstance(logicType, output) as MyBotLogic;
            output.InitLogic(logic);
        }
 private void CreateActions(IMyBot bot, Type actionImplType)
 {
     m_tmpTypeArray[0] = bot.GetType();
     var constructor = actionImplType.GetConstructor(m_tmpTypeArray);
     if (constructor == null)
         bot.BotActions = Activator.CreateInstance(actionImplType) as MyBotActionsBase;
     else
         bot.BotActions = Activator.CreateInstance(actionImplType, bot) as MyBotActionsBase;
     m_tmpTypeArray[0] = null;
 }
Esempio n. 53
0
 public MyAgentLogic(IMyBot bot)
     : base(bot)
 {
 }
        public MyBehaviorTreeState PerformAction(IMyBot bot, MyStringId actionId, object[] args)
        {
            Debug.Assert(m_actions.ContainsKey(actionId), "Given bot action does not exist!");

            var action = m_actions[actionId];
            if (action == null) return MyBehaviorTreeState.ERROR;

            var botMemory = bot.BotMemory.CurrentTreeBotMemory;
            if (action.ParametersDesc.Count == 0)
            {
                return action.Action(bot, args);
            }
            else
            {
                Debug.Assert(args != null, "Args were not provided, aborting action");
                if (args == null)
                    return MyBehaviorTreeState.FAILURE;

                LoadActionParams(action, args, botMemory);
                var state = action.Action(bot, action.ActionParams);
                SaveActionParams(action, args, botMemory);
                return state;
            }
        }
 public static ActionCollection CreateActionCollection(IMyBot bot)
 {
     var actions = new ActionCollection();
     var methodInfos = bot.BotActions.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
     foreach (var methodInfo in methodInfos)
     {
         ExtractAction(actions, methodInfo);
     }
     return actions;
 }
Esempio n. 56
0
 public MyHumanoidBotLogic(IMyBot bot)
     : base(bot)
 {
 }
 public MyObjectBuilder_Bot GetBotObjectBuilder(IMyBot myAgentBot)
 {
     return m_objectFactory.CreateObjectBuilder<MyObjectBuilder_Bot>(myAgentBot);
 }
Esempio n. 58
0
 public void Tick(IMyBot bot)
 {
     m_root.Tick(bot, bot.BotMemory.CurrentTreeBotMemory);
 }
 public MyAbstractBotActionProxy GetActionsByBehaviorName(IMyBot bot, string name)
 {
     throw new NotImplementedException();
 }
Esempio n. 60
0
 public MyBotLogic(IMyBot bot)
 {
     m_bot = bot;
 }