Example #1
0
        //GetTargetShipSystem
        public static void GetFilteredBlockLists(IMyCubeGrid targetGrid, BlockTargetTypes systemTarget, out List <IMyTerminalBlock> targetBlocksList, out List <IMyTerminalBlock> decoyList)
        {
            decoyList        = new List <IMyTerminalBlock>();
            targetBlocksList = new List <IMyTerminalBlock>();

            try{
                var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(targetGrid);
                List <IMyTerminalBlock> blockList = new List <IMyTerminalBlock>();
                gts.GetBlocksOfType <IMyTerminalBlock>(blockList);

                foreach (var block in blockList)
                {
                    if (block.IsFunctional == false)
                    {
                        continue;
                    }

                    if (block as IMyDecoy != null)
                    {
                        decoyList.Add(block);

                        if (systemTarget == BlockTargetTypes.Decoys)
                        {
                            targetBlocksList.Add(block);
                        }

                        continue;
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.All))
                    {
                        targetBlocksList.Add(block);
                        continue;
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Communications))
                    {
                        if (block as IMyLaserAntenna != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }

                        if (block as IMyBeacon != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }

                        if (block as IMyRadioAntenna != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Containers))
                    {
                        if (block as IMyCargoContainer != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.GravityBlocks))
                    {
                        if (block as IMyGravityGeneratorBase != null || block as IMyArtificialMassBlock != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Guns))
                    {
                        if (block as IMyUserControllableGun != null && block as IMyLargeTurretBase == null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.JumpDrive))
                    {
                        if (block as IMyJumpDrive != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Power))
                    {
                        if (block as IMyPowerProducer != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Production))
                    {
                        if (block as IMyProductionBlock != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }

                        if (block as IMyGasGenerator != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Propulsion))
                    {
                        if (block as IMyThrust != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Shields))
                    {
                        if (ShieldBlockIDs.Contains(block.SlimBlock.BlockDefinition.Id) == true)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.ShipControllers))
                    {
                        if (block as IMyShipController != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Tools))
                    {
                        if (block as IMyShipToolBase != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }

                    if (systemTarget.HasFlag(BlockTargetTypes.Turrets))
                    {
                        if (block as IMyLargeTurretBase != null)
                        {
                            targetBlocksList.Add(block);
                            continue;
                        }
                    }
                }
            }catch (Exception exc) {
            }
        }
Example #2
0
        public static List <IMyEntity> FilterBlocksByFamily(List <IMyEntity> entityList, BlockTargetTypes family, bool replaceResultWithDecoys = false)
        {
            var blockList = new List <IMyEntity>();
            var decoyList = new List <IMyEntity>();

            if (family.HasFlag(BlockTargetTypes.All) == true)
            {
                return(entityList);
            }

            for (int i = entityList.Count - 1; i >= 0; i--)
            {
                var block = entityList[i] as IMyTerminalBlock;

                if (block == null)
                {
                    continue;
                }

                //Decoys
                if (family.HasFlag(BlockTargetTypes.Decoys) == true)
                {
                    if (block as IMyDecoy != null)
                    {
                        blockList.Add(block);
                        decoyList.Add(block);
                        continue;
                    }
                }

                //Shields
                if (family.HasFlag(BlockTargetTypes.Shields) == true)
                {
                    if (ShieldBlockIDs.Contains(block.SlimBlock.BlockDefinition.Id) == true)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Containers
                if (family.HasFlag(BlockTargetTypes.Containers) == true)
                {
                    if (block as IMyCargoContainer != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //GravityBlocks
                if (family.HasFlag(BlockTargetTypes.GravityBlocks) == true)
                {
                    if (block as IMyGravityGeneratorBase != null || block as IMyArtificialMassBlock != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Guns
                if (family.HasFlag(BlockTargetTypes.Guns) == true)
                {
                    if (block as IMyUserControllableGun != null && block as IMyLargeTurretBase == null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //JumpDrive
                if (family.HasFlag(BlockTargetTypes.JumpDrive) == true)
                {
                    if (block as IMyJumpDrive != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Power
                if (family.HasFlag(BlockTargetTypes.Power) == true)
                {
                    if (block as IMyPowerProducer != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Production
                if (family.HasFlag(BlockTargetTypes.Production) == true)
                {
                    if (block as IMyProductionBlock != null || block as IMyGasGenerator != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Propulsion
                if (family.HasFlag(BlockTargetTypes.Propulsion) == true)
                {
                    if (block as IMyThrust != null || block as IMyGyro != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //ShipControllers
                if (family.HasFlag(BlockTargetTypes.ShipControllers) == true)
                {
                    if (block as IMyShipController != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Tools
                if (family.HasFlag(BlockTargetTypes.Tools) == true)
                {
                    if (block as IMyShipToolBase != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Turrets
                if (family.HasFlag(BlockTargetTypes.Turrets) == true)
                {
                    if (block as IMyLargeTurretBase != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }

                //Communications
                if (family.HasFlag(BlockTargetTypes.Communications) == true)
                {
                    if (block as IMyRadioAntenna != null || block as IMyLaserAntenna != null)
                    {
                        blockList.Add(block);
                        continue;
                    }
                }
            }

            if (replaceResultWithDecoys == true && decoyList.Count > 0)
            {
                return(decoyList);
            }
            else
            {
                return(blockList);
            }
        }