Пример #1
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 = null;

            if (!m_botActions.ContainsKey(newBot.BotActions.GetType()))
            {
                botActions = new ActionCollection();
                GetBotActions(newBot, botActions);
                m_botActions[newBot.GetType()] = botActions;
            }
            else
            {
                botActions = m_botActions[newBot.GetType()];
            }

            newBot.InitActions(botActions);
            if (string.IsNullOrEmpty(newBot.BehaviorSubtypeName))
            {
                m_behaviorTreeCollection.AssignBotToBehaviorTree(newBot.BotDefinition.BotBehaviorTree.SubtypeName, newBot);
            }
            else
            {
                m_behaviorTreeCollection.AssignBotToBehaviorTree(newBot.BehaviorSubtypeName, newBot);
            }
            m_allBots.Add(botHandler, newBot);
            m_botsQueue.Add(botHandler);

            if (m_botsCountPerBehavior.ContainsKey(newBot.BotDefinition.BehaviorType))
            {
                m_botsCountPerBehavior[newBot.BotDefinition.BehaviorType]++;
            }
            else
            {
                m_botsCountPerBehavior[newBot.BotDefinition.BehaviorType] = 1;
            }

#if DEBUG
            if (Sandbox.Game.Gui.MyMichalDebugInputComponent.Static != null && Sandbox.Game.Gui.MyMichalDebugInputComponent.Static.OnSelectDebugBot)
            {
                Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS = true;
                SelectBotForDebugging(newBot);
            }
#endif
        }
Пример #2
0
 public void AddBot(int botHandler, IMyBot newBot)
 {
     if (!this.m_allBots.ContainsKey(botHandler))
     {
         ActionCollection actionCollection = null;
         if (this.m_botActions.ContainsKey(newBot.BotActions.GetType()))
         {
             actionCollection = this.m_botActions[newBot.GetType()];
         }
         else
         {
             actionCollection = ActionCollection.CreateActionCollection(newBot);
             this.m_botActions[newBot.GetType()] = actionCollection;
         }
         newBot.InitActions(actionCollection);
         if (string.IsNullOrEmpty(newBot.BehaviorSubtypeName))
         {
             this.m_behaviorTreeCollection.AssignBotToBehaviorTree(newBot.BotDefinition.BotBehaviorTree.SubtypeName, newBot);
         }
         else
         {
             this.m_behaviorTreeCollection.AssignBotToBehaviorTree(newBot.BehaviorSubtypeName, newBot);
         }
         this.m_allBots.Add(botHandler, newBot);
         this.m_botsQueue.Add(botHandler);
         if (!this.m_botsCountPerBehavior.ContainsKey(newBot.BotDefinition.BehaviorType))
         {
             this.m_botsCountPerBehavior[newBot.BotDefinition.BehaviorType] = 1;
         }
         else
         {
             string behaviorType = newBot.BotDefinition.BehaviorType;
             this.m_botsCountPerBehavior[behaviorType] += 1;
         }
     }
 }