Exemplo n.º 1
0
 public void Save()
 {
     ini.Set("General", "AbortDistance", AbortDistance);
     ini.Set("General", "ScanningDistance", ScanningDistance);
     ini.Set("General", "MaxSpeed", MaxSpeed);
     ini.Set("General", "ActionTimeout", ActionTimeout);
     ini.Set("General", "TransmitTag", TransmitTag);
     ini.Set("General", "Dock", DockLocation.ToString());
     ini.Set("General", "DockApproach", DockApproachVector.ToString());
     ini.Set("General", "GrinderGroup", GrinderGroup);
     if (Vector3D.IsZero(GrinderApproach))
     {
         ini.Delete("General", "GrinderLocation");
         ini.Delete("General", "GrinderApproach");
     }
     else
     {
         ini.Set("General", "GrinderLocation", GrinderLocation.ToString());
         ini.Set("General", "GrinderApproach", GrinderApproach.ToString());
     }
     foreach (var kv in Approaches)
     {
         string data = string.Join("\n", kv.Value.Select <Vector3D, string>((v) => $"GPS:waypoint:{v.X:F3}:{v.Y:F3}:{v.Z:F3}:"));
         ini.Set("Approach", kv.Key, data);
     }
     ini.Set("Runtime", "CurrentState", State_Machine?.CurrentState ?? "");
     ini.Set("Runtime", "TargetLocation", TargetLocation.ToString());
     ini.Set("Runtime", "ChosenApproach", ChosenApproach);
     ini.Set("Runtime", "ApproachIndex", ApproachIndex);
     ini.Set("Runtime", "TargetEntityID", TargetEntityID);
     Storage = ini.ToString();
 }
        public void Activate()
        {
            Reset();
            Active = true;
            if (Subsystems.ContainsKey("docking"))
            {
                Subsystems["docking"].Command(TimeSpan.Zero, "dock", null);
            }

            MyIni Parser = new MyIni();

            if (!Parser.TryParse(Context.Reference.CustomData))
            {
                return;
            }

            Parser.Delete("Manager", "StartActive");
            Context.Reference.CustomData          = Parser.ToString();
            Context.Reference.CubeGrid.CustomName = myName;
        }
Exemplo n.º 3
0
        void Save(MyIni state)
        {
            state.Set(ID, "Policy", AssemblerPolicy.ToString());
            state.Set(ID, "MaxQueue", MaxQueue);
            state.Set(ID, "IgnoreSurvivalKits", IgnoreSurvivalKits);
            state.Set(ID, "Update", Tick);
            string cat = ID + ".Limits";

            if (DesiredStock.Count > 0)
            {
                foreach (var kv in DesiredStock)
                {
                    state.Set(cat, kv.Key.SubtypeId, kv.Value);
                }
            }
            else
            {
                state.Set(cat, "Dummy", 0);
                state.SetSectionComment(cat, "You can set item limits like this:\nComponent/SteelPlate=1000\nComponent/LargeTube=50\n");
                state.Delete(cat, "Dummy");
            }
        }
