예제 #1
0
        public void ChangePlaneLoadoutTest()
        {
            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);
            Player   otherPlayer = player.Enemies[0];
            BaseUnit Airport     = player.Units.Find(u => u.UnitClass.Id == "ukairportlarge");

            Assert.IsNotNull(Airport, "Airport should not be null.");
            AircraftUnit f22unit = (AircraftUnit)Airport.AircraftHangar.Aircraft.First <AircraftUnit>(a => a.UnitClass.Id == "f22");

            game.IsGamePlayStarted = true;             //a lie
            string desiredWeaponLoad = "Naval Strike";

            f22unit.SetDirty(TTG.NavalWar.NWComms.GameConstants.DirtyStatus.Clean);
            Airport.SetDirty(TTG.NavalWar.NWComms.GameConstants.DirtyStatus.Clean);
            BaseUnitInfo info = Airport.GetBaseUnitInfo();

            f22unit.SetWeaponLoad(desiredWeaponLoad);
            info = Airport.GetBaseUnitInfo();
            Assert.IsTrue(f22unit.ReadyInSec > 500, "F22 should not be ready after loadout change.");
            Assert.IsTrue(f22unit.CurrentWeaponLoadName == desiredWeaponLoad, "Current loadout name should be 'Naval Strike'");
            bool launchResult = Airport.LaunchAircraft(new List <AircraftUnit> {
                f22unit
            }, string.Empty, "No planes", null, "");

            Assert.IsFalse(launchResult, "Air group should not be launched.");
            info = Airport.GetBaseUnitInfo();
        }
예제 #2
0
        public void CreateUnitFromClass()
        {
            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, 0, 80);
            BaseUnit     unit = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Arleigh Burke", pos, true);
            AircraftUnit helo = unit.AircraftHangar.Aircraft.First <AircraftUnit>();

            Assert.IsNotNull(helo, "Helo in hangar should not be null.");
            Assert.IsTrue(helo.ReadyInSec == 0, "Helo in hangar should be ready.");
            unit.LaunchAircraft(new List <AircraftUnit> {
                helo
            }, string.Empty, string.Empty, null, "");
            Assert.IsTrue(unit.SupportsRole(GameConstants.Role.AttackSurface));
            Assert.IsNotNull(unit.Weapons.First <BaseWeapon>(), "No weapons!");
            Assert.IsNotNull(unit.AircraftHangar, "Has no aircraft hangar!");

            Assert.IsTrue(helo.Position != null, "Launched helo group should not be null.");             //no idea why this sometimes fails after rebuild!
            Assert.IsTrue(unit.AircraftHangar.Aircraft.Count == 1, "Destroyer should have one carried unit left.");
            Assert.IsNotNull(unit.AircraftHangar.Aircraft.First <AircraftUnit>().Weapons.First <BaseWeapon>(), "Carried helo should have weapon.");

            GameManager.Instance.TerminateGame();
        }
예제 #3
0
        public void AircraftMovement()
        {
            GameManager.Instance.Log.LogDebug("*** Running test AircraftMovement");
            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, 0, 80);
            BaseUnit     unit = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Arleigh Burke", pos, true);
            AircraftUnit helo = unit.AircraftHangar.Aircraft.First <AircraftUnit>();

            unit.LaunchAircraft(new List <AircraftUnit> {
                helo
            }, string.Empty, string.Empty, null, "");
            var wp = new Waypoint(new Position(new Coordinate(70, -13)));

            wp.Position.HeightOverSeaLevelM = 500;
            var moveOrder = new MovementOrder(wp);

            helo.MovementOrder = moveOrder;
            helo.SetActualSpeed(300);
            helo.UserDefinedSpeed = GameConstants.UnitSpeedType.Cruise;
            int    countLoop      = 100;
            double lastBearingDeg = (double)helo.ActualBearingDeg;

            for (int i = 0; i < countLoop; i++)
            {
                helo.MoveToNewPosition3D(1);
                double newBearingDeg  = (double)helo.ActualBearingDeg;
                double bearingDiffRad = Math.Abs(newBearingDeg.ToRadian() - lastBearingDeg.ToRadian());
                if (i > 2 && bearingDiffRad > 0.001)
                {
                    GameManager.Instance.Log.LogDebug(
                        string.Format("BearingDeg has changed: Iteration {0}  Old {1:F}   New {2:F}",
                                      i, lastBearingDeg, newBearingDeg));
                    Assert.IsTrue(false, "Bearing should never change abruptly.");
                }
                lastBearingDeg = newBearingDeg;
            }
            double distanceM = MapHelper.CalculateDistance3DM(pos, helo.Position);

            Assert.IsTrue(distanceM > 8000, "Helo should have moved over 8000m.");             //in fact, around 8333 m in 100 sec at 300 kph
        }
예제 #4
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");
        }