static private byte getVerbosityFilter(BaconArgs ArgBag)
                {
                    byte slug      = 0;
                    int  verbosity = ArgBag.getFlag(BMyArgParams.LOG_VERBOSITY);

                    if (verbosity >= 1)
                    {
                        slug |= BMyLog4PB.E_FATAL;
                    }
                    if (verbosity >= 2)
                    {
                        slug |= BMyLog4PB.E_ERROR;
                    }
                    if (verbosity >= 3)
                    {
                        slug |= BMyLog4PB.E_WARN;
                    }
                    if (verbosity >= 4)
                    {
                        slug |= BMyLog4PB.E_INFO;
                    }
                    if (verbosity >= 5 && ArgBag.hasOption(BMyArgParams.LOG_ENABLEDEBUG))
                    {
                        slug |= BMyLog4PB.E_DEBUG;
                    }
                    if (verbosity >= 6 && ArgBag.hasOption(BMyArgParams.LOG_ENABLEDEBUG))
                    {
                        slug |= BMyLog4PB.E_TRACE;
                    }

                    return(slug);
                }
Esempio n. 2
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
        }