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); }