Esempio n. 1
0
        private void ProcessAirlockCommand()
        {
            var modifiers = default(CycleModifiers);

            modifiers.AutoOpenAll  = CommandLine.Switch("open");
            modifiers.SkipWaitTime = CommandLine.Switch("skip-wait");
            string doorTag;

            foreach (var s in CommandLine.Switches.Where(x => x.Contains("=")))
            {
                if (!string.IsNullOrEmpty(doorTag = StringUtils.After("open=", s)))
                {
                    if (modifiers.AutoOpen == null)
                    {
                        modifiers.AutoOpen = new HashSet <string>();
                    }
                    modifiers.AutoOpen.Add(doorTag);
                }
            }
            switch (CommandLine.Argument(0).ToLower())
            {
            case "pressurize":
            case "in":
                Airlocks[CommandLine.Argument(1)].CycleIn(modifiers);
                break;

            case "depressurize":
            case "out":
                Airlocks[CommandLine.Argument(1)].CycleOut(modifiers);
                break;

            case "toggle":
                Airlocks[CommandLine.Argument(1)].CycleToggle(modifiers);
                break;
            }
        }
        private void ParseArgument(string arg)
        {
            arg = arg.ToLower();
            // If the argument is only 'update', then we run ParseArgument with the arg stored in storage.
            if (arg.Trim() == "update")
            {
                arg = Storage;
            }
            // If the argument is only 'output', then we output the stored arg to the display screen attached to the programmable block and then leave.
            if (arg.Trim() == "output")
            {
                var surface = Me.GetSurface(0);
                surface.ContentType = ContentType.NONE;
                surface.WriteText(Storage);
                return;
            }
            // We check to see if the '-add' flag is true. We could do this with a simple .contains check, but I'm testing out this feature.
            MyCommandLine myCommandLine = new MyCommandLine();

            if (myCommandLine.TryParse(arg))
            {
                // If we do have the flag, then we add the current arg to the storage and run ParseArgument with the full storage arg.
                if (myCommandLine.Switch("add"))
                {
                    // We want to remove the flag so we dont keep adding every time we run update.
                    arg.Replace("-add", "");
                    Storage += ";" + arg;
                    arg      = Storage;
                }
            }
            // Clearing the lists so we dont multi-add displays.
            MissingOreDisplays         = new List <IMyTextSurface>();
            IngotCoverageDisplays      = new List <IMyTextSurface>();
            TotalIngotCoverageDisplays = new List <IMyTextSurface>();
            QueuedItemsDisplays        = new List <IMyTextSurface>();

            // We use ; as a command seperator.
            var commands = arg.Split(';');

            foreach (var commandLine in commands)
            {
                // Each command has to have an assignment.
                var commandSplit = commandLine.Split('=');
                if (commandSplit.Length != 2)
                {
                    continue;
                }
                var command = commandSplit[0].Trim();
                var value   = commandSplit[1];
                List <IMyTerminalBlock> valueSearch = new List <IMyTerminalBlock>();
                // We search for blocks with that name.
                GridTerminalSystem.SearchBlocksOfName(value, valueSearch);
                // And we filter it because we only care about IMyTextSurface blocks (lcd screens and the like)
                var valueLcdSearch = new List <IMyTextSurface>();
                foreach (var searchBlock in valueSearch)
                {
                    // We only consider blocks on the same grid.
                    if (!searchBlock.CubeGrid.IsSameConstructAs(Me.CubeGrid))
                    {
                        continue;
                    }
                    if (searchBlock is IMyTextSurface)
                    {
                        valueLcdSearch.Add(searchBlock as IMyTextSurface);
                    }
                }
                // If we can't find any text surfaces with that name then we print an error message on the control panel screen of the programmable block.
                if (valueLcdSearch.Count == 0)
                {
                    Echo("No text surface by the name of '" + value + "'");
                    continue;
                }

                // Here is where the command names go. Putting variations of them here.
                switch (command)
                {
                case "missing ore":
                case "missingore":
                case "missing":
                    MissingOreDisplays.AddList(valueLcdSearch);
                    break;

                case "coverage":
                    IngotCoverageDisplays.AddList(valueLcdSearch);
                    break;

                case "totalcoverage":
                case "total coverage":
                case "total":
                    TotalIngotCoverageDisplays.AddList(valueLcdSearch);
                    break;

                case "queue":
                case "queued items":
                case "queueditems":
                    QueuedItemsDisplays.AddList(valueLcdSearch);
                    break;

                case "missingrecipe":
                case "unknown":
                    MissingRecipeDisplays.AddList(valueLcdSearch);
                    break;

                default:
                    break;
                }
            }
            // Once we get to the end we store the arg. This is so we know what screens to use on startup and reduces the number of times we have to search for screens.
            Storage = arg;
        }
