Ejemplo n.º 1
0
        /// <summary>
        /// Based on uncertainty and Position, create a region wherein the detectedunit is found
        /// </summary>
        /// <returns></returns>
        public Region GetPositionRegion(DetectedUnitSensor sensor)
        {
            Region     region = new Region();
            Coordinate coord  = sensor.DetectionPlatform.Position.Coordinate;

            region.Coordinates.Add(coord);
            Coordinate coord1 = MapHelper.CalculateNewPosition2(
                coord, sensor.BearingDetectorToTargetDeg - (_ErrorBearingDeg * 0.5),
                sensor.DistanceDetectorToTargetM);

            region.Coordinates.Add(coord1);
            Coordinate coord2 = MapHelper.CalculateNewPosition2(
                coord, sensor.BearingDetectorToTargetDeg,
                sensor.DistanceDetectorToTargetM + _ErrorDistanceM);

            region.Coordinates.Add(coord2);
            Coordinate coord3 = MapHelper.CalculateNewPosition2(
                coord, sensor.BearingDetectorToTargetDeg + (_ErrorBearingDeg * 0.5),
                sensor.DistanceDetectorToTargetM);

            region.Coordinates.Add(coord3);
            region.Coordinates.Add(coord);
            return(region);
        }
Ejemplo n.º 2
0
        public DetectedUnitInfo GetDetectedUnitInfo()
        {
            DetectedUnitInfo   info   = new DetectedUnitInfo();
            DetectedUnitSensor sensor = null;

            //Debug.Assert(_DetectionSensors != null && _DetectionSensors.Count > 0,
            //    "DetectionSensors should contain at least one entry.");
            if (this._DetectionSensors != null && this._DetectionSensors.Count > 0)
            {
                sensor = this._DetectionSensors[0];                 //provide information from first sensor
                foreach (var DetSensor in _DetectionSensors)
                {
                    info.DetectionSensors.Add(DetSensor.GetDetectedUnitSensorInfo());
                }
            }
            info.Id = Id;
            //info.DetectedUnitDescription = ToLongString();
            info.DetectionClassification = DetectionClassification;
            info.DomainType = DomainType;
            info.FriendOrFoeClassification = FriendOrFoeClassification;
            info.ThreatClassification      = ThreatClassification;
            if (sensor != null)
            {
                info.IsBearingOnly = sensor.IsBearingOnly;
            }
            info.HasLightingOn      = HasLightingOn;
            info.KnownDamagePercent = KnownDamagePercent;
            info.KnownFireLevel     = KnownFireLevel;

            info.IsFixed                 = IsFixed;
            info.IsIdentified            = IsIdentified;
            info.IsKnownToUseActiveRadar = IsKnownToUseActiveRadar;
            info.IsKnownToUseActiveSonar = IsKnownToUseActiveSonar;
            info.IsKnownToBeCivilianUnit = IsKnownToBeCivilianUnit;
            info.Position                = GetPositionInfo();
            info.DetectedGroupId         = DetectedGroupId;
            info.IsFiredUpon             = this.IsFiredUpon;
            info.IsTargetted             = this.IsTargetted;
            if (this.PositionRegion != null)
            {
                info.PositionRegion = this.PositionRegion.GetRegionInfo();
            }
            if (RefersToUnit != null)
            {
                WeatherSystem weather = RefersToUnit.GetWeatherSystem();
                if (weather != null)
                {
                    info.WeatherSystemInfo = weather.GetWeatherSystemInfo();
                }
            }
            if (IsIdentified && RefersToUnit != null)
            {
                info.RefersToUnitName    = RefersToUnit.Name;
                info.RefersToUnitClassId = RefersToUnit.UnitClass.Id;
                if (OwnerPlayer != null)
                {
                    info.OwnerPlayerId   = OwnerPlayer.Id;
                    info.OwnerPlayerName = OwnerPlayer.Name;
                }
            }
            //info.UncertaintyRangeM = UncertaintyRangeM;
            return(info);
        }
Ejemplo n.º 3
0
 public bool RemoveSensor(DetectedUnitSensor detectionSensor)
 {
     return(_DetectionSensors.Remove(detectionSensor));
 }
