コード例 #1
0
        /// <summary>
        /// Determines whether or not this ship can mount anything in the specified slot
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool CanUseSlot(ShipSlots slot)
        {
            int      Slot   = (int)slot;
            bool     Result = false;
            BitArray Mask   = null;

            if (Slot < 8)
            {
                if (Slot < 4)
                {
                    if (Slot >= _ship.WeaponMounts.Length)
                    {
                        return(false);
                    }

                    if (_ship.WeaponMounts[Slot].PartType != 1)
                    {
                        return(false);
                    }

                    Mask = _ship.WeaponMounts[Slot].PartMask;
                }
                else
                {
                    int TurretIndex = GetWeaponCount() + (Slot - 4);
                    if (TurretIndex >= _ship.WeaponMounts.Length)
                    {
                        return(false);
                    }
                    Mask = _ship.WeaponMounts[TurretIndex].PartMask;
                }
            }

            if (Mask == null)
            {
                Mask = _ship.UseMasks[((int)slot) - 8];
            }

            foreach (bool value in Mask)
            {
                if (value == true)
                {
                    Result = value;
                    break;
                }
            }

            return(Result);
        }
コード例 #2
0
        /// <summary>
        /// Determines whether or not this ship can mount the specified part
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public bool CanMountPart(IGCCorePart part, ShipSlots slot)
        {
            if (part == null)
            {
                return(CanUseSlot(slot));
            }

            bool     Result   = false;
            BitArray SlotMask = null;

            // Find which SlotMask we need to compare
            int MaskIndex = -1;

            switch (part.ModuleType)
            {
            case AGCObjectType.AGC_ChaffType:
                if (slot == ShipSlots.Chaff || (int)slot > 15)
                {
                    MaskIndex = (int)ShipUseMasks.Counter;
                }
                break;

            case AGCObjectType.AGC_MineType:
                if (slot == ShipSlots.Pack || (int)slot > 15)
                {
                    MaskIndex = (int)ShipUseMasks.Pack;
                }
                break;

            case AGCObjectType.AGC_MissileType:
                if (slot == ShipSlots.Missile || (int)slot > 15)
                {
                    MaskIndex = (int)ShipUseMasks.Missile;
                }
                break;

            case AGCObjectType.AGC_ProbeType:
                if (slot == ShipSlots.Pack || (int)slot > 15)
                {
                    MaskIndex = (int)ShipUseMasks.Pack;
                }
                break;

            case AGCObjectType.AGC_PartType:
                switch (part.PartType)
                {
                case PartType.Afterburner:
                    if (slot == ShipSlots.Booster || (int)slot > 15)
                    {
                        MaskIndex = (int)ShipUseMasks.Booster;
                    }
                    break;

                case PartType.Cloak:
                    if (slot == ShipSlots.Cloak || (int)slot > 15)
                    {
                        MaskIndex = (int)ShipUseMasks.Cloak;
                    }
                    break;

                case PartType.Shield:
                    if (slot == ShipSlots.Shield || (int)slot > 15)
                    {
                        MaskIndex = (int)ShipUseMasks.Shield;
                    }
                    break;

                case PartType.Pack:
                    if ((int)slot < 16)                                     // You can't mount ammo or fuel in bays
                    {
                        return(false);
                    }
                    else
                    {
                        SlotMask = new BitArray(16, true);
                    }
                    break;

                case PartType.Weapon:
                    int Slot = (int)slot;
                    if (Slot >= 8 && Slot < 16)
                    {
                        return(false);
                    }

                    if (Slot < 8)
                    {
                        if (_ship.WeaponMounts.Length == 0)
                        {
                            return(false);
                        }

                        if (Slot < 4)
                        {
                            SlotMask = (BitArray)_ship.WeaponMounts[Slot].PartMask.Clone();
                        }
                        else
                        {
                            SlotMask = (BitArray)_ship.WeaponMounts[GetWeaponCount() + (Slot - 4)].PartMask.Clone();
                        }
                    }
                    else
                    {
                        SlotMask = new BitArray(16, true);
                    }
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }

            // Get the required slot mask for comparison if it isn't a gun/turret
            if (SlotMask == null)
            {
                if (MaskIndex == -1)
                {
                    return(false);
                }
                SlotMask = (BitArray)_ship.UseMasks[MaskIndex].Clone();
            }

            SlotMask.And(part.UseMask);
            // Check if part matches the slot mask
            if (Techtree.BitArrayEquals(SlotMask, part.UseMask) || (int)slot > 15)
            {                   // Part can be mounted. Is it available?
                BitArray CurrentDefs = _team.CalculateDefs();
                CurrentDefs.And(part.Techtree.Pres);
                if (part.Techtree.PreEquals(CurrentDefs))
                {
                    Result = true;
                }
            }

            return(Result);
        }