void GrabRemotes() { GridTerminalSystem.SearchBlocksOfName(gyroName, gyroList); GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(remotes); for (int i = 0; i < remotes.Count; i++) { var thisRemote = remotes[i] as IMyRemoteControl; if (thisRemote.CustomName.Contains(shooterReferenceName)) { shooterRefrenceList.Add(thisRemote as IMyRemoteControl); Echo("Found Shooter"); } if (thisRemote.CustomName.Contains(missileReferenceName)) { missileRefrenceList.Add(thisRemote as IMyRemoteControl); Echo("Found Missile"); } } //---Check if we do not have an shooter remote if (shooterRefrenceList.Count == 0) { Echo("No shooter refrence block found"); hasRun = false; return; } //---Check if we do not have a missile remote else if (missileRefrenceList.Count == 0) { Echo("No missile refrence block found"); hasRun = false; return; } else if (gyroList.Count == 0) { Echo("No control gyro found"); hasRun = false; return; } else { Echo("Ready to run"); shooterRefrence = shooterRefrenceList[0] as IMyRemoteControl; missileRefrence = missileRefrenceList[0] as IMyRemoteControl; hasRun = true; } }
public static List <IMyTerminalBlock> GetBlocksWithTag(this IMyGridTerminalSystem grid, string tag) { var blocks = new List <IMyTerminalBlock>(); grid.SearchBlocksOfName(tag, blocks); return(blocks); }
public void Main(string argument) { List <IMyTerminalBlock> CameraBlocks; CameraBlocks = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName("camera", CameraBlocks); foreach (IMyCameraBlock camera in CameraBlocks) { camera.EnableRaycast = true; if (camera.CanScan(50000)) { Echo("we can scan"); } else { Echo("no scan"); } info = camera.Raycast(10000, 0, 0); Echo(info.Name); Echo(info.Type.ToString()); Echo(info.Relationship.ToString()); Echo(info.Position.ToString("0.000")); Echo(info.BoundingBox.Size.ToString("0.000")); } }
public IMyTerminalBlock GetBlockWithNameOnGrid(string name) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName(name, blocks, x => x.CubeGrid == Me.CubeGrid); return(blocks[0]); }
public static List <T> GetBlocksByNameOfType <T>(IMyGridTerminalSystem GridTerminalSystem, string name, string gridId = "") { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); List <T> casted = new List <T>(); if (gridId != "") { GridTerminalSystem.SearchBlocksOfName(name, blocks, block => (block is T) && (block.CubeGrid.ToString() == gridId)); } else { GridTerminalSystem.SearchBlocksOfName(name, blocks, block => block is T); } foreach (var block in blocks) { casted.Add((T)block); } return(casted); }
public LCD(IMyGridTerminalSystem gts) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); gts.SearchBlocksOfName("[Base]HangarDoorLCD", blocks); textPanels = blocks.Where(x => x as IMyTextPanel != null).Select(x => x as IMyTextPanel).ToArray(); foreach (var x in textPanels) { x.ShowPublicTextOnScreen(); } SetText("Hallo"); }
public Hangar( Action <string> echo, IMyGridTerminalSystem system, IMyProgrammableBlock controller) { Echo = echo; this.controller = controller; GridTerminalSystem = system; name = controller.CustomName.Split('-')[0].Trim(); List <IMyTerminalBlock> sensors = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName(name, sensors, sensor => sensor is IMySensorBlock && !sensor.CustomName.Contains("exit")); sensor = sensors[0] as IMySensorBlock; }
public void CollectUniqueContainers(List <IMyEntity> containers, IMyGridTerminalSystem gts) { if (inventoryBlockNames.Count == 0) { gts.GetBlocksOfType(containers, DefaultInventoryOwnerFilter); } else { var blocks = new List <IMyTerminalBlock>(); for (var i = 0; i < inventoryBlockNames.Count; i++) { gts.SearchBlocksOfName(inventoryBlockNames[i], blocks); } containers.AddRange(blocks.OfType <IMyEntity>().Where(b => b.HasInventory).Distinct()); } }
private void Init() { List <IMyTerminalBlock> rotors = new List <IMyTerminalBlock>(); grid.SearchBlocksOfName("Cell", rotors, delegate(IMyTerminalBlock block) { return(block is IMyMotorStator && Util.NameRegex(block, CellPattern).Success); }); program.Echo("initialized with " + rotors.Count + " rotors"); for (int n = 0; n < rotors.Count; n++) { PrisonCell p = new PrisonCell(this, rotors[n] as IMyMotorStator); prisons[p.id] = p; } }
public LCDArray(IMyGridTerminalSystem gts, string lcdArrayName) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); gts.SearchBlocksOfName("[LCDArray]", blocks); lcdArray = new IMyTextPanel[2, 1]; lcdArray[0, 0] = blocks.Where(x => x.CustomName == "[LCDArray][0,0]").FirstOrDefault() as IMyTextPanel; lcdArray[1, 0] = blocks.Where(x => x.CustomName == "[LCDArray][1,0]").FirstOrDefault() as IMyTextPanel; foreach (IMyTextPanel tp in lcdArray) { tp.ShowPublicTextOnScreen(); tp.Font = "Monospace"; } }
/// <summary> /// Nalezeni bloku /// </summary> /// <param name="name">Nazev</param> /// <returns></returns> public static SortedDictionary <string, IMyTerminalBlock> Find(string name) { // debugger Debugger.Log("Looking for block '" + name + "'"); // definice List <IMyTerminalBlock> searched = new List <IMyTerminalBlock>(); SortedDictionary <string, IMyTerminalBlock> blocks = new SortedDictionary <string, IMyTerminalBlock>(); // nalezeni bloku terminal.SearchBlocksOfName(name, searched); // debugger Debugger.Log("Found blocks", searched); // prirazeni do slovniku if (searched.Count > 0) { foreach (IMyTerminalBlock search in searched) { // kontrola ze block zacina pozadovanym nazvem if (!search.CustomName.StartsWith(name)) { continue; } // kontrola unikatnosti if (blocks.ContainsKey(search.CustomName)) { throw new Exception("E-TE-01: Block '" + name + "' is not unique"); } // kontrola poyadovaneho typu blocks.Add(search.CustomName, search); } // debugger Debugger.Log("Filtered blocks", blocks); } else { throw new Exception("E-TE-02: Block '" + name + "' doesn't exist"); } // vraceni return(blocks); }
private static List <IMyTerminalBlock> GetAllBlocksWithName(IMyGridTerminalSystem MyGridTerminalSystem, String blockName) { // Verify the input parameter if (blockName == null || blockName.Length == 0) { throw new ArgumentException("Invalid block name"); } // Get all the blocks having the given name List <IMyTerminalBlock> allFoundBlocks = new List <IMyTerminalBlock>(); MyGridTerminalSystem.SearchBlocksOfName(blockName, allFoundBlocks); // If there's no block with the given name, then throw an exception if (allFoundBlocks == null || allFoundBlocks.Count == 0) { throw new ArgumentException("Cannot find a block named [" + blockName + "]"); } // Return the result return(allFoundBlocks); }
public static IMyTextSurface GetScreen(IMyGridTerminalSystem gridTerminalSystem, IMyProgrammableBlock Me, LCDConfigItem config) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); gridTerminalSystem.SearchBlocksOfName(config.BlockName, blocks, b => b.IsSameConstructAs(Me)); if (blocks.Count == 0) { throw new Exception($"No blocks with name \"{config.BlockName}\" found"); } if (blocks.Count > 1) { throw new Exception($"Multiple blocks with name \"{config.BlockName}\" found"); } if (config.IsProvider) { IMyTextSurfaceProvider surfaceProvider = blocks[0] as IMyTextSurfaceProvider; return(surfaceProvider.GetSurface(config.ProviderScreenIndex)); } else { return(blocks[0] as IMyTextSurface); } }
public AutoDoorProgram(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; doors = new List <IMyDoor>(); sensors = new List <IMySensorBlock>(); List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); grid.SearchBlocksOfName(PREFIX, blocks); // Add some error handling for blocks not found for (int i = 0; i < blocks.Count; i++) { IMyTerminalBlock block = blocks[i]; String blockType = block.DefinitionDisplayNameText; String blockName = block.CustomName; //Echo("Processing block " + blockName); if (blockType.Equals("Sensor")) { IMySensorBlock sensor = block as IMySensorBlock; sensor.ApplyAction("OnOff_On"); List <ITerminalProperty> properties = new List <ITerminalProperty>(); sensor.GetProperties(properties); sensor.SetValueFloat("Back", SensorBack); sensor.SetValueFloat("Bottom", SensorBottom); sensor.SetValueFloat("Top", SensorTop); sensor.SetValueFloat("Left", SensorLeft); sensor.SetValueFloat("Right", SensorRight); sensor.SetValueFloat("Front", SensorFront); sensor.SetValueBool("Detect Asteroids", false); sensor.SetValueBool("Detect Enemy", false); sensor.SetValueBool("Detect Floating Objects", false); sensor.SetValueBool("Detect Friendly", true); sensor.SetValueBool("Detect Large Ships", false); sensor.SetValueBool("Detect Neutral", false); sensor.SetValueBool("Detect Owner", true); sensor.SetValueBool("Detect Players", true); sensor.SetValueBool("Detect Small Ships", false); sensor.SetValueBool("Detect Stations", false); sensor.SetValueBool("Audible Proximity Alert", false); sensors.Add(sensor); } else if (blockType.Equals("Sliding Door") || blockType.Equals("Door")) { IMyDoor door = block as IMyDoor; door.ApplyAction("Open_Off"); doors.Add(door); } else if (blockType.Equals("Rotor") || blockType.Equals("Advanced Rotor")) { rotor = block as IMyMotorStator; rotor.ApplyAction("OnOff_On"); rotor.SetValueFloat("Torque", 3.36E+07f); rotor.SetValueFloat("BrakingTorque", 3.36E+07f); rotor.SetValueFloat("Velocity", rotorSpeed); rotor.SetValueFloat("UpperLimit", float.PositiveInfinity); rotor.SetValueFloat("LowerLimit", float.NegativeInfinity); // Add config here } } }
void Main(string argument, UpdateType updateSource) { if (argument == "start") { _stop = false; } else if (argument == "stop") { _stop = true; } var nextState = _state; _log = new StringBuilder(""); _log.AppendLine("State is: " + _state.ToString()); var piston = GridTerminalSystem.GetBlockWithName("Piston Middle") as IMyPistonBase; var panel = GridTerminalSystem.GetBlockWithName("LCD Status") as IMyTextPanel; _log.AppendLine("Piston is at " + piston.CurrentPosition.ToString()); var gears_a = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName("Landing Gear a", gears_a); var gears_b = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName("Landing Gear b", gears_b); if (_stop) { ToggleGear(gears_a, true); ToggleGear(gears_b, true); return; } //States: //1. Extending (Gears A locked, gears B unlocked, piston extending) //2. Retracting (Gears B locked, Gears A unlocked, piston retracting) if (_state == 1) { if (piston.CurrentPosition == 10.0f) { _state = 2; ToggleGear(gears_b, true); piston.Velocity = RetractingSpeed; } else { piston.Velocity = ExtendingSpeed; ToggleGear(gears_a, true); if (AreLocked(gears_a)) { ToggleGear(gears_b, false); } } } else if (_state == 2) { if (piston.CurrentPosition == 0f) { _state = 1; ToggleGear(gears_a, true); piston.Velocity = ExtendingSpeed; } else { ToggleGear(gears_b, true); piston.Velocity = RetractingSpeed; if (AreLocked(gears_b)) { ToggleGear(gears_a, false); } } } if (panel != null) { panel.WriteText(_log.ToString(), false); } }
public void ScanForKeypads(IMyGridTerminalSystem gts) { // Scan for blocks with the "keypad" tag (make this customizable) // and add them to the dictionary. // Read in the config data from custom data // custom data example: // door_name = <name of the door> // pass_code = passcode:Message to display // pass_code = passcod2:Second Msg List <IMyTerminalBlock> keypadsSearch = new List <IMyTerminalBlock>(); gts.SearchBlocksOfName("[keypad]", keypadsSearch); Echo("Before scan, keypads is: " + keypads.Count.ToString()); if (keypadsSearch.Count > 0) { for (int i = 0; i < keypadsSearch.Count; i++) { if (!keypads.ContainsKey(keypadsSearch[i].CustomName)) { string tmpName = keypadsSearch[i].CustomName; // key was not found add the keypad string CustomData = keypadsSearch[i].CustomData; List <string> dataLines = CustomData.Split('\n').ToList();; if (dataLines.Count > 0) { // create a temp instance of the keypad Keypad tmpKeypad = new Keypad(tmpName); // now split the lines for (int j = 0; j < dataLines.Count; j++) { //var passcodeIn = ""; if (dataLines[j].Length < 1) { continue; } if (dataLines[j][0] == '\n' || dataLines[j][0] == '#') { continue; } List <string> lineElements = dataLines[j].Split('=').ToList(); if (lineElements.Count != 2) { Echo("Error: Keypad: " + tmpName + " invalid custom data"); tmpKeypad = null; } else { string name = lineElements[0]; string value = lineElements[1]; if (name == "" || value == "") { Echo("Error: Keypad: " + tmpName + " invalid custom data"); tmpKeypad = null; } else { // process the custom data switch (name) { case "door_name": if (tmpKeypad != null) { tmpKeypad.setDoorName(value, gts); } break; case "passcode": List <string> passElements = value.Split(new[] { ':' }, 2).ToList(); if (passElements.Count != 2) { Echo("Error: Keypad: " + tmpName + " invalid custom data"); tmpKeypad = null; } else { // element 0 is code, element 1 is message. if (passElements[0] == "" || passElements[1] == "") { Echo("Error: Keypad: " + tmpName + " invalid custom data"); tmpKeypad = null; } if (tmpKeypad != null) { //Echo("Added Passcode: " + passElements[0] + " to keypad " + tmpKeypad.Name); /*int index = passElements[1].IndexOf("\\n"); * if(index > -1) * { * string tmpString = ""; * tmpString = passElements[1].Substring(0, index) + " \n"; * tmpString = tmpString + passElements[1].Substring(index + 3); * }*/ tmpKeypad.passcodes.Add(passElements[0], passElements[1].Replace("\\n", "\n")); } } break; case "lcd_name": LCDHandler lcd = new LCDHandler(value, gts, this); if (lcd != null) { if (tmpKeypad != null) { tmpKeypad.lcdHandler = lcd; tmpKeypad.Reset(); } } else { Echo("Error: Keypad: " + tmpName + " invalid LCD name"); tmpKeypad = null; } break; default: break; } if (tmpKeypad == null) { break; // break the for loop } } } } // last check before we add the keypad if (tmpKeypad != null && tmpKeypad.Name != "" && tmpKeypad.getDoorName() != "" && tmpKeypad.passcodes.Count > 0) { keypads.Add(tmpKeypad.Name, tmpKeypad); } else { Echo("Error: Cannot add keypad. Invalid Custom Data."); if (tmpKeypad == null) { Echo(" tmpKeyPad is null"); } else { Echo(" name: " + tmpKeypad.Name); Echo(" door: " + tmpKeypad.getDoorName()); Echo(" pcnt: " + tmpKeypad.passcodes.Count.ToString()); } tmpKeypad = null; } } } // end contians if } } Echo("After Scan keypads is: " + keypads.Count.ToString()); }
public void FindBlocks(IMyGridTerminalSystem TB, List <IMyTerminalBlock> res, Func <IMyTerminalBlock, bool> Fp = null) { TB.SearchBlocksOfName(inv ? "" : Val, res, x => Complies(x) && (Fp == null || Fp(x))); }
public AutoDoorProgram(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; doors = new List<IMyDoor>(); sensors = new List<IMySensorBlock>(); List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>(); grid.SearchBlocksOfName(PREFIX, blocks); // Add some error handling for blocks not found for (int i = 0; i < blocks.Count; i++) { IMyTerminalBlock block = blocks[i]; String blockType = block.DefinitionDisplayNameText; String blockName = block.CustomName; //Echo("Processing block " + blockName); if (blockType.Equals("Sensor")) { IMySensorBlock sensor = block as IMySensorBlock; sensor.ApplyAction("OnOff_On"); List<ITerminalProperty> properties = new List<ITerminalProperty>(); sensor.GetProperties(properties); sensor.SetValueFloat("Back", SensorBack); sensor.SetValueFloat("Bottom", SensorBottom); sensor.SetValueFloat("Top", SensorTop); sensor.SetValueFloat("Left", SensorLeft); sensor.SetValueFloat("Right", SensorRight); sensor.SetValueFloat("Front", SensorFront); sensor.SetValueBool("Detect Asteroids", false); sensor.SetValueBool("Detect Enemy", false); sensor.SetValueBool("Detect Floating Objects", false); sensor.SetValueBool("Detect Friendly", true); sensor.SetValueBool("Detect Large Ships", false); sensor.SetValueBool("Detect Neutral", false); sensor.SetValueBool("Detect Owner", true); sensor.SetValueBool("Detect Players", true); sensor.SetValueBool("Detect Small Ships", false); sensor.SetValueBool("Detect Stations", false); sensor.SetValueBool("Audible Proximity Alert", false); sensors.Add(sensor); } else if (blockType.Equals("Sliding Door") || blockType.Equals("Door")) { IMyDoor door = block as IMyDoor; door.ApplyAction("Open_Off"); doors.Add(door); } else if (blockType.Equals("Rotor") || blockType.Equals("Advanced Rotor")) { rotor = block as IMyMotorStator; rotor.ApplyAction("OnOff_On"); rotor.SetValueFloat("Torque", 3.36E+07f); rotor.SetValueFloat("BrakingTorque", 3.36E+07f); rotor.SetValueFloat("Velocity", rotorSpeed); rotor.SetValueFloat("UpperLimit", float.PositiveInfinity); rotor.SetValueFloat("LowerLimit", float.NegativeInfinity); // Add config here } } }