Ejemplo n.º 1
0
        public void FormationOrder()
        {
            GameManager.Instance.Log.LogDebug("Running test FormationOrder().");
            Player player = new Player();
            Group  group  = new Group();

            GameManager.Instance.GameData.InitAllData();
            GameManager.Instance.CreateGame(player, "test game");
            Position pos      = new Position(60, 3, 0, 45);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "", pos, true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(61.0, 4.0)));
            unitMain.ActualSpeedKph = 40.0;
            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null.");

            unitMain.MoveToNewCoordinate(1.0);

            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null after movement.");
            pos = new Position(61, 4, 0, 40);
            BaseUnit unitFollow = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "", pos, true);

            MovementFormationOrder order = new MovementFormationOrder(unitMain, 5000, -1000, 0);
            Waypoint waypoint            = order.GetActiveWaypoint();

            unitFollow.Position = waypoint.Position.Clone();
            double distanceM = MapHelper.CalculateDistanceM(unitMain.Position.Coordinate, unitFollow.Position.Coordinate);

            Assert.IsTrue(distanceM > 5000 && distanceM < 5100, "Distance should be between 5000 and 5100 M.");
            Assert.IsTrue(Math.Abs((double)unitFollow.Position.BearingDeg - 45) < 1, "UnitFollow bearing should be 45 deg");
            GameManager.Instance.Log.LogDebug("*** Offset right:" + order.PositionOffset.RightM + "  Offset forward:" + order.PositionOffset.ForwardM);
            GameManager.Instance.Log.LogDebug("Main unit pos: " + unitMain.Position.ToString());
            GameManager.Instance.Log.LogDebug("Calculated pos: " + waypoint.Position.ToString());
            GameManager.Instance.TerminateGame();
        }
Ejemplo n.º 2
0
        public void SimpleMovementPlane()
        {
            Player player = new Player();

            player.Name = "Plane movement test player";
            GameManager.Instance.CreateGame(player, "test game");
            BaseUnit unit = new BaseUnit();

            unit.UnitClass   = new UnitClass("Plane", GameConstants.UnitType.FixedwingAircraft);
            unit.OwnerPlayer = player;
            unit.UnitClass.TurnRangeDegrSec        = 20;
            unit.UnitClass.MaxAccelerationKphSec   = 40;
            unit.UnitClass.MaxSpeedKph             = 900;
            unit.UnitClass.MaxClimbrateMSec        = 50;
            unit.UnitClass.MaxFallMSec             = 100;
            unit.UnitClass.HighestOperatingHeightM = 10000;
            unit.UnitClass.MaxHitpoints            = 100;
            unit.Position             = new Position(60.0, 1.0, 50, 2);
            unit.UserDefinedElevation = GameConstants.HeightDepthPoints.MediumHeight;
            unit.SetActualSpeed(500);
            unit.Name = "F-Flop/B";
            Position dest = new Position(61.0, 2.0, 5000);

            unit.MovementOrder.AddWaypoint(new Waypoint(dest));
            unit.ReCalculateEta();
            TimeSpan OldEtaAllSec = unit.EtaAllWaypoints;

            unit.MovementOrder.AddWaypoint(new Waypoint(new Position(62.0, 2.0)));
            unit.ReCalculateEta();
            TimeSpan NewEtaAllSec = unit.EtaAllWaypoints;

            Assert.IsTrue(OldEtaAllSec != NewEtaAllSec, "Old and new ETA should not be the same after added waypoint.");
            unit.ActualSpeedKph = 400.0;
            int MaxIterations = 1000000;
            int Count         = 0;

            do
            {
                unit.MoveToNewCoordinate(100.0);
                Count++;
            } while (MapHelper.CalculateDistanceM(unit.Position.Coordinate, dest.Coordinate) > 100 &&
                     Count < MaxIterations);               //it has to be 100, since a plane will not stop at destinatation, but continue on minimum speed
            Assert.IsTrue(unit.Position.HeightOverSeaLevelM == 2000, "Height over sea level should be 2000 m.");
            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.");

            var oldWp = unit.GetActiveWaypoint().Clone();

            unit.MovementOrder.AddWaypointToTop(new Position(55, 1));
            var newWp = unit.GetActiveWaypoint().Clone();

            Assert.IsTrue(oldWp.Position.Coordinate.LatitudeDeg != newWp.Position.Coordinate.LatitudeDeg, "New wp should be activated");
            GameManager.Instance.TerminateGame();
        }