Exemplo n.º 4
0
        private void ParseCommand(String argument)
        {
            var words   = argument.Split(' ');
            var command = words.ElementAtOrDefault(0).ToLower();

            switch (command)
            {
            case "activate":
                switch (words.ElementAtOrDefault(1).ToLower())
                {
                case "":
                    Execute = true;
                    QueueOnce();
                    break;

                case "battle":
                    if (!GridState.HasFlag(EntityState.Battle))
                    {
                        UpdateNeeded = true;
                        GridState   |= EntityState.Battle;
                    }
                    break;

                case "destruct":
                    if (!GridState.HasFlag(EntityState.Destruct))
                    {
                        UpdateNeeded = true;
                        GridState   |= EntityState.Destruct;
                    }
                    break;
                }
                break;

            case "deactivate":
                switch (words.ElementAtOrDefault(1).ToLower())
                {
                case "":
                    Execute = false;
                    break;

                case "battle":
                    if (GridState.HasFlag(EntityState.Battle))
                    {
                        UpdateNeeded = true;
                        GridState   &= ~EntityState.Battle;
                    }
                    break;

                case "destruct":
                    if (GridState.HasFlag(EntityState.Destruct))
                    {
                        UpdateNeeded = true;
                        GridState   &= ~EntityState.Destruct;
                    }
                    break;
                }
                break;

            case "toggle":
                switch (words.ElementAtOrDefault(1).ToLower())
                {
                case "":
                    if (Execute)
                    {
                        Execute = false;
                    }
                    else
                    {
                        Execute = true;
                        QueueOnce();
                    }
                    break;

                case "battle":
                    if (GridState.HasFlag(EntityState.Battle))
                    {
                        GridState &= ~EntityState.Battle;
                    }
                    else
                    {
                        GridState |= EntityState.Battle;
                    }
                    UpdateNeeded = true;
                    break;

                case "destruct":
                    if (GridState.HasFlag(EntityState.Destruct))
                    {
                        GridState &= ~EntityState.Destruct;
                    }
                    else
                    {
                        GridState |= EntityState.Destruct;
                    }
                    UpdateNeeded = true;
                    break;
                }
                break;

            case "set":
                switch (words.ElementAtOrDefault(1).ToLower())
                {
                case "lowpower":
                    var    powerValue = words.ElementAtOrDefault(2);
                    Double powerParsed;

                    if (Double.TryParse(powerValue, out powerParsed) && powerParsed >= 0 && powerParsed < 1)
                    {
                        PowerThreshold = powerParsed;
                        Echo($"Low power threshold has been set to {powerParsed}.");
                    }
                    else
                    {
                        Echo($"Low power threshold must be a decimal value >= 0 < 1.");
                    }
                    break;

                case "countdown":
                    var    countdownValue = words.ElementAtOrDefault(2);
                    Single countdownParsed;

                    if (Single.TryParse(countdownValue, out countdownParsed) && countdownParsed > 0)
                    {
                        Countdown = countdownParsed;
                        Echo($"Self Destruct timer has been set to {TimeSpan.FromSeconds(Countdown)}.");
                    }
                    else
                    {
                        Echo($"Self Destruct timer must be a decimal value greater than 0.");
                    }
                    break;
                }
                break;

            case "group":
                var verb       = String.Join(" ", words.Skip(1).Take(2));
                var parameters = String.Join(" ", words.Skip(3)).Split(';');

                if (parameters.Count() == 0 || parameters.Count() > 2)
                {
                    break;
                }

                var group  = parameters.ElementAt(0);
                var target = parameters.ElementAtOrDefault(1);

                var blocks = new List <IMyTerminalBlock>();
                var config = new MyIni();
                var values = new List <String>();

                GridTerminalSystem.GetBlockGroupWithName(group).GetBlocks(blocks);

                if (!blocks.Any())
                {
                    break;
                }

                switch (verb)
                {
                case "add function":
                case "function add":
                    if (target == "")
                    {
                        break;
                    }

                    foreach (var block in blocks)
                    {
                        config.TryParse(block.CustomData);
                        config.Get(ConfigSection, "functions").GetLines(values);

                        if (!values.Contains(target))
                        {
                            values.Add(target);
                            config.Set(ConfigSection, "functions", String.Join("\n", values));

                            block.CustomData = config.ToString();
                        }
                    }
                    break;

                case "remove function":
                case "function remove":
                    foreach (var block in blocks)
                    {
                        config.TryParse(block.CustomData);
                        config.Get(ConfigSection, "functions").GetLines(values);

                        if (target == "")
                        {
                            config.Delete(ConfigSection, "functions");
                            block.CustomData = config.ToString();
                        }
                        else if (values.Contains(target))
                        {
                            values.Remove(target);
                            config.Set(ConfigSection, "functions", String.Join("\n", values));
                        }
                    }
                    break;

                case "add zone":
                case "zone add":
                    if (target == "")
                    {
                        break;
                    }

                    foreach (var block in blocks)
                    {
                        config.TryParse(block.CustomData);
                        config.Get(ConfigSection, "zones").GetLines(values);

                        if (!values.Contains(target))
                        {
                            values.Add(target);
                            config.Set(ConfigSection, "zones", String.Join("\n", values));

                            block.CustomData = config.ToString();
                        }
                    }
                    break;

                case "remove zone":
                case "zone remove":
                    foreach (var block in blocks)
                    {
                        config.TryParse(block.CustomData);
                        config.Get(ConfigSection, "zones").GetLines(values);

                        if (target == "")
                        {
                            config.Delete(ConfigSection, "zones");
                            block.CustomData = config.ToString();
                        }
                        else if (values.Contains(target))
                        {
                            values.Remove(target);
                            config.Set(ConfigSection, "zones", String.Join("\n", values));
                        }
                    }
                    break;
                }
                break;
            }
        }
