void Main() { // initialize VRage.MyFixedPoint totalVolume = 0; VRage.MyFixedPoint totalMaxVolume = 0; var blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyInventoryOwner>(blocks, FilterInventoryOwner); if (blocks.Count == 0) { throw new Exception("Did not find any cargo container."); } for (int i = 0; i < blocks.Count; ++i) { var invOwner = blocks[i] as IMyInventoryOwner; for (int j = 0; j < invOwner.InventoryCount; ++j) { var inv = invOwner.GetInventory(j); totalVolume += inv.CurrentVolume; totalMaxVolume += inv.MaxVolume; } } blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyBeacon>(blocks, FilterAntenna); GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(blocks, FilterAntenna); if (blocks.Count == 0) { throw new Exception("Did not find the specified antenna"); } var antenna = blocks[0]; StringBuilder sb = new StringBuilder(); sb.Append(antennaName).Append(" - "); sb.Append((long)(totalVolume * K)).Append(" / ").Append((long)(totalMaxVolume * K)); sb.Append(" (").Append(VRageMath.MathHelper.RoundOn2(100 * (float)(totalVolume * K) / (float)(totalMaxVolume * K))).Append("%)"); //antenna.SetCustomName(sb.ToString()); if (totalVolume == totalMaxVolume) { IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(stop); if (block == null) { throw new Exception("Could not find block with name: '" + stop + "'"); } block.SetCustomName(block.CustomName + "full,"); block.ApplyAction("Run"); } Echo(sb.ToString()); debug.Clear(); }
public void replaceBlockname(IMyTerminalBlock Block, Glob Filter, Argument Arg, int blockNumber) { StringBuilder slug = new StringBuilder(Block.CustomName); string[] matches = Filter.getMatches(Block.CustomName); for (int i = 0; i < matches.Length; i++) { if (matches[i].Length > 0) { Echo(Block.CustomName + " => \"" + matches[i] + "\""); slug = slug.Replace(matches[i], Arg.replacement.Replace(MARKER_MATCH, matches[i])); slug = slug.Replace(MARKER_NUMBER, blockNumber.ToString()); } } Block.SetCustomName(slug.ToString()); }
/// <summary> /// gets the message that was sent from player / ingame programming /// </summary> public static List <Message> getFromName(IMyTerminalBlock sender) { string name = sender.DisplayNameText; int start = name.IndexOf(startOfSend) + startOfSend.Length; int length = name.LastIndexOf(endOfSend) - start; if (start <= startOfSend.Length || length < 1) // nothing to send { log("nothing to send for " + name, "getFromName()", Logger.severity.TRACE); return(null); } // clear message from name string NameNew = name.Remove(start - startOfSend.Length); sender.SetCustomName(NameNew); string[] sent = name.Substring(start, length).Split(separator); string message; if (sent.Length < 3) // not possible to send { log("cannot send while split has length " + sent.Length + ", for " + name, "getFromName()", Logger.severity.DEBUG); return(null); } else if (sent.Length == 3) { message = sent[2]; } else // sent.Length > 3 { StringBuilder messageSB = new StringBuilder(); for (int index = 2; index < sent.Length; index++) { if (index != 2) { messageSB.Append(separator); } messageSB.Append(sent[index]); } message = messageSB.ToString(); } return(Message.buildMessages(message, sent[0], sent[1], sender as IMyCubeBlock, NameNew)); }
/// <summary> /// <para>performs actions before splitting instructions by : & ;</para> /// <para>Currently, performs a substitution for pasted GPS tags</para> /// </summary> private string preParse(IMyCubeBlock block) { string blockName = block.DisplayNameText; blockName = GPS_tag.Replace(blockName, replaceWith); //myLogger.debugLog("replaced name: " + blockName, "preParse()"); IMyTerminalBlock asTerm = block as IMyTerminalBlock; if (asTerm != null) { asTerm.SetCustomName(blockName); } else { myLogger.debugLog("not functional, name will not be updated: " + block.getBestName(), "preParse()", Logger.severity.WARNING); } return(blockName); }
void Main() { List <IMyTerminalBlock> blocks = GridTerminalSystem.Blocks; List <IMyBlockGroup> blockGroups = GridTerminalSystem.BlockGroups; GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(blocks, FuncTest); GridTerminalSystem.SearchBlocksOfName(blockName, blocks, FuncTest); var block = GridTerminalSystem.GetBlockWithName(blockName); IMyCubeBlock cubeBlock = block; bool IsBeingHacked = cubeBlock.IsBeingHacked; bool IsFunctional = cubeBlock.IsFunctional; bool IsWorking = cubeBlock.IsWorking; VRageMath.Vector3I Position = cubeBlock.Position; IMyTerminalBlock terminalBlock = block; string CustomName = terminalBlock.CustomName; string CustomNameWithFaction = terminalBlock.CustomNameWithFaction; string DetailedInfo = terminalBlock.DetailedInfo; bool HasLocalPlayerAccess = terminalBlock.HasLocalPlayerAccess(); bool HasPlayerAccess = terminalBlock.HasPlayerAccess(playerId); //terminalBlock.RequestShowOnHUD(enable); terminalBlock.SetCustomName(CustomName); //terminalBlock.SetCustomName(stringBuilder); bool ShowOnHUD = terminalBlock.ShowOnHUD; List <ITerminalAction> resultList = new List <ITerminalAction>(); terminalBlock.GetActions(resultList, FuncTest); //terminalBlock.SearchActionsOfName(actionName, resultList, FuncTest); //ITerminalAction terminalAction = terminalBlock.GetActionWithName(actionName); //string Id = terminalAction.Id; //StringBuilder Name = terminalAction.Name; //terminalAction.Apply(cubeBlock); IMyFunctionalBlock functionalBlock = block as IMyFunctionalBlock; bool Enabled = functionalBlock.Enabled; }
/// <summary> /// gets the message that was sent from player / ingame programming /// </summary> public static List<Message> getFromName(IMyTerminalBlock sender) { string name = sender.DisplayNameText; int start = name.IndexOf(startOfSend) + startOfSend.Length; int length = name.LastIndexOf(endOfSend) - start; if (start <= startOfSend.Length || length < 1) // nothing to send { myLogger.debugLog("nothing to send for " + name, "getFromName()", Logger.severity.TRACE); return null; } // clear message from name string NameNew = name.Remove(start - startOfSend.Length); sender.SetCustomName(NameNew); string[] sent = name.Substring(start, length).Split(separator); string message; if (sent.Length < 3) // not possible to send { myLogger.debugLog("cannot send while split has length " + sent.Length + ", for " + name, "getFromName()", Logger.severity.DEBUG); return null; } else if (sent.Length == 3) message = sent[2]; else // sent.Length > 3 { StringBuilder messageSB = new StringBuilder(); for (int index = 2; index < sent.Length; index++) { if (index != 2) messageSB.Append(separator); messageSB.Append(sent[index]); } message = messageSB.ToString(); } return Message.buildMessages(message, sent[0], sent[1], sender as IMyCubeBlock, NameNew); }
/// <summary> /// writes the message from mod to display name /// </summary> public static void writeToName(IMyTerminalBlock recipient, Message message) { recipient.SetCustomName(recipient.CustomName + startOfReceive + message.SourceGridName + separator + message.SourceBlockName + separator + message.Content + endOfReceive); return; }
void Main(string args) { debug("BEGIN"); if (args.Trim().Length > 0) { GROUP_TAG = args; } debug("Groupname: " + GROUP_TAG); List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(Blocks, (x => x.IsWorking && x.CubeGrid.Equals(Me.CubeGrid))); if (Blocks.Count > 0) { IMyRemoteControl RC = Blocks[0] as IMyRemoteControl; debug("Using Remotecontrol: " + RC.CustomName); List <IMyBlockGroup> Groups = new List <IMyBlockGroup>(); GridTerminalSystem.GetBlockGroups(Groups); Blocks.Clear(); for (int i = 0; i < Groups.Count; i++) { if (Groups[i].Name.Contains(GROUP_TAG)) { for (int j = 0; j < Groups[i].Blocks.Count; j++) { if ( ((Groups[i].Blocks[j] is IMyRadioAntenna) || (Groups[i].Blocks[j] is IMyBeacon)) && Groups[i].Blocks[j].IsFunctional && Groups[i].Blocks[j].CubeGrid.Equals(Me.CubeGrid) ) { Blocks.Add(Groups[i].Blocks[j]); } } } } Vector3D PlayerPos; Vector3D PbPos = RC.GetPosition(); RC.GetNearestPlayer(out PlayerPos); debug("Nearest Player: (" + String.Format("{0:0}", Vector3D.Distance(PlayerPos, PbPos)) + " m)" + PlayerPos.ToString()); debug("Functional Antennas/Beacons: " + Blocks.Count.ToString()); for (int i = 0; i < Blocks.Count; i++) { IMyTerminalBlock RA = Blocks[i] as IMyTerminalBlock; int d_pos = RA.CustomName.IndexOf("DEBUG"); string d_name = RA.CustomName.Trim(); if (d_pos > -1) { d_name = RA.CustomName.Substring(0, d_pos).Trim(); RA.SetCustomName(d_name); } double radius = 0.0; if (RA is IMyRadioAntenna) { radius = Convert.ToDouble((RA as IMyRadioAntenna).Radius); } else if (RA is IMyBeacon) { radius = Convert.ToDouble((RA as IMyBeacon).Radius); } double cutOffPoint = radius * CUT_OFF_FACTOR; double distance = Vector3D.Distance(PlayerPos, PbPos); string info = "% (radius: " + String.Format("{0:0}", radius) + " m; cut-off point: " + String.Format("{0:0}", cutOffPoint) + " m; distance: " + String.Format("{0:0}", distance) + " m)"; if (distance < cutOffPoint) { info = "Enable: " + info; // RA.ApplyAction("OnOff_On"); } else { info = "Disable '" + info; // RA.ApplyAction("OnOff_Off"); } Echo(info.Replace("%", RA.CustomName)); if (DEBUG) { d_pos = RA.CustomName.IndexOf("DEBUG"); d_name = RA.CustomName.Trim(); if (d_pos > -1) { d_name = RA.CustomName.Substring(0, d_pos).Trim(); } RA.SetCustomName(d_name + " DEBUG: " + info.Replace("%", "")); } } } else { debug("Remote Control not found."); } debug("END"); }