Esempio n. 1
0
 private void btnMove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         double       Lat  = double.Parse(txtLat.Text);
         double       Lon  = double.Parse(txtLon.Text);
         BaseUnitInfo info = lstUnits.SelectedItem as BaseUnitInfo;
         string       Id;
         if (info != null)
         {
             Id = info.Id;
         }
         else
         {
             ShowInfo("Select a unit in ListBox first.");
             return;
         }
         UnitMovementOrder order = new UnitMovementOrder();
         order.Id = Id;
         PositionInfo pos = new PositionInfo();
         pos.Latitude  = Lat;
         pos.Longitude = Lon;
         order.RemoveAllExistingWaypoints = (bool)chkClearWaypoints.IsChecked;
         order.Waypoints.Add(new WaypointInfo(pos));
         order.UnitSpeedType = GameConstants.UnitSpeedType.UnchangedDefault;
         _gameClient.Send(order);
         ShowInfo("*** Movement order sent to unit " + info.UnitName);
         lstUnits.SelectedIndex      = -1;
         lstDetections.SelectedIndex = -1;
     }
     catch (Exception ex)
     {
         ShowInfo("Select a unit. Use decimal points for Lat and Long. " + ex.Message);
     }
 }
Esempio n. 2
0
    public void Launch(BaseUnitInfo unit, List <CarriedUnit> unitsToLaunch, GameConstants.UnitOrderType unitOrderType, Coordinate coord)
    {
        if (unit != null)
        {
            UnitOrder order = new UnitOrder(unitOrderType, unit.Id);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Launcing Aircrafts:");

            foreach (CarriedUnit cui in unitsToLaunch)
            {
                order.ParameterList.Add(cui.UnitInfo.Id);
                sb.AppendLine(cui.UnitInfo.Id);
            }

            UnitMovementOrder moveOrder = new UnitMovementOrder();
            moveOrder.Waypoints.Add(new WaypointInfo(new PositionInfo(coord.Latitude, coord.Longitude)));
            order.UnitOrders.Add(moveOrder);



            GameManager.Instance.MessageManager.AddMessage(sb.ToString(), GameManager.MessageTypes.Game, unit.Position);

            GameManager.Instance.NetworkManager.Send(order);
        }
    }
Esempio n. 3
0
    public void Move(double lat, double lng, BaseUnitInfo info, bool removeWaypoints)
    {
        string Id;

        if (info != null)
        {
            Id = info.Id;
        }
        else
        {
            return;
        }
        UnitMovementOrder order = OrderFactory.CreateUnitMovementOrder(Id, new PositionInfo(lat, lng), removeWaypoints);

        //order.Id = Id;
        //PositionInfo pos = new PositionInfo();
        //pos.Latitude = lat;
        //pos.Longitude = lng;
        //order.RemoveAllExistingWaypoints = removeWaypoints;
        //order.Waypoints.Add(new WaypointInfo(pos));

        GameManager.Instance.NetworkManager.Send(order);

        //GameManager.Instance.MessageManager.AddMessage(string.Format("Move order sendt. Heading for {0}, {1}", lat, lng), GameManager.MessageTypes.Game);
    }
Esempio n. 4
0
        public static UnitMovementOrder CreateUnitMovementOrder(string unitId,
                                                                WaypointInfo wayPoint, GameConstants.UnitSpeedType unitSpeedType,
                                                                bool clearExisting)
        {
            UnitMovementOrder order = new UnitMovementOrder();

            order.Id = unitId;
            order.RemoveAllExistingWaypoints = clearExisting;
            order.Waypoints.Add(wayPoint);
            order.UnitSpeedType = unitSpeedType;
            return(order);
        }
Esempio n. 5
0
        public static UnitMovementOrder CreateUnitMovementOrder(string unitId,
                                                                PositionInfo position,
                                                                bool clearExisting)
        {
            UnitMovementOrder order = new UnitMovementOrder();

            order.Id = unitId;
            order.RemoveAllExistingWaypoints = clearExisting;
            order.Waypoints.Add(new WaypointInfo(position));
            order.UnitSpeedType = GameConstants.UnitSpeedType.UnchangedDefault;
            return(order);
        }