Ejemplo n.º 3
0
        public void UnitFormationMovement()
        {
            GameManager.Instance.Log.LogDebug("Running test UnitFormationMovement().");
            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();

            GameManager.Instance.GameData.InitAllData();
            GameManager.Instance.CreateGame(player, "test game");
            Position pos      = new Position(60, 3, 0, 45);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "lead",
                                                                         pos, true);
            BaseUnit unit1 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "follow1",
                                                                      pos.Offset(30, 300), true);
            BaseUnit unit2 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "follow2",
                                                                      pos.Offset(120, 400), true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(50.0, 3.0)));
            unitMain.SetActualSpeed(unitMain.GetSpeedInKphFromSpeedType(GameConstants.UnitSpeedType.Cruise));
            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null.");

            group.AutoAssignUnitsToFormation();

            game.IsNetworkEnabled = false;
            long counter        = 0;
            long maxInterations = 1000;
            long leaveAtCounter = maxInterations;
            bool leaveLoop      = false;

            do
            {
                unitMain.MoveToNewCoordinate(1000);
                unit1.MoveToNewCoordinate(1000);
                unit2.MoveToNewCoordinate(1000);
                //unitMain.CheckIfGroupIsStaging();
                //unit1.CheckIfGroupIsStaging();
                //unit2.CheckIfGroupIsStaging();
                if (counter == 10)
                {
                    Assert.IsTrue(unit1.IsAtFormationPosition, "10: Unit 1 should be at formation position");
                    Assert.IsTrue(unit2.IsAtFormationPosition, "10: Unit 2 should be at formation position");
                }
                if (counter == 11)
                {
                    unitMain.MovementOrder.ClearAllWaypoints();
                    unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(70, 3)));
                }
                if (counter == 12)
                {
                    Assert.IsNotNull(unitMain.GetActiveWaypoint(), "Main should have ActiveWaypoint");
                    Assert.IsTrue(group.IsStaging, "Group should be Staging");
                    //Assert.IsFalse(unit1.IsAtFormationPosition, "12: Unit 1 should NOT be at formation position");
                    //Assert.IsFalse(unit2.IsAtFormationPosition, "12: Unit 2 should NOT be at formation position");
                }
                if ((counter > 13 && unit1.IsAtFormationPosition && unit2.IsAtFormationPosition && !leaveLoop))
                {
                    //unitMain.MoveToNewCoordinate(1000);
                    leaveLoop      = true;
                    leaveAtCounter = counter + 10;
                }
                counter++;
            } while (counter < maxInterations && counter < leaveAtCounter);
            double speed = unitMain.GetSpeedInKphFromSpeedType(GameConstants.UnitSpeedType.Cruise);

            group.CheckIfGroupIsStaging();
            unitMain.ResolveUnitAndGroupSpeed();
            unit1.ResolveUnitAndGroupSpeed();
            unit2.ResolveUnitAndGroupSpeed();
            unitMain.UpdateActualSpeed(10);
            unit1.UpdateActualSpeed(10);
            unit2.UpdateActualSpeed(10);
            group.CheckIfGroupIsStaging();
            Assert.IsTrue(unitMain.ActualSpeedKph == speed, "Unit Main Should be at cruise speed");
            Assert.IsTrue(unit1.ActualSpeedKph == speed, "Unit 1 Should be at cruise speed");
            Assert.IsTrue(unit2.ActualSpeedKph == speed, "Unit 2 Should be at cruise speed");
            Assert.IsTrue(counter < maxInterations, "Should not use all iterations to get to formation positions");
            GameManager.Instance.TerminateGame();
        }
Ejemplo n.º 4
0
        public void AutomaticFormationOrderTest()
        {
            GameManager.Instance.Log.LogDebug("Running test AutomaticFormationOrderTest().");
            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();

            GameManager.Instance.GameData.InitAllData();
            GameManager.Instance.CreateGame(player, "test game");
            Position pos      = new Position(60, 3, 0, 45);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "lead",
                                                                         pos, true);
            BaseUnit unit1 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "follow1",
                                                                      pos.Offset(30, 300), true);
            BaseUnit unit2 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "follow2",
                                                                      pos.Offset(120, 400), true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(61.0, 4.0)));
            unitMain.SetActualSpeed(40.0);
            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null.");

            group.AutoAssignUnitsToFormation();

            game.IsNetworkEnabled = false;

            ScheduledOrder sched      = new ScheduledOrder(1);
            var            innerOrder = new BaseOrder(unit1.OwnerPlayer, GameConstants.OrderType.SetSpeed);

            innerOrder.UnitSpeedType = GameConstants.UnitSpeedType.Slow;
            sched.Orders.Add(innerOrder);
            unit1.Orders.Enqueue(sched);
            GameManager.Instance.Game.RunGameInSec = 1;
            GameManager.Instance.Game.StartGamePlay();
            unitMain.ReCalculateEta();
            unit1.ReCalculateEta();
            unit2.ReCalculateEta();

            Assert.IsTrue(unit1.MovementOrder is MovementFormationOrder, "Unit 1 should have a movement formation order.");
            Assert.IsTrue(unit2.MovementOrder is MovementFormationOrder, "Unit 2 should have a movement formation order.");
            Assert.IsFalse(unitMain.MovementOrder is MovementFormationOrder, " MainUnit should NOT have movement formation order.");


            unitMain.HitPoints           = 0;
            unitMain.IsMarkedForDeletion = true;
            group.AutoAssignUnitsToFormation();
            //GameManager.Instance.Game.RunGameInSec = 1;
            //GameManager.Instance.Game.StartGamePlay();

            Assert.IsTrue(group.MainUnit.Id == unit1.Id, "Unit 1 should now be main unit.");
            Assert.IsFalse(unit1.MovementOrder is MovementFormationOrder, "Unit 1 should NOT have a movement formation order.");
            Assert.IsTrue(unit2.MovementOrder is MovementFormationOrder, "Unit 2 should still have a movement formation order.");
            var activeWp = unit1.GetActiveWaypoint();

            Assert.IsTrue(activeWp != null, "Unit 1 should have an ActiveWaypoint.");


            GameManager.Instance.TerminateGame();
        }