コード例 #1
0
        /// <summary>
        /// Creates gun's positions from ship's model. If find preferred position, then mark it as preffered.
        /// </summary>
        /// <param name="modelEnum">Ship's model</param>
        /// <param name="maxSlots">Weapons maximum on ship</param>
        /// <param name="maxWeapons"> </param>
        private void AddGunsPositionsFromShipModel(MyModelsEnum modelEnum, int maxSlots)
        {
            List <MyModelSubObject> shipsSubObjects = MyModelSubObjects.GetModelSubObjects(modelEnum);

            if (shipsSubObjects != null)
            {
                for (int i = 0; i < maxSlots; i++)
                {
                    string gunPrefix = GUN_PREFIX_NAME + (i + 1).ToString("##00");

                    // try find guns subobject by prefix (GUN_XX)
                    MyModelSubObject subObjectGun = shipsSubObjects.Find(x => x.Name.StartsWith(gunPrefix));

                    // if not found, then stop adding gun's positions, because there are no gun's subobjects
                    if (subObjectGun == null)
                    {
                        return;
                    }

                    // if not exists slot at this index, then create new one
                    if (WeaponSlots.Count <= i)
                    {
                        MyWeaponSlot newWeaponSlot = new MyWeaponSlot();
                        WeaponSlots.Add(newWeaponSlot);
                        newWeaponSlot.OnWeaponMounting   += m_weaponMounting;
                        newWeaponSlot.OnWeaponDismouting += m_weaponDismounting;
                    }

                    WeaponSlots[i].WeaponSubObject = subObjectGun;

                    // if this gun's position is preffered by any gun
                    if (subObjectGun.Name.Length != gunPrefix.Length)
                    {
                        string prefferedGunName = subObjectGun.Name.Substring(gunPrefix.Length + 1, subObjectGun.Name.Length - gunPrefix.Length - 1);
                        MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum weaponType;
                        if (m_weaponsModelNames.TryGetValue(prefferedGunName, out weaponType))
                        {
                            WeaponSlots[i].WeaponSubObject.AuxiliaryParam0 = (int)weaponType;
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns max weapon's slots from ship's model enum
        /// </summary>
        /// <param name="shipModelEnum">Ship's model enum</param>
        /// <returns>Max weapon's slots</returns>
        public static int GetMaxWeaponsSlots(MyModelsEnum shipModelEnum)
        {
            int slots = 0;
            List <MyModelSubObject> shipsSubObjects = MyModelSubObjects.GetModelSubObjects(shipModelEnum);

            while (true)
            {
                string gunPrefix = GUN_PREFIX_NAME + (slots + 1).ToString("##00");

                // try find guns subobject by prefix (GUN_XX)
                MyModelSubObject subObjectGun = shipsSubObjects.Find(x => x.Name.StartsWith(gunPrefix));

                // if not found, then stop adding gun's positions, because there are no gun's subobjects
                if (subObjectGun == null)
                {
                    break;
                }
                slots++;
            }
            return(slots);
        }