Ejemplo n.º 4
0
        public DetectedUnitSensor AddOrUpdateSensor(BaseUnit unit, BaseSensor detectionSensor,
                                                    double detectionStrength, double distanceM, double targetApparentSizeArcSec, double minDetectableSizeArcSec)
        {
            DetectedUnitSensor sensor = _DetectionSensors.Find(d => d.Id == detectionSensor.Id);

            if (sensor == null)
            {
                sensor    = new DetectedUnitSensor();
                sensor.Id = detectionSensor.Id;
                sensor.DetectionSensor   = detectionSensor;
                sensor.DetectionPlatform = detectionSensor.OwnerUnit;
                sensor.DetectedUnit      = this;
                DetectionClassification  = unit.UnitClass.DetectionClassification;
                SetDirty(GameConstants.DirtyStatus.UnitChanged);

                _DetectionSensors.Add(sensor);
            }
            if ((detectionSensor.SensorClass.SensorType == GameConstants.SensorType.Radar ||
                 detectionSensor.SensorClass.SensorType == GameConstants.SensorType.Sonar) &&
                detectionSensor.IsActive && detectionSensor.SensorClass.IsPassiveActiveSensor)
            {
                unit.DetectionWithActiveSensor(detectionSensor, detectionStrength);
            }
            sensor.DetectedUnit = this;
            sensor.BearingDetectorToTargetDeg = MapHelper.CalculateBearingDegrees(
                detectionSensor.OwnerUnit.Position.Coordinate, unit.Position.Coordinate);
            sensor.DistanceDetectorToTargetM = distanceM;
            sensor.DetectionStrength         = detectionStrength;
            sensor.ApparentSizeArcSec        = targetApparentSizeArcSec;
            DetectedGameWorldTimeSec         = GameManager.Instance.Game.GameWorldTimeSec;
            sensor.DetectedWorldGameTimeSec  = GameManager.Instance.Game.GameWorldTimeSec;

            // Check if more than one unit has contact with the detected unit, and if so set fixed
            if (_DetectionSensors.Count > 1)
            {
                var firstPlatformId =
                    _DetectionSensors.First(s => !string.IsNullOrEmpty(s.DetectionPlatform.Id)).DetectionPlatform.Id;

                if (_DetectionSensors.Any(s => s.DetectionPlatform.Id != firstPlatformId))
                {
                    IsFixed = true;
                }
            }

            sensor.IsBearingOnly = false;
            switch (detectionSensor.SensorClass.SensorType)
            {
            case GameConstants.SensorType.Radar:

                if (detectionSensor.SensorClass.IsPassiveActiveSensor && detectionSensor.IsActive)                         //Active radar
                {
                    IsFixed = true;
                    if (detectionStrength > detectionSensor.SensorClass.IdentifyDetectionStrength)
                    {
                        IsIdentified = true;
                    }
                }
                else                         //passive radar, ie ESM
                {
                    IsIdentified            = true;
                    sensor.IsBearingOnly    = true;
                    IsKnownToUseActiveRadar = unit.IsUsingActiveRadar();
                }
                break;

            case GameConstants.SensorType.Sonar:
                if (detectionSensor.SensorClass.IsPassiveActiveSensor && !detectionSensor.IsActive &&
                    detectionStrength >= detectionSensor.SensorClass.IdentifyDetectionStrength)
                {
                    IsIdentified = true;
                }
                if ((detectionSensor.SensorClass.IsPassiveActiveSensor && !detectionSensor.IsActive) || (!detectionSensor.SensorClass.IsPassiveActiveSensor))
                {
                    IsKnownToUseActiveSonar = unit.IsUsingActiveSonar();
                }
                break;

            case GameConstants.SensorType.MAD:
                //IsFixed = false;
                //IsIdentified = false;
                break;

            case GameConstants.SensorType.Infrared:
            case GameConstants.SensorType.Visual:
                IsFixed = true;
                if (detectionStrength >= detectionSensor.SensorClass.IdentifyDetectionStrength)
                {
                    IsIdentified = true;
                }
                break;

            default:
                break;
            }
            if (unit != null)
            {
                RefersToUnit = unit;
                if (!IsFixed)
                {
                    sensor.UncertaintyRangeDeg = 10.0 / detectionStrength;
                    if (sensor.UncertaintyRangeDeg < 0.5)
                    {
                        sensor.UncertaintyRangeDeg = 0;
                    }
                    sensor.UncertaintyRangeM = sensor.DistanceDetectorToTargetM / 10.0;
                    if (detectionStrength > sensor.DetectionSensor.SensorClass.IdentifyDetectionStrength)
                    {
                        sensor.UncertaintyRangeM = sensor.UncertaintyRangeM / 2.0;
                    }
                    Coordinate newCoordinate = new Coordinate(unit.Position.Coordinate);
                    //TODO: UncertaintyRangeDeg betyr to forskjellige ting her...
                    if ((sensor.UncertaintyRangeM > 0 || sensor.UncertaintyRangeDeg > 0) &&
                        _ErrorDistanceM == 0 && _ErrorBearingDeg == 0)
                    {
                        double errorBearingDeg = 0;
                        double errorDistanceM  = 0;
                        CalculatePositionFromUncertainty(
                            distanceM, ref errorBearingDeg, ref errorDistanceM, ref newCoordinate);
                        _ErrorBearingDeg = errorBearingDeg;
                        _ErrorDistanceM  = errorDistanceM;
                    }
                    var coord = MapHelper.CalculateNewPosition2(unit.Position.Coordinate, _ErrorBearingDeg, _ErrorDistanceM);
                    Position = new Position(coord);
                    Position.HeightOverSeaLevelM     = unit.Position.HeightOverSeaLevelM;
                    Position.BearingDeg              = unit.Position.BearingDeg;
                    sensor.DistanceDetectorToTargetM = MapHelper.CalculateDistanceRoughM(
                        sensor.DetectionPlatform.Position.Coordinate, coord);
                    sensor.BearingDetectorToTargetDeg = MapHelper.CalculateBearingDegrees(
                        sensor.DetectionPlatform.Position.Coordinate, coord);
                    PositionRegion = GetPositionRegion(sensor);
                }
                else
                {
                    PositionRegion = null;
                    Position       = unit.Position.Clone();
                }
            }
            //sensor.UncertaintyRangeM = 0;
            return(sensor);
        }