当前位置: 首页>>代码示例>>C#>>正文


C# IMyCubeGrid.GetBlocks方法代码示例

本文整理汇总了C#中IMyCubeGrid.GetBlocks方法的典型用法代码示例。如果您正苦于以下问题:C# IMyCubeGrid.GetBlocks方法的具体用法?C# IMyCubeGrid.GetBlocks怎么用?C# IMyCubeGrid.GetBlocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMyCubeGrid的用法示例。


在下文中一共展示了IMyCubeGrid.GetBlocks方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ThrustProfiler

		public ThrustProfiler(IMyCubeGrid grid)
		{
			if (grid == null)
				throw new NullReferenceException("grid");

			myLogger = new Logger("ThrustProfiler", () => grid.DisplayName);
			myGrid = grid;

			foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections)
				thrustersInDirection.Add(direction, new List<MyThrust>());

			List<IMySlimBlock> thrusters = new List<IMySlimBlock>();
			myGrid.GetBlocks(thrusters, block => block.FatBlock != null && block.FatBlock is IMyThrust);
			foreach (IMySlimBlock thrust in thrusters)
				newThruster(thrust);

			myGrid.OnBlockAdded += grid_OnBlockAdded;
			myGrid.OnBlockRemoved += grid_OnBlockRemoved;
		}
开发者ID:helppass,项目名称:Autopilot,代码行数:19,代码来源:ThrustProfiler.cs

示例2: GridCellCache

        private GridCellCache(IMyCubeGrid grid)
        {
            m_logger = new Logger("GridCellCache", () => grid.DisplayName);
            m_grid = grid;

            List<IMySlimBlock> dummy = new List<IMySlimBlock>();
            MainLock.UsingShared(() => {
                using (lock_cellPositions.AcquireExclusiveUsing())
                    grid.GetBlocks(dummy, slim => {
                        Add(slim);
                        return false;
                    });

                grid.OnBlockAdded += grid_OnBlockAdded;
                grid.OnBlockRemoved += grid_OnBlockRemoved;
                grid.OnClosing += grid_OnClosing;
            });

            m_logger.debugLog("Initialized");
        }
开发者ID:Souper07,项目名称:Autopilot,代码行数:20,代码来源:GridShapeProfiler.cs

示例3: ThrustProfiler

        public ThrustProfiler(IMyCubeBlock autopilot)
        {
            if (autopilot == null)
                throw new NullReferenceException("autopilot");

            myLogger = new Logger(GetType().Name, autopilot);
            myGrid = autopilot.CubeGrid;
            Standard = new StandardFlight(autopilot, Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
            Gravity = new StandardFlight(autopilot, Base6Directions.Direction.Up, Base6Directions.Direction.Forward);

            foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections)
                thrustersInDirection.Add(direction, new List<MyThrust>());

            List<IMySlimBlock> thrusters = new List<IMySlimBlock>();
            myGrid.GetBlocks(thrusters, block => block.FatBlock != null && block.FatBlock is IMyThrust);
            foreach (IMySlimBlock thrust in thrusters)
                newThruster(thrust);

            myGrid.OnBlockAdded += grid_OnBlockAdded;
            myGrid.OnBlockRemoved += grid_OnBlockRemoved;

            ClearOverrides();
        }
开发者ID:Souper07,项目名称:Autopilot,代码行数:23,代码来源:ThrustProfiler.cs

示例4: GetZonesInGrid

        public static Dictionary<string, List<IMyCubeBlock>> GetZonesInGrid(IMyCubeGrid cubeGrid)
        {
            Dictionary<String, List<IMyCubeBlock>> testList = new Dictionary<string, List<IMyCubeBlock>>();
            List<IMySlimBlock> cubeBlocks = new List<IMySlimBlock>();
            cubeGrid.GetBlocks(cubeBlocks);
            foreach (IMySlimBlock entityBlock in cubeBlocks)
            {
                if (entityBlock.FatBlock == null)
                    continue;

                if (!(entityBlock.FatBlock is IMyCubeBlock))
                    continue;

                IMyCubeBlock cubeBlock = (IMyCubeBlock)entityBlock.FatBlock;

                if (!(cubeBlock is Sandbox.ModAPI.Ingame.IMyBeacon))
                    continue;

                Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock;
                if (beacon.CustomName == null || beacon.CustomName == "")
                    continue;

                if (testList.ContainsKey(beacon.CustomName))
                {
                    testList[beacon.CustomName].Add(entityBlock.FatBlock);
                }
                else
                {
                    List<IMyCubeBlock> testBeaconList = new List<IMyCubeBlock>();
                    testBeaconList.Add(entityBlock.FatBlock);
                    testList.Add(beacon.CustomName, testBeaconList);
                }
            }

            Dictionary<String, List<IMyCubeBlock>> resultList = new Dictionary<string, List<IMyCubeBlock>>();
            foreach (KeyValuePair<String, List<IMyCubeBlock>> p in testList)
            {
                if (p.Value.Count == 4)
                {
                    resultList.Add(p.Key, p.Value);
                }
            }

            return resultList;
        }
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:45,代码来源:DockingZone.cs

