Esempio n. 1
0
        private int WorkingDecoys(IMyEntity target)
        {
            IMyCubeGrid grid = target as IMyCubeGrid;

            if (grid == null || RelationsBlock.canConsiderFriendly(grid))
            {
                return(0);
            }

            CubeGridCache cache = CubeGridCache.GetFor(grid);

            if (cache == null)
            {
                return(0);
            }
            return(cache.CountByType(typeof(MyObjectBuilder_Decoy), block => block.IsWorking));
        }
Esempio n. 2
0
        private static LinkedList <Ingame.IMyTextPanel> findTextPanel(IMyCubeBlock showoff)
        {
            string searchForName = getTextPanelName(showoff);

            if (searchForName == null)
            {
                return(null);
            }

            List <IMySlimBlock> allBlocks = new List <IMySlimBlock>();

            showoff.CubeGrid.GetBlocks(allBlocks);

            LinkedList <Ingame.IMyTextPanel> textPanels = new LinkedList <Ingame.IMyTextPanel>();

            foreach (IMySlimBlock block in allBlocks)
            {
                IMyCubeBlock fatblock = block.FatBlock;
                if (fatblock == null)
                {
                    continue;
                }

                Ingame.IMyTextPanel panel = fatblock as Ingame.IMyTextPanel;
                if (panel == null)
                {
                    log("not a panel: " + fatblock.DisplayNameText, "findTextPanel()", Logger.severity.TRACE);
                    continue;
                }

                if (!showoff.canConsiderFriendly(fatblock))
                {
                    log("not friendly: " + fatblock.DisplayNameText, "findTextPanel()", Logger.severity.TRACE);
                    continue;
                }

                if (fatblock.DisplayNameText.looseContains(searchForName))
                {
                    log("adding panel: " + fatblock.DisplayNameText, "findTextPanel()", Logger.severity.TRACE);
                    textPanels.AddLast(panel);
                }
            }
            return(textPanels);
        }
Esempio n. 3
0
        /// <summary>
        /// Tests for sendFrom is working and grid attached or in range. Use without range to skip range test. If sendTo is not a block or a grid, will skip grid test. If sendTo is a block, it must be working.
        /// </summary>
        /// <param name="sendFrom"></param>
        /// <param name="sendTo"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        public static bool canSendTo(this IMyCubeBlock sendFrom, IMyEntity sendTo, bool friendsOnly, float range = 0, bool rangeIsSquared = false)
        {
            sendFrom.throwIfNull_argument("sendFrom");
            sendTo.throwIfNull_argument("sendTo");

            if (sendFrom.Closed || !sendFrom.IsWorking)
            {
                return(false);
            }

            IMyCubeBlock sendToAsBlock = sendTo as IMyCubeBlock;

            if (sendToAsBlock != null)
            {
                if (sendToAsBlock.Closed || !sendToAsBlock.IsWorking)
                {
                    return(false);
                }

                if (friendsOnly && !sendFrom.canConsiderFriendly(sendToAsBlock))
                {
                    return(false);
                }

                if (AttachedGrids.isGridAttached(sendFrom.CubeGrid, sendToAsBlock.CubeGrid))
                {
                    return(true);
                }

                if (range > 0)
                {
                    double distanceSquared = (sendFrom.GetPosition() - sendTo.GetPosition()).LengthSquared();
                    if (rangeIsSquared)
                    {
                        return(distanceSquared < range);
                    }
                    else
                    {
                        return(distanceSquared < range * range);
                    }
                }
            }
            else
            {
                IMyCubeGrid sendToAsGrid = sendTo as IMyCubeGrid;
                if (sendToAsGrid != null)
                {
                    if (friendsOnly && !sendFrom.canConsiderFriendly(sendToAsGrid))
                    {
                        return(false);
                    }

                    if (Rynchodon.AttachedGrids.isGridAttached(sendFrom.CubeGrid, sendToAsGrid))
                    {
                        return(true);
                    }
                }

                // may or may not be grid
                if (range > 0)
                {
                    double distance = sendTo.WorldAABB.Distance(sendFrom.GetPosition());
                    if (rangeIsSquared)
                    {
                        return(distance * distance < range);
                    }
                    else
                    {
                        return(distance < range);
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
 private bool IsConnected(RelayNode node)
 {
     return(!node.Block.Closed && node.Block.IsWorking && m_block.canConsiderFriendly(node.Block) && AttachedGrid.IsGridAttached(m_block.CubeGrid, node.Block.CubeGrid, AttachedGrid.AttachmentKind.Terminal));
 }