public void TestDetectionDistance() { Player player = new Player(); player.Name = "GoodGuy"; player.IsComputerPlayer = true; Player playerEnemy = new Player(); playerEnemy.Name = "BadGuy"; playerEnemy.IsComputerPlayer = true; Group group = new Group(); GameManager.Instance.GameData.InitAllData(); Game game = GameManager.Instance.CreateGame(player, "test game"); game.Players.Add(player); game.Players.Add(playerEnemy); GameManager.Instance.Game.SetAllPlayersEnemies(); Position pos = new Position(60, 3, 22000, 120); BaseUnit unit = GameManager.Instance.GameData.CreateUnit(player, group, "e3sentry", "AWACS", pos, true); unit.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true); BaseUnit unitJammer = GameManager.Instance.GameData.CreateUnit(player, group, "p8poseidon", "Jammer", pos, true); unitJammer.SetWeaponLoad("Electronic warfare"); unitJammer.Position = unit.Position.Offset(90, 1000).Clone(); unitJammer.Position.BearingDeg = 90; var weaponJammer = unitJammer.GetSpecialWeapon(GameConstants.SpecialOrders.JammerRadarDegradation); Assert.IsNotNull(weaponJammer, "Jammer weapon should not be null"); Coordinate NextDoor = MapHelper.CalculateNewPosition2(unit.Position.Coordinate, 45, 100000); Position NextDoorPos = new Position(NextDoor); NextDoorPos.HeightOverSeaLevelM = 0; NextDoorPos.SetNewBearing(130); var jammingUnitOrder = OrderFactory.CreateRadarDegradationJammingOrder(unitJammer.Id, NextDoorPos.GetPositionInfo()); var jammingBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(jammingUnitOrder); Assert.IsTrue(jammingBaseOrder.SpecialOrders == GameConstants.SpecialOrders.JammerRadarDegradation, "Order should be jamming"); Group grpEnemy = new Group(); BaseUnit unitEnemy = GameManager.Instance.GameData.CreateUnit(playerEnemy, grpEnemy, "arleighburke", "DDG Vicious", NextDoorPos, true); unitEnemy.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, false); foreach (var wpn in unitEnemy.Weapons) { wpn.AmmunitionRemaining = 0; //so enemy can't launch missiles } game.IsNetworkEnabled = false; GameManager.Instance.Game.RunGameInSec = 1; GameManager.Instance.Game.StartGamePlay(); unitJammer.Orders.Enqueue(jammingBaseOrder); unitJammer.ExecuteOrders(); var jammingEffect = GameManager.Instance.Game.GetJammingDegradationPercent( unitEnemy.Position.Coordinate, playerEnemy); Assert.IsTrue(jammingEffect > 0.0, "Jamming should be in effect!"); Assert.IsTrue(player.DetectedUnits.Count == 1, "One and only one unit should have been detected."); player.AIHandler.SetPriorityScoresOnDetectedUnits(); double distanceToRadarHorizon0m = MapHelper.CalculateMaxRadarLineOfSightM(0, 20); double sizeArcSec0 = unitEnemy.CalculateApparentSizeArcSec( GameConstants.DirectionCardinalPoints.E, distanceToRadarHorizon0m); double distanceToRadarHorizon1000m = MapHelper.CalculateMaxRadarLineOfSightM(1000, 20); double sizeArcSec1000 = unitEnemy.CalculateApparentSizeArcSec( GameConstants.DirectionCardinalPoints.E, distanceToRadarHorizon1000m); double distanceToRadarHorizon5000m = MapHelper.CalculateMaxRadarLineOfSightM(5000, 20); double sizeArcSec5000 = unitEnemy.CalculateApparentSizeArcSec( GameConstants.DirectionCardinalPoints.E, distanceToRadarHorizon5000m); double distanceToRadarHorizon20000m = MapHelper.CalculateMaxRadarLineOfSightM(20000, 20); double sizeArcSec20000 = unitEnemy.CalculateApparentSizeArcSec( GameConstants.DirectionCardinalPoints.E, distanceToRadarHorizon20000m); var radar = unit.Sensors.First <BaseSensor>(s => s.SensorClass.IsPassiveActiveSensor); bool detectResult = radar.AttemptDetectUnit(unitEnemy, 600000); var log = GameManager.Instance.Log; log.LogDebug("*** TestDetectionDistance:\n"); log.LogDebug(string.Format("Height: {0}m \t RadarHor: {1:F}m {2:F}nm \t Size: {3:F}ArcSec", 0, distanceToRadarHorizon0m, distanceToRadarHorizon0m.ToNmilesFromMeters(), sizeArcSec0)); log.LogDebug(string.Format("Height: {0}m \t RadarHor: {1:F}m {2:F}nm \t Size: {3:F}ArcSec", 1000, distanceToRadarHorizon1000m, distanceToRadarHorizon1000m.ToNmilesFromMeters(), sizeArcSec1000)); log.LogDebug(string.Format("Height: {0}m \t RadarHor: {1:F}m {2:F}nm \t Size: {3:F}ArcSec", 5000, distanceToRadarHorizon5000m, distanceToRadarHorizon5000m.ToNmilesFromMeters(), sizeArcSec5000)); log.LogDebug(string.Format("Height: {0}m \t RadarHor: {1:F}m {2:F}nm \t Size: {3:F}ArcSec", 20000, distanceToRadarHorizon20000m, distanceToRadarHorizon20000m.ToNmilesFromMeters(), sizeArcSec20000)); }