// Arguments separated by commas // Display name // Components public BaseStatistics() { Runtime.UpdateFrequency = UpdateFrequency.Update100; baseGrid = Me.CubeGrid; List <IMyTextPanel> allPanels = new List <IMyTextPanel>(); GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(allPanels); inventoryDisplays = new Dictionary <int, IMyTextPanel>(); foreach (IMyTextPanel panel in allPanels) { if (panel.CustomName.Contains("Inventory Display")) { int panelIndex = int.Parse(panel.CustomName[panel.CustomName.Length - 1].ToString()); panel.ContentType = ContentType.TEXT_AND_IMAGE; panel.BackgroundColor = new Color(0f); inventoryDisplays.Add(panelIndex, panel); } } cargoContainers = FindCargoContainers(); refineries = FindRefineries(); assemblers = FindAssemblers(); itemTypes = new Dictionary <string, MyItemType>(); itemTypes.Add("Iron", MyItemType.MakeIngot("Iron")); itemTypes.Add("Cobalt", MyItemType.MakeIngot("Cobalt")); }
private void ScanReactors(ref ReactorsState reactorsState) { foreach (var reactor in state.Reactors) { for (var i = 0; i < reactor.InventoryCount; i++) { var inventory = reactor.GetInventory(i); reactorsState.FuelAvailableKg += (float)inventory.GetItemAmount(MyItemType.MakeIngot("Uranium")); } reactorsState.PowerConsumedMW += reactor.CurrentOutput; reactorsState.MaxPowerDrawMW += reactor.MaxOutput; if (reactor.Enabled) { reactorsState.Enabled++; } } }
public static void Load(StationMonitorCore sm) { MonitorBlockBuilder mbb = sm.MBBuilder; mbb["Reactor"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyReactor>(parser) { InfoMaker = (IMyReactor block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") }, { "eff", new Efficiency(block, "Efficiency") }, { "sto", new Store(block, MyItemType.MakeIngot("Uranium"), "Stored Uranium") } }; } }); }; mbb["SolarPanel"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMySolarPanel>(parser) { InfoMaker = (IMySolarPanel block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") }, { "eff", new Efficiency(block, "Efficiency") } }; } }); }; mbb["Battery"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyBatteryBlock>(parser) { InfoMaker = (IMyBatteryBlock block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") }, { "eff", new Efficiency(block, "Efficiency") }, { "in", new Input(block, "Input") }, { "cha", new Charge(block, "Charge") } }; } }); }; mbb["HydrogenEngine"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyPowerProducer>(parser) { SubFilter = (IMyTerminalBlock block) => { if (!block.BlockDefinition.SubtypeId.Contains("HydrogenEngine")) { return false; } return true; }, InfoMaker = (IMyPowerProducer block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") }, { "eff", new Efficiency(block, "Efficiency") }, { "sto", new Store(block, "Stored Hydrogen") } }; } }); }; mbb["WindTurbine"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyPowerProducer>(parser) { SubFilter = (IMyTerminalBlock block) => { if (!block.BlockDefinition.SubtypeId.Contains("WindTurbine")) { return false; } return true; }, InfoMaker = (IMyPowerProducer block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") }, { "eff", new Efficiency(block, "Efficiency") } }; } }); }; mbb["PowerProducer"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyPowerProducer>(parser) { InfoMaker = (IMyPowerProducer block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") } }; } }); }; mbb["PowerGenerator"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyPowerProducer>(parser) { SubFilter = (IMyTerminalBlock block) => { if (block.BlockDefinition.SubtypeId.Contains("Battery")) { return false; } return true; }, InfoMaker = (IMyPowerProducer block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "PowerGen" } }, { "out", new Output(block, "Output") } }; } }); }; }
public static void Load(StationMonitorCore sm) { MonitorBlockBuilder mbb = sm.MBBuilder; mbb["Container"] = (MonitorBlockParser parser) => { MonitorOption option; string targetIngot = null; string targetOre = null; string desc = ""; string name; if (parser.Options.TryGetValue("ore", out option)) { targetOre = option.StrValue; if (OreNameTable.TryGetValue(targetOre, out name)) { desc = $"Stored {name}"; } } if (parser.Options.TryGetValue("ingot", out option)) { targetIngot = option.StrValue; if (IngotNameTable.TryGetValue(targetIngot, out name)) { desc = $"Stored {name}"; } } return(new MonitorBlock <IMyCargoContainer>(parser) { InfoMaker = (IMyCargoContainer block, int index) => { Store store = new Store(); if ((targetOre == null) && (targetIngot == null)) { store = new Store(block, desc); } else if (targetOre != null) { store = new Store(block, MyItemType.MakeOre(targetOre), desc); } else if (targetIngot != null) { store = new Store(block, MyItemType.MakeIngot(targetIngot), desc); } return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "Container" } }, { "sto", store } }; } }); }; mbb["Inventory"] = (MonitorBlockParser parser) => { MonitorOption option; string targetIngot = null; string targetOre = null; string desc = ""; string name; if (parser.Options.TryGetValue("ore", out option)) { targetOre = option.StrValue; if (OreNameTable.TryGetValue(targetOre, out name)) { desc = $"Stored {name}"; } } if (parser.Options.TryGetValue("ingot", out option)) { targetIngot = option.StrValue; if (IngotNameTable.TryGetValue(targetIngot, out name)) { desc = $"Stored {name}"; } } return(new MonitorBlock <IMyTerminalBlock>(parser) { SubFilter = (IMyTerminalBlock block) => { if (block.InventoryCount == 0) { return false; } return true; }, InfoMaker = (IMyTerminalBlock block, int index) => { Store store = new Store(); if ((targetOre == null) && (targetIngot == null)) { store = new Store(block, desc); } else if (targetOre != null) { store = new Store(block, MyItemType.MakeOre(targetOre), desc); } else if (targetIngot != null) { store = new Store(block, MyItemType.MakeIngot(targetIngot), desc); } return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "Container" } }, { "sto", store } }; } }); }; mbb["Refinery"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyRefinery>(parser) { InfoMaker = (IMyRefinery block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "Factory" } }, { "instore", new Store(block.InputInventory) }, { "outstore", new Store(block.OutputInventory) }, { "product", new Production(block) } }; } }); }; mbb["Assembler"] = (MonitorBlockParser parser) => { return(new MonitorBlock <IMyAssembler>(parser) { InfoMaker = (IMyAssembler block, int index) => { return new MonitorInfo { { "block", new CommonInfo(block, index) { Icon = "Factory" } }, { "instore", new Store(block.InputInventory) }, { "outstore", new Store(block.OutputInventory) }, { "product", new Production(block) }, { "assemble", new Assembler(block) } }; } }); }; }
public void Main(string argument, UpdateType updateSource) { #region Initial setup // Do some initial setup on the first call if (updateSource.HasFlag(UpdateType.Once)) { Me.GetSurface(0).WriteText("Storage Overview"); // Enumerate all the LCD panels and find the ones that are configured for ingots var textSurfaceProviders = new List <IMyTextSurfaceProvider>(); GridTerminalSystem.GetBlocksOfType(textSurfaceProviders); foreach (var textSurfaceProvider in textSurfaceProviders) { string configData = ((IMyTerminalBlock)textSurfaceProvider).CustomData; if (configData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)) { string ingotType = configData.Substring(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX.Length); int ingotIndex; if (ingotLookup.TryGetValue(ingotType, out ingotIndex)) { for (var surfaceIndex = 0; surfaceIndex < textSurfaceProvider.SurfaceCount; ++surfaceIndex) { var textSurface = textSurfaceProvider.GetSurface(surfaceIndex); textSurface.Alignment = TextAlignment.CENTER; textSurface.Font = "Monospace"; textSurface.FontSize = 2.4f; textSurface.TextPadding = 8.0f; textSurface.WriteText($"{ingotType}\nInitializing..."); textSurfaces[ingotIndex].Add(textSurface); } } } } // Find all the lights and sound blocks configured for ingot GridTerminalSystem.GetBlocksOfType(alertSoundBlocks, soundBlock => soundBlock.CustomData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)); GridTerminalSystem.GetBlocksOfType(alertOrWarningLights, interiorLight => interiorLight.CustomData.StartsWith(CUSTOMDATA_INGOT_STATUS_CONFIG_PREFIX)); } #endregion #region Update list of inventories // Only update the list of inventories we care about if (tenticksUntilNextUpdate == 0) { inventories.Clear(); GridTerminalSystem.GetBlocksOfType(inventoryBlocks, otherBlock => otherBlock.IsSameConstructAs(Me) && otherBlock.HasInventory); foreach (var inventoryBlock in inventoryBlocks) { for (var inventoryIndex = 0; inventoryIndex < inventoryBlock.InventoryCount; ++inventoryIndex) { inventories.Add(inventoryBlock.GetInventory(inventoryIndex)); } } tenticksUntilNextUpdate = NUMBER_OF_TENTICKS_BETWEEN_EACH_UPDATE - 1; return; } #endregion tenticksUntilNextUpdate--; // Count the ingots & ores of each ingot type foreach (var inventory in inventories) { for (var ingotIndex = 0; ingotIndex < INGOT_TYPES.Length; ++ingotIndex) { ingotCounts[ingotIndex] += inventory.GetItemAmount(MyItemType.MakeIngot(INGOT_TYPES[ingotIndex].Type)); oreCounts[ingotIndex] += inventory.GetItemAmount(MyItemType.MakeOre(INGOT_TYPES[ingotIndex].Type)); } } #region Update each ingot type // Update the status of each ingot type var anyAlerts = false; var anyWarnings = false; for (var ingotIndex = 0; ingotIndex < INGOT_TYPES.Length; ++ingotIndex) { var ingotConfig = INGOT_TYPES[ingotIndex]; var ingotCount = ingotCounts[ingotIndex].ToIntSafe(); ingotCounts[ingotIndex].RawValue = 0; var oreCount = oreCounts[ingotIndex].ToIntSafe(); oreCounts[ingotIndex].RawValue = 0; // Generate the text for the display displayBuilder.Clear(); displayBuilder.AppendLine(ingotConfig.Type); displayBuilder.AppendLine(); displayBuilder.AppendLine(ingotCount.ToString("N0")); displayBuilder.AppendLine("available"); if ((oreCount * ingotConfig.ConversionRatio) >= 1) { displayBuilder.AppendLine((oreCount * ingotConfig.ConversionRatio * REFINERY_EFFICIENCY).ToString("N0")); displayBuilder.AppendLine("processing"); } // Determine if there are any alerts or warnings, and pick the right font & background color var fontColor = Color.White; var backgroundColor = Color.Black; if (ingotCount < ingotConfig.AlertThreshold) { anyAlerts = true; fontColor = ALERT_FONT_COLOR; backgroundColor = ALERT_BACKGROUND_COLOR; } else if (ingotCount < ingotConfig.WarningThreshold) { anyWarnings = true; fontColor = WARNING_FONT_COLOR; backgroundColor = WARNING_BACKGROUND_COLOR; } foreach (var textSurface in textSurfaces[ingotIndex]) { textSurface.FontColor = fontColor; textSurface.BackgroundColor = backgroundColor; textSurface.WriteText(displayBuilder); } } #endregion #region Update global warning / alert systems // See if the worst status has changed and updated sound blocks & lights IngotStatus newIngotStatus = IngotStatus.Normal; if (anyAlerts) { newIngotStatus = IngotStatus.Alert; } else if (anyWarnings) { newIngotStatus = IngotStatus.Warning; } if (previousIngotStatus != newIngotStatus) { previousIngotStatus = newIngotStatus; bool playSound = false; Color?optionalLightColor = null; switch (newIngotStatus) { case IngotStatus.Alert: playSound = true; optionalLightColor = ALERT_BACKGROUND_COLOR; break; case IngotStatus.Warning: optionalLightColor = WARNING_BACKGROUND_COLOR; break; } foreach (var soundBlock in alertSoundBlocks) { if (playSound) { soundBlock.Play(); } else { soundBlock.Stop(); } } if (optionalLightColor.HasValue) { Color lightColor = optionalLightColor.Value; foreach (var interiorLight in alertOrWarningLights) { interiorLight.Enabled = true; interiorLight.Color = lightColor; } } else { foreach (var interiorLight in alertOrWarningLights) { interiorLight.Enabled = false; } } } #endregion }
public static MyInventoryItem MockIngot(String subType, float amount = 1) { return(new MyInventoryItem(MyItemType.MakeIngot(subType), 0, (MyFixedPoint)amount)); }