예제 #1
0
        public void BearingOnlyAttackAndSoftKillTest()
        {
            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);
            Coordinate NextDoor  = MapHelper.CalculateNewPosition2(unitBurke.Position.Coordinate,
                                                                   45, 10000);
            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.
            var unitEngOrder = OrderFactory.CreateEngagePositionOrder(unitBurke.Id,
                                                                      unitEnemyBurke.Position.GetPositionInfo(), "rgm84harpoon",
                                                                      GameConstants.EngagementOrderType.BearingOnlyAttack,
                                                                      GameConstants.EngagementStrength.MinimalAttack,
                                                                      1);

            //var baseEngOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(unitEngOrder);
            //unitBurke.Orders.Enqueue(baseEngOrder);
            player.HandleMessageFromClient(unitEngOrder);
            Assert.IsTrue(unitBurke.Orders.Count > 0, "There should be an order in the queue on the Burke.");
            unitBurke.ExecuteOrders();
            var missiles = from u in player.Units
                           where u.UnitClass.IsMissileOrTorpedo
                           select u;
            int missileCount = missiles.Count <BaseUnit>();

            Assert.IsTrue(missileCount > 0, "At least one missile should have been launched on bearing only launch.");
            //var missileSearchOrder = from o in
            var missile = missiles.FirstOrDefault <BaseUnit>() as MissileUnit;

            Assert.IsNotNull(missile.MovementOrder, "Missile has movement order");
            bool hasMissileSearchOrder = false;

            foreach (var wp in missile.MovementOrder.GetWaypoints())
            {
                if (wp.Orders.Count > 0)
                {
                    foreach (var o in wp.Orders)
                    {
                        if (o.OrderType == GameConstants.OrderType.MissileSearchForTarget)
                        {
                            hasMissileSearchOrder = true;
                        }
                    }
                }
            }
            Assert.IsTrue(hasMissileSearchOrder, "Missile should have a MissileSearchForTarget order");
            Assert.IsTrue(missile.TargetDetectedUnit == null, "Missile should not have a TargetDetectedUnit now");
            unitEnemyBurke.SetSensorsActivePassive(GameConstants.SensorType.Radar, true);
            unitBurke.SensorSweep();
            Assert.IsTrue(player.DetectedUnits.Count > 0, "At least one enemy unit should be detected.");

            missile.SearchForTarget();

            Assert.IsTrue(missile.TargetDetectedUnit != null, "Missile should now have a TargetDetectedUnit");
            bool       isSoftKillPossible = false;
            BaseWeapon softKillWeapon     = null;

            foreach (var wpn in unitEnemyBurke.Weapons)
            {
                if (wpn.WeaponClass.IsNotWeapon && wpn.WeaponClass.EwCounterMeasures != GameConstants.EwCounterMeasuresType.None)
                {
                    if (missile.CanBeSoftKilled(wpn))
                    {
                        isSoftKillPossible = true;
                        softKillWeapon     = wpn;
                    }
                }
            }

            Assert.IsTrue(isSoftKillPossible, "Soft kill should be possible");
            Assert.IsNotNull(softKillWeapon, "Soft kill weapon should be specified");
            bool isItSoftKilled = unitEnemyBurke.InflictMissileSoftkill(missile); //this is random
        }