Esempio n. 1
0
        public void EngagementOrderTest()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            Player playerEnemy = new Player();

            playerEnemy.Name             = "BadGuy";
            playerEnemy.IsComputerPlayer = true;

            Group group1 = new Group();
            Group group2 = 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   pos1      = new Position(60, 3, 0, 120);
            BaseUnit   unitBurke = GameManager.Instance.GameData.CreateUnit(player, group1, "arleighburke", "DDG Valiant", pos1, true);
            Position   pos2      = new Position(60, 3.2, 500, 120);
            BaseUnit   unitF22   = GameManager.Instance.GameData.CreateUnit(player, group2, "f22", "F22-AA", pos2, true);
            Coordinate NextDoor  = MapHelper.CalculateNewPosition2(unitBurke.Position.Coordinate,
                                                                   45, 1000);

            unitF22.UserDefinedSpeed = TTG.NavalWar.NWComms.GameConstants.UnitSpeedType.Slow;
            Position NextDoorPos = new Position(NextDoor);

            NextDoorPos.HeightOverSeaLevelM = 0;
            NextDoorPos.SetNewBearing(130);
            Group    grpEnemy       = new Group();
            BaseUnit unitEnemyBurke = GameManager.Instance.GameData.CreateUnit(
                playerEnemy, grpEnemy, "arleighburke", "DDG Vicious", NextDoorPos, true);

            game.IsNetworkEnabled = false;

            GameManager.Instance.Game.RunGameInSec = 1;
            GameManager.Instance.Game.StartGamePlay();
            var detectedEnemy = player.DetectedUnits[0];

            Assert.IsNotNull(detectedEnemy, "Enemy should have been detected.");
            //adding two attack orders on same target; second should be ignored.
            unitBurke.EngageDetectedUnit(detectedEnemy,
                                         TTG.NavalWar.NWComms.GameConstants.EngagementOrderType.EngageNotClose, false);
            unitBurke.EngageDetectedUnit(detectedEnemy,
                                         TTG.NavalWar.NWComms.GameConstants.EngagementOrderType.EngageNotClose, false);
            var attackOrders = from o in unitBurke.Orders
                               where o is EngagementOrder && (o as EngagementOrder).TargetDetectedUnit.Id == detectedEnemy.Id
                               select o;
            int countAttackOnBurke = attackOrders.Count <BaseOrder>();

            Assert.IsTrue(countAttackOnBurke == 1, "Exactly one attack order on enemy Burke should be in orders queue.");
        }
