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);
        }
Example #2
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 IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition)
        {
            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);
            }
            Debug.Assert(m_botTypeByDefinitionType.ContainsKey(botDefinition.TypeDefinitionId.TypeId), "Type not found. Bot is not going to be created!");
            if (!m_botTypeByDefinitionType.ContainsKey(botDefinition.TypeDefinitionId.TypeId))
            {
                return(null);
            }
            var    botData          = m_botDataByBehaviorType[botDefinition.BehaviorType];
            var    behaviorTypeData = m_botTypeByDefinitionType[botDefinition.TypeDefinitionId.TypeId];
            IMyBot output           = CreateBot(behaviorTypeData.BotType, player, botDefinition);

            CreateActions(output, botData.BotActionsType);
            CreateLogic(output, botData.LogicType, botDefinition.BehaviorSubtype);
            if (botBuilder != null)
            {
                output.Init(botBuilder);
            }
            return(output);
        }