private IEnumerator <bool> Init()
        {
            EchoStat("GridManager creation start");
            _gridManager = new GridManager(Me, GridTerminalSystem);
            EchoStat("GridManager creation end");
            yield return(false);

            EchoStat("Assemblers creation start");
            _assemblerManager = new AssemblerManager(GridTerminalSystem, _gridManager);
            EchoStat("Assemblers creation end");
            yield return(false);

            EchoStat("ContainerManager creation start");
            _containerManager = new ContainerManager(GridTerminalSystem, _gridManager);
            EchoStat("ContainerManager creation end");
            yield return(false);

            EchoStat("Inventories creation start");
            ScanMiscInventories(GridTerminalSystem, _gridManager, true);
            EchoStat("Inventories creation end");
            yield return(false);

            EchoStat("Refineries creation start");
            ScanRefineries(GridTerminalSystem, _gridManager, true);
            EchoStat("Refineries creation end");
            yield return(true);
        }
Exemplo n.º 2
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            this.manager = Process.CreateManager(this.Echo);
            var logger = new Logger(this.manager, this.Me.GetSurface(0), echo: this.Echo);

            this.command = new CommandLine("Inventory Manager", logger.Log, this.manager);

            int counter = 0;
            var ini     = new MyIni();

            ini.TryParse(this.Me.CustomData);

            this.manager.Spawn(p => this.gridManager          = new GridManager(this, ini, this.manager, logger.Log), "gm-init", period: ++counter, useOnce: true);
            this.manager.Spawn(p => this.containerManager     = new ContainerManager(this.GridTerminalSystem, this.gridManager, this.manager, logger.Log), "cm-init", period: ++counter, useOnce: true);
            this.manager.Spawn(p => this.assemblerManager     = new AssemblerManager(this.GridTerminalSystem, this.gridManager, this.manager), "am-init", period: ++counter, useOnce: true);
            this.manager.Spawn(p => this.refineryManager      = new RefineryManager(this.GridTerminalSystem, this.gridManager, this.manager), "rm-init", period: ++counter, useOnce: true);
            this.manager.Spawn(p => this.miscInventoryManager = new MiscInventoryManager(this.GridTerminalSystem, this.gridManager, this.manager, logger.Log), "mim-init", period: ++counter, useOnce: true);
            this.manager.Spawn(p => new InventoriesGroomer(this.gridManager, this.containerManager, this.assemblerManager,
                                                           this.miscInventoryManager, this.refineryManager, this.manager, logger.Log), "ig-init", period: ++counter, useOnce: true);
        }
Exemplo n.º 3
0
 public InventoriesGroomer(GridManager gridManager, ContainerManager contManager, AssemblerManager assemblerManager,
                           MiscInventoryManager miscInventoryManager, RefineryManager refineryManager, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger             = logger;
     this._outputInventories = new List <IOutputInventoryCollection> {
         assemblerManager, miscInventoryManager, refineryManager
     };
     spawner.Spawn(p => this._groomContainers(contManager), "container-groomer", period: 100);
     spawner.Spawn(p => this.groomOutputInventories(gridManager, contManager), "producer-groomer", period: 47);
 }
