public new void Main(string arguments) { enemies.Clear(); lostContact.Clear(); sinceLastAlarm += Runtime.TimeSinceLastRun; DetectedEntityData entityData; foreach (string serialized in arguments.Split(entitySeparator)) { if (DetectedEntityData.TryDeserialize(serialized, out entityData)) { if (entityData.relations == Relation_Enemy) { enemies.Add(TerminalActionParameter.Get(entityData.entityId)); // sound alarm if enemy is near if (sinceLastAlarm >= alarmInterval && (entityData.volume > 100 || entityData.volume == 0f) && entityData.secondsSinceDetected < 60 && Vector3D.DistanceSquared(Me.GetPosition(), entityData.predictedPosition) < 10000 * 10000) { sinceLastAlarm = new TimeSpan(); IMySoundBlock alarm = GridTerminalSystem.GetBlockWithName("Proximity Alarm") as IMySoundBlock; if (alarm == null) { Terminate("Proximity Alarm is not a sound block"); return; } else { alarm.ApplyAction("PlaySound"); } } } else if (entityData.relations == Relation_Owner && entityData.secondsSinceDetected > 10) { lostContact.Add(TerminalActionParameter.Get(entityData.entityId)); } } else { Terminate("Deserialize failed: " + serialized); return; } } DisplayEntitiesOnPanel("Wide LCD panel for Enemy", enemies); DisplayEntitiesOnPanel("Wide LCD panel for Lost Contact", lostContact); }
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")); } } }