示例5: GetGridBlocks

 private static void GetGridBlocks( IMyCubeGrid grid, List<IMySlimBlock> blockList, Func<IMySlimBlock, bool> collect = null )
 {
     blockList.Clear( );
     List<IMySlimBlock> blocks = new List<IMySlimBlock>( );
     grid.GetBlocks( blocks, collect );
     blockList.AddRange( blocks );
 }
开发者ID:Pingperfect,项目名称:EssentialsPlugin,代码行数:7,代码来源:CubeGrid.cs

示例6: EnableGrid

		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);
					_enableCount++;
				}
			}

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

				GridBlocksDisabled.Remove(grid.EntityId);
			}
		}
开发者ID:dodexahedron,项目名称:EssentialsPlugin,代码行数:46,代码来源:BlockManagement.cs

示例7: DisableGrid

		private void DisableGrid(IMyCubeGrid grid)
		{
			HashSet<long> disabledBlocks = new HashSet<long>();
			List<IMySlimBlock> blocks = new List<IMySlimBlock>();
			grid.GetBlocks(blocks);

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

				IMyCubeBlock cubeBlock = block.FatBlock;

				if(!(cubeBlock is IMyFunctionalBlock))
					continue;

				if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
					cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Thrust) ||
					cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Battery) ||
					cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel) ||
					cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Gyro) ||
					cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
				{
					continue;
				}

				if(cubeBlock is IMyProductionBlock)
				{
					IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;

					if (productionBlock.IsProducing)
						continue;
				}

				if (FunctionalBlockEntity.GetState(cubeBlock))
				{
					FunctionalBlockEntity.SetState(cubeBlock, false);
					disabledBlocks.Add(cubeBlock.EntityId);
					_enableCount++;
				}
			}

			lock (GridDisabled)
			{
				GridDisabled.Add(grid.EntityId);
				//if (disabledBlocks.Count > 0)
				//{
					Console.WriteLine("Adding");
					GridBlocksDisabled.Add(grid.EntityId, disabledBlocks);
				//}				
			}
		}
开发者ID:dodexahedron,项目名称:EssentialsPlugin,代码行数:52,代码来源:BlockManagement.cs

示例8: _cubeGrid_OnBlockOwnershipChanged

        private void _cubeGrid_OnBlockOwnershipChanged(IMyCubeGrid cubeGrid)
        {
            // only execute on server instance
            if (ChatCommandLogic.Instance != null && ChatCommandLogic.Instance.ServerCfg == null)
                return;

            if (_firstOwnershipChange)
            {
                _firstOwnershipChange = false;
                _cachedOwners = new List<long>(cubeGrid.GetAllSmallOwners());
                return;
            }

            var allSmallOwners = cubeGrid.GetAllSmallOwners();

            if (_cachedOwners == allSmallOwners)
                return;

            // if the grid wasn't owned or a owner was removed, we dont need to do anything but update the cached owners
            if (_cachedOwners.Count == 0 || _cachedOwners.Count > allSmallOwners.Count)
            {
                _cachedOwners = new List<long>(allSmallOwners);
                return;
            }

            var newOwners = allSmallOwners.Except(_cachedOwners).ToList();

            if (newOwners.Count == 0)
                return;

            if (!ProtectionHandler.IsProtected(cubeGrid))
            {
                _cachedOwners = new List<long>(allSmallOwners);
                return;
            }

            Dictionary<long, int> blocksPerOwner = new Dictionary<long, int>();

            foreach (IMyCubeGrid attachedCubeGrid in cubeGrid.GetAttachedGrids(AttachedGrids.Static))
            {

                List<IMySlimBlock> blocks = new List<IMySlimBlock>();
                attachedCubeGrid.GetBlocks(blocks, b => b.FatBlock != null);

                foreach (IMySlimBlock block in blocks)
                {
                    long ownerId = block.FatBlock.OwnerId;

                    // we dont want the new owners, the small owners or the 'nobody' (0)
                    if (ownerId == 0 || !attachedCubeGrid.BigOwners.Contains(ownerId) || newOwners.Contains(ownerId))
                        continue;

                    if (!blocksPerOwner.ContainsKey(ownerId))
                        blocksPerOwner.Add(ownerId, 1);
                    else
                        blocksPerOwner[ownerId]++;
                }
            }

            var sortedBpo = new List<KeyValuePair<long, int>>(blocksPerOwner.OrderBy(pair => pair.Value));

            // if we cannot identify an owner we allow the change
            if (sortedBpo.Count == 0)
            {
                _cachedOwners = new List<long>(allSmallOwners);
                return;
            }

            var bigOwner = sortedBpo[0].Key;

            List<IMySlimBlock> ownershipChangedBlocks = new List<IMySlimBlock>();
            cubeGrid.GetBlocks(ownershipChangedBlocks, b => b.FatBlock != null && newOwners.Contains(b.FatBlock.OwnerId));
            foreach (IMySlimBlock slimBlock in ownershipChangedBlocks)
            {
                var block = (Sandbox.Game.Entities.MyCubeBlock)slimBlock.FatBlock;
                block.ChangeOwner(bigOwner, MyOwnershipShareModeEnum.None);
                ConnectionHelper.SendMessageToAllPlayers(new MessageSyncBlockOwner() {OwnerId = bigOwner, EntityId = block.EntityId});
                // no need to update the cached owners as we don't want them to change
            }

            // TODO maybe allow the faction to build...
        }
开发者ID:DigTron,项目名称:Space-Engineers-Admin-script-mod,代码行数:82,代码来源:ProtectedCubeGrid.cs

示例9: GetBoundingBox

        public static OrientedBoundingBoxD GetBoundingBox(IMyCubeGrid entity)
        {
            var min = new Vector3D(int.MaxValue, int.MaxValue, int.MaxValue);
            var max = new Vector3D(int.MinValue, int.MinValue, int.MinValue);

            float multiplier = 2.5f;
            if (entity.GridSizeEnum == MyCubeSize.Small)
                multiplier = 0.5f;

            List<IMySlimBlock> blocks = new List<IMySlimBlock>();
            entity.GetBlocks(blocks, null);

            foreach (IMySlimBlock block in blocks)
            {
                //Vector3 pos = Entity.GetBlockEntityPosition(block);
                min = Vector3D.Min(block.Position * multiplier, min);
                max = Vector3D.Max(block.Position * multiplier, max);
            }

            Vector3D size = max - min;
            BoundingBoxD bb = new BoundingBoxD(new Vector3D(0, 0, 0), size).Translate(entity.GetPosition() - (size / 2));
            return new OrientedBoundingBoxD(bb.Center, bb.HalfExtents, Quaternion.CreateFromRotationMatrix(entity.WorldMatrix.GetOrientation()));
        }
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:23,代码来源:Entity.cs