Esempio n. 2
0
        public void CloseAndEngageTest()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            Player playerEnemy = new Player();

            playerEnemy.Name             = "BadGuy";
            playerEnemy.IsComputerPlayer = true;

            Group group1 = new Group();
            Group group2 = 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 pos1      = new Position(60, 3, 0, 120);
            BaseUnit unitBurke = GameManager.Instance.GameData.CreateUnit(player, group1, "arleighburke", "DDG Valiant", pos1, true);

            unitBurke.SetSensorsActivePassive(GameConstants.SensorType.Sonar, true);
            unitBurke.UserDefinedSpeed = GameConstants.UnitSpeedType.Crawl;
            Coordinate NextDoor = MapHelper.CalculateNewPosition2(unitBurke.Position.Coordinate,
                                                                  45, 1000);
            Position NextDoorPos = new Position(NextDoor);

            NextDoorPos.HeightOverSeaLevelM = 0;
            NextDoorPos.SetNewBearing(130);
            Group    grpEnemy       = new Group();
            BaseUnit unitEnemyBurke = GameManager.Instance.GameData.CreateUnit(
                playerEnemy, grpEnemy, "arleighburke", "DDG Vicious", NextDoorPos, true);


            var subPos = pos1.Offset(4, 1100);

            subPos.HeightOverSeaLevelM = -40;
            var unitEnemySub = GameManager.Instance.GameData.CreateUnit(
                playerEnemy, null, "lada", "Lada sub", subPos, true);

            Position pos2 = NextDoorPos.Offset(90, 120000);

            pos2.BearingDeg = 90;
            BaseUnit unitF22 = GameManager.Instance.GameData.CreateUnit(player, group2, "f22", "F22-AA", pos2, true);

            unitF22.SetWeaponLoad("Naval strike");
            unitF22.UserDefinedSpeed = TTG.NavalWar.NWComms.GameConstants.UnitSpeedType.Slow;
            var weaponHarpoons = unitF22.Weapons.Where <BaseWeapon>(w => w.WeaponClass.Id == "jassmer");
            var weaponHarpoon  = weaponHarpoons.First <BaseWeapon>();

            Assert.IsNotNull(weaponHarpoon, "JASSM-ER weapon should be found on F22");
            foreach (var wpn in unitBurke.Weapons)
            {
                wpn.AmmunitionRemaining = 0;
            }
            foreach (var wpn in unitEnemyBurke.Weapons)
            {
                wpn.AmmunitionRemaining = 0;
            }
            pos2             = NextDoorPos.Offset(90, weaponHarpoon.WeaponClass.MaxWeaponRangeM + 5000);
            pos2.BearingDeg  = 90;
            unitF22.Position = pos2.Clone();

            game.IsNetworkEnabled = false;

            var gameTimeStartUp = GameManager.Instance.Game.GameCurrentTime;

            GameManager.Instance.Game.RunGameInSec = 1;
            GameManager.Instance.Game.StartGamePlay();

            var gameTimeAfter   = GameManager.Instance.Game.GameCurrentTime;
            var gameTimeElapsed = gameTimeAfter.Subtract(gameTimeStartUp);

            //Assert.IsTrue(Math.Abs(gameTimeElapsed.TotalSeconds - 20.0) < 0.01, "10 seconds of gametime should have elapsed."); //different on 32 and 64-bit!

            Assert.IsTrue(unitF22.CurrentWeaponLoadName.ToLower() == "naval strike", "F22 should be set for naval strike");

            var detectedEnemyShip = player.DetectedUnits.FirstOrDefault <DetectedUnit>(u => u.DomainType == GameConstants.DomainType.Surface);
            var detectedEnemySub  = player.DetectedUnits.FirstOrDefault <DetectedUnit>(u => u.DomainType == GameConstants.DomainType.Subsea);
            var detectedMyUnit    = playerEnemy.DetectedUnits[0];

            Assert.IsNotNull(detectedEnemyShip, "Enemy should have been detected.");
            Assert.IsNotNull(detectedMyUnit, "Enemy should have detected my unit.");
            Assert.IsNotNull(detectedEnemySub, "Enemy sub should have been detected.");

            detectedEnemyShip.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
            detectedEnemySub.FriendOrFoeClassification  = GameConstants.FriendOrFoe.Foe;
            foreach (var wpn in unitBurke.Weapons) //rearm again
            {
                wpn.AmmunitionRemaining = wpn.MaxAmmunition;
            }

            var allWeaponStatuses = unitBurke.GetAllWeaponEngagementStatuses("", detectedEnemySub);

            var bestWeaponSub = unitBurke.GetBestAvailableWeapon("", detectedEnemySub, false);

            Assert.IsNotNull(bestWeaponSub, "A best weapon to target sub should be found.");
            Assert.IsTrue(bestWeaponSub.EngagementStatusResult == GameConstants.EngagementStatusResultType.ReadyToEngage, "ASW weapon should be ready to engage.");

            double distanceBefore         = MapHelper.CalculateDistance3DM(unitF22.Position, detectedEnemyShip.Position);
            bool   hasAnyEngagementOrders = unitF22.HasAnyEngagementOrders();

            Assert.IsTrue(!hasAnyEngagementOrders, "Should NOT have engagement orders");
            unitF22.UserDefinedSpeed = TTG.NavalWar.NWComms.GameConstants.UnitSpeedType.Cruise;
            EngagementOrder order = new EngagementOrder(
                detectedEnemyShip, TTG.NavalWar.NWComms.GameConstants.EngagementOrderType.CloseAndEngage);

            unitF22.Orders.Enqueue(order);
            unitF22.ExecuteOrders();
            hasAnyEngagementOrders = unitF22.HasAnyEngagementOrders();
            //bool hasSpecificEngOrder = unitF22.HasAnyEngagementOrders(detectedEnemyShip);
            Assert.IsTrue(hasAnyEngagementOrders, "Should have engagement orders");
            //Assert.IsTrue(hasSpecificEngOrder, "Should have engagement orders");
            unitF22.EngageDetectedUnit(
                detectedEnemyShip,
                TTG.NavalWar.NWComms.GameConstants.EngagementOrderType.CloseAndEngage,
                true);

            GameManager.Instance.Game.RunGameInSec      = 1;
            GameManager.Instance.Game.IsGameLoopStarted = false;

            GameManager.Instance.Game.StartGamePlay();
            double distanceAfter = MapHelper.CalculateDistance3DM(unitF22.Position, detectedEnemyShip.Position);

            Assert.IsTrue(distanceBefore > distanceAfter, "F22 should have closed the distance.");
            GameManager.Instance.Game.RealTimeCompressionFactor = 1;
            //var engageOrder = unitF22.MovementOrder.GetActiveWaypoint().Orders[0];
            //Assert.IsNotNull(engageOrder, "F22 should have an order in waypoint");
            //var engageOrderAsEngage = engageOrder as EngagementOrder;
            //Assert.IsNotNull(engageOrderAsEngage, "F22 order should be engagementorder");
            //Assert.IsTrue(engageOrderAsEngage.TargetDetectedUnit.Id == detectedEnemy.Id,
            //    "Enemy target should be in wp order.");
            var bestWpnF22 = unitF22.GetUnitEngagementStatus("", detectedEnemyShip, true);

            foreach (var wpn in unitBurke.Weapons)
            {
                wpn.AmmunitionRemaining = wpn.WeaponClass.MaxAmmunition;
            }
            foreach (var wpn in unitEnemyBurke.Weapons)
            {
                wpn.AmmunitionRemaining = wpn.WeaponClass.MaxAmmunition;
            }

            var bestWpnBurke        = unitBurke.GetUnitEngagementStatus("", detectedEnemyShip, false);
            var allWpnStatusesBurke = unitBurke.GetAllWeaponEngagementStatuses("", detectedEnemyShip);
            var allWpnStatusesF22   = unitF22.GetAllWeaponEngagementStatuses("", detectedEnemyShip);

            var allWpnStatusesEnemyBurke = unitEnemyBurke.GetAllWeaponEngagementStatuses("", detectedMyUnit);

            Assert.IsTrue(bestWpnF22.Weapon.CanTargetDetectedUnit(detectedEnemyShip, true),
                          "Selected weapon should be able to target enemy");
            Assert.IsTrue(bestWpnBurke.Weapon.CanTargetDetectedUnit(detectedEnemyShip, true),
                          "Selected weapon should be able to target enemy");
            // Assert.IsTrue(bestWpnF22.WeaponCanBeUsedAgainstTarget, "Can be used against target");
            Assert.IsTrue(bestWpnBurke.WeaponCanBeUsedAgainstTarget, "Can be used against target");

            //GameManager.Instance.Game.RealTimeCompressionFactor = 100;
            //GameManager.Instance.Game.RunGameInSec = 8;
            //GameManager.Instance.Game.IsGameLoopStarted = false;

            //GameManager.Instance.Game.StartGamePlay();
            //double distanceAfterLast = MapHelper.CalculateDistance3DM(unitF22.Position, detectedEnemy.Position);
            ////Assert.IsTrue(distanceAfterLast < distanceAfter, "F22 should have closed the distance even further.");
            //Assert.IsTrue(detectedEnemy.IsFiredUpon, "Enemy should have been fired upon!");
            //var missiles = player.Units.Where<BaseUnit>(u => u.UnitClass.IsMissileOrTorpedo);
            //Assert.IsTrue(missiles.Count<BaseUnit>() > 0, "At least one missile should exist.");
        }
Esempio n. 3
0
        public void MissileSearchForTargetTest()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            Player playerEnemy = new Player();

            playerEnemy.Name             = "BadGuy";
            playerEnemy.IsComputerPlayer = true;

            Group group1 = new Group();
            Group group2 = 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 pos1           = new Position(60, 3, 1000, 70);
            BaseUnit unitP8         = GameManager.Instance.GameData.CreateUnit(player, group1, "p8poseidon", "Poseidon", pos1, true);
            string   weaponLoadName = "Naval strike";

            unitP8.SetWeaponLoad(weaponLoadName);
            Assert.IsTrue(unitP8.CurrentWeaponLoadName == weaponLoadName, "P8 should be set to naval strike");
            var wpnHarpoon = unitP8.Weapons.FirstOrDefault <BaseWeapon>(w => w.WeaponClass.WeaponClassName.Contains("arpoon"));
            var pos2       = pos1.Offset(70, wpnHarpoon.WeaponClass.EffectiveWeaponRangeM - 10000.0);
            var unitPamela = GameManager.Instance.GameData.CreateUnit(playerEnemy, null, "pamela", "Pamela", pos2, true);

            pos2.HeightOverSeaLevelM = 1000;
            var unitHelo = GameManager.Instance.GameData.CreateUnit(player, null, "sh60b", "sh60b", pos2, true);

            unitHelo.SetSensorsActivePassive(GameConstants.SensorType.Radar, true);
            unitHelo.SensorSweep();

            Assert.IsTrue(player.DetectedUnits.Count > 0, "Player should have detected at least one unit.");
            var detPamela = player.DetectedUnits.First <DetectedUnit>();

            unitP8.EngageDetectedUnit(detPamela, GameConstants.EngagementOrderType.EngageNotClose, false);
            unitP8.ExecuteOrders();

            var missiles = from m in player.Units
                           where m.UnitClass.IsMissileOrTorpedo
                           select m;

            Assert.IsTrue(missiles.Count <BaseUnit>() > 0, "There should be missiles that have been fired.");
            var missile = missiles.FirstOrDefault <BaseUnit>() as MissileUnit;

            var distanceToTarget = double.MaxValue;

            while (distanceToTarget > 4000 && !missile.IsMarkedForDeletion)
            {
                distanceToTarget = MapHelper.CalculateDistance3DM(missile.Position, unitPamela.Position);
                missile.MoveToNewPosition3D(1);
            }
            Assert.IsTrue(missile.IsMarkedForDeletion == false, "Missile should not have been deleted.");
            Assert.IsTrue(distanceToTarget <= 4000, "Distance should be under 4000m");

            missile.SearchForTarget();

            detPamela.IsMarkedForDeletion = true;
            player.DetectedUnits.Clear();

            //Search for target while it actually exists
            unitHelo.SensorSweep();
            missile.SearchForTarget();

            Assert.IsTrue(missile.TargetDetectedUnit != null, "Missile should now have a target.");


            //Search for target while it does not exist!
            missile.TargetDetectedUnit.IsMarkedForDeletion = true;
            unitPamela.IsMarkedForDeletion = true;
            player.DetectedUnits.Clear();
            missile.SearchForTarget();

            Assert.IsTrue(missile.IsMarkedForDeletion, "Missile should have been deleted.");
        }