Exemplo n.º 4
0
        void Init()
        {
            SetupMessages = new List <string>();

            Ingots     = new List <IMyTerminalBlock>();
            Components = new List <IMyTerminalBlock>();
            Ores       = new List <IMyTerminalBlock>();
            Tools      = new List <IMyTerminalBlock>();
            Empty      = new List <IMyTerminalBlock>();

            ExternalExporter = new List <ExternalExportDefinition>();

            List <IMyAssembler> assemblers = new List <IMyAssembler>();

            Display.ResetDisplayList();

            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType(allBlocks, x => x.IsSameConstructAs(Me));

            foreach (var block in allBlocks)
            {
                if (block.InventoryCount > 0 || block is IMyTextSurfaceProvider)
                {
                    if (block is IMyAssembler)
                    {
                        assemblers.Add(block as IMyAssembler);
                    }

                    int indexOfTag = block.CustomName.IndexOf(TAG);
                    if (indexOfTag >= 0)
                    {
                        string part = block.CustomName.Substring(indexOfTag + TAG.Length);
                        part = part.Split(' ')[0];

                        //Find and remove potential screen index designation.
                        int indexOfAt    = part.IndexOf("@");
                        int displayIndex = 0;
                        if (indexOfAt != -1)
                        {
                            if (!int.TryParse(part.Substring(indexOfAt + 1), out displayIndex))
                            {
                                SetupMessages.Add("Did not understand LCD index. Don't understand ' " + part.Substring(indexOfAt + 1) + " '. It should be a number. (@'" + block.CustomName + "')");
                            }
                            part = part.Substring(0, part.Length - (part.Length - indexOfAt));
                        }

                        switch (part.ToLower())
                        {
                        case "ingot":
                        case "ingots":
                            if (block is IMyCargoContainer)
                            {
                                Ingots.Add(block);
                            }
                            else
                            {
                                SetupMessages.Add("Ingot storage can only be in containters. (@'" + block.CustomName + "'')");;
                            }
                            break;

                        case "component":
                        case "components":
                            if (block is IMyCargoContainer)
                            {
                                Components.Add(block);
                            }
                            else
                            {
                                SetupMessages.Add("Component storage can only be in containters. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "ore":
                        case "ores":
                            if (block is IMyCargoContainer)
                            {
                                Ores.Add(block);
                            }
                            else
                            {
                                SetupMessages.Add("Ore storage can only be in containters. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "tool":
                        case "tools":
                        case "misc":
                            if (block is IMyCargoContainer)
                            {
                                Tools.Add(block);
                            }
                            break;

                        case "empty":
                            Empty.Add(block);
                            break;


                        case "export-ingot":
                        case "export-ingots":
                            if (block is IMyShipConnector)
                            {
                                Empty.Add(block);
                                ExternalExporter.Add(new ExternalExportDefinition()
                                {
                                    connector = block as IMyShipConnector, exportFrom = Ingots
                                });
                            }
                            else
                            {
                                SetupMessages.Add("Export can only be set on a connector. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "export-component":
                        case "export-components":
                            if (block is IMyShipConnector)
                            {
                                Empty.Add(block);
                                ExternalExporter.Add(new ExternalExportDefinition()
                                {
                                    connector = block as IMyShipConnector, exportFrom = Components
                                });
                            }
                            else
                            {
                                SetupMessages.Add("Export can only be set on a connector. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "export-ore":
                        case "export-ores":
                            if (block is IMyShipConnector)
                            {
                                Empty.Add(block);
                                ExternalExporter.Add(new ExternalExportDefinition()
                                {
                                    connector = block as IMyShipConnector, exportFrom = Ores
                                });
                            }
                            else
                            {
                                SetupMessages.Add("Export can only be set on a connector. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "export-tool":
                        case "export-tools":
                            if (block is IMyShipConnector)
                            {
                                Empty.Add(block);
                                ExternalExporter.Add(new ExternalExportDefinition()
                                {
                                    connector = block as IMyShipConnector, exportFrom = Tools
                                });
                            }
                            else
                            {
                                SetupMessages.Add("Export can only be set on a connector. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "export-empty":
                            if (block is IMyShipConnector)
                            {
                                Empty.Add(block);
                                ExternalExporter.Add(new ExternalExportDefinition()
                                {
                                    connector = block as IMyShipConnector, exportFrom = Empty
                                });
                            }
                            else
                            {
                                SetupMessages.Add("Export can only be set on a connector. (@'" + block.CustomName + "')");
                            }
                            break;

                        case "display":
                        case "screen":
                        case "show":
                        case "lcd":
                            if (!Display.AddDisplay(block, displayIndex))
                            {
                                SetupMessages.Add("Block has no accesible LCDs. (@'" + block.CustomName + "')");
                            }
                            break;

                        default:
                            SetupMessages.Add("Option '" + part + "' wasn't understood. (@'" + block.CustomName + "')");
                            break;
                        }
                    }
                }
            }

            if (assemblers.Count > 0)
            {
                Assemblers = new AssemblerManager(Me, assemblers);
            }

            initialized     = true;
            RunStateMachine = Run();
        }