Example #1
0
        public bool CanScan(Ingame.MyDetectedEntityInfo Target)
        {
            try
            {
                if (RadarCore.AllowScanningTargets == false)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scanning disabled in settings");
                    return(false);
                }
                if (!Radar.IsWorking())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Radar is disabled");
                    return(false);
                }
                if (!IsScanReady)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scan cooldown not expired");
                    return(false);
                }
                if (Target.IsEmpty())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target struct is empty");
                    return(false);
                }
                if (!Radar.DetectedEntities.Any(x => x.EntityId == Target.EntityId))
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target not found");
                    return(false);
                }

                if (!Target.IsGrid())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target is not a grid");
                    return(false);
                }
                IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid;
                if (Grid == null)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Cannot resolve EntityID");
                    return(false);
                }
                float Distance        = Radar.Position.DistanceTo(Target.Position);
                float MaxScanDistance = 3000 / (float)Math.Pow(RadarCore.DecoyScanDisruptionCoefficient, Grid.AsRadarable().DecoysCount);
                if (Distance > RadarCore.GuaranteedDetectionRange && Distance > MaxScanDistance)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Out of range: dist={Distance}; scanrange={MaxScanDistance}");
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }