Exemplo n.º 1
0
        public IEnumerable <MyCubeBlock> Blocks(CubeGridCache cache)
        {
            if (m_sourceCount != CubeGridCache.DefinitionType.Count)
            {
                UpdateFromSource();
            }

            m_lock.AcquireShared();
            try
            {
                for (int order = 0; order < m_blocks.Length; order++)
                {
                    MyDefinitionId[] array = m_blocks[order];
                    for (int index = 0; index < array.Length; index++)
                    {
                        foreach (MyCubeBlock block in cache.BlocksOfType(array[index]))
                        {
                            yield return(block);
                        }
                    }
                }
            }
            finally
            {
                m_lock.ReleaseShared();
            }
        }
Exemplo n.º 2
0
        private bool GetStatorRotor(IMyCubeGrid grid, out IMyMotorStator Stator, IMyMotorStator IgnoreStator = null)
        {
            CubeGridCache cache = CubeGridCache.GetFor(grid);

            // first stator that are found that are not working
            // returned if a working set is not found
            IMyMotorStator offStator = null;

            foreach (MyObjectBuilderType type in types_Rotor)
            {
                foreach (IMyMotorRotor rotor in cache.BlocksOfType(type))
                {
                    if (!FaceBlock.canControlBlock(rotor))
                    {
                        Log.DebugLog("Cannot control: " + rotor.nameWithId());
                        continue;
                    }

                    Stator = (IMyMotorStator)rotor.Base;
                    if (Stator == null || Stator == IgnoreStator)
                    {
                        continue;
                    }

                    if (IgnoreStator != null && !ArePerpendicular(IgnoreStator, Stator))
                    {
                        Log.DebugLog("Not perpendicular: " + IgnoreStator.nameWithId() + " & " + Stator.nameWithId());
                        continue;
                    }

                    if (Stator.IsWorking)
                    {
                        return(true);
                    }
                    else if (offStator == null)
                    {
                        offStator = Stator;
                    }
                }
            }

            if (offStator != null)
            {
                Stator = offStator;
                return(true);
            }

            Stator = null;
            return(false);
        }