public static void DeleteTemplate(MySmallShipTemplate template)
        {
            Debug.Assert(!template.SavedToServer, "Cannot delete template that is already saved on server!");

            var typeTemplates = m_templates[(int)template.Builder.ShipType];

            bool deleted = typeTemplates.Remove(template);

            Debug.Assert(deleted);
        }
        public static void AddTemplate(MySmallShipTemplate newTemplate)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(newTemplate.Name.ToString()));
            Debug.Assert(newTemplate.Builder != null);

            var typeTemplates = m_templates[(int)newTemplate.Builder.ShipType];

            Debug.Assert(GetTemplate(typeTemplates, newTemplate.Name) == null);

            typeTemplates.Add(newTemplate);
        }
        private void OnEditBot(MyMwcObjectBuilder_SmallShip bldr, MySmallShipTemplate smallShipTemplate)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                smallShipTemplate.Builder.ShipType,
                null,
                null,
                null,
                smallShipTemplate.Builder.AssignmentOfAmmo,
                null,
                null,
                smallShipTemplate.Builder.ShipMaxHealth,
                smallShipTemplate.Builder.ShipHealthRatio,
                smallShipTemplate.Builder.ArmorHealth,
                smallShipTemplate.Builder.Oxygen,
                smallShipTemplate.Builder.Fuel,
                smallShipTemplate.Builder.ReflectorLight,
                smallShipTemplate.Builder.ReflectorLongRange,
                smallShipTemplate.Builder.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, bldr.AIPriority, false, true); // faction will be assigned after spawnpoint genertation
            newTemplate.m_builder.ShipTemplateID = smallShipTemplate.ID;
            newTemplate.m_name = smallShipTemplate.Name.ToString();
            int key = m_selectShipsListbox.GetSelectedItem().Key;
            m_selectShipsListbox.RemoveItem(key);
            
            m_selectShipsListbox.AddItem(key, smallShipTemplate.Name);

            m_bots[key] = newTemplate;
        }
        private void AddBot(MyMwcObjectBuilder_SmallShip bldr, MySmallShipTemplate smallShipTemplate)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;            

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                smallShipTemplate.Builder.ShipType,
                null,
                null,
                null,
                smallShipTemplate.Builder.AssignmentOfAmmo,
                null,
                null,
                smallShipTemplate.Builder.ShipMaxHealth,
                smallShipTemplate.Builder.ShipHealthRatio,
                smallShipTemplate.Builder.ArmorHealth,
                smallShipTemplate.Builder.Oxygen,
                smallShipTemplate.Builder.Fuel,
                smallShipTemplate.Builder.ReflectorLight,
                smallShipTemplate.Builder.ReflectorLongRange,
                smallShipTemplate.Builder.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, 0, false, true); // faction will be assigned after spawnpoint genertation
            newTemplate.m_builder.ShipTemplateID = smallShipTemplate.ID;            
            
            newTemplate.m_name = smallShipTemplate.Name.ToString();

            // find nearest new non template index
            int index = -1;
            foreach (int key in m_bots.Keys)
            {
                if (index < key && key < TEMPLATE_INDEX_OFFSET)
                {
                    index = key;
                }
            }
            index++;

            AddBot(index, newTemplate);

        }
        public static void DeleteTemplate(MySmallShipTemplate template)
        {
            Debug.Assert(!template.SavedToServer, "Cannot delete template that is already saved on server!");

            var typeTemplates = m_templates[(int)template.Builder.ShipType];

            bool deleted = typeTemplates.Remove(template);
            Debug.Assert(deleted);
        }
        public static void AddTemplate(MySmallShipTemplate newTemplate)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(newTemplate.Name.ToString()));
            Debug.Assert(newTemplate.Builder != null);

            var typeTemplates = m_templates[(int) newTemplate.Builder.ShipType];

            Debug.Assert(GetTemplate(typeTemplates, newTemplate.Name) == null);

            typeTemplates.Add(newTemplate);
        }
        private void OnRenameButtonClick(MyGuiControlButton sender)
        {
            var selectedItem = m_templatesListbox.GetSelectedItem();
            if (selectedItem != null)
            {
                var selectedType = (MyMwcObjectBuilder_SmallShip_TypesEnum)m_shipTypeCombobox.GetSelectedKey();
                m_selectedTemplate = MySmallShipTemplates.GetTemplate(selectedType, selectedItem.Value);

                MyGuiManager.AddScreen(new MyGuiScreenInputString(NameForRenameChosen, MyTextsWrapperEnum.NewTemplateName, m_selectedTemplate.Name));
            }
        }
        private void OnEditButtonClick(MyGuiControlButton sender)
        {
            var selectedItem = m_templatesListbox.GetSelectedItem();
            if (selectedItem != null)
            {
                var selectedType = (MyMwcObjectBuilder_SmallShip_TypesEnum) m_shipTypeCombobox.GetSelectedKey();
                m_selectedTemplate = MySmallShipTemplates.GetTemplate(selectedType, selectedItem.Value);

                var builders = new List<MySmallShipBuilderWithName> { new MySmallShipBuilderWithName(m_selectedTemplate.Builder) };

                var inventory = new MyInventory();
                inventory.FillInventoryWithAllItems(null, 100);
                var gui = new MyGuiScreenInventory(
                    builders,
                    0,
                    inventory.GetObjectBuilder(false),
                    MyTextsWrapper.Get(MyTextsWrapperEnum.AllItemsInventory));

                gui.OnSave += UpdateTemplate;
                MyGuiManager.AddScreen(gui);
            }
            else
            {
                WarnNotSelected();
            }
        }