public void Sync(IMyGridTerminalSystem GridTerminalSystem, IMyCubeGrid grid) { MergeBlocks.Clear(); MiningDrills.Clear(); GatlingGuns.Clear(); RocketLaunchers.Clear(); ProgramBlocks.Clear(); LaserAntennas.Clear(); RadioAntennas.Clear(); TextPanels.Clear(); ControlUnits.Clear(); Connectors.Clear(); Sensors.Clear(); Gyros.Clear(); Thrusters.Clear(); Cameras.Clear(); AllBlocks.Clear(); AllMyBlocks.Clear(); Reactors.Clear(); Batteries.Clear(); Groups.Clear(); GridTerminalSystem.GetBlocks(AllBlocks); GridTerminalSystem.GetBlocksOfType(AllMyBlocks, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(MergeBlocks, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Cameras, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Gyros, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Thrusters, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Sensors, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Connectors, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(ProgramBlocks, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(LaserAntennas, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(RadioAntennas, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(TextPanels, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(ControlUnits, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(MiningDrills, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(GatlingGuns, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(RocketLaunchers, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Reactors, b => b.CubeGrid == grid); GridTerminalSystem.GetBlocksOfType(Batteries, b => b.CubeGrid == grid); GridTerminalSystem.GetBlockGroups(Groups); foreach (var sensor in Sensors) { sensor.DetectEnemy = true; sensor.DetectPlayers = true; sensor.DetectLargeShips = true; sensor.DetectSmallShips = true; sensor.DetectOwner = true; sensor.DetectStations = true; sensor.DetectAsteroids = true; sensor.BackExtend = 50; sensor.FrontExtend = 50; sensor.LeftExtend = 50; sensor.RightExtend = 50; sensor.TopExtend = 50; sensor.BottomExtend = 50; } }
public static IEnumerable <IMyBlockGroup> GetGroupsForBlock(this IMyGridTerminalSystem src, IMyTerminalBlock searchBlock) { List <IMyBlockGroup> groups = new List <IMyBlockGroup>(); src.GetBlockGroups(groups); foreach (var group in groups) { if (group.GetBlocks().Contains(searchBlock)) { yield return(group); } } }
public HangarController(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; hangarDoors = new List <IMyDoor> [groups.Count]; interiorDoors = new List <IMyDoor> [groups.Count]; exteriorDoors = new List <IMyDoor> [groups.Count]; soundBlocks = new List <IMySoundBlock> [groups.Count]; warningLights = new List <IMyInteriorLight> [groups.Count]; airVents = new List <IMyAirVent> [groups.Count]; hangarOpen = new Boolean[groups.Count]; // Get list of groups on this station/ship List <IMyBlockGroup> BlockGroups = new List <IMyBlockGroup>(); GridTerminalSystem.GetBlockGroups(BlockGroups); // Search all groups that exist for the groups with name as specified in groups list for (int i = 0; i < BlockGroups.Count; i++) { int pos = groups.IndexOf(BlockGroups[i].Name); // If name is one of our candidates... if (pos != -1) { List <IMyTerminalBlock> blocks = BlockGroups[i].Blocks; // Define list of blocks for each group List <IMyDoor> hangarDoorList = new List <IMyDoor>(); List <IMyDoor> interiorDoorList = new List <IMyDoor>(); List <IMyDoor> exteriorDoorList = new List <IMyDoor>(); List <IMySoundBlock> soundBlockList = new List <IMySoundBlock>(); List <IMyInteriorLight> warningLightList = new List <IMyInteriorLight>(); List <IMyAirVent> airVentList = new List <IMyAirVent>(); // Go through all blocks and add to appropriate list // Also initialize to a sane known state e.g. closed, on... for (int j = 0; j < blocks.Count; j++) { IMyTerminalBlock block = blocks[j]; String blockType = block.DefinitionDisplayNameText; String blockName = block.CustomName; block.ApplyAction("OnOff_On"); if (blockType.Equals("Airtight Hangar Door")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); hangarDoorList.Add(item); } else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Interior")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); interiorDoorList.Add(item); } else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Exterior")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); exteriorDoorList.Add(item); } else if (blockType.Equals("Sound Block")) { IMySoundBlock item = block as IMySoundBlock; item.ApplyAction("StopSound"); item.SetValueFloat("LoopableSlider", 10); soundBlockList.Add(item); } else if (blockType.Equals("Interior Light")) { IMyInteriorLight item = block as IMyInteriorLight; item.ApplyAction("OnOff_Off"); item.SetValueFloat("Blink Interval", 1); item.SetValueFloat("Blink Lenght", 50); item.SetValueFloat("Blink Offset", 0); item.SetValue <Color>("Color", Color.Red); warningLightList.Add(item); } else if (blockType.Contains("Air Vent")) { IMyAirVent item = block as IMyAirVent; item.ApplyAction("Depressurize_Off"); airVentList.Add(item); } } // Some cleanup hangarDoorList.TrimExcess(); interiorDoorList.TrimExcess(); exteriorDoorList.TrimExcess(); soundBlockList.TrimExcess(); warningLightList.TrimExcess(); airVentList.TrimExcess(); if (hangarDoorList.Count == 0) { Echo("Warning: no hangar doors detected for " + BlockGroups[i].Name); } else if (interiorDoorList.Count == 0) { Echo("Warning: no interior doors detected for " + BlockGroups[i].Name); } else if (soundBlockList.Count == 0) { Echo("Warning: no sound blocks detected for " + BlockGroups[i].Name); } else if (warningLightList.Count == 0) { Echo("Warning: no warning lights detected for " + BlockGroups[i].Name); } else if (airVentList.Count == 0) { Echo("Warning: no air vents detected for " + BlockGroups[i].Name); } // Now that we have populated lists add them to the correct position in the group list hangarDoors[pos] = hangarDoorList; interiorDoors[pos] = interiorDoorList; exteriorDoors[pos] = exteriorDoorList; soundBlocks[pos] = soundBlockList; warningLights[pos] = warningLightList; airVents[pos] = airVentList; hangarOpen[pos] = false; // Exterior doors have been requested to close so we set a check to lock them when they are in fact closed requests.Add(new requestTicket(pos, "lockExteriorDoors")); } } }
void check_thruster_control_changed() { bool changes_made = false; foreach (var cur_direction in _thrusters) { foreach (var cur_thruster in cur_direction) { cur_thruster.Value.group_no_RCS = false; } } IMyGridTerminalSystem grid_terminal = MyAPIGateway.TerminalActionsHelper?.GetTerminalSystemForGrid(_grid); if (grid_terminal == null) { return; } _all_groups.Clear(); grid_terminal.GetBlockGroups(_all_groups); foreach (var cur_group in _all_groups) { MyThrust cur_thruster; if (cur_group.Name.ToUpper().Contains("[NO RCS]")) { _blocks_in_group.Clear(); cur_group.GetBlocks(_blocks_in_group); foreach (var cur_block in _blocks_in_group) { cur_thruster = cur_block as MyThrust; if (cur_thruster == null) { continue; } foreach (var cur_direction in _thrusters) { if (cur_direction.ContainsKey(cur_thruster)) { cur_direction[cur_thruster].group_no_RCS = true; break; } } } } } foreach (var cur_direction in _thrusters) { thruster_info cur_thruster_info; foreach (var cur_thruster in cur_direction) { cur_thruster_info = cur_thruster.Value; if (cur_thruster_info.actual_max_force < 0.01f * cur_thruster_info.max_force || !cur_thruster.Key.IsWorking) { cur_thruster_info.is_RCS = false; } else if (!(cur_thruster_info.is_RCS ^ cur_thruster_info.group_no_RCS)) { cur_thruster_info.is_RCS = !cur_thruster_info.group_no_RCS; changes_made = true; } if (!cur_thruster_info.is_RCS && !cur_thruster_info.override_cleared) { cur_thruster.Key.SetValueFloat("Override", 0.0f); cur_thruster_info.override_cleared = changes_made = true; } } } //screen_text("", string.Format("THR = {0}/{1}", num_thr - num_nc_thr, num_thr), 2000, controlled_only: true); if (changes_made) { for (int dir_index = 0; dir_index < 6; ++dir_index) { _max_force[dir_index] = 0.0f; foreach (var cur_thruster_info in _thrusters[dir_index].Values) { if (cur_thruster_info.is_RCS) { _max_force[dir_index] += cur_thruster_info.max_force; } } } /* * log_ECU_action("check_thruster_control_changed", string.Format("{0}/{1}/{2}/{3}/{4}/{5} kN", * _max_force[(int) thrust_dir.fore ] / 1000.0f, * _max_force[(int) thrust_dir.aft ] / 1000.0f, * _max_force[(int) thrust_dir.starboard] / 1000.0f, * _max_force[(int) thrust_dir.port ] / 1000.0f, * _max_force[(int) thrust_dir.dorsal ] / 1000.0f, * _max_force[(int) thrust_dir.ventral ] / 1000.0f)); */ } if (changes_made || _thruster_added_or_removed) { refresh_thruster_info(); update_reference_vectors(); refresh_control_sets(); _thruster_added_or_removed = false; } }
public HangarController(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; hangarDoors = new List<IMyDoor>[groups.Count]; interiorDoors = new List<IMyDoor>[groups.Count]; exteriorDoors = new List<IMyDoor>[groups.Count]; soundBlocks = new List<IMySoundBlock>[groups.Count]; warningLights = new List<IMyInteriorLight>[groups.Count]; airVents = new List<IMyAirVent>[groups.Count]; hangarOpen = new Boolean[groups.Count]; // Get list of groups on this station/ship List<IMyBlockGroup> BlockGroups = new List<IMyBlockGroup>(); GridTerminalSystem.GetBlockGroups(BlockGroups); // Search all groups that exist for the groups with name as specified in groups list for (int i = 0; i < BlockGroups.Count; i++) { int pos = groups.IndexOf(BlockGroups[i].Name); // If name is one of our candidates... if (pos != -1) { List<IMyTerminalBlock> blocks = BlockGroups[i].Blocks; // Define list of blocks for each group List<IMyDoor> hangarDoorList = new List<IMyDoor>(); List<IMyDoor> interiorDoorList = new List<IMyDoor>(); List<IMyDoor> exteriorDoorList = new List<IMyDoor>(); List<IMySoundBlock> soundBlockList = new List<IMySoundBlock>(); List<IMyInteriorLight> warningLightList = new List<IMyInteriorLight>(); List<IMyAirVent> airVentList = new List<IMyAirVent>(); // Go through all blocks and add to appropriate list // Also initialize to a sane known state e.g. closed, on... for (int j = 0; j < blocks.Count; j++) { IMyTerminalBlock block = blocks[j]; String blockType = block.DefinitionDisplayNameText; String blockName = block.CustomName; block.ApplyAction("OnOff_On"); if (blockType.Equals("Airtight Hangar Door")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); hangarDoorList.Add(item); } else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Interior")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); interiorDoorList.Add(item); } else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Exterior")) { IMyDoor item = block as IMyDoor; item.ApplyAction("Open_Off"); exteriorDoorList.Add(item); } else if (blockType.Equals("Sound Block")) { IMySoundBlock item = block as IMySoundBlock; item.ApplyAction("StopSound"); item.SetValueFloat("LoopableSlider", 10); soundBlockList.Add(item); } else if (blockType.Equals("Interior Light")) { IMyInteriorLight item = block as IMyInteriorLight; item.ApplyAction("OnOff_Off"); item.SetValueFloat("Blink Interval", 1); item.SetValueFloat("Blink Lenght", 50); item.SetValueFloat("Blink Offset", 0); item.SetValue<Color>("Color", Color.Red); warningLightList.Add(item); } else if (blockType.Contains("Air Vent")) { IMyAirVent item = block as IMyAirVent; item.ApplyAction("Depressurize_Off"); airVentList.Add(item); } } // Some cleanup hangarDoorList.TrimExcess(); interiorDoorList.TrimExcess(); exteriorDoorList.TrimExcess(); soundBlockList.TrimExcess(); warningLightList.TrimExcess(); airVentList.TrimExcess(); if (hangarDoorList.Count == 0) { Echo("Warning: no hangar doors detected for " + BlockGroups[i].Name); } else if (interiorDoorList.Count == 0) { Echo("Warning: no interior doors detected for " + BlockGroups[i].Name); } else if (soundBlockList.Count == 0) { Echo("Warning: no sound blocks detected for " + BlockGroups[i].Name); } else if (warningLightList.Count == 0) { Echo("Warning: no warning lights detected for " + BlockGroups[i].Name); } else if (airVentList.Count == 0) { Echo("Warning: no air vents detected for " + BlockGroups[i].Name); } // Now that we have populated lists add them to the correct position in the group list hangarDoors[pos] = hangarDoorList; interiorDoors[pos] = interiorDoorList; exteriorDoors[pos] = exteriorDoorList; soundBlocks[pos] = soundBlockList; warningLights[pos] = warningLightList; airVents[pos] = airVentList; hangarOpen[pos] = false; // Exterior doors have been requested to close so we set a check to lock them when they are in fact closed requests.Add(new requestTicket(pos, "lockExteriorDoors")); } } }