Ejemplo n.º 1
0
        public void DeploySonobuoy()
        {
            Player player = new Player();
            Group  group  = new Group();

            GameManager.Instance.GameData.InitAllData();
            GameManager.Instance.CreateGame(player, "test game");
            GameManager.Instance.Game.UpperLeftCorner  = new Coordinate(70, -10);
            GameManager.Instance.Game.LowerRightCorner = new Coordinate(40, 10);
            Position pos  = new Position(60, 3, 200, 80);
            BaseUnit unit = GameManager.Instance.GameData.CreateUnit(player, group, "sh60b", "Helo", pos, true);

            Assert.IsNotNull(unit, "Helo unit should not be null.");
            var unitOrder = OrderFactory.CreateSonobuoyDeploymentOrder(unit.Id, null, true, true);
            var baseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(unitOrder);

            Assert.IsNotNull(baseOrder, "Order should not be null");
            Assert.IsTrue(baseOrder.SpecialOrders == GameConstants.SpecialOrders.DropSonobuoy, "Should be sonobuoy order");
            unit.Orders.Enqueue(baseOrder);

            unit.ExecuteOrders();

            Sonobuoy buoy = (Sonobuoy)player.Units.First <BaseUnit>(u => u.UnitClass.UnitType == GameConstants.UnitType.Sonobuoy);

            Assert.IsNotNull(buoy, "Sonobuoy should exist");
            Assert.IsTrue(buoy.Position.HeightOverSeaLevelM < 0, "Sonobuoy should be below surface.");
            Assert.IsTrue(buoy.Sensors.Count <BaseSensor>() > 0, "Sonobuoy should have at least one sensor.");
        }
Ejemplo n.º 2
0
        public void TestCreateAircraftLaunchOrderEngage()
        {
            Player player = new Player();

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

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


            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, 1000, 120);
            var      nextDoorPos = pos.Offset(75, 10000);
            BaseUnit unitMain    = GameManager.Instance.GameData.CreateUnit(player, null, "nimitz", "Nimitz", pos, true);

            unitMain.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);

            BaseUnit unitEnemy = GameManager.Instance.GameData.CreateUnit(playerEnemy, null, "boeing767", "", nextDoorPos, true);

            Assert.IsNotNull(unitEnemy, "Enemy is not null");
            unitEnemy.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);
            game.IsGamePlayStarted = true;             //lying!
            unitMain.SensorSweep();
            unitEnemy.SensorSweep();
            Assert.IsTrue(player.DetectedUnits.Count > 0, "Player should have detected an enemy.");
            var targetForAttack = player.DetectedUnits[0];
            var unitToLaunch    = unitMain.AircraftHangar.Aircraft.First <AircraftUnit>(u => u.SupportsRole(GameConstants.Role.AttackAir) && u.IsReady);

            Assert.IsNotNull(unitToLaunch, "UnitToLaunch should not be null");
            var airList = new List <string>();

            airList.Add(unitToLaunch.Id);
            var unitOrderClient = OrderFactory.CreateAircraftLaunchOrder(unitMain.Id, airList, targetForAttack.GetDetectedUnitInfo());
            var baseOrder       = game.GetBaseOrderFromUnitOrder(unitOrderClient);

            Assert.IsTrue(baseOrder.OrderType == GameConstants.OrderType.LaunchOrder, "BaseOrder type should be LaunchOrder");
            var engageOrder = baseOrder.Orders[0] as EngagementOrder;

            Assert.IsNotNull(engageOrder, "EngagementOrder in Launchorder should not be null");
            Assert.IsTrue(engageOrder.TargetDetectedUnit.Id == targetForAttack.Id, "EngagementOrder should have target set to right enemy");
            player.HandleMessageFromClient(unitOrderClient);
            unitMain.ExecuteOrders();
            Assert.IsNotNull(unitToLaunch.Position, "Unit to launch should have non null position");
            Assert.IsNotNull(unitToLaunch.TargetDetectedUnit, "Launched unit should have target detected unit.");
        }
Ejemplo n.º 3
0
        public void SplitAndJoinGroups()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            GameManager.Instance.GameData.InitAllData();
            Game game = GameManager.Instance.CreateGame(player, "test game");

            GameManager.Instance.GameData.LoadGameScenario("test", game);
            Group    group    = new Group();
            BaseUnit unitMain = player.GetUnitById("tag:main");

            Assert.IsNotNull(unitMain, "Unit should not be null");
            BaseUnit unit2 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Bulke",
                                                                      unitMain.Position.Offset(new PositionOffset(3000, 3000)), true);
            BaseUnit unit3 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Brande",
                                                                      unitMain.Position.Offset(new PositionOffset(3000, 2800)), true);

            unit2.SetActualSpeed(20);
            unit3.SetActualSpeed(20);
            group.AutoAssignUnitsToFormation();

            //TEST: Some units in a group should be joined into an existing group.

            Group groupSag = player.GetGroupById(unitMain.GroupId);

            Assert.IsNotNull(groupSag, "groupSag should not be null");
            UnitOrder order = new UnitOrder(TTG.NavalWar.NWComms.GameConstants.UnitOrderType.JoinGroups, unit2.Id);

            order.SecondId = groupSag.Id;
            player.HandleMessageFromClient(order);
            //unit2.JoinNewGroupAllUnits(groupSag.Id);
            Assert.IsTrue(unit2.Orders.Count > 0, "There should be at least 1 unit orders for Unit2.");
            unit2.ExecuteOrders();
            Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should be member of new group.");

            //TEST: Split some members of a group out into a separate, new group
            var unitList = new List <string>();

            unitList.Add(unit2.Id);
            unitList.Add(unit3.Id);
            groupSag.SplitGroup(unitList);
            Assert.IsTrue(unit2.GroupId != groupSag.Id, "Unit2 should no longer be member of GroupSag.");
            var newGroup = player.GetGroupById(unit2.GroupId);

            Assert.IsNotNull(newGroup, "New group should not be null.");

            var joinUnitOrder = OrderFactory.CreateJoinGroupOrder(groupSag.Id, unit2.Id, unitList);
            var joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder);

            Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null.");
            Assert.IsTrue(joinBaseOrder.SecondId == groupSag.Id, "Group sag should be the group to join");
            unit2.JoinNewGroup(joinBaseOrder);

            Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should again be a member of GroupSag.");
            Assert.IsTrue(unit3.GroupId == groupSag.Id, "Unit3 should again be a member of GroupSag.");

            //TEST: Units that are not members of any group should join an existing group

            groupSag.RemoveUnit(unit2);
            Assert.IsTrue(string.IsNullOrEmpty(unit2.GroupId), "Unit2 should no longer be member of ANY group.");

            unitList = new List <string>();
            unitList.Add(unit2.Id);
            joinUnitOrder = OrderFactory.CreateJoinGroupOrder(groupSag.Id, unit2.Id, unitList);
            joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder);
            Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null.");
            unit2.JoinNewGroup(joinBaseOrder);
            Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should again be a member of GroupSag.");

            //TEST: Units that are not members of any group should join a NEW group

            groupSag.RemoveUnit(unit2);
            Assert.IsTrue(string.IsNullOrEmpty(unit2.GroupId), "Unit2 should no longer be member of ANY group.");

            unitList = new List <string>();
            unitList.Add(unit2.Id);

            joinUnitOrder = OrderFactory.CreateJoinGroupOrder(string.Empty, unit2.Id, unitList);
            joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder);
            Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null.");
            unit2.JoinNewGroup(joinBaseOrder);

            Assert.IsTrue(!string.IsNullOrEmpty(unit2.GroupId), "Unit2 should now be a member of NEW group.");
            Assert.IsTrue(unit2.GroupId != groupSag.Id, "Unit2 should no longer be member of GroupSag.");
        }
Ejemplo n.º 4
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.");
        }
Ejemplo n.º 5
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.");
        }
Ejemplo n.º 6
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
        }
Ejemplo n.º 7
0
        public void AircraftReturnToBaseTest()
        {
            Player player = new Player();

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

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


            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, 0, 120);
            var      nextDoorPos = pos.Offset(75, 10000);
            BaseUnit unitMain    = GameManager.Instance.GameData.CreateUnit(player, null, "nimitz", "Nimitz", pos, true);

            unitMain.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);

            //BaseUnit unitEnemy = GameManager.Instance.GameData.CreateUnit(playerEnemy, null, "boeing767", "", nextDoorPos, true);
            //Assert.IsNotNull(unitEnemy, "Enemy is not null");
            //unitEnemy.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);
            game.IsGamePlayStarted = true;             //lying!
            unitMain.SensorSweep();
            //unitEnemy.SensorSweep();
            var unitToLaunch = unitMain.AircraftHangar.Aircraft.First <AircraftUnit>(u => u.SupportsRole(GameConstants.Role.AttackAir) && u.IsReady);

            Assert.IsNotNull(unitToLaunch, "UnitToLaunch should not be null");
            var airList = new List <string>();

            airList.Add(unitToLaunch.Id);
            var destPos   = pos.Offset(75, 10000);
            var moveOrder = new UnitMovementOrder();

            moveOrder.Id       = unitToLaunch.Id;
            moveOrder.Position = destPos.GetPositionInfo();
            var unitOrderClient = OrderFactory.CreateAircraftLaunchOrder(unitMain.Id, airList, moveOrder);
            //var unitOrderClient = OrderFactory.CreateAircraftLaunchOrder(unitMain.Id, airList, targetForAttack.GetDetectedUnitInfo());
            var baseOrder = game.GetBaseOrderFromUnitOrder(unitOrderClient);

            Assert.IsTrue(baseOrder.OrderType == GameConstants.OrderType.LaunchOrder, "BaseOrder type should be LaunchOrder");
            player.HandleMessageFromClient(unitOrderClient);
            unitMain.ExecuteOrders();
            Assert.IsNotNull(unitToLaunch.Position, "Unit to launch should have non null position");
            unitMain.Tick(10);
            unitToLaunch.Position = destPos.Clone();                                             //teleport it
            unitToLaunch.FuelDistanceCoveredSinceRefuelM = unitToLaunch.MaxRangeCruiseM - 10000; // unitToLaunch.FuelDistanceRemainingM;
            unitToLaunch.MoveToNewCoordinate(100);
            Assert.IsTrue(unitToLaunch.IsOrderedToReturnToBase, "Launched unit should have been ordered to return to base.");
            var distM = MapHelper.CalculateDistance3DM(unitMain.Position, unitToLaunch.MovementOrder.GetActiveWaypoint().Position);

            Assert.IsTrue(distM < 1, "Launched unit current waypoint should be carrier position");
            var iterations = 0;

            do
            {
                var distanceToCarrierM = MapHelper.CalculateDistance3DM(unitMain.Position, unitToLaunch.Position);
                unitMain.Tick(1);
                unitToLaunch.Tick(1);
                iterations++;
            } while (unitToLaunch.CarriedByUnit == null && iterations < 100000);

            Assert.IsTrue(iterations < 100000, "No more than 100000 iterations should have passed.");
        }
Ejemplo n.º 8
0
        public void LaunchMultipleAircraftToEngageTarget()
        {
            Player player = new Player();

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

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


            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, 1000, 120);
            var      nextDoorPos = pos.Offset(75, 10000);

            nextDoorPos.HeightOverSeaLevelM = 0;

            var nextDoorPos2 = pos.Offset(75, 10050);

            nextDoorPos2.HeightOverSeaLevelM = 0;
            Group    enemyGroup = new Group();
            BaseUnit unitMain   = GameManager.Instance.GameData.CreateUnit(player, null, "nimitz", "Nimitz", pos, true);

            unitMain.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);

            BaseUnit unitEnemy  = GameManager.Instance.GameData.CreateUnit(playerEnemy, enemyGroup, "pamela", "Pamela 1", nextDoorPos, true);
            BaseUnit unitEnemy2 = GameManager.Instance.GameData.CreateUnit(playerEnemy, enemyGroup, "pamela", "Pamela 2", nextDoorPos2, true);

            Assert.IsNotNull(unitEnemy, "Enemy is not null");
            Assert.IsTrue(enemyGroup.Units.Count == 2, "Enemy group should have two units.");

            unitEnemy.SetSensorsActivePassive(TTG.NavalWar.NWComms.GameConstants.SensorType.Radar, true);
            game.IsGamePlayStarted = true;             //lying!
            unitMain.SensorSweep();
            unitEnemy.SensorSweep();
            Assert.IsTrue(player.DetectedUnits.Count > 0, "Player should have detected an enemy.");
            var targetForAttack = player.DetectedUnits[0];
            var unitsToLaunch   = unitMain.AircraftHangar.Aircraft.Where <AircraftUnit>(u => u.SupportsRole(GameConstants.Role.AttackSurfaceStandoff) && u.IsReady);

            int launchCount = 2;
            int idx         = 0;

            Assert.IsNotNull(unitsToLaunch, "UnitToLaunch should not be null");
            Assert.IsTrue(unitsToLaunch.Count <AircraftUnit>() > 2, "More that two units should be found to launch");
            var airList = new List <string>();

            foreach (var aircraft in unitsToLaunch)
            {
                airList.Add(aircraft.Id);
                idx++;
                if (idx >= launchCount)
                {
                    break;
                }
            }
            var airCraftList = new List <BaseUnit>();

            foreach (var air in airList)
            {
                var plane = player.GetUnitById(air);
                airCraftList.Add(plane);
            }
            Assert.IsTrue(airList.Count == launchCount, "The right unit count should be picked for launch");
            var unitOrderClient = OrderFactory.CreateAircraftLaunchOrder(unitMain.Id, airList, targetForAttack.GetDetectedUnitInfo());
            var baseOrder       = game.GetBaseOrderFromUnitOrder(unitOrderClient);

            Assert.IsTrue(baseOrder.OrderType == GameConstants.OrderType.LaunchOrder, "BaseOrder type should be LaunchOrder");
            var engageOrder = baseOrder.Orders[0] as EngagementOrder;

            Assert.IsNotNull(engageOrder, "EngagementOrder in LaunchOrder should not be null");
            Assert.IsTrue(engageOrder.TargetDetectedUnit.Id == targetForAttack.Id, "EngagementOrder should have target set to right enemy");
            player.HandleMessageFromClient(unitOrderClient);
            unitMain.ExecuteOrders();
            var firstPlane  = airCraftList[0];
            var secondPlane = airCraftList[1];

            Assert.IsNotNull(firstPlane.Position, "First plane should have non null position");
            Assert.IsNotNull(firstPlane.TargetDetectedUnit, "First Plane should have target detected unit.");
            Assert.IsNotNull(secondPlane.Position, "Second Plane should have non null position");
            Assert.IsNotNull(secondPlane.TargetDetectedUnit, "Second Plane should have target detected unit.");
        }