Esempio n. 3
0
 void DeltaRequest()
 {
     DeltaRequest(commandLine.Argument(1), int.Parse(commandLine.Argument(2)) * (commandLine.Switch("s") ? -1 : 1));
 }
Esempio n. 4
0
        public void Main(string argument, UpdateType updateSource)
        {
            addMessageLine("Automatic Minig Manager");
            addMessageLine("============================");
            addMessageLine((stopped_ ? "Stopped " : (doInit_ ? "Initilizing " : "Running ")) + ticker_[tickerCount_++]);
            if (tickerCount_ >= 4)
            {
                tickerCount_ = 0;
            }

            addMessageLine("Pistons:             " + pistons_.Count);
            addMessageLine("Piston Velocity: " + dropDownSpeedPerPiston_.ToString("#0.00###") + "m/s (Per Piston)");
            if (miningDepth_ > 0)
            {
                addMessageLine("Minig Depth:      " + currentMinigDepth().ToString("###0.00") + "m / " + miningDepth_.ToString("###0.00") + "m");
            }
            else
            {
                addMessageLine("Minig Depth:      " + currentMinigDepth().ToString("###0.00") + "m");
            }
            addMessageLine("Drill Rotor:         " + (drillRotor_ != null ? "Found" : "Not Found"));
            addMessageLine("Production Unit: " + (production_ != null ? "Found" : "Not Found"));

            // fill ratio
            if (inventory_ != null)
            {
                addMessageLine("Filled:                 " + (inventory_.FillRatio * 100d).ToString("##0.00") + "%");
            }

            if (stopped_)
            {
                addMessageLine("Restart:              " + (stoppedByUser_ ? "Manually" : "Automatic"));
            }
            else
            {
                addMessageLine("Restart:              Currently Running");
            }


            if (doInit_)
            {
                if (init())
                {
                    doInit_                 = false;
                    stopped_                = true;
                    stoppedByUser_          = GetConfigStoppedByUser();
                    Runtime.UpdateFrequency = UpdateFrequency.Update100;
                    flushMessages(lcd_);
                    return;
                }

                // stop automatic update
                addMessageLine("\nError on initializing.... script stopped!");
                Runtime.UpdateFrequency = UpdateFrequency.None;
                flushMessages(lcd_);
                return;
            }

            // normal tick
            if ((updateSource & UpdateType.Update100) != 0)
            {
                bool miningDepthArrived = maxMiningDepth_ <= 0f ? false : (currentMinigDepth() >= maxMiningDepth_ ? true : false);

                if (!stopped_ && (inventory_.FillRatio >= maxFillValue_ || miningDepthArrived))
                {
                    stop();
                    stopped_ = true;
                }
                else if (stopped_ && (inventory_.FillRatio <= restartFillRatio_ && !miningDepthArrived))
                {
                    if (!stoppedByUser_)
                    {
                        resume();
                        stopped_ = false;
                    }
                }

                // manage production
                if (production_ != null)
                {
                    production_.checkQueue();
                }
            }

            // executed by trigger
            if ((updateSource & UpdateType.Terminal) != 0 || (updateSource & UpdateType.Trigger) != 0)
            {
                MyCommandLine cl = new MyCommandLine();
                if (cl.TryParse(argument))
                {
                    if (cl.Switch("start"))
                    {
                        stoppedByUser_ = false;
                        resume();
                    }
                    else if (cl.Switch("stop"))
                    {
                        stoppedByUser_ = true;
                        stopped_       = true;
                        stop();
                    }
                    else if (cl.Switch("reset"))
                    {
                        stopped_       = true;
                        stoppedByUser_ = true;
                        reset();
                    }

                    for (int c = 0; c < cl.ArgumentCount; c++)
                    {
                        string cmd = cl.Argument(c).ToLower();
                        if (cmd == "maxdepth")
                        {
                            if (cl.ArgumentCount > (c + 1))
                            {
                                float value = -1f;
                                if (float.TryParse(cl.Argument(++c), out value))
                                {
                                    miningDepth_ = value;
                                }
                            }
                        }
                    }
                }
            }

            flushMessages(lcd_);
        }