示例10: CheckRevealMedbay

        private static bool CheckRevealMedbay(IMyCubeGrid grid, ulong steamId)
        {
            // Live dangerously
            List<IMySlimBlock> blocks = new List<IMySlimBlock>();
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                        continue;

                    long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                    //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                    if(medical.HasPlayerAccess(playerId))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:26,代码来源:EntityManagement.cs

示例11: CheckRevealBlockRules

        private static bool CheckRevealBlockRules(IMyCubeGrid grid, List<IMyPlayer> players, out string reason)
        {
            reason = "";
            // This is actually faster, but doesn't include power checks

            // Live dangerously
            List<IMySlimBlock> blocks = new List<IMySlimBlock>();
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(m_processedGrids, grid, blocks, x => x.FatBlock != null);
            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock;
                    if (!beacon.Enabled)
                        continue;

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    //Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to beacon broadcast: {1}", player.DisplayName, distance);
                                return true;
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                        continue;

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to antenna broadcast: {1}", player.DisplayName, distance);
                                return true;
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                        continue;

                    Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    if (!functionalBlock.IsFunctional)
                        continue;

                    //if (!functionalBlock.Enabled)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (m_online)
                        {
                            foreach (ulong connectedPlayer in m_online)
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                                //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                                if (functionalBlock.OwnerId == playerId)
                                {
                                    reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                                    return true;
//.........这里部分代码省略.........
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:101,代码来源:EntityManagement.cs

示例12: CheckConcealBlockRules

        private static bool CheckConcealBlockRules(IMyCubeGrid grid, List<IMyPlayer> players)
        {
            List<IMySlimBlock> blocks = new List<IMySlimBlock>();

            // Live dangerously
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(m_processedGrids, grid, blocks, x => x.FatBlock != null);

            int beaconCount = 0;
            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock;
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    beaconCount++;
                    // Keep this return here, as 4 beacons always means true
                    if(beaconCount >= 4)
                    {
                        return true;
                    }

                    if (!beacon.Enabled)
                        continue;

                    Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.IMyTerminalBlock)cubeBlock;
            //					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //{
            //						continue;
                    //}

                    foreach(IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if(Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
            //								Console.WriteLine("Not concealed due to broadcast radius");
                                //found = true;
                                //break;
                                return true;
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                        continue;

                    Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.IMyTerminalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
            //								Console.WriteLine("Not concealed due to antenna broadcast radius");
                                //found = true;
                                //break;
                                return true;
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock;

                    if (!medical.Enabled)
                        continue;

                    Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    if(PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (m_online)
                        {
                            foreach (ulong connectedPlayer in m_online)
                            {
                                //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                                //continue;
//.........这里部分代码省略.........
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:101,代码来源:EntityManagement.cs

示例13: SwitchShipSystemsOnOff

        private int SwitchShipSystemsOnOff(IMyCubeGrid cubeGrid, SwitchSystems control, bool mode)
        {
            int counter = 0;
            var blocks = new List<IMySlimBlock>();
            cubeGrid.GetBlocks(blocks, f => f.FatBlock != null);

            foreach (var block in blocks)
            {
                // reactors, batteries
                if ((SwitchSystems.Power & control) == SwitchSystems.Power && block.FatBlock is IMyFunctionalBlock
                    && (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock)))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                // refineries, arc furnaces, assemblers
                if ((SwitchSystems.Production & control) == SwitchSystems.Production && block.FatBlock is IMyFunctionalBlock
                    && (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler)))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Programmable & control) == SwitchSystems.Programmable && block.FatBlock is IMyFunctionalBlock
                    && block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MyProgrammableBlock))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Projectors & control) == SwitchSystems.Projectors && block.FatBlock is IMyFunctionalBlock
                    && block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Projector))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Timers & control) == SwitchSystems.Timers && block.FatBlock is IMyFunctionalBlock
                    && block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TimerBlock))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Weapons & control) == SwitchSystems.Weapons && block.FatBlock is IMyFunctionalBlock
                    && (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeGatlingTurret)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SmallGatlingGun)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SmallMissileLauncher)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SmallMissileLauncherReload)))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.SpotLights & control) == SwitchSystems.SpotLights && block.FatBlock is IMyFunctionalBlock
                    && block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ReflectorLight))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Sensors & control) == SwitchSystems.Sensors && block.FatBlock is IMyFunctionalBlock
                    && block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SensorBlock))
                {
                    ((IMyFunctionalBlock)block.FatBlock).RequestEnable(mode); // turn power on/off.
                    counter++;
                }
                if ((SwitchSystems.Medical & control) == SwitchSystems.Medical && block.FatBlock is IMyFunctionalBlock
                    && (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom)
                        || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_CryoChamber)))
                {
                    // Switch the power systems that control the grid instead.
                    // I'm unsure if we should go with it like this, which is why it is as yet undocumented.
                    // The idea is, if you have turned the power off to all ships, you can turn the power back on only for grids with Medical and Cryo.
                    SwitchShipSystemsOnOff(cubeGrid, SwitchSystems.Power, mode);
                    counter++;
                }
            }

            return counter;
        }
开发者ID:DigTron,项目名称:Space-Engineers-Admin-script-mod,代码行数:79,代码来源:CommandShipSwitch.cs


注:本文中的IMyCubeGrid.GetBlocks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。