Esempio n. 6
0
        public static UnitOrder CreateAircraftLaunchOrder(string unitId,
                                                          List <string> aircraftList, DetectedUnitInfo attackTarget)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.LaunchAircraft, unitId);

            foreach (var id in aircraftList)
            {
                order.ParameterList.Add(id);
            }
            UnitMovementOrder moveOrder = new UnitMovementOrder();

            moveOrder.Position = null;
            moveOrder.SecondId = attackTarget.Id;
            order.UnitOrders.Add(moveOrder);
            return(order);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates and returns new UnitMovementOrder
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="wayPoints"></param>
        /// <param name="unitSpeedType"></param>
        /// <param name="clearExisting"></param>
        /// <param name="isRecurring"></param>
        /// <returns></returns>
        public static UnitMovementOrder CreateUnitMovementOrder(string unitId,
                                                                List <WaypointInfo> wayPoints, GameConstants.UnitSpeedType unitSpeedType,
                                                                bool clearExisting, bool isRecurring)
        {
            UnitMovementOrder order = new UnitMovementOrder();

            order.Id = unitId;
            order.RemoveAllExistingWaypoints = clearExisting;
            foreach (var wp in wayPoints)
            {
                order.Waypoints.Add(wp);
            }
            order.IsParameter   = isRecurring;
            order.UnitSpeedType = unitSpeedType;
            return(order);
        }
Esempio n. 8
0
    public void LaunchAttack(BaseUnitInfo unit, DetectedUnitInfo det, List <CarriedUnit> unitsToLaunch, Coordinate coord)
    {
        List <string> units = new List <string>();

        foreach (CarriedUnit cui in unitsToLaunch)
        {
            units.Add(cui.UnitInfo.Id);
        }
        UnitMovementOrder moveOrder = new UnitMovementOrder();

        if (coord != null)
        {
            moveOrder.Waypoints.Add(new WaypointInfo(new PositionInfo(coord.Latitude, coord.Longitude)));
        }
        GameManager.Instance.NetworkManager.Send(OrderFactory.CreateAircraftLaunchOrder(unit.Id, units, moveOrder));

        GameManager.Instance.NetworkManager.Send(OrderFactory.CreateEngagementOrder(unit.Id, det.Id, string.Empty, GameConstants.EngagementOrderType.CloseAndEngage,
                                                                                    GameConstants.EngagementStrength.DefaultAttack, true));
    }
Esempio n. 9
0
        private void btnLaunchAircraft_Click(object sender, RoutedEventArgs e)
        {
            BaseUnitInfo unit = lstUnits.SelectedItem as BaseUnitInfo;

            if (unit != null)
            {
                UnitOrder      order        = new UnitOrder(GameConstants.UnitOrderType.LaunchAircraft, unit.Id);
                LaunchAircraft launchDialog = new LaunchAircraft();
                launchDialog.AircraftList = unit.CarriedUnits;
                launchDialog.Init();
                bool?result = launchDialog.ShowDialog();
                order.ParameterList = launchDialog.GetSelectedIds();

                //int unitcount = 0;
                //int maxUnits = 1;
                //string aircraftlist = string.Empty;
                //if(unit.UnitClassId.Contains("airport"))
                //{
                //    maxUnits = 3;
                //}
                //foreach (var c in unit.CarriedUnits)
                //{
                //    if (c.ReadyInSec < 1 && unitcount < maxUnits)
                //    {
                //        order.ParameterList.Add(c.Id);
                //        aircraftlist += c.ToString() + " ";
                //        unitcount++;
                //    }
                //}
                ShowInfo(string.Format(
                             "UnitOrder to unit {0} : Launch {1} aircraft.",
                             order.Id, order.ParameterList.Count));
                UnitMovementOrder moveOrder = new UnitMovementOrder();
                moveOrder.Waypoints.Add(new WaypointInfo(new PositionInfo(55, 3)));
                order.UnitOrders.Add(moveOrder);
                _gameClient.Send(order);
            }
            else
            {
                ShowInfo("No unit selected!");
            }
        }
Esempio n. 10
0
        public static UnitOrder CreateAircraftLaunchOrder(string unitId,
                                                          List <string> aircraftList, UnitMovementOrder moveOrder)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.LaunchAircraft, unitId);

            foreach (var id in aircraftList)
            {
                order.ParameterList.Add(id);
            }
            order.UnitOrders.Add(moveOrder);
            return(order);
        }
Esempio n. 11
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.");
        }