Esempio n. 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
        }
Esempio n. 2
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. 3
0
 private void CreateActions(IMyBot bot, Type actionImplType)
 {
     this.m_tmpTypeArray[0] = bot.GetType();
     if (actionImplType.GetConstructor(this.m_tmpTypeArray) == null)
     {
         bot.BotActions = Activator.CreateInstance(actionImplType) as MyBotActionsBase;
     }
     else
     {
         object[] args = new object[] { bot };
         bot.BotActions = Activator.CreateInstance(actionImplType, args) as MyBotActionsBase;
     }
     this.m_tmpTypeArray[0] = null;
 }
        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. 5
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;
         }
     }
 }
Esempio n. 6
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;
 }
 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;
 }