Beispiel #1
0
        public void Main(string argument, UpdateType updateSource)
        {
            System.Collections.Generic.List <IMyTextPanel> displays = new System.Collections.Generic.List <IMyTextPanel>();
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(displays, d => MyIni.HasSection(d.CustomData, "energy"));
            string           report1 = display1.Render(energyInfo1);
            string           report2 = display2.Render(energyInfo2);
            MyIni            menuIni = new MyIni();
            MyIniParseResult br;

            foreach (IMyTextPanel d in displays)
            {
                if (menuIni.TryParse(d.CustomData, out br))
                {
                    string group = menuIni.Get("energy", "group").ToString();
                    if (group.Equals("1"))
                    {
                        d.WriteText(report1);
                    }
                    else if (group.Equals("2"))
                    {
                        d.WriteText(report2);
                    }
                }
            }
            SpinningBar.Step();
        }
Beispiel #2
0
            public static Role Build(string roleName, MyIni config, Program program = null)
            {
                Role builtRole;

                switch (roleName)
                {
                case "miner":
                    builtRole = new Miner(config);
                    break;

                case "drone_controller":
                    builtRole = new DroneController(config);
                    break;

                case "tester":
                    builtRole = new Tester(config);
                    break;

                case "network_tester":
                    builtRole = new NetworkTester(config);
                    break;

                case "surveyor":
                    builtRole = new Surveyor(config);
                    break;

                default:
                    throw new Exception($"Unable to build role: {roleName}");
                    break;
                }

                return(builtRole);
            }
Beispiel #3
0
 public void Load(MyIni ini)
 {
     if (!TryGetValue(ini.Get(key), out value))
     {
         throw new IniMissingException(key.Name);
     }
 }
        // -----------------------------------------------------------------------
        public void readConfig()
        {
            MyIni ini = new MyIni();

            if (ini.TryParse(program.Me.CustomData))
            {
                List <MyIniKey> configKeys = new List <MyIniKey>();
                ini.GetKeys("Configuration", configKeys);
                foreach (MyIniKey key in configKeys)
                {
                    Option handler;
                    if (options.TryGetValue(key.Name, out handler))
                    {
                        string[] parameters = ini.Get(key).ToString().Split(',');
                        for (int p = 0; p < parameters.Length; p++)
                        {
                            parameters[p] = parameters[p].Trim();
                        }
                        handler.setParameters(parameters);
                    }
                }
            }
            else
            {
                program.Echo("Warning : Failed to parse configuration");
            }
        }
 void LoadHandle(MyIni theIni)
 {
     foreach (var handler in LoadHandlers)
     {
         handler(_SaveIni);
     }
 }
            void SaveHandler(MyIni theIni)
            {
//                _program.ErrorLog("wicocontrol save handler");
//                _program.ErrorLog("WCSH:M=" + _iMode.ToString() + " S=" + _iState.ToString());
                theIni.Set("WicoControl", "Mode", _iMode);
                theIni.Set("WicoControl", "State", _iState);
            }
Beispiel #7
0
            public ArmController(MyIni ini, MyGridProgram p, CommandLine cmd, IMyShipController cont, WheelsController wCont, ISaveManager manager)
            {
                var rotors = new List <IMyMotorStator>();

                p.GridTerminalSystem.GetBlocksOfType(rotors, r => r.CubeGrid == p.Me.CubeGrid && r.DisplayNameText.Contains("Arm Rotor"));
                this.rotors = rotors.Select(r => new ArmRotor(r, r.WorldMatrix.Up.Dot(cont.WorldMatrix.Right) > 0)).ToList();
                var keys = new List <MyIniKey>();

                ini.GetKeys(SECTION, keys);
                this.pos               = keys.Where(k => !k.Name.StartsWith("$")).ToDictionary(k => k.Name, k => new ArmPos(ini.Get(k).ToString()));
                this.pos["$top"]       = new ArmPos(this.rotors[0].Max);
                this.pos["$mid"]       = new ArmPos(0.2f);
                this.pos["$bottom"]    = new ArmPos(this.rotors[0].Min);
                this.pos["$auto-high"] = new ArmPos(ArmPos.R_ELEVATION, 0);
                this.pos["$auto-low"]  = new ArmPos(ArmPos.L_ELEVATION, 0);
                var tools = new List <IMyFunctionalBlock>();

                p.GridTerminalSystem.GetBlocksOfType(tools, t => t.IsSameConstructAs(cont) && (t is IMyShipToolBase || t is IMyShipDrill));
                this.autoCont = new ArmAutoControl(ini, this.Angle, wCont, tools);

                cmd.RegisterCommand(new Command("arm-del", Command.Wrap(this.deletePosition), "Deletes a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-elevation", Command.Wrap(this.autoElevate), "Makes the arm elevate at the correct position", detailedHelp: @"First argument is elevation ('high'/'low'/float)
Second argument is angle", maxArgs: 2));
                cmd.RegisterCommand(new Command("arm-drill", Command.Wrap(this.drill), "Engages the drills and move slowly to position", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-recall", Command.Wrap(this.recallPosition), "Recalls a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-save", Command.Wrap(this.savePosition), "Saves the current position of the arm", nArgs: 1));
                manager.Spawn(pc => this.updateRotors(cont), "arm-handle");
                manager.AddOnSave(this.save);
            }
            void LoadHandler(MyIni Ini)
            {
                int iCount = 0;

                iCount = Ini.Get(sAsteroidSection, "count").ToInt32(0);

                asteroidsInfo.Clear();
                Vector3D v3D;
                long     eId = 0;

                for (int j1 = 0; j1 < iCount; j1++)
                {
                    eId = Ini.Get(sAsteroidSection, "EntityId" + j1.ToString()).ToInt32(0);
                    if (eId <= 0)
                    {
                        continue; // skip bad data
                    }
                    BoundingBoxD box = new BoundingBoxD();

                    Vector3D.TryParse(Ini.Get(sAsteroidSection, "BBMin" + j1.ToString()).ToString(), out v3D);
                    box.Min = v3D;
                    Vector3D.TryParse(Ini.Get(sAsteroidSection, "BBMax" + j1.ToString()).ToString(), out v3D);
                    box.Max = v3D;

                    AsteroidInfo ast = new AsteroidInfo
                    {
                        EntityId    = eId,
                        BoundingBox = box
                    };
                    asteroidsInfo.Add(ast);
                }
            }
            public Logger(Program prog, string requiredIniSection, bool enforceSameCubegrid = true)
            {
                var blocks = new List <IMyTerminalBlock>();

                prog.GridTerminalSystem.GetBlocksOfType(blocks, bl =>
                {
                    var hasSection   = MyIni.HasSection(bl.CustomData, requiredIniSection);
                    var sameCubegrid = enforceSameCubegrid ? bl.CubeGrid == prog.Me.CubeGrid : true;
                    return(hasSection && sameCubegrid);
                });
                foreach (var block in blocks)
                {
                    if (block is IMyTextSurface)
                    {
                        prog.Echo($"Found text surface \"{block.CustomName}\" for logging.");
                        AddSurface((IMyTextSurface)block);
                    }
                    else if (block is IMyTextSurfaceProvider)
                    {
                        prog.Echo($"Found text surface provider \"{block.CustomName}\" for logging.");
                        AddSurface(((IMyTextSurfaceProvider)block).GetSurface(0));
                    }
                }
                if (surfaces.Count == 0)
                {
                    prog.Echo("Warning: Couldn't find any displays during logger initialization!");
                }
            }
Beispiel #10
0
 void LoadHandler(MyIni Ini)
 {
     /*
      *             int iCount = -1;
      *          long eId = 0;
      *          string sBaseName = "";
      *          Vector3D position = new Vector3D();
      *          bool bJumpCapable = false;
      *
      *          iniWicoCraftSave.GetValue(sBaseSavedListSection, "count", ref iCount);
      *
      *          for (int j1 = 0; j1 < iCount; j1++)
      *          {
      *              iniWicoCraftSave.GetValue(sBaseSavedListSection, "ID" + j1.ToString(), ref eId);
      *              iniWicoCraftSave.GetValue(sBaseSavedListSection, "name" + j1.ToString(), ref sBaseName);
      *              iniWicoCraftSave.GetValue(sBaseSavedListSection, "position" + j1.ToString(), ref position);
      *              iniWicoCraftSave.GetValue(sBaseSavedListSection, "Jumpable" + j1.ToString(), ref bJumpCapable);
      *
      *              BaseInfo b1 = new BaseInfo
      *              {
      *                  baseId = eId,
      *                  baseName = sBaseName,
      *                  position = position,
      *                  bJumpCapable = bJumpCapable
      *              };
      *
      *              baseList.Add(b1);
      *          }
      *
      *          return iCount;
      */
 }
Beispiel #11
0
 void Load(MyIni state)
 {
     InventorySlice = state.Get(JobName, "InventorySlice").ToUInt16(50);
     Policy         = state.Get(JobName, "Policy").ToString("SameConstruct");
     Owner.Unsubscribe(UpdateInventoryTick, Tick);
     Tick = Owner.Subscribe(UpdateInventoryTick, state.Get(JobName, "Update").ToString(), "update100s");
 }
Beispiel #12
0
 void Save(MyIni state)
 {
     state.Set(JobName, "InventorySlice", InventorySlice);
     state.Set(JobName, "Policy", Policy.ToString());
     state.Set(JobName, "IgnoreTools", IgnoreTools);
     state.Set(JobName, "Update", Tick);
 }
        public void SearchForNDBMessages()
        {
            List <MyIni> ActiveNDBTransmitters    = new List <MyIni>();
            List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>();

            IGC.GetBroadcastListeners(listeners);

            // Parse any messages from active listeners on the selected channel.
            listeners.ForEach(listener => {
                if (!listener.IsActive)
                {
                    return;
                }
                if (listener.Tag != NDBAntennaChannel)
                {
                    return;
                }
                if (listener.HasPendingMessage)
                {
                    ActiveNDBTransmitters.Add(
                        ParseBroadcastedMessage(listener.AcceptMessage())
                        );
                }
            });

            double shortestDistance       = 99999;
            MyIni  selectedNDBTransmitter = new MyIni();

            // Select the transmitter closest to the ship.
            ActiveNDBTransmitters.ForEach(transmitter =>
            {
                string _GPS     = transmitter.Get("Station", "Position").ToString();
                double distance = CalculateShipDistanceFromGPSString(_GPS);

                if (distance < shortestDistance)
                {
                    selectedNDBTransmitter = transmitter;
                }
            });

            if (ActiveNDBTransmitters.Count == 0)
            {
                Echo("Not able to connect to any NDB transmitter signals.");
                return;
            }

            string Name     = selectedNDBTransmitter.Get("Station", "Name").ToString();
            string Position = selectedNDBTransmitter.Get("Station", "Position").ToString();

            Echo("Connected to NDB: " + Name);

            config.Set("NDBStation", "Name", Name);
            config.Set("NDBStation", "Position", Position);

            SaveStorage();

            ShipHasSelectedNDB     = true;
            ShipShouldListenForNDB = false;
        }
Beispiel #14
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;

            _ini    = new MyIni();
            _drills = InitDrills();
            ConfigureDisplays();
        }
Beispiel #15
0
 public ScriptHandler(Program program, MyIni storage, string scriptName, string scriptVersion)
 {
     _program       = program;
     _storage       = storage;
     _scriptName    = scriptName;
     _scriptVersion = scriptVersion;
     _config        = new Config(_ini, _scriptName);
 }
Beispiel #16
0
 private double getIniDouble(MyIni ini, string section, string key, double defaultValue)
 {
     if (!ini.ContainsKey(section, key))
     {
         return(defaultValue);
     }
     return(ini.Get(section, key).ToDouble(defaultValue));
 }
Beispiel #17
0
 void save(MyIni ini)
 {
     foreach (KeyValuePair <string, ArmPos> kv in this.pos.Where(k => !k.Key.StartsWith("$")))
     {
         ini.Set(SECTION, kv.Key, kv.Value.ToString());
     }
     this.autoCont.Save(ini);
 }
Beispiel #18
0
            public MyIni GetConfig()
            {
                MyIni config = new MyIni();

                config.TryParse(Program.Me.CustomData);

                return(config);
            }
Beispiel #19
0
 private long getIniLong(MyIni ini, string section, string key, long defaultValue)
 {
     if (!ini.ContainsKey(section, key))
     {
         return(defaultValue);
     }
     return(ini.Get(section, key).ToInt64());
 }
Beispiel #20
0
 bool LoadHandle(MyIni theIni)
 {
     foreach (var handler in LoadHandlers)
     {
         handler(_SaveIni);
     }
     return(false); // no need to run again
 }
Beispiel #21
0
 private int getIniInteger(MyIni ini, string section, string key, int defaultValue)
 {
     if (!ini.ContainsKey(section, key))
     {
         return(defaultValue);
     }
     return(ini.Get(section, key).ToInt32());
 }
Beispiel #22
0
        bool SubProcessDisableBroadcasting()
        {
            var antenna = FindFirstBlockOfType <IMyRadioAntenna>(blk => MyIni.HasSection(blk.CustomData, ScriptPrefixTag));

            antenna.EnableBroadcasting = false;

            return(true);
        }
Beispiel #23
0
        private void Setup()
        {
            _groupList.Clear();

            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            // Find all blocks with a "[LandingPad]" section in custom data.
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, block => MyIni.HasSection(block.CustomData, MyConstants.SectionName) && block.IsSameConstructAs(Me));

            // Step through each block and determine groups
            foreach (IMyTerminalBlock block in blocks)
            {
                // parse the custom data for the block
                MyIniParseResult parsedIniResult;
                if (_data.TryParse(block.CustomData, out parsedIniResult))
                {
                    MyConfiguration blockConfig = new MyConfiguration(_data);

                    // Get the Group value.
                    string groupName = blockConfig.GroupName;

                    // If there is no group specified and if this is a text panel, use that as a main panel,
                    // otherwise continue with next block.
                    if (blockConfig.GroupName == MyConstants.DefaultGroupName)
                    {
                        IMyTextPanel lcdPanel = block as IMyTextPanel;
                        if (lcdPanel != null)
                        {
                            DisplayPanel panel = new DisplayPanel(_groupList, lcdPanel);
                            _mainPanels.Add(panel);
                        }

                        continue;
                    }
                    ;

                    // If group does not exist, add a new group with this name.
                    if (!_groupList.Exists(x => x.GroupName == groupName))
                    {
                        LandingPadGroup landingLightGroup = new LandingPadGroup(groupName);
                        _groupList.Add(landingLightGroup);
                    }

                    // Get the group for this block it should be added to.
                    LandingPadGroup group = _groupList.Find(x => x.GroupName == groupName);

                    AddBlockToGroup(group, block, blockConfig);
                }
            }


            // All block should now be assigned.
            // Configure the individual blocks for each group.
            foreach (LandingPadGroup group in _groupList)
            {
                group.ConfigureBlocks();
            }
        }
 void Load(MyIni state)
 {
     if (!GridPolicy.TryParse(state.Get(ID, "Policy").ToString(), out Policy))
     {
         Policy = GridPolicy.Types.SameConstruct;
     }
     Owner.Unsubscribe(UpdateBlock, Tick);
     Tick = Owner.Subscribe(UpdateBlock, state.Get(ID, "Update").ToString(), "update100s");
 }
Beispiel #25
0
 ConnectionRequest deserializeRequest(MyIni ini, string sectionName, string requestName)
 {
     return(new ConnectionRequest {
         Address = ini.GetThrow(sectionName, $"{requestName}-address").ToInt64(),
         Orientation = ini.GetVector(sectionName, $"{requestName}-orientation"),
         Position = ini.GetVector(sectionName, $"{requestName}-position"),
         Size = (MyCubeSize)Enum.Parse(typeof(MyCubeSize), ini.GetThrow(sectionName, $"{requestName}-size").ToString())
     });
 }
Beispiel #26
0
 public GridManager(MyGridProgram program, MyIni ini, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger = logger;
     this._block = program.Me;
     this.Scan(program.GridTerminalSystem);
     spawner.Spawn(p => this.Scan(program.GridTerminalSystem), "grid-scanner", period: 100);
     this._managedGrids = new HashSet <string>(ini.Get(INI_SECTION, "managed-grids").ToString().Split(SPLIT_VALUES_CHAR, StringSplitOptions.RemoveEmptyEntries));
     this.log($"We manage {this._managedGrids.Count} grids");
 }
Beispiel #27
0
            private void ParseConfig(MyIni config)
            {
                if (!config.Get(Name(), "parent_address").TryGetInt64(out ParentAddress))
                {
                    throw new Exception("Parent address is missing");
                }

                config.Get(Name(), "parent_address").TryGetString(out State);
            }
Beispiel #28
0
        private void RefreshBlockList()
        {
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(_blocksWithInventory, block =>
                                                                  block.HasInventory && block.IsSameConstructAs(Me) &&
                                                                  (!_optInWithTag || MyIni.HasSection(block.CustomData, _tagName)));

            _inventories.Clear();
            _inventories.AddRange(_blocksWithInventory.SelectMany(block => Enumerable.Range(0, block.InventoryCount).Select(block.GetInventory)));
        }
Beispiel #29
0
 public Program()
 {
     Airlocks                = new Dictionary <string, Airlock>();
     CommandLine             = new MyCommandLine();
     InitSettings            = new MyIni();
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
     Output = new StringBuilder();
     Initialize();
 }
Beispiel #30
0
        /// <summary>Parses the text and throws if the parse was unsucessful.</summary>
        /// <param name="ini">This</param>
        /// <param name="data">Serialized ini</param>
        public static void Parse(this MyIni ini, string data)
        {
            MyIniParseResult res;

            if (!ini.TryParse(data, out res))
            {
                throw new InvalidOperationException($"Error '{res.Error}' at line {res.LineNo} when parsing");
            }
        }