Beispiel #1
0
        public void EnableGrid(IMyCubeGrid grid)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);

            lock (GridDisabled)
            {
                if (!GridBlocksDisabled.ContainsKey(grid.EntityId))
                {
                    if (GridDisabled.Contains(grid.EntityId))
                    {
                        GridDisabled.Remove(grid.EntityId);
                    }

                    return;
                }
            }

            HashSet <long> disabledBlocks = GridBlocksDisabled[grid.EntityId];

            foreach (IMySlimBlock block in blocks)
            {
                if (block.FatBlock == null)
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;

                if (!(cubeBlock is IMyFunctionalBlock))
                {
                    continue;
                }

                if (!disabledBlocks.Contains(cubeBlock.EntityId))
                {
                    continue;
                }

                if (!FunctionalBlockEntity.GetState(cubeBlock))
                {
                    FunctionalBlockEntity.SetState(cubeBlock, true);
                    m_enableCount++;
                }
            }

            lock (GridDisabled)
            {
                if (GridDisabled.Contains(grid.EntityId))
                {
                    GridDisabled.Remove(grid.EntityId);
                }

                GridBlocksDisabled.Remove(grid.EntityId);
            }
        }
Beispiel #2
0
        private void GridListCleanup()
        {
            if (DateTime.Now - m_lastCleanup < TimeSpan.FromSeconds(120))
            {
                return;
            }

            m_lastCleanup = DateTime.Now;

            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(entities);

            lock (GridDisabled)
            {
                int removed = GridDisabled.RemoveWhere(x => entities.FirstOrDefault(y => y.EntityId == x) == null);
                if (removed > 0)
                {
                    Logging.WriteLineAndConsole(string.Format("Removed {0} entities from Disabled Grid List", removed));
                }

                HashSet <long> removeSet = new HashSet <long>();
                foreach (KeyValuePair <long, HashSet <long> > p in GridBlocksDisabled)
                {
                    if (entities.FirstOrDefault(x => x.EntityId == p.Key) == null)
                    {
                        removeSet.Add(p.Key);
                    }
                }

                foreach (long item in removeSet)
                {
                    GridBlocksDisabled.Remove(item);
                }
            }
        }