Example #1
0
        private void TargetBench(string[] args)
        {
            IMyTerminalBlock tblock;

            if (QuickActionHudSpace.TryGetTargetedBlock(100d, out tblock))
            {
                int  iterations;
                bool getProperties = false;

                int.TryParse(args[0], out iterations);

                if (args.Length > 1)
                {
                    bool.TryParse(args[1], out getProperties);
                }

                Stopwatch timer = new Stopwatch();
                timer.Start();

                var grid   = new TerminalGrid();
                var pBlock = new PropertyBlock();

                grid.SetGrid(tblock.CubeGrid);

                for (int n = 0; n < iterations; n++)
                {
                    IMyTerminalBlock temp;
                    QuickActionHudSpace.TryGetTargetedBlock(100d, out temp);
                    pBlock.SetBlock(grid, tblock);

                    if (getProperties)
                    {
                        pBlock.GetEnabledElementCount();
                    }
                }

                timer.Stop();
                ExceptionHandler.SendChatMessage
                (
                    $"Target Bench:\n" +
                    $"\tGetProperties: {getProperties}\n" +
                    $"\tTime: {(timer.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond):G6} ms\n" +
                    $"\tIsHighResolution: {Stopwatch.IsHighResolution}\n" +
                    $"\tIterations: {iterations}"
                );
            }
            else
            {
                ExceptionHandler.SendChatMessage($"Cant start target bench. No target found.");
            }
        }
Example #2
0
        /// <summary>
        /// Tries to get terminal block being targeted by the local player if there is one.
        /// </summary>
        private bool TryGetTarget()
        {
            IMyTerminalBlock block;
            bool             canDisplaceBlock = LocalPlayer.CurrentBuilderBlock != null && !BvConfig.Current.targeting.canOpenIfPlacing,
                             canTarget = !canDisplaceBlock || BvConfig.Current.genUI.legacyModeEnabled;

            if (canTarget && TryGetTargetedBlockInternal(BvConfig.Current.targeting.maxOpenRange, out block))
            {
                if (block != null)
                {
                    TerminalPermissionStates permissions = block.GetAccessPermissions();

                    if ((permissions & TerminalPermissionStates.Granted) > 0 ||
                        LocalPlayer.HasAdminSetting(MyAdminSettingsEnum.UseTerminals))
                    {
                        if (Target.TBlock == null || block != Target.TBlock)
                        {
                            targetGrid.SetGrid(block.CubeGrid);
                            Target.SetBlock(targetGrid, block);

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if ((permissions & TerminalPermissionStates.GridUnfriendly) > 0)
                        {
                            hudNotification.Text = $"Access denied. Grid unfriendly.";
                        }
                        else
                        {
                            hudNotification.Text = "Access denied";
                        }

                        hudNotification.Show();
                    }
                }
            }

            return(false);
        }