/// <summary> /// Initialize slots by small ship's model and preferred weapon's positions /// </summary> /// <param name="shipTypeProperties">Type properties of ship</param> /// <param name="maxSlots">Maximum weapons that can be mounted</param> private void InitSlots(MyShipTypeProperties shipTypeProperties, int maxSlots) { // initialize slot for drill DrillSlot = new MyWeaponSlot(); DrillSlot.WeaponSubObject = MyModelSubObjects.GetModelSubObject(shipTypeProperties.Visual.ModelLod0Enum, DRILL_NAME); DrillSlot.OnWeaponMounting += m_weaponMounting; DrillSlot.OnWeaponDismouting += m_weaponDismounting; // initialize slot for harvester HarvestingDeviceSlot = new MyWeaponSlot(); HarvestingDeviceSlot.WeaponSubObject = MyModelSubObjects.GetModelSubObject(shipTypeProperties.Visual.ModelLod0Enum, HARVESTER_NAME); HarvestingDeviceSlot.OnWeaponMounting += m_weaponMounting; HarvestingDeviceSlot.OnWeaponDismouting += m_weaponDismounting; // initialize slots for weapons WeaponSlots = new List <MyWeaponSlot>(); AddGunsPositionsFromShipModel(shipTypeProperties.Visual.ModelLod0Enum, maxSlots); }
/// <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; } } } } }
/// <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); }