Example #1
0
 public bool Filter(IMyTerminalBlock block)
 {
     if (block is IMyGasGenerator)
     {
         return(true);
     }
     if (!block.HasInventory)
     {
         return(false);
     }
     return(block.AnyInventoryCanContain(MyItemType.MakeOre("Ice")));
 }
Example #2
0
            public void Visit(IMyTerminalBlock block)
            {
                for (var i = 0; i < block.InventoryCount; i++)
                {
                    var inventory   = block.GetInventory(i);
                    var amountOfIce = inventory.GetItemAmount(MyItemType.MakeOre("Ice"));
                    if (amountOfIce == 0)
                    {
                        continue;
                    }

                    iceDetailsByGrid.Add(block.CubeGrid.CustomName, new IceDetails {
                        AmountOfIce = (float)amountOfIce
                    });
                }
                if (block is IMyGasGenerator)
                {
                    iceDetailsByGrid.Add(block.CubeGrid.CustomName, new IceDetails {
                        NumberOfH2O2Generators = 1
                    });
                }
            }
Example #3
0
            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) }
                            };
                        }
                    });
                };
            }
Example #4
0
        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
        }
Example #5
0
 public static MyInventoryItem MockOre(String subType, float amount = 1)
 {
     return(new MyInventoryItem(MyItemType.MakeOre(subType), 0, (MyFixedPoint)amount));
 }
Example #6
0
            public static void Load(StationMonitorCore sm)
            {
                MonitorBlockBuilder mbb = sm.MBBuilder;

                mbb["GasGenerator"] = (MonitorBlockParser parser) => {
                    return(new MonitorBlock <IMyGasGenerator>(parser)
                    {
                        InfoMaker = (IMyGasGenerator block, int index) => {
                            return new MonitorInfo
                            {
                                { "block", new CommonInfo(block, index)
                                  {
                                      Icon = "GasTank"
                                  } },
                                { "sto", new Store(block, MyItemType.MakeOre("Ice"), "Stored Ice") }
                            };
                        }
                    });
                };

                mbb["OxygenFarm"] = (MonitorBlockParser parser) => {
                    return(new MonitorBlock <IMyOxygenFarm>(parser)
                    {
                        InfoMaker = (IMyOxygenFarm block, int index) => {
                            var store = new Store("Oxygen Output");
                            // CubeBlocks.sbc <SubtypeId>LargeBlockOxygenFarm</SubtypeId> <MaxOutputPerSecond>0.03</MaxOutputPerSecond>
                            store.Max = 0.03f;  // unit is "L"
                            store.Current = store.Max * block.GetOutput();
                            return new MonitorInfo
                            {
                                { "block", new CommonInfo(block, index)
                                  {
                                      Icon = "GasTank"
                                  } },
                                { "sto", store }
                            };
                        }
                    });
                };

                mbb["OxygenTank"] = (MonitorBlockParser parser) => {
                    return(new MonitorBlock <IMyGasTank>(parser)
                    {
                        SubFilter = (IMyTerminalBlock block) => {
                            if (block.BlockDefinition.SubtypeId.Contains("Hydrogen"))
                            {
                                return false;
                            }
                            return true;
                        },

                        InfoMaker = (IMyGasTank block, int index) =>
                        {
                            return new MonitorInfo
                            {
                                { "block", new CommonInfo(block, index)
                                  {
                                      Icon = "O2Tank"
                                  } },
                                { "sto", new Store(block, "Stored Oxygen") }
                            };
                        }
                    });
                };

                mbb["HydrogenTank"] = (MonitorBlockParser parser) => {
                    return(new MonitorBlock <IMyGasTank>(parser)
                    {
                        SubFilter = (IMyTerminalBlock block) =>
                        {
                            if (!block.BlockDefinition.SubtypeId.Contains("Hydrogen"))
                            {
                                return false;
                            }
                            return true;
                        },

                        InfoMaker = (IMyGasTank block, int index) =>
                        {
                            return new MonitorInfo
                            {
                                { "block", new CommonInfo(block, index)
                                  {
                                      Icon = "H2Tank"
                                  } },
                                { "sto", new Store(block, "Stored Hydrogen") }
                            };
                        }
                    });
                };
            }