Exemplo n.º 5
0
        public Program()
        {
            var containers = new List <IMyCargoContainer>();
            var assemblers = new List <IMyAssembler>();

            _ini.TryParse(Me.CustomData);
            if (_ini.Get(_sectionSettings, "WriteStockpileDefaults").ToBoolean())
            {
                var names = new Dictionary <string, MyFixedPoint>
                {
                    ["SteelPlate"]         = 5000,
                    ["SmallTube"]          = 5000,
                    ["Construction"]       = 4000,
                    ["InteriorPlate"]      = 4000,
                    ["Motor"]              = 3000,
                    ["LargeTube"]          = 2500,
                    ["Computer"]           = 2500,
                    ["MetalGrid"]          = 2500,
                    ["Display"]            = 2000,
                    ["BulletproofGlass"]   = 2000,
                    ["PowerCell"]          = 1500,
                    ["SolarCell"]          = 750,
                    ["Detector"]           = 750,
                    ["RadioCommunication"] = 750,
                    ["Explosives"]         = 100,
                };
                _stockpileCount = names.ToDictionary(x => GetBlueprint(x.Key), x => x.Value);

                foreach (var item in names)
                {
                    _ini.Set(_sectionStockpile, item.Key, item.Value.ToString());
                }

                _ini.Delete(_sectionSettings, "WriteStockpileDefaults");
                Me.CustomData = _ini.ToString();
            }
            else
            {
                _stockpileCount = new Dictionary <MyDefinitionId, MyFixedPoint>();
                var keys = new List <MyIniKey>();
                _ini.GetKeys(_sectionStockpile, keys);

                foreach (var item in keys)
                {
                    MyDefinitionId id;
                    if (TryGetBlueprint(item.Name, out id))
                    {
                        var amount = MyFixedPoint.DeserializeStringSafe(_ini.Get(item).ToString());
                        _stockpileCount.Add(id, amount);
                    }
                    else
                    {
                        Echo($"Unknown item type {item.Name}");
                    }
                }
            }

            _cargoItemCount         = new Dictionary <MyDefinitionId, MyFixedPoint>();
            _productionQueueCount   = new Dictionary <MyDefinitionId, MyFixedPoint>();
            _unqueuedStockpileCount = new Dictionary <MyDefinitionId, MyFixedPoint>();

            if (_ini.ContainsKey(_sectionSettings, "ContainerGroup"))
            {
                GridTerminalSystem
                .GetBlockGroupWithName(_ini
                                       .Get(_sectionSettings, "ContainerGroup")
                                       .ToString())
                .GetBlocksOfType(containers);
            }
            else
            {
                GridTerminalSystem
                .GetBlocksOfType(containers);
            }

            _cargoItemPanel = _ini.ContainsKey(_sectionSettings, "CargoItemPanel")
                ? GridTerminalSystem.GetBlockWithName(_ini.Get(_sectionSettings, "CargoItemPanel").ToString()) as IMyTextPanel
                : null;
            _productionQueuePanel = _ini.ContainsKey(_sectionSettings, "ProductionQueuePanel")
                ? GridTerminalSystem.GetBlockWithName(_ini.Get(_sectionSettings, "ProductionQueuePanel").ToString()) as IMyTextPanel
                : null;
            _unqueuedStockpilePanel = _ini.ContainsKey(_sectionSettings, "UnqueuedStockpilePanel")
                ? GridTerminalSystem.GetBlockWithName(_ini.Get(_sectionSettings, "UnqueuedStockpilePanel").ToString()) as IMyTextPanel
                : null;
            _stockpilePanel = _ini.ContainsKey(_sectionSettings, "StockpilePanel")
                ? GridTerminalSystem.GetBlockWithName(_ini.Get(_sectionSettings, "StockpilePanel").ToString()) as IMyTextPanel
                : null;

            DisplayStockpile(EchoTo(_stockpilePanel));

            GridTerminalSystem
            .GetBlockGroupWithName(_ini
                                   .Get(_sectionSettings, "AssemblerGroup")
                                   .ToString("Assemblers"))
            .GetBlocksOfType(assemblers);

            _containers = containers.ToArray();
            _assemblers = assemblers.ToArray();

            _enumerator = Step();

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }