public void Main(string argument)
        {
            if (RCs == null)
            {
                RCs = new List <IMyRemoteControl>();
            }
            Args = BaconArgs.parse(argument);
            EchoF("START - Remotes: {0}", RCs.Count);

            if (Args.getOption("reset").Count > 0)
            {
                Echo("RESET");
                reset();
            }
            List <IMyShipController> ShipCon = new List <IMyShipController>();

            GridTerminalSystem.GetBlocksOfType <IMyShipController>(ShipCon, (s => s.CustomName.Contains("[BWDA]")));
            if (ShipCon.Count > 0)
            {
                EchoF("Using {0} as Anchor", ShipCon[0].CustomName);
                foreach (IMyRemoteControl Remote in RCs)
                {
                    updateDrone(Remote, ShipCon[0]);
                }
            }
            Echo("END");
        }
Пример #2
0
        public void Main(string argument)
        {
            List <IMyTextPanel> TTYs = new List <IMyTextPanel>();

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(TTYs, (IMyTextPanel x) => x.CustomName.Contains("TTY") && x.CubeGrid.Equals(Me.CubeGrid));
            BaconShell.Environment env = new BaconShell.Environment(this, GridTerminalSystem, new BaconDebug("debug", GridTerminalSystem, this, 99));
            BaconShell             bs  = new BaconShell(env);

            for (int i_TTY = 0; i_TTY < TTYs.Count; i_TTY++)
            {
                IMyTextPanel TTY   = TTYs[i_TTY];
                string       stdin = TTY.GetPrivateText();
                if (!stdin.Equals(""))
                {
                    StringBuilder stdout  = new StringBuilder();
                    string[]      command = stdin.Split(new Char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < command.Length; i++)
                    {
                        BaconArgs Args = BaconArgs.parse(command[i]);
                        stdout.Append(bs.runCommand(Args, env).ToString());
                    }
                    TTY.WritePrivateText("");
                    TTY.WritePublicText(stdout.ToString());
                }
            }
        }
 public Environment(Program App, string argument, UpdateType updateSource)
 {
     this.App          = App;
     this.argumentRaw  = argument;
     this.GlobalArgs   = BaconArgs.parse(argument);
     this.updateSource = updateSource;
     this.Log          = NewLog();
 }
Пример #4
0
        /**
         * BaconSort
         * ==============
         * Copyright 2016 Thomas Klose <*****@*****.**>
         * License: https://github.com/BaconFist/SpaceEngineersIngameScript/blob/master/LICENSE
         * Source: https://github.com/BaconFist/SpaceEngineersIngameScript/blob/master/SpaceEngineersIngameScript/Scripts/BaconSort.cs
         *
         * Inventory Sorting
         * - Sort Items by tags in the Blockname
         *      Tags: #ammo, #component, #bottle, #ingot, #ore, #handtool
         * - Ignore all Reactors by default (can be changed by arguments)
         * - Ignore all Weapons by default (can be changed by arguments)
         * - Ignore all containers with "#!BaconSort" in their Name (can be changed by arguments)
         * - Ignore docked Ships & Stations (can be changed by arguments)
         * - Sorts only once every 5 minutes (can be changed by arguments)
         *
         * How it works:
         * Add any tag to a Container with an Inventory to pull items of this type in it.
         * Script is lazy, it will sort a item only if it is not in a Container with a matching tag. (Example: It will not pull an SteelPlate from an container called "Large Cargo Container #component")
         * Source & Target Block must match some requirements: 1. Same Grid as PB, 2. Must be connected throug Conveyor-System
         *
         *
         *
         *
         * Arguments for Storting:
         * ====================================
         *  --reactors
         *      Also sort Inventories of reactors
         *  --weapons
         *      Also sort Inventories of Weapons
         *  --docked
         *      Also sort inventories from docked Ships and Stations
         *  --ignore="TAG"
         *      ignore all Blocks with TAG in its name where TAG defaults to "#!BaconSort"
         *
         *
         * Arguments for Logging:
         * ====================================
         *  --log-noecho
         *      Disable log messages in Detailed Info
         *
         *  --log-lcd="TAG"
         *      Print Log Messages on TextPanels/LCDs where TAG is in its Name
         *
         *  --log-filter="F" (Default: fatal,error,warn,info)
         *      Only log messages if type "F" wehre F can be any of TRACE,DEBUG,INFO,WARN,ERROR,FATAL,ALL.
         *      Can be defined more than once (like --log-filter="info" --log-filter="warn")
         *      Can also be defined like --log-filter="debug,WARN,Fatal".
         *      "ALL" is equal to a combination of all other filters.
         *
         * Arguments for other stuff:
         * ==================================
         *  --sleep="N"
         *      scipt waits N seconfs before executing sorting loop where N defaults to 300 (5 minutes)
         *          //this is a workaround for flashing timer bug on Dedicated Servers.
         *
         **/


        public void Main(string argument)
        {
            BaconArgs Args = BaconArgs.parse(argument);

            BootstrapLog(Args);
            try {
                Log?.Debug("Stat Script at {0}", DateTime.Now);
                if (isAllowedToExecute(Args))
                {
                    Run(Args);
                }
            } catch (Exception e) {
                Log?.Fatal("Exception of Type {0} occured. Script Execution Terminated. => {1}", e.GetType().Name, e.Message);
            } finally
            {
                Log?.Flush();
            }
        }
        public void Main(string argument)
        {
            BaconArgs Args = BaconArgs.parse(argument);
            List <IMyUserControllableGun> Guns = new List <IMyUserControllableGun>();

            GridTerminalSystem.GetBlocksOfType <IMyUserControllableGun>(Guns, (b => ((Args.getOption("allGrids").Count > 0) || b.CubeGrid.Equals(Me.CubeGrid))));
            if (Args.getOption("enable").Count > 0)
            {
                for (int i = 0; i < Guns.Count; i++)
                {
                    Guns[i].ApplyAction("OnOff_On");
                }
            }
            else
            {
                for (int i = 0; i < Guns.Count; i++)
                {
                    Guns[i].ApplyAction("OnOff_Off");
                }
            }
        }
        /*
         *  example implementation for BaconArgs:
         *  run the PB with
         *      --source="TextPanel 1" --destination="TextPanel 2"
         *  to copy PublicText from TextPanel 1 to TextPanel 2
         */
        public void Main(string argument)
        {
            // parse PB arguments with Baconargs
            BaconArgs Args = BaconArgs.parse(argument);

            // validate if there is one --source and one --destination option given
            // as you can see the options are accessed without the leading --
            if (Args.getOption("source").Count == 1 && Args.getOption("destination").Count == 1)
            {
                // get the TextPanels using --source and --destination options
                // as options saved as a List<string> they are accessed like getOption("the option name")[zero-based-index]
                IMyTextPanel SourcePanel      = GridTerminalSystem.GetBlockWithName(Args.getOption("source")[0]) as IMyTextPanel;
                IMyTextPanel DestinationPanel = GridTerminalSystem.GetBlockWithName(Args.getOption("destination")[0]) as IMyTextPanel;

                //copy private text from source to destination if both block could be found
                if (SourcePanel != null && DestinationPanel != null)
                {
                    DestinationPanel.WritePublicText(SourcePanel.GetPublicText());
                }
            }
        }
Пример #7
0
 public BaconMessages(IMyTextPanel StorageDevice)
 {
     this.StorageDevice = StorageDevice;
     string[] data = (this.StorageDevice.GetPublicText() + this.StorageDevice.GetPrivateText()).Split(new Char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
     for (int i = 0; i < data.Length; i++)
     {
         BaconArgs R = BaconArgs.parse(data[0]);
         if ((R.getOption(Message.OPT_SENDER).Count > 0) && (R.getOption(Message.OPT_TIMECREATED).Count > 0) && (R.getOption(Message.OPT_TIMETOLIVE).Count > 0) && (R.getOption(Message.OPT_TYPE).Count > 0) && (R.getArguments().Count > 0))
         {
             int    TimeToLive  = 0;
             double TimeCreated = 0;
             string Content     = R.getArguments()[0];
             string Type        = R.getOption(Message.OPT_TYPE)[0];
             string Sender      = R.getOption(Message.OPT_SENDER)[0];
             if (int.TryParse(R.getOption(Message.OPT_TIMETOLIVE)[0], out TimeToLive) && double.TryParse(R.getOption(Message.OPT_TIMECREATED)[0], out TimeCreated))
             {
                 Message msg = new Message(Content, Sender, Type, TimeToLive, TimeCreated);
                 Add(msg);
             }
         }
     }
 }
Пример #8
0
        private void init()
        {
            #region initialization

            oldPBName = Me.CustomName;

            unique_id = (new Random()).Next();

            all_blocks_found = true;

            autopilot_en = true;

            location_name = "UNKNOWN";

            // For spinner
            counter = 0;

            string parse = Me.CustomName.Replace(BLOCK_PREFIX, "");
            int    id1   = Me.CustomName.IndexOf('[');
            int    id2   = Me.CustomName.IndexOf(']');
            if (id1 >= 0 && id2 >= 0)
            {
                parse = parse.Substring(id1 + 1, id2 - id1 - 1);
            }
            else
            {
                parse = "";
            }

            BaconArgs Args = BaconArgs.parse(parse);

            IS_BASE = (Args.getFlag('b') > 0);

            DOCK_LEFT = (Args.getFlag('l') > 0);

            IS_PLANET = (Args.getFlag('p') > 0);

            if (IS_PLANET)
            {
                IS_BASE = true;
            }

            List <string> nameArg = Args.getOption("name");

            if (nameArg.Count > 0 && nameArg[0] != null)
            {
                location_name = nameArg[0];
            }

            // Set all known blocks to null or clear lists
            lcdPanel        = null;
            messageReceiver = null;
            WANProgram      = null;
            connector       = null;
            remoteControl   = null;
            door            = null;
            timer           = null;
            landLight       = null;
            mainGear        = 0;

            gyros.Clear();
            destinations.Clear();
            gears.Clear();

            // Get all blocks
            List <IMyTerminalBlock> blks = new List <IMyTerminalBlock>();
            GridTerminalSystem.SearchBlocksOfName(BLOCK_PREFIX, blks, hasPrefix);
            num_blocks_found = blks.Count;


            // Assign blocks to variables as appropriate
            foreach (var blk in blks)
            {
                // LCD panel for printing
                if (blk is IMyTextPanel)
                {
                    lcdPanel = blk as IMyTextPanel;
                    lcdPanel.ShowPublicTextOnScreen();
                    lcdPanel.SetValueFloat("FontSize", 1.2f);
                }
                // Wico Area Network programmable block
                else if (blk is IMyProgrammableBlock && !blk.Equals(Me))
                {
                    WANProgram = blk as IMyProgrammableBlock;
                }
                // Autopilot
                else if (!IS_BASE && blk is IMyRemoteControl)
                {
                    remoteControl = blk as IMyRemoteControl;
                }

                /* Ship or station connector for docking
                 * Used to connect to station and for orientation info
                 */
                else if (!IS_PLANET && blk is IMyShipConnector)
                {
                    connector = blk as IMyShipConnector;
                }

                /* Door used for docking; used for orientation information
                 * since it's more obvious which way a door faces than a connector
                 */
                else if (!IS_PLANET && blk is IMyDoor)
                {
                    door = blk as IMyDoor;
                }
                // Gyros for ship orientation
                else if (!IS_BASE && blk is IMyGyro)
                {
                    IMyGyro g = blk as IMyGyro;
                    gyros.Add(g);
                }
                // Timer block so that we can orient ship properly - requires multiple calls/sec
                else if (!IS_BASE && blk is IMyTimerBlock)
                {
                    timer = blk as IMyTimerBlock;
                    timer.SetValueFloat("TriggerDelay", 1.0f);
                }
                // Light (interior or spotlight) determines where we will land
                else if (IS_BASE && IS_PLANET && blk is IMyInteriorLight)
                {
                    landLight = blk as IMyInteriorLight;
                }
                // Landing gear....
                else if (!IS_BASE && blk is IMyLandingGear)
                {
                    IMyLandingGear gear = blk as IMyLandingGear;
                    gears.Add(gear);
                    if (gear.CustomName.ToLower().Contains("main"))
                    {
                        mainGear = gears.Count - 1;
                    }
                }
            }

            // Make sure all gyros reset
            resetGyros();

            // Clear block list
            blks.Clear();

            // Get text panel blocks used by Wico Area Network for communication
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(blks, hasWANRPrefix);

            if (blks.Count == 0)
            {
                Echo("Error: Can't find message received text panel for Wico Area Network");
                all_blocks_found = false;
            }
            else
            {
                messageReceiver = blks[0] as IMyTextPanel;
                messageReceiver.WritePublicTitle("");
                messageReceiver.WritePrivateTitle("NAV");
            }

            if (WANProgram == null)
            {
                Echo("Error: Can't find programming block for Wico Area Network");
                all_blocks_found = false;
            }

            if (lcdPanel == null)
            {
                Echo("Error: Expect 1 LCD");
                all_blocks_found = false;
            }

            if (!IS_PLANET && connector == null)
            {
                Echo("Error: Can't find any connectors to use for docking");
                all_blocks_found = false;
            }

            if (!IS_BASE && remoteControl == null)
            {
                Echo("Error: Can't find any remote control blocks");
                all_blocks_found = false;
            }

            if (!IS_PLANET && door == null)
            {
                Echo("Error: Can't find door");
                all_blocks_found = false;
            }

            if (!IS_BASE && gyros.Count == 0)
            {
                Echo("Error: No gyros detected");
                all_blocks_found = false;
            }

            if (!IS_BASE && timer == null)
            {
                Echo("Error: No timer found");
                all_blocks_found = false;
            }
            if (IS_PLANET && landLight == null)
            {
                Echo("Error: No light for landing ship destination found");
                all_blocks_found = false;
            }
            if (!IS_BASE && gears.Count == 0)
            {
                Echo("Warning: no landing gear found.  You will not be able to land on planets");
            }

            // Init communicator state machine
            comm = communicate().GetEnumerator();

            // Clear autopilot state machine
            fly = null;
            #endregion
        }
 public BMyEnvironment(Program Assembly, string arguments)
 {
     this.Assembly = Assembly;
     ArgBag        = BaconArgs.parse(arguments);
     Log           = BMyLoggerFactory.getLogger(ArgBag, Assembly);
 }