コード例 #1
0
ファイル: ScenarioTest.cs プロジェクト: JHaugland/WetAffairs
        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 GroupEngagementTest()
        {
            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("small", game);
            Player otherPlayer = player.Enemies[0];

            Assert.IsTrue(game.Players.Count == 2, "There should be two players in game.");
            //Assert.IsTrue(otherPlayer.Units.Count == 15, "Player 1 should have 15 units.");
            BaseUnit unit = player.GetUnitById("tag:main");

            Assert.IsNotNull(unit, "Unit with tag main should exist.");
            var wp = unit.MovementOrder.GetActiveWaypoint();

            Assert.IsNotNull(wp, "Main unit waypoint should not be null.");
            BaseUnitInfo info = unit.GetBaseUnitInfo();

            Assert.IsTrue(info.IsGroupMainUnit, "Main unit should be main unit");

            //foreach (var u in player.Units)
            //{
            //    if (string.IsNullOrEmpty(u.CurrentWeaponLoadName))
            //    {
            //        GameManager.Instance.Log.LogDebug(
            //            string.Format("Unit {0} has empty CurrentWeaponLoad.", u.ToShortString()));
            //    }
            //}
            game.IsNetworkEnabled                  = false;
            game.RealTimeCompressionFactor         = 10;
            GameManager.Instance.Game.RunGameInSec = 1;
            var sentryPlane = player.GetUnitById("tag:sentry");

            Assert.IsNotNull(sentryPlane, "Sentry plane should exist and not be null.");
            sentryPlane.SetSensorsActivePassive(GameConstants.SensorType.Radar, true);

            GameManager.Instance.Game.StartGamePlay();
            var detectedGroup = player.DetectedGroups.FirstOrDefault <DetectedGroup>();

            Assert.IsNotNull(detectedGroup, "Detected group should be found");
            var result = unit.EngageDetectedGroup(detectedGroup, GameConstants.EngagementOrderType.EngageNotClose, GameConstants.EngagementStrength.DefaultAttack, true);

            Assert.IsTrue(result, "EngageDetectedGroup should respond true");
        }
コード例 #3
0
ファイル: ScenarioTest.cs プロジェクト: JHaugland/WetAffairs
        public void LoadTestScenario()
        {
            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];

            Assert.IsTrue(game.Players.Count == 2, "There should be two players in game.");
            //Assert.IsTrue(otherPlayer.Units.Count == 15, "Player 1 should have 15 units.");
            BaseUnit unit = player.GetUnitById("tag:main");

            Assert.IsNotNull(unit, "Unit with tag main should exist.");
            var wp = unit.MovementOrder.GetActiveWaypoint();

            Assert.IsNotNull(wp, "Main unit waypoint should not be null.");
            BaseUnitInfo info = unit.GetBaseUnitInfo();

            Assert.IsTrue(info.IsGroupMainUnit, "Main unit should be main unit");
        }
コード例 #4
0
        public void SimpleUnitMovementDetail()
        {
            Player player = new Player();

            GameManager.Instance.CreateGame(new Player(), "test game");
            GameManager.Instance.GameData.InitAllData();
            BaseUnit unit = GameManager.Instance.GameData.CreateUnit(player, new Group(),
                                                                     "f22", "", new Position(60.0, 5.0, 0, 2), true);
            Position dest1     = new Position(62.0, -1.0);
            Position dest2     = new Position(63.0, 0.0);
            Position finalDest = new Position(61.0, 0.5);
            Position extraDest = new Position(65.0, 2);

            GameManager.Instance.Game.RealTimeCompressionFactor = 1.0;
            unit.MovementOrder.AddWaypoint(dest1);
            unit.MovementOrder.AddWaypoint(dest2);
            unit.MovementOrder.AddWaypoint(finalDest.Clone());
            unit.UserDefinedSpeed = GameConstants.UnitSpeedType.Cruise;
            int MaxIterations = 1000000;
            int Count         = 0;

            //double DistanceToTargetM = 0;
            double[] listDistances          = new double[MaxIterations];
            Position previousPosition       = unit.Position.Clone();
            double   distanceToFinalTargetM = double.MaxValue;
            double   maxDeviationM          = 250.0 + 250.0;  //double to account for "snap" on arrival

            do
            {
                unit.MoveToNewCoordinate(1000.0);
                //DistanceToTargetM = MapHelper.CalculateDistanceMeters(unit.Position.Coordinate, dest.Coordinate);
                if (Count > 0)
                {
                    listDistances[Count] = MapHelper.CalculateDistanceM(unit.Position.Coordinate, previousPosition.Coordinate);
                    Assert.IsTrue(listDistances[Count] < maxDeviationM, "Unit should never move faster than MaxDev m/sec. Distance=" + Math.Round(listDistances[Count]), 2);                     //~235 m/sec
                }
                previousPosition       = unit.Position.Clone();
                distanceToFinalTargetM = MapHelper.CalculateDistanceM(unit.Position.Coordinate, finalDest.Coordinate);
                Count++;
            } while (distanceToFinalTargetM > 100 && Count < MaxIterations);

            GameManager.Instance.Log.LogDebug("SimpleUnitMovement test: Unit short = " + unit.ToShortString());
            GameManager.Instance.Log.LogDebug("SimpleUnitMovement test: Unit long = " + unit.ToLongString());
            GameManager.Instance.Log.LogDebug("SimpleUnitMovement test: Position = " + unit.Position.ToString());

            Assert.IsFalse(Count >= MaxIterations, "Count should not go MaxIterations iterations.");
            Assert.AreNotEqual(unit.Position.Coordinate.LatitudeDeg, 60.0, "unit should not still be at latitude 60");
            Assert.AreNotEqual(unit.Position.Coordinate.LongitudeDeg, 1.0, "unit should not still be at longitude 1");
            Assert.IsNotNull(unit.Position.BearingDeg, "Bearing should not be null.");

            unit.MovementOrder.AddWaypoint(dest1);
            unit.MovementOrder.AddWaypoint(dest2);
            unit.MovementOrder.AddWaypoint(finalDest.Clone());

            unit.MovementOrder.AddWaypointToTop(extraDest.Clone());
            var wp   = unit.MovementOrder.GetActiveWaypoint();
            var dist = MapHelper.CalculateDistance3DM(wp.Position, extraDest);

            Assert.IsTrue(dist < 1, "ActiveWaypoint and extra waypoint should be the same.");
            var unitInfo = unit.GetBaseUnitInfo();
            var infoWp   = unitInfo.Waypoints[0];

            dist = MapHelper.CalculateDistance3DM(wp.Position, new Position(infoWp.Position));
            Assert.IsTrue(dist < 1, "ActiveWaypoint and BaseUnitInfo first WP should be the same.");
            GameManager.Instance.TerminateGame();
        }