public EasyLCD(EasyBlocks block, double scale = 1.0) { this.block = block.GetBlock(0); if(this.block.Type() == "Wide LCD panel") this.wPanel = 72; this.screen = (IMyTextPanel)(block.GetBlock(0).Block); this.fontSize = block.GetProperty<Single>("FontSize"); this.width = (int)((double)this.wPanel / this.fontSize); this.height = (int)((double)this.hPanel / this.fontSize); this.buffer = new char[this.width * this.height]; this.clear(); this.update(); }
/*** Refreshes blocks. If you add or remove blocks, call this. ***/ public void Refresh() { List <IMyTerminalBlock> kBlocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocks(kBlocks); Blocks = new EasyBlocks(kBlocks); }
public void MoveTo(EasyBlocks Blocks, int Inventory = 0) { for (int i = 0; i < Items.Count; i++) { Items[i].MoveTo(Blocks, Inventory); } }
public void MoveTo(EasyBlocks Blocks, int Inventory = 0) { for(int i = 0; i < Items.Count; i++) { Items[i].MoveTo(Blocks, Inventory); } }
public void AddEvents(EasyBlocks blocks, Func<EasyBlock, bool> evnt, Func<EasyBlock, bool> action) { for(int i = 0; i < blocks.Count(); i++) { this.AddEvent(new EasyEvent<EasyBlock>(blocks.GetBlock(i), evnt, action)); } }
public void AddEvents(EasyBlocks blocks, Func <EasyBlock, bool> evnt, Func <EasyBlock, bool> action, bool onChange = false) { for (int i = 0; i < blocks.Count(); i++) { this.AddEvent(new EasyEvent(blocks.GetBlock(i), evnt, action, onChange)); } }
public void MoveTo(EasyBlocks Blocks, int Inventory = 0, int dummy = 0) { // Right now it moves them to all of them. Todo: determine if the move was successful an exit for if it was. // In the future you will be able to sort EasyBlocks and use this to prioritize where the items get moved. for (int i = 0; i < Blocks.Count(); i++) { this.Inventory.TransferItemTo(Blocks.GetBlock(i).Block.GetInventory(Inventory), ItemIndex); } }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { EasyBlocks monitoredBlocks = Blocks; // The event will be added to all these blocks AddEvents( monitoredBlocks, delegate(EasyBlock block) { // When this function returns true, the event is triggered return(block.Damage() > 1); // when the block is damage more than 1% }, damaged1Percent // this is called when the event is triggered ); }
public EasyBlocks Minus(EasyBlocks Blocks) { List <EasyBlock> FilteredList = new List <EasyBlock>(); FilteredList.AddRange(this.Blocks); for (int i = 0; i < Blocks.Count(); i++) { FilteredList.Remove(Blocks.GetBlock(i)); } return(new EasyBlocks(FilteredList)); }
public AttackDetector(StorageSetter storage, IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { ammo = VRage.MyFixedPoint.DeserializeStringSafe(storage.getStorage()); turrets = Blocks.InGroupsNamed("Turrets"); log = new EasyLCD(Blocks.Named("LCD Panel Attacks Log")); beacon = Blocks.InGroupsNamed("Beacon Attack Detector").GetBlock(0); this.storage = storage; Every(5 * EasyAPI.Seconds, doWork); On("clear", delegate() { log.SetText(""); beacon.SetName("Beacon Attack Detector"); }); }
public EasyBlocks Plus(EasyBlocks Blocks) { List <EasyBlock> FilteredList = new List <EasyBlock>(); FilteredList.AddRange(this.Blocks); for (int i = 0; i < Blocks.Count(); i++) { if (!FilteredList.Contains(Blocks.GetBlock(i))) { FilteredList.Add(Blocks.GetBlock(i)); } } return(new EasyBlocks(FilteredList)); }
public EasyLCD(EasyBlocks block, double scale = 1.0) { this.block = block.GetBlock(0); if (this.block.Type() == "Wide LCD panel") { this.wPanel = 72; } this.screen = (IMyTextPanel)(block.GetBlock(0).Block); this.fontSize = block.GetProperty <Single>("FontSize"); this.width = (int)((double)this.wPanel / this.fontSize); this.height = (int)((double)this.hPanel / this.fontSize); this.buffer = new char[this.width * this.height]; this.clear(); this.update(); }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Test Menu", new [] { new EasyMenuItem("Play Sound", playSound), new EasyMenuItem("Door Status", new[] { new EasyMenuItem("Door 1", toggleDoor, doorStatus), new EasyMenuItem("Door 2", toggleDoor, doorStatus), new EasyMenuItem("Door 3", toggleDoor, doorStatus), new EasyMenuItem("Door 4", toggleDoor, doorStatus) }), new EasyMenuItem("Do Nothing") }); // Get blocks this.speaker = Blocks.Named("MenuSpeaker").FindOrFail("MenuSpeaker not found!"); this.lcd = new EasyLCD(Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!")); // Handle Arguments On("Up", delegate() { this.menu.Up(); doUpdates(); }); On("Down", delegate() { this.menu.Down(); doUpdates(); }); On("Choose", delegate() { this.menu.Choose(); doUpdates(); }); On("Back", delegate() { this.menu.Back(); doUpdates(); }); On("Update", delegate() { doUpdates(); }); }
public void plot(EasyBlocks blocks, double x, double y, double scale = 1.0, char brush = 'o', bool showBounds = true, char boundingBrush = '?') { VRageMath.Vector3D max = new Vector3D(this.screen.CubeGrid.Max); VRageMath.Vector3D min = new Vector3D(this.screen.CubeGrid.Min); VRageMath.Vector3D size = new Vector3D(max - min); int width = (int)size.GetDim(0); int height = (int)size.GetDim(1); int depth = (int)size.GetDim(2); int minX = (int)min.GetDim(0); int minY = (int)min.GetDim(1); int minZ = (int)min.GetDim(2); int maxX = (int)max.GetDim(0); int maxY = (int)max.GetDim(1); int maxZ = (int)max.GetDim(2); double s = (double)depth + 0.01; if (width > depth) { s = (double)width + 0.01; } if (showBounds) { box(x + -(((0 - (width / 2.0)) / s) * scale), y + -(((0 - (depth / 2.0)) / s) * scale), x + -(((maxX - minX - (width / 2.0)) / s) * scale), y + -(((maxZ - minZ - (depth / 2.0)) / s) * scale), boundingBrush); } for (int n = 0; n < blocks.Count(); n++) { var block = blocks.GetBlock(n); Vector3D pos = new Vector3D(block.Block.Position); pset(x + -((((double)(pos.GetDim(0) - minX - (width / 2.0)) / s)) * scale), y + -((((double)(pos.GetDim(2) - minZ - (depth / 2.0)) / s)) * scale), brush); } }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Test Menu", new [] { new EasyMenuItem("Play Sound", playSound), new EasyMenuItem("Door Status", new[] { new EasyMenuItem("Door 1", toggleDoor, doorStatus), new EasyMenuItem("Door 2", toggleDoor, doorStatus), new EasyMenuItem("Door 3", toggleDoor, doorStatus), new EasyMenuItem("Door 4", toggleDoor, doorStatus) }), new EasyMenuItem("Do Nothing") }); // Get blocks this.speaker = Blocks.Named("MenuSpeaker").FindOrFail("MenuSpeaker not found!"); this.lcd = new EasyLCD(Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!")); // Handle Arguments On("Up", delegate() { this.menu.Up(); doUpdates(); }); On("Down", delegate() { this.menu.Down(); doUpdates(); }); On("Choose", delegate() { this.menu.Choose(); doUpdates(); }); On("Back", delegate() { this.menu.Back(); doUpdates(); }); }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { doors = Blocks.OfType("Door"); // split work over time so it doesn't throw a complexity error (tested with 384 doors) In(1 * EasyAPI.Seconds, delegate() { // In one second, create the events. doors.AddEvent( delegate(EasyBlock block) { // When a door is opened return(block.Open()); }, delegate(EasyBlock block) { // Do the following In(2 * EasyAPI.Seconds, delegate() { // In 2 seconds block.ApplyAction("Open_Off"); // close the door }); return(true); }, true // only trigger event when the condition (door open) goes from false to true ); }); }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Test Menu", new [] { new EasyMenuItem("Play Sound", playSound), new EasyMenuItem("Door Status", new[] { new EasyMenuItem("Door 1", toggleDoor, doorStatus), new EasyMenuItem("Door 2", toggleDoor, doorStatus), new EasyMenuItem("Door 3", toggleDoor, doorStatus), new EasyMenuItem("Door 4", toggleDoor, doorStatus) }), new EasyMenuItem("Do Nothing") }); // Get blocks this.timer = Blocks.Named("MenuTimer").FindOrFail("MenuTimer not found!"); this.screen = Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!"); this.speaker = Blocks.Named("MenuSpeaker").FindOrFail("MenuSpeaker not found!"); this.lcd = new EasyLCD(this.screen); Every(100 * Milliseconds, doUpdates); }
public void plot(EasyBlocks blocks, double x, double y, double scale = 1.0, char brush = 'o', bool showBounds = true, char boundingBrush = '?') { VRageMath.Vector3D max = new Vector3D(this.screen.CubeGrid.Max); VRageMath.Vector3D min = new Vector3D(this.screen.CubeGrid.Min); VRageMath.Vector3D size = new Vector3D(max - min); int width = (int)size.GetDim(0); int height = (int)size.GetDim(1); int depth = (int)size.GetDim(2); int minX = (int)min.GetDim(0); int minY = (int)min.GetDim(1); int minZ = (int)min.GetDim(2); int maxX = (int)max.GetDim(0); int maxY = (int)max.GetDim(1); int maxZ = (int)max.GetDim(2); double s = (double)depth + 0.01; if(width > depth) { s = (double)width + 0.01; } if(showBounds) { box(x + -(((0 - (width / 2.0)) / s) * scale), y + -(((0 - (depth / 2.0)) / s) * scale), x + -(((maxX - minX - (width / 2.0)) / s) * scale), y + -(((maxZ - minZ - (depth / 2.0)) / s) * scale), boundingBrush); } for(int n = 0; n < blocks.Count(); n++) { var block = blocks.GetBlock(n); Vector3D pos = new Vector3D(block.Block.Position); pset(x + -((((double)(pos.GetDim(0) - minX - (width / 2.0)) / s)) * scale), y + -((((double)(pos.GetDim(2) - minZ - (depth / 2.0)) / s)) * scale), brush); } }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Explore", new [] { new EasyMenuItem("Actions", delegate(EasyMenuItem actionsItem) { List <string> types = new List <string>(); for (int n = 0; n < Blocks.Count(); n++) { var block = Blocks.GetBlock(n); if (!types.Contains(block.Type())) { types.Add(block.Type()); } } types.Sort(); actionsItem.children.Clear(); for (int n = 0; n < types.Count; n++) { actionsItem.children.Add(new EasyMenuItem(types[n], delegate(EasyMenuItem typeItem) { typeItem.children.Clear(); var blocks = Blocks.OfType(typeItem.Text); for (int o = 0; o < blocks.Count(); o++) { var block = blocks.GetBlock(o); typeItem.children.Add(new EasyMenuItem(block.Name(), delegate(EasyMenuItem blockItem) { blockItem.children.Clear(); var actions = block.GetActions(); for (int p = 0; p < actions.Count; p++) { var action = actions[p]; blockItem.children.Add(new EasyMenuItem(action.Name + "", delegate(EasyMenuItem actionItem) { block.ApplyAction(action.Id); return(false); })); } blockItem.children.Sort(); return(true); })); } typeItem.children.Sort(); return(true); })); } actionsItem.children.Sort(); return(true); }) }); // Get blocks this.screen = Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!"); this.lcd = new EasyLCD(this.screen); // Handle Arguments On("Up", delegate() { this.menu.Up(); doUpdates(); }); On("Down", delegate() { this.menu.Down(); doUpdates(); }); On("Choose", delegate() { this.menu.Choose(); doUpdates(); }); On("Back", delegate() { this.menu.Back(); doUpdates(); }); On("Update", delegate() { doUpdates(); }); }
private void doCommand() { while (pos < text.Length && text[pos] != ';') { skipNonCode(); string command = getIdentifier(); if (command == "") { return; } string parm = ""; switch (command) { case "function": skipNonCode(); string identifier = getIdentifier(); skipNonCode(); require('('); skipNonCode(); require(')'); skipNonCode(); require('{'); skipNonCode(); string function = getFunction(); if (functions.ContainsKey(identifier)) { failure("Function " + identifier + " already defined!"); } functions.Add(identifier, function); return; case "Echo": parm = getParm(); api.Echo(parm); break; case "Blocks": api.Refresh(); this.blocks = api.Blocks; break; /*** Actions ***/ case "ApplyAction": parm = getParm(); blocks.ApplyAction(parm); break; case "WritePublicText": parm = getParm(); blocks.WritePublicText(parm); break; case "WriteCustomData": case "WritePrivateText": parm = getParm(); blocks.WriteCustomData(parm); break; case "AppendPublicText": parm = getParm(); blocks.AppendPublicText(parm); break; case "On": parm = getParm(); blocks.On(); break; case "Off": parm = getParm(); blocks.Off(); break; case "Toggle": parm = getParm(); blocks.Toggle(); break; case "DebugDump": parm = getParm(); blocks.DebugDump(); break; case "DebugDumpActions": parm = getParm(); blocks.DebugDumpActions(); break; case "DebugDumpProperties": parm = getParm(); blocks.DebugDumpProperties(); break; case "Run": parm = getParm(); blocks.Run(api, parm); break; case "RunPB": parm = getParm(); blocks.RunPB(parm); break; /*** Filters ***/ case "Named": parm = getParm(); blocks = blocks.Named(parm); break; case "NamedLike": parm = getParm(); blocks = blocks.NamedLike(parm); break; case "NotNamed": parm = getParm(); blocks = blocks.NotNamed(parm); break; case "NotNamedLike": parm = getParm(); blocks = blocks.NotNamedLike(parm); break; case "InGroupsNamed": parm = getParm(); blocks = blocks.InGroupsNamed(parm); break; case "InGroupsNamedLike": parm = getParm(); blocks = blocks.InGroupsNamedLike(parm); break; case "InGroupsNotNamed": parm = getParm(); blocks = blocks.InGroupsNotNamed(parm); break; case "InGroupsNotNamedLike": parm = getParm(); blocks = blocks.InGroupsNotNamedLike(parm); break; case "OfType": parm = getParm(); blocks = blocks.OfType(parm); break; case "OfTypeLike": parm = getParm(); blocks = blocks.OfTypeLike(parm); break; case "NotOfType": parm = getParm(); blocks = blocks.NotOfType(parm); break; case "NotOfTypeLike": parm = getParm(); blocks = blocks.OfTypeLike(parm); break; default: failure("Invalid command: '" + command + "'"); break; } skipNonCode(); if (pos < text.Length && text[pos] == '.') { pos++; } } }
/*** Refreshes blocks. If you add or remove blocks, call this. ***/ public void Refresh() { List<IMyTerminalBlock> kBlocks = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocks(kBlocks); Blocks = new EasyBlocks(kBlocks); }