Ejemplo n.º 9
0
        public void MissileLaunchAndMovement()
        {
            Player player1 = new Player();

            player1.Name = "Player1";
            Player player2 = new Player();

            player2.Name = "Player2";

            Group group1 = new Group();
            Group group2 = new Group();

            GameManager.Instance.GameData.InitAllData();
            Game game = GameManager.Instance.CreateGame(player1, "test game");

            GameManager.Instance.Game.UpperLeftCorner  = new Coordinate(70, -10);
            GameManager.Instance.Game.LowerRightCorner = new Coordinate(40, 10);
            game.AddPlayer(player2);

            Position     pos1       = new Position(60, 3, 0, 70 + 180);
            Position     pos2       = pos1.Offset(new PositionOffset(1800, 1780));
            BaseUnit     unitNansen = GameManager.Instance.GameData.CreateUnit(player1, group1, "fridtjofnansen", "Nansen", pos1, true);
            AircraftUnit helo       = unitNansen.AircraftHangar.Aircraft.First <AircraftUnit>();

            unitNansen.LaunchAircraft(new List <AircraftUnit> {
                helo
            }, string.Empty, "", null, "");
            helo.SetSensorsActivePassive(GameConstants.SensorType.Radar, true);

            BaseUnit unitEnemyBurke = GameManager.Instance.GameData.CreateUnit(player2, group2, "arleighburke", "Enemy Burke", pos2, true);

            unitNansen.SensorSweep();
            helo.SensorSweep();

            Assert.IsTrue(player1.DetectedUnits.Count == 1, "Player1 should have detected one unit.");
            DetectedUnit enemyUnit = player1.DetectedUnits[0];

            enemyUnit.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
            var engagementOrder = new EngagementOrder(enemyUnit, GameConstants.EngagementOrderType.EngageNotClose);

            engagementOrder.WeaponClassId = "nsm";
            unitNansen.Orders.Enqueue(engagementOrder);
            unitNansen.ExecuteOrders();
            MissileUnit missile     = (MissileUnit)player1.Units.First <BaseUnit>(u => u.UnitClass.IsMissileOrTorpedo);
            double      OldDistance = MapHelper.CalculateDistanceM(
                unitEnemyBurke.Position.Coordinate, missile.Position.Coordinate);
            double distanceM  = 0;
            int    iterations = 0;

            do
            {
                iterations++;
                missile.MoveToNewCoordinate(100);
                var heightM = missile.Position.HeightOverSeaLevelM;
                distanceM = MapHelper.CalculateDistanceM(
                    unitEnemyBurke.Position.Coordinate, missile.Position.Coordinate);
                if (distanceM < 5000)
                {
                    GameManager.Instance.Log.LogDebug(string.Format(
                                                          "MissileLaunchAndMovement test: {0} at pos {1} ** distanceM={2} FuelM={3}",
                                                          missile, missile.Position, Math.Round(distanceM, 0), Math.Round(missile.FuelDistanceRemainingM, 0)));
                }
            } while (distanceM > GameConstants.DISTANCE_TO_TARGET_IS_HIT_M * 2 && !missile.IsMarkedForDeletion);

            double newDistance = MapHelper.CalculateDistanceM(
                unitEnemyBurke.Position.Coordinate, missile.Position.Coordinate);

            Assert.IsTrue(newDistance < OldDistance, "Missile should have moved closer to target.");
            Assert.IsTrue(newDistance < 200, "Missile should be closer to target than 200m");
        }
Ejemplo n.º 10
0
        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));
        }