protected override void GuideMissiles(HashSet <IMyEntity> missileSet)
 {
     // Log.Info("called guidemissiles in flarelauncher");
     try
     {
         if (missileSet == null)
         {
             return;
         }
         if (missileSet.Count == 0)
         {
             return;
         }
         Log.Info("Set wasnt 0 or empty");
         ISet <IMyEntity> incomingMissiles = GuidedMissileSingleton.GetMissilesByTargetGrid(Entity.GetTopMostParent());
         if (incomingMissiles.Count == 0)
         {
             return;
         }
         foreach (IMyEntity guidedMissile in incomingMissiles)
         {
             foreach (IMyEntity flare in missileSet)
             {
                 if (!_flareSet.Contains(flare))
                 {
                     Log.Info("got a flare: ");
                     _flareSet.Add(flare);
                     int randomNumber = GuidedMissileCore.GetSyncedRandom().Next(1, 10);
                     if (randomNumber > (int)Math.Round(DeflectChance * 10))
                     {
                         GuidedMissileSingleton.SetTargetForMissile(guidedMissile, flare);
                         Log.Info("won dice roll! setting flare target for missile! " + randomNumber);
                     }
                     else
                     {
                         Log.Info("failed dice roll! not deflecting missile! " + randomNumber);
                     }
                 }
             }
         }
         foreach (IMyEntity flare in _flareSet)
         {
             if ((flare == null) || (flare.MarkedForClose))
             {
                 _deleteSet.Add(flare);
             }
             _flareSet.ExceptWith(_deleteSet);
             _deleteSet.Clear();
         }
     }
     catch (Exception e)
     {
         Log.Info("flares failed to work! caught exception: " + e);
     }
 }
        public static IMyEntity GetRandomBlockInGrid(IMyEntity grid)
        {
            if (grid == null)
            {
                return(null);
            }
            // if(target.OwnerId == Entity.OwnerId) return false; //faction check?
            if (grid.Hierarchy == null)
            {
                return(null);
            }
            if (grid.Hierarchy.Children == null)
            {
                return(null);
            }
            HashSet <IMyEntity> componentSet = new HashSet <IMyEntity>();

            grid.Hierarchy.GetChildrenRecursive(componentSet);
            List <IMyEntity> componentList = new List <IMyEntity>();

            componentList.AddRange(componentSet);
            IMyEntity randomTarget = null;

            //  Random r = new Random();

            if (componentList.Count == 0)
            {
                return(null);
            }
            // Log.Info("ComponentList.Count = " + componentList.Count);
            while (randomTarget == null)
            {
                int randInt = GuidedMissileCore.GetSyncedRandom().Next(0, componentList.Count - 1);

                randomTarget = componentList[randInt];
                //Log.Info("Got random block: " + randomTarget.GetType() + " by virtue of random number: " + randInt);
            }

            return(randomTarget);
        }