Example #1
0
        /// <summary>Finds the maximum range between an antenna and a specific target.</summary>
        /// <returns>The maximum distance at which the two spacecraft could communicate.</returns>
        /// <param name="antenna">The antenna attempting to target.</param>
        /// <param name="target">The satellite being targeted by <paramref name="antenna"/>.</param>
        /// <param name="antennaSat">The satellite on which <paramref name="antenna"/> is mounted.</param>
        /// <param name="rangeFunc">A function that computes the maximum range between two 
        /// satellites, given their individual ranges.</param>
        public static double GetRangeInContext(IAntenna antenna, ISatellite target, ISatellite antennaSat,
            Func<double, double, double> rangeFunc) {
            // Which antennas on the other craft are capable of communication?
            IEnumerable<IAntenna>  omnisB = GetOmnis(target);
            IEnumerable<IAntenna> dishesB = GetDishesThatSee(target, antennaSat);

            // Pick the best range for each case
            double maxOmniB =  omnisB.Any() ?  omnisB.Max(ant => ant.Omni) : 0.0;
            double maxDishB = dishesB.Any() ? dishesB.Max(ant => ant.Dish) : 0.0;
            double   bonusB = GetMultipleAntennaBonus(omnisB, maxOmniB);

            // Also need local antenna bonus, if antenna is an omni
            IEnumerable<IAntenna> omnisA  = GetOmnis(antennaSat);
            double maxOmniA = omnisA.Any()  ? omnisA.Max( ant => ant.Omni) : 0.0;
            double   bonusA = GetMultipleAntennaBonus(omnisA, maxOmniA);

            // What is the range?
            // Note: IAntenna.Omni and IAntenna.Dish are zero for antennas of the other type
            double maxOmni = Math.Max(CheckRange(rangeFunc, antenna.Omni + bonusA, omniClamp, maxOmniB + bonusB, omniClamp),
                                      CheckRange(rangeFunc, antenna.Omni + bonusA, omniClamp, maxDishB         , dishClamp));
            double maxDish = Math.Max(CheckRange(rangeFunc, antenna.Dish         , dishClamp, maxOmniB + bonusB, omniClamp), 
                                      CheckRange(rangeFunc, antenna.Dish         , dishClamp, maxDishB         , dishClamp));

            return Math.Max(maxOmni, maxDish);
        }
 public static bool IsTargetingPlanet(this IAntenna a, ISatellite sat_b, ISatellite sat_a)
 {
     var planets = RTCore.Instance.Network.Planets;
     if (!planets.ContainsKey(a.Target) || sat_b.Body != planets[a.Target]) return false;
     var dir_cb = (planets[a.Target].position - sat_a.Position);
     var dir_b = (sat_b.Position - sat_a.Position);
     if (Vector3d.Dot(dir_cb.normalized, dir_b.normalized) >= a.Radians) return true;
     return false;
 }
        public static bool IsTargetingActiveVessel(this IAntenna a, ISatellite sat_b)
        {
            var active_vessel = FlightGlobals.ActiveVessel;
            if (active_vessel == null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                active_vessel = MapView.MapCamera.target.vessel;
            }

            return a.Target == NetworkManager.ActiveVesselGuid && active_vessel != null && sat_b.Guid == active_vessel.id;
        }
Example #4
0
        /// <summary>Constructs a link between two satellites, if one is possible.</summary>
        /// <returns>The new link, or null if the two satellites cannot connect.</returns>
        /// <param name="rangeFunc">A function that computes the maximum range between two
        /// satellites, given their individual ranges.</param>
        public static NetworkLink <ISatellite> GetLink(ISatellite satA, ISatellite satB,
                                                       Func <double, double, double> rangeFunc)
        {
            // Which antennas on either craft are capable of communication?
            IEnumerable <IAntenna> omnisA  = GetOmnis(satA);
            IEnumerable <IAntenna> omnisB  = GetOmnis(satB);
            IEnumerable <IAntenna> dishesA = GetDishesThatSee(satA, satB);
            IEnumerable <IAntenna> dishesB = GetDishesThatSee(satB, satA);

            // Pick the best range for each case
            double maxOmniA = omnisA.Any() ?  omnisA.Max(ant => ant.Omni) : 0.0;
            double maxOmniB = omnisB.Any() ?  omnisB.Max(ant => ant.Omni) : 0.0;
            double maxDishA = dishesA.Any() ? dishesA.Max(ant => ant.Dish) : 0.0;
            double maxDishB = dishesB.Any() ? dishesB.Max(ant => ant.Dish) : 0.0;

            double bonusA = GetMultipleAntennaBonus(omnisA, maxOmniA);
            double bonusB = GetMultipleAntennaBonus(omnisB, maxOmniB);

            double distance = satA.DistanceTo(satB);

            // Which antennas have the range to reach at least one antenna on the other satellite??
            omnisA = omnisA.Where(ant =>
                                  CheckRange(rangeFunc, ant.Omni + bonusA, omniClamp, maxOmniB + bonusB, omniClamp) >= distance ||
                                  CheckRange(rangeFunc, ant.Omni + bonusA, omniClamp, maxDishB, dishClamp) >= distance);
            dishesA = dishesA.Where(ant =>
                                    CheckRange(rangeFunc, ant.Dish, dishClamp, maxOmniB + bonusB, omniClamp) >= distance ||
                                    CheckRange(rangeFunc, ant.Dish, dishClamp, maxDishB, dishClamp) >= distance);
            omnisB = omnisB.Where(ant =>
                                  CheckRange(rangeFunc, ant.Omni + bonusB, omniClamp, maxOmniA + bonusA, omniClamp) >= distance ||
                                  CheckRange(rangeFunc, ant.Omni + bonusB, omniClamp, maxDishA, dishClamp) >= distance);
            dishesB = dishesB.Where(ant =>
                                    CheckRange(rangeFunc, ant.Dish, dishClamp, maxOmniA + bonusA, omniClamp) >= distance ||
                                    CheckRange(rangeFunc, ant.Dish, dishClamp, maxDishA, dishClamp) >= distance);

            // Just because an antenna is in `omnisA.Concat(dishesA)` doesn't mean it can connect to *any*
            //  antenna in `omnisB.Concat(dishesB)`, and vice versa. Pick the max to be safe.
            IAntenna selectedAntennaA = omnisA.Concat(dishesA)
                                        .OrderByDescending(ant => Math.Max(ant.Omni, ant.Dish)).FirstOrDefault();
            IAntenna selectedAntennaB = omnisB.Concat(dishesB)
                                        .OrderByDescending(ant => Math.Max(ant.Omni, ant.Dish)).FirstOrDefault();

            if (selectedAntennaA != null && selectedAntennaB != null)
            {
                List <IAntenna> interfaces = omnisA.Concat(dishesA).ToList();

                LinkType type = (dishesA.Contains(selectedAntennaA) || dishesB.Contains(selectedAntennaB)
                    ? LinkType.Dish : LinkType.Omni);

                return(new NetworkLink <ISatellite>(satB, interfaces, type));
            }

            return(null);
        }
 public DynamicTarget(Guid g)
 {
     if (RTCore.Instance.Network[g] != null) {
         sat = RTCore.Instance.Network[g];
         type = TargetTypes.ISATELLITE;
     } else if (RTCore.Instance.Network.Planets.ContainsKey(g)) {
         body = RTCore.Instance.Network.Planets[g];
         type = TargetTypes.BODY;
     } else {
         type = TargetTypes.NOTARGET;
     }
 }
Example #6
0
        /// <summary>Constructs a link between two satellites, if one is possible.</summary>
        /// <returns>The new link, or null if the two satellites cannot connect.</returns>
        /// <param name="rangeFunc">A function that computes the maximum range between two 
        /// satellites, given their individual ranges.</param>
        public static NetworkLink<ISatellite> GetLink(ISatellite satA, ISatellite satB, 
            Func<double, double, double> rangeFunc) {
            // Which antennas on either craft are capable of communication?
            IEnumerable<IAntenna>  omnisA = GetOmnis(satA);
            IEnumerable<IAntenna>  omnisB = GetOmnis(satB);
            IEnumerable<IAntenna> dishesA = GetDishesThatSee(satA, satB);
            IEnumerable<IAntenna> dishesB = GetDishesThatSee(satB, satA);

            // Pick the best range for each case
            double maxOmniA =  omnisA.Any() ?  omnisA.Max(ant => ant.Omni) : 0.0;
            double maxOmniB =  omnisB.Any() ?  omnisB.Max(ant => ant.Omni) : 0.0;
            double maxDishA = dishesA.Any() ? dishesA.Max(ant => ant.Dish) : 0.0;
            double maxDishB = dishesB.Any() ? dishesB.Max(ant => ant.Dish) : 0.0;

            double bonusA = GetMultipleAntennaBonus(omnisA, maxOmniA);
            double bonusB = GetMultipleAntennaBonus(omnisB, maxOmniB);

            double distance = satA.DistanceTo(satB);

            // Which antennas have the range to reach at least one antenna on the other satellite??
            omnisA = omnisA.Where(ant => 
                   CheckRange(rangeFunc, ant.Omni + bonusA, omniClamp, maxOmniB + bonusB, omniClamp) >= distance
                || CheckRange(rangeFunc, ant.Omni + bonusA, omniClamp, maxDishB         , dishClamp) >= distance);
            dishesA = dishesA.Where(ant => 
                   CheckRange(rangeFunc, ant.Dish         , dishClamp, maxOmniB + bonusB, omniClamp) >= distance 
                || CheckRange(rangeFunc, ant.Dish         , dishClamp, maxDishB         , dishClamp) >= distance);
            omnisB = omnisB.Where(ant => 
                   CheckRange(rangeFunc, ant.Omni + bonusB, omniClamp, maxOmniA + bonusA, omniClamp) >= distance
                || CheckRange(rangeFunc, ant.Omni + bonusB, omniClamp, maxDishA         , dishClamp) >= distance);
            dishesB = dishesB.Where(ant => 
                   CheckRange(rangeFunc, ant.Dish         , dishClamp, maxOmniA + bonusA, omniClamp) >= distance 
                || CheckRange(rangeFunc, ant.Dish         , dishClamp, maxDishA         , dishClamp) >= distance);

            // Just because an antenna is in `omnisA.Concat(dishesA)` doesn't mean it can connect to *any*
            //  antenna in `omnisB.Concat(dishesB)`, and vice versa. Pick the max to be safe.
            IAntenna selectedAntennaA = omnisA.Concat(dishesA)
                .OrderByDescending(ant => Math.Max(ant.Omni, ant.Dish)).FirstOrDefault();
            IAntenna selectedAntennaB = omnisB.Concat(dishesB)
                .OrderByDescending(ant => Math.Max(ant.Omni, ant.Dish)).FirstOrDefault();

            if (selectedAntennaA != null && selectedAntennaB != null)
            {
                List<IAntenna> interfaces = omnisA.Concat(dishesA).ToList();

                LinkType type = (dishesA.Contains(selectedAntennaA) || dishesB.Contains(selectedAntennaB) 
                    ? LinkType.Dish : LinkType.Omni);

                return new NetworkLink<ISatellite>(satB, interfaces, type);
            }

            return null;
        }
    private Boolean ValidateSaveField()
    {
        ISatellite SatelliteMgr = (ISatellite)ObjectFactory.CreateInstance("BusinessProcess.Administration.BSatellite, BusinessProcess.Administration");
        DataTable  theDT        = SatelliteMgr.GetSatelliteByID_Name(txtSatelliteID.Text, txtSatelliteName.Text);

        if (txtSatelliteID.Text == "")
        {
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["Control"] = "Satellite ID";
            IQCareMsgBox.Show("BlankTextBox", theBuilder, this);
            txtSatelliteID.Focus();
            return(false);
        }
        else if (txtSatelliteName.Text == "")
        {
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["Control"] = "Satellite Name";
            IQCareMsgBox.Show("BlankTextBox", theBuilder, this);
            txtSatelliteName.Focus();
            return(false);
        }
        else if (txtPriority.Text == "")
        {
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["Control"] = "Priority";
            IQCareMsgBox.Show("BlankTextBox", theBuilder, this);
            txtPriority.Focus();
            return(false);
        }
        if (theDT.Rows[0]["Exist"].ToString() == "1")
        {
            if ((txtSatelliteID.Text == theDT.Rows[0]["SatelliteID"].ToString()) && (txtSatelliteName.Text == theDT.Rows[0]["Name"].ToString()))
            {
                IQCareMsgBox.Show("SatelliteIDName", this);
                txtSatelliteID.Focus();
                return(false);
            }
            else if (txtSatelliteID.Text == theDT.Rows[0]["SatelliteID"].ToString())
            {
                IQCareMsgBox.Show("SatelliteID", this);
                txtSatelliteID.Focus();
                return(false);
            }
            else if (txtSatelliteName.Text == theDT.Rows[0]["Name"].ToString())
            {
                IQCareMsgBox.Show("SatelliteName", this);
                txtSatelliteName.Focus();
                return(false);
            }
        }
        return(true);
    }
 public IEnumerable <NetworkLink <ISatellite> > FindNeighbors(ISatellite s)
 {
     // Special case for finding our own neighbours
     if (s == this)
     {
         return(FindNeighbors());
     }
     // Pass through to the regular function
     else
     {
         return(RTCore.Instance.Network.FindNeighbors(s));
     }
 }
 public IEnumerable<NetworkLink<ISatellite>> FindNeighbors(ISatellite s)
 {
     // Special case for finding our own neighbours
     if (s == this)
     {
         return FindNeighbors();
     }
     // Pass through to the regular function
     else
     {
         return RTCore.Instance.Network.FindNeighbors(s);
     }
 }
Example #10
0
        public static NetworkLink <ISatellite> GetLink(ISatellite sat_a, ISatellite sat_b)
        {
            var omni_a = sat_a.Antennas.Where(a => a.Omni > 0);
            var omni_b = sat_b.Antennas.Where(b => b.Omni > 0);
            var dish_a = sat_a.Antennas.Where(a => a.Dish > 0 && (a.IsTargetingDirectly(sat_b) || a.IsTargetingActiveVessel(sat_b) || a.IsTargetingPlanet(sat_b, sat_a)));
            var dish_b = sat_b.Antennas.Where(b => b.Dish > 0 && (b.IsTargetingDirectly(sat_a) || b.IsTargetingActiveVessel(sat_a) || b.IsTargetingPlanet(sat_a, sat_b)));

            double max_omni_a = omni_a.Any() ? omni_a.Max(a => a.Omni) : 0.0;
            double max_omni_b = omni_b.Any() ? omni_b.Max(b => b.Omni) : 0.0;
            double max_dish_a = dish_a.Any() ? dish_a.Max(a => a.Dish) : 0.0;
            double max_dish_b = dish_b.Any() ? dish_b.Max(b => b.Dish) : 0.0;
            double bonus_a    = 0.0;
            double bonus_b    = 0.0;

            if (RTSettings.Instance.MultipleAntennaMultiplier > 0.0)
            {
                double sum_omni_a = omni_a.Sum(a => a.Omni);
                double sum_omni_b = omni_b.Sum(b => b.Omni);

                bonus_a = (sum_omni_a - max_omni_a) * RTSettings.Instance.MultipleAntennaMultiplier;
                bonus_b = (sum_omni_b - max_omni_b) * RTSettings.Instance.MultipleAntennaMultiplier;
            }

            double max_a    = Math.Max(max_omni_a + bonus_a, max_dish_a);
            double max_b    = Math.Max(max_omni_b + bonus_b, max_dish_b);
            double distance = sat_a.DistanceTo(sat_b);

            omni_a = omni_a.Where(a => MaxDistance(a.Omni + bonus_a, max_b, OmniRangeClamp) >= distance);
            dish_a = dish_a.Where(a => MaxDistance(a.Dish, max_omni_b + bonus_b, OmniRangeClamp) >= distance || MaxDistance(a.Dish, max_dish_b, DishRangeClamp) >= distance);
            omni_b = omni_b.Where(b => MaxDistance(b.Omni + bonus_b, max_a, OmniRangeClamp) >= distance);
            dish_b = dish_b.Where(b => MaxDistance(b.Dish, max_omni_a + bonus_a, OmniRangeClamp) >= distance || MaxDistance(b.Dish, max_dish_a, DishRangeClamp) >= distance);

            var conn_a = omni_a.Concat(dish_a).FirstOrDefault();
            var conn_b = omni_b.Concat(dish_b).FirstOrDefault();

            if (conn_a != null && conn_b != null)
            {
                var interfaces = omni_a.Concat(dish_a).ToList();
                var type       = LinkType.Omni;
                if (dish_a.Contains(conn_a) || dish_b.Contains(conn_b))
                {
                    type = LinkType.Dish;
                }
                return(new NetworkLink <ISatellite>(sat_b, interfaces, type));
            }

            return(null);
        }
 public static bool HasLineOfSightWith(this ISatellite a, ISatellite b)
 {
     var aPos = a.Position;
     var bPos = b.Position;
     foreach (CelestialBody referenceBody in FlightGlobals.Bodies)
     {
         Vector3d bodyFromA = referenceBody.position - aPos;
         Vector3d bFromA = bPos - aPos;
         if (Vector3d.Dot(bodyFromA, bFromA) <= 0) continue;
         Vector3d bFromAnorm = bFromA.normalized;
         if (Vector3d.Dot(bodyFromA, bFromAnorm) >= bFromA.magnitude) continue;
         Vector3d lateralOffset = bodyFromA - Vector3d.Dot(bodyFromA, bFromAnorm) * bFromAnorm;
         if (lateralOffset.magnitude < referenceBody.Radius - 5) return false;
     }
     return true;
 }
Example #12
0
        public static bool IsTargetingPlanet(this IAntenna a, ISatellite sat_b, ISatellite sat_a)
        {
            var planets = RTCore.Instance.Network.Planets;

            if (!planets.ContainsKey(a.Target) || sat_b.Body != planets[a.Target])
            {
                return(false);
            }
            var dir_cb = (planets[a.Target].position - sat_a.Position);
            var dir_b  = (sat_b.Position - sat_a.Position);

            if (Vector3d.Dot(dir_cb.normalized, dir_b.normalized) >= a.Radians)
            {
                return(true);
            }
            return(false);
        }
Example #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AppLocation"] == null || Session.Count == 0 || Session["AppUserID"].ToString() == "")
        {
            IQCareMsgBox.Show("SessionExpired", this);
            Response.Redirect("~/frmlogin.aspx", true);
        }
        lblTitle.Text = Request.QueryString["name"];

        //(Master.FindControl("lblRoot") as Label).Text = " » Customize Lists";
        //(Master.FindControl("lblMark") as Label).Visible = false;
        //(Master.FindControl("lblheader") as Label).Text = "Satellite";
        (Master.FindControl("levelOneNavigationUserControl1").FindControl("lblRoot") as Label).Text   = "Customize Lists";
        (Master.FindControl("levelOneNavigationUserControl1").FindControl("lblheader") as Label).Text = " >> Satellite";

        if (!IsPostBack)
        {
            ViewState["redirect"] = Request.QueryString["Redirect"];
            /*For Save or Update Message*/
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["Name"] = "Satellite";
            /*****/
            ViewState["ID"] = "";
            if (lblTitle.Text == "Edit")
            {
                int ID = Convert.ToInt32(Request.QueryString["SatelliteId"]);
                lblTitle.Text = "Edit Satellite/Location";
                btnSave.Text  = "Update";
                IQCareMsgBox.ShowConfirm("CustomUpdateRecord", theBuilder, btnSave);
                ISatellite SatelliteEditMgr = (ISatellite)ObjectFactory.CreateInstance("BusinessProcess.Administration.BSatellite, BusinessProcess.Administration");
                DataTable  DT = SatelliteEditMgr.GetSatellite(ID);
                ViewState["ID"]        = DT.Rows[0]["ID"].ToString();
                txtSatelliteID.Text    = DT.Rows[0]["SatelliteID"].ToString();
                txtSatelliteName.Text  = DT.Rows[0]["Name"].ToString();
                ddStatus.SelectedValue = DT.Rows[0]["DeleteFlag"].ToString();
                txtPriority.Text       = DT.Rows[0]["SRNo"].ToString();
            }
            else
            {
                td1.Visible   = false;
                td2.ColSpan   = 2;
                lblTitle.Text = "Add Satellite/Location";
                IQCareMsgBox.ShowConfirm("CustomSaveRecord", theBuilder, btnSave);
            }
        }
    }
Example #14
0
 public DynamicTarget(Guid g)
 {
     if (RTCore.Instance.Network[g] != null)
     {
         sat  = RTCore.Instance.Network[g];
         type = TargetTypes.ISATELLITE;
     }
     else if (RTCore.Instance.Network.Planets.ContainsKey(g))
     {
         body = RTCore.Instance.Network.Planets[g];
         type = TargetTypes.BODY;
     }
     else
     {
         type = TargetTypes.NOTARGET;
     }
 }
Example #15
0
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            FlightCtrlState delayed = new FlightCtrlState();

            // Keep the throttle on no connection
            if (this.KeepThrottleNoConnect == true)
            {
                delayed.mainThrottle = fcs.mainThrottle;
            }

            while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = mFlightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
Example #16
0
        public static NetworkLink<ISatellite> GetLink(ISatellite sat_a, ISatellite sat_b)
        {
            var omni_a = sat_a.Antennas.Where(a => a.Omni > 0);
            var omni_b = sat_b.Antennas.Where(b => b.Omni > 0);
            var dish_a = sat_a.Antennas.Where(a => a.Dish > 0 && (a.IsTargetingDirectly(sat_b) || a.IsTargetingActiveVessel(sat_b) || a.IsTargetingPlanet(sat_b, sat_a)));
            var dish_b = sat_b.Antennas.Where(b => b.Dish > 0 && (b.IsTargetingDirectly(sat_a) || b.IsTargetingActiveVessel(sat_a) || b.IsTargetingPlanet(sat_a, sat_b)));

            double max_omni_a = omni_a.Any() ? omni_a.Max(a => a.Omni) : 0.0;
            double max_omni_b = omni_b.Any() ? omni_b.Max(b => b.Omni) : 0.0;
            double max_dish_a = dish_a.Any() ? dish_a.Max(a => a.Dish) : 0.0;
            double max_dish_b = dish_b.Any() ? dish_b.Max(b => b.Dish) : 0.0;
            double bonus_a = 0.0;
            double bonus_b = 0.0;

            if (RTSettings.Instance.MultipleAntennaMultiplier > 0.0)
            {
                double sum_omni_a = omni_a.Sum(a => a.Omni);
                double sum_omni_b = omni_b.Sum(b => b.Omni);

                bonus_a = (sum_omni_a - max_omni_a) * RTSettings.Instance.MultipleAntennaMultiplier;
                bonus_b = (sum_omni_b - max_omni_b) * RTSettings.Instance.MultipleAntennaMultiplier;
            }

            double max_a = Math.Max(max_omni_a + bonus_a, max_dish_a);
            double max_b = Math.Max(max_omni_b + bonus_b, max_dish_b);
            double distance = sat_a.DistanceTo(sat_b);

            omni_a = omni_a.Where(a => MaxDistance(a.Omni + bonus_a, max_b, OmniRangeClamp) >= distance);
            dish_a = dish_a.Where(a => MaxDistance(a.Dish, max_omni_b + bonus_b, OmniRangeClamp) >= distance || MaxDistance(a.Dish, max_dish_b, DishRangeClamp) >= distance);
            omni_b = omni_b.Where(b => MaxDistance(b.Omni + bonus_b, max_a, OmniRangeClamp) >= distance);
            dish_b = dish_b.Where(b => MaxDistance(b.Dish, max_omni_a + bonus_a, OmniRangeClamp) >= distance || MaxDistance(b.Dish, max_dish_a, DishRangeClamp) >= distance);

            var conn_a = omni_a.Concat(dish_a).FirstOrDefault();
            var conn_b = omni_b.Concat(dish_b).FirstOrDefault();

            if (conn_a != null && conn_b != null)
            {
                var interfaces = omni_a.Concat(dish_a).ToList();
                var type = LinkType.Omni;
                if (dish_a.Contains(conn_a) || dish_b.Contains(conn_b)) type = LinkType.Dish;
                return new NetworkLink<ISatellite>(sat_b, interfaces, type);
            }

            return null;
        }
Example #17
0
        /// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary>
        /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param>
        /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param>
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            //TODO: `sat` parameter is never used. Check if is needed somewhere: if it's not, remove it.
            var delayed = new FlightCtrlState();

            // Keep the throttle on no connection
            if (KeepThrottleNoConnect)
            {
                delayed.mainThrottle = fcs.mainThrottle;
            }

            while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = _flightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
        /// <summary>Determines if an antenna can connect to a target indirectly, using a cone.</summary>
        /// <returns><c>true</c> if <paramref name="target"/> lies within the cone of <paramref name="dish"/>; 
        /// otherwise, <c>false</c>.</returns>
        /// <param name="dish">The antenna being queried.</param>
        /// <param name="target">The satellite being tested for being the antenna target.</param>
        /// <param name="antennaSat">The satellite containing <paramref name="dish"/>.</param>
        /// 
        /// <exceptsafe>The program state is unchanged in the event of an exception.</exceptsafe>
        public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatellite antennaSat)
        {
            if (dish.Target == Guid.Empty) {
                return false;
            }

            Vector3d? coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);

            if (coneCenter.HasValue)
            {
                Vector3d dirToConeCenter = (coneCenter.Value - antennaSat.Position);
                Vector3d dirToTarget     = (target.Position  - antennaSat.Position);

                return (Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle);
            }

            return false;
        }
Example #19
0
        /// <summary>Determines if an antenna can connect to a target indirectly, using a cone.</summary>
        /// <returns><c>true</c> if <paramref name="target"/> lies within the cone of <paramref name="dish"/>;
        /// otherwise, <c>false</c>.</returns>
        /// <param name="dish">The antenna being queried.</param>
        /// <param name="target">The satellite being tested for being the antenna target.</param>
        /// <param name="antennaSat">The satellite containing <paramref name="dish"/>.</param>
        ///
        /// <exceptsafe>The program state is unchanged in the event of an exception.</exceptsafe>
        public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatellite antennaSat)
        {
            if (dish.Target == Guid.Empty)
            {
                return(false);
            }

            Vector3d?coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);

            if (coneCenter.HasValue)
            {
                Vector3d dirToConeCenter = (coneCenter.Value - antennaSat.Position);
                Vector3d dirToTarget     = (target.Position - antennaSat.Position);

                return(Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle);
            }

            return(false);
        }
Example #20
0
        /// <summary>Returns the SoI of a target identified only by its Guid</summary>
        /// <returns>If target refers to a celestial body, returns that body. If target refers
        /// to an ISatellite, returns the body whose SoI currently contains the ISatellite.</returns>
        /// <param name="target">The item whose position is desired. May be either a satellite
        /// or a celestial body.</param>
        /// Throws System.ArgumentException if target or network does not exist.
        public static CelestialBody targetBody(Guid target)
        {
            if (RTCore.Instance != null && RTCore.Instance.Network != null &&
                target != Guid.Empty)
            {
                ISatellite targetSat = RTCore.Instance.Network[target];
                if (targetSat != null)
                {
                    return(targetSat.Body);
                }

                try {
                    CelestialBody targetPlanet = RTCore.Instance.Network.Planets[target];
                    return(targetPlanet);
                } catch (KeyNotFoundException) {}
            }

            throw new System.ArgumentException("No such Guid found", "target");
        }
Example #21
0
    public void UpdateDisplayInfo()
    {
        if (!orbitListDisplay || !numSatellitesDisplay || !furthestOrbitDisplay)
        {
            return;
        }

        orbitListDisplay.text     = initialStar.SatellitesToString();
        numSatellitesDisplay.text = "Satellites: " + initialStar.NumSatellites;

        ISatellite furthest = initialStar.FurthestSatellite;

        if (furthest != null)
        {
            furthestOrbitDisplay.text = "Furthest Orbit: " + furthest.MaxOrbitRadius;
        }
        else
        {
            furthestOrbitDisplay.text = "Furthest Orbit: None";
        }
    }
Example #22
0
        /// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary>
        /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param>
        /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param>
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            var delayed = new FlightCtrlState();

            delayed.mainThrottle = fcs.mainThrottle;

            if (!KeepThrottleNoConnect && !InputAllowed) // enforce the rule of shutting throttle down on connection loss
            {
                delayed.mainThrottle = 0f;
            }
            else if (KeepThrottleNoConnect && LockedThrottleNoConnect) // when connection is lost with the disabled rule of shutting throttle down, throttle is locked
            {
                delayed.mainThrottle = LockedThrottlePositionNoConnect;
            }

            while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = _flightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
    public ISatellite GetFurthestSatellite()
    {
        if (_satellites.Count <= 0)
        {
            return(null);
        }

        ISatellite furthest = _satellites[0];
        float      furthestOrbitDistance = furthest.MaxOrbitRadius;

        foreach (ISatellite sat in _satellites)
        {
            float satMaxOrbit = sat.MaxOrbitRadius;

            if (satMaxOrbit > furthestOrbitDistance)
            {
                furthest = sat;
                furthestOrbitDistance = satMaxOrbit;
            }
        }

        return(furthest);
    }
        /// <summary>Tests whether two satellites have line of sight to each other</summary>
        /// <returns><c>true</c> if a straight line from a to b is not blocked by any celestial body; 
        /// otherwise, <c>false</c>.</returns>
        public static bool HasLineOfSightWith(this ISatellite satA, ISatellite satB)
        {
            const double MIN_HEIGHT = 5.0;
            Vector3d satAPos = satA.Position;
            Vector3d satBPos = satB.Position;

            foreach (CelestialBody referenceBody in FlightGlobals.Bodies)
            {
                Vector3d bodyFromA = referenceBody.position - satAPos;
                Vector3d bFromA = satBPos - satAPos;

                // Is body at least roughly between satA and satB?
                if (Vector3d.Dot(bodyFromA, bFromA) <= 0) continue;
                Vector3d bFromANorm = bFromA.normalized;
                if (Vector3d.Dot(bodyFromA, bFromANorm) >= bFromA.magnitude) continue;

                // Above conditions guarantee that Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm 
                // lies between the origin and bFromA
                Vector3d lateralOffset = bodyFromA - Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm;
                if (lateralOffset.magnitude < referenceBody.Radius - MIN_HEIGHT) return false;
            }
            return true;
        }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         int    Flag       = 1;
         String Createdate = "";
         if (btnSave.Text != "Update")
         {
             Flag = 0;
             if (ValidateSaveField() == false)
             {
                 return;
             }
         }
         else
         {
             if (ValidateUpdateField() == false)
             {
                 return;
             }
         }
         ISatellite SatelliteMgr = (ISatellite)ObjectFactory.CreateInstance("BusinessProcess.Administration.BSatellite, BusinessProcess.Administration");
         int        Satellite    = (int)SatelliteMgr.SaveUpdateSatellite(ViewState["ID"].ToString(), txtSatelliteID.Text, txtSatelliteName.Text, ddStatus.SelectedValue, Convert.ToInt32(txtPriority.Text), Flag, Convert.ToInt32(Session["AppUserId"]), Createdate);
         redirect();
     }
     catch (Exception err)
     {
         MsgBuilder theBuilder = new MsgBuilder();
         theBuilder.DataElements["MessageText"] = err.Message.ToString();
         IQCareMsgBox.Show("#C1", theBuilder, this);
     }
     finally
     {
         //SatelliteMgr = null;
     }
 }
Example #26
0
 /// <summary>Returns all omnidirectional antennas on a satellite.</summary>
 /// <returns>A possibly empty collection of omnis.</returns>
 private static IEnumerable <IAntenna> GetOmnis(ISatellite sat)
 {
     return(sat.Antennas.Where(a => a.Omni > 0));
 }
Example #27
0
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            FlightCtrlState delayed = new FlightCtrlState();

            // Keep the throttle on no connection
            if(this.KeepThrottleNoConnect == true)
            {
                delayed.mainThrottle = fcs.mainThrottle;
            }

            while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = mFlightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
Example #28
0
 /// <summary>Constructs a link between two satellites, if one is possible.</summary>
 /// <returns>The new link, or null if the two satellites cannot connect.</returns>
 public static NetworkLink<ISatellite> GetLink(ISatellite satA, ISatellite satB) {
     return AbstractRangeModel.GetLink(satA, satB, MaxDistance);
 }
Example #29
0
        /// <summary>Tests whether an antenna can connect to a target</summary>
        /// <returns>The range to the target, or a diagnostic error message. Returns the
        /// empty string if target is invalid.</returns>
        /// <param name="antenna">The antenna attempting to make a connection.</param>
        /// <param name="target">The Guid to which it is trying to connect.</param>
        public static KeyValuePair <string, UnityEngine.Color> tryConnection(IAntenna antenna, Guid target)
        {
            String status = "ok";

            // What kind of target?
            if (RTCore.Instance != null && RTCore.Instance.Network != null &&
                target != Guid.Empty && target != NetworkManager.ActiveVesselGuid)
            {
                bool warning = false, error = false;

                ISatellite mySat = RTCore.Instance.Network[antenna.Guid];
                if (mySat == null)
                {
                    return(new KeyValuePair <string, UnityEngine.Color>("", UnityEngine.Color.white));
                }

                List <string> conditions = new List <string>();

                // Most probably a satellite
                ISatellite targetSat = RTCore.Instance.Network[target];
                if (targetSat != null)
                {
                    if (!RangeModelExtensions.HasLineOfSightWith(mySat, targetSat))
                    {
                        status = "No line of sight";
                        error  = true;
                    }

                    double dist = RangeModelExtensions.DistanceTo(mySat, targetSat);
                    // Only standard model supported for now, RangeModel isn't designed for this problem
                    double maxDist = Math.Max(antenna.Omni, antenna.Dish);
                    conditions.Add("Current distance:" + RTUtil.FormatSI(dist, "m"));
                    conditions.Add("Antenna range:" + RTUtil.FormatSI(maxDist, "m"));
                    if (dist > maxDist)
                    {
                        status = "Target not in range";
                        error  = true;
                    }
                }

                try {
                    CelestialBody targetPlanet = RTCore.Instance.Network.Planets[target];
                    double        dist         = Vector3d.Distance(mySat.Position, targetPlanet.position);
                    double        maxDist      = Math.Max(antenna.Omni, antenna.Dish);
                    double        spread       = 2.0 * dist * Math.Sqrt(1 - antenna.CosAngle * antenna.CosAngle);
                    int           numTargets   = countInCone(antenna, target);

                    if (spread < 2.0 * targetPlanet.Radius)
                    {
                        // WHAT does this info?
                        // conditions.Add("Small Cone");
                        warning = true;
                    }

                    conditions.Add("Current distance:" + RTUtil.FormatSI(dist, "m"));
                    conditions.Add("Antenna range:" + RTUtil.FormatSI(maxDist, "m"));

                    if (dist <= maxDist)
                    {
                        conditions.Add(String.Format("Info:{0} beam covers {1} targets)",
                                                     RTUtil.FormatSI(spread, "m"),
                                                     numTargets
                                                     ));
                    }
                    else
                    {
                        status = "Target not in range";
                        error  = true;
                    }
                    if (numTargets <= 0)
                    {
                        warning = true;
                    }
                } catch (KeyNotFoundException) {}

                conditions.Add("Status:" + status);

                return(new KeyValuePair <string, UnityEngine.Color>(
                           String.Join("; ", conditions.ToArray()),
                           error ? UnityEngine.Color.red : (warning ? UnityEngine.Color.yellow : UnityEngine.Color.white)
                           ));
            }

            // Default behavior
            return(new KeyValuePair <string, UnityEngine.Color>("", UnityEngine.Color.white));
        }
Example #30
0
 public void Refresh(ISatellite sat)
 {
     if (sat == Satellite) Hide();
 }
Example #31
0
 private void OnSatelliteUnregister(ISatellite s)
 {
     mEdges.RemoveWhere(e => e.A == s || e.B == s);
 }
Example #32
0
 /// <summary>Finds the distance between two ISatellites</summary>
 /// <returns>The distance in meters.</returns>
 public static double DistanceTo(this ISatellite a, ISatellite b)
 {
     return(Vector3d.Distance(a.Position, b.Position));
 }
Example #33
0
 private void OnSatelliteUnregister(ISatellite s)
 {
     mEdges.RemoveWhere(e => e.A == s || e.B == s);
 }
 /// <summary>
 /// Our own version of the distance function, less accurate, but far lower execution cost.
 /// </summary>
 public static double DistanceTo(ISatellite a, NetworkLink <ISatellite> b)
 {
     return((Math.Abs(a.Position.x - b.Target.Position.x) +
             Math.Abs(a.Position.y - b.Target.Position.y) +
             Math.Abs(a.Position.z - b.Target.Position.z)) * DIST_FACTOR);
 }
 /// <summary>
 /// Our own version of the distance function, less accurate, but far lower execution cost.
 /// </summary>
 public static double DistanceTo(ISatellite a, ISatellite b)
 {
     return((Math.Abs(a.Position.x - b.Position.x) +
             Math.Abs(a.Position.y - b.Position.y) +
             Math.Abs(a.Position.z - b.Position.z)) * DIST_FACTOR);
 }
        /// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary>
        /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param>
        /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param>
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            //TODO: `sat` parameter is never used. Check if is needed somewhere: if it's not, remove it.
            var delayed = new FlightCtrlState();

            // Keep the throttle on no connection
            if(KeepThrottleNoConnect)
            {
                delayed.mainThrottle = fcs.mainThrottle;
            }

            while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = _flightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
Example #37
0
 void HandleMessageReceived(object sender, TransportMessageReceivedEventArgs e, ISatellite satellite)
 {
     if (!satellite.Handle(e.Message))
     {
         ((ITransport)sender).AbortHandlingCurrentMessage();
     }
 }
 public IEnumerable<IAntenna> For(ISatellite satellite)
 {
     return For(satellite.Guid);
 }
Example #39
0
 private void OnLinkRemove(ISatellite a, NetworkLink<ISatellite> link)
 {
     mEdges.Remove(new BidirectionalEdge<ISatellite>(a, link.Target, link.Port));
 }
Example #40
0
 void HandleMessageReceived(object sender, TransportMessageReceivedEventArgs e, ISatellite satellite)
 {
     if (!satellite.Handle(e.Message))
     {
         ((ITransport) sender).AbortHandlingCurrentMessage();
     }
 }
Example #41
0
 /// <summary>Finds the maximum range between an antenna and a potential target.</summary>
 /// <returns>The maximum distance at which the two spacecraft could communicate.</returns>
 /// <param name="antenna">The antenna attempting to target.</param>
 /// <param name="target">The satellite being targeted by <paramref name="antenna"/>.</param>
 /// <param name="antennaSat">The satellite on which <paramref name="antenna"/> is mounted.</param>
 public static double GetRangeInContext(IAntenna antenna, ISatellite target, ISatellite antennaSat) {
     return AbstractRangeModel.GetRangeInContext(antenna, target, antennaSat, MaxDistance);
 }
 private void OnSatellite(ISatellite satellite)
 {
     if (satellite == mFocus) {
         mOnClick.Invoke(null);
         mForceClose.Invoke();
     }
 }
 public AntennaWindow(IAntenna antenna, ISatellite sat)
     : base("Antenna Configuration", new Rect(100, 100, 0, 0), WindowAlign.Floating)
 {
     mAntenna = antenna;
     mSatellite = sat;
 }
Example #44
0
 void HandleMessageReceived(object sender, TransportMessageReceivedEventArgs e, ISatellite satellite)
 {
     try
     {
         satellite.Handle(e.Message);
     }
     catch (Exception ex)
     {
         Logger.ErrorFormat("{0} could not handle message. Exception: {1}", satellite.GetType().Name, ex.Message);
         throw;
     }
 }
 /// <summary>Rebuilds list of target vessels</summary>
 /// <description>Rebuilds the list of target vessels, preserving the rest of the target list state. Does 
 ///     not alter planets or special targets, call RefreshPlanets() for that.</description>
 /// <param name="sat">The satellite whose status has just changed.</param>
 public void Refresh(ISatellite sat)
 {
     Refresh();
 }
Example #46
0
 /// <summary>Returns all omnidirectional antennas on a satellite.</summary>
 /// <returns>A possibly empty collection of omnis.</returns>
 private static IEnumerable<IAntenna> GetOmnis(ISatellite sat)
 {
     return sat.Antennas.Where(a => a.Omni > 0);
 }
 public AntennaWindow(IAntenna antenna, ISatellite sat)
     : base("Antenna Configuration", new Rect(100, 100, 0, 0), WindowAlign.Floating)
 {
     mAntenna   = antenna;
     mSatellite = sat;
 }
Example #48
0
 /// <summary>Returns all dishes on a satellite that are pointed, directly or indirectly, 
 /// at a particular target.</summary>
 /// <returns>A possibly empty collection of dishes.</returns>
 /// <param name="sat">The satellite whose dishes are being queried.</param>
 /// <param name="target">The target to be contacted.</param>
 private static IEnumerable<IAntenna> GetDishesThatSee(ISatellite sat, ISatellite target)
 {
     return sat.Antennas.Where(a => a.Dish > 0 
         && (a.IsTargetingDirectly(target) || a.IsTargetingActiveVessel(target) || a.IsInFieldOfView(target, sat)));
 }
Example #49
0
 public IEnumerable <IAntenna> this[ISatellite s] {
     get { return(For(s.Guid)); }
 }
Example #50
0
 /// <summary>Determines if an antenna has a specific satellite as its target.</summary>
 /// <returns><c>true</c> if a's target is set to <paramref name="target"/>; false otherwise.</returns>
 /// <param name="dish">The antenna being queried.</param>
 /// <param name="target">The satellite being tested for being the antenna target.</param>
 public static bool IsTargetingDirectly(this IAntenna dish, ISatellite target)
 {
     return(dish.Target == target.Guid);
 }
Example #51
0
 /// <summary>Returns all dishes on a satellite that are pointed, directly or indirectly,
 /// at a particular target.</summary>
 /// <returns>A possibly empty collection of dishes.</returns>
 /// <param name="sat">The satellite whose dishes are being queried.</param>
 /// <param name="target">The target to be contacted.</param>
 private static IEnumerable <IAntenna> GetDishesThatSee(ISatellite sat, ISatellite target)
 {
     return(sat.Antennas.Where(a => a.Dish > 0 &&
                               (a.IsTargetingDirectly(target) || a.IsTargetingActiveVessel(target) || a.IsInFieldOfView(target, sat))));
 }
Example #52
0
 void HandleMessageReceived(object sender, TransportMessageReceivedEventArgs e, ISatellite satellite)
 {
     try
     {
         satellite.Handle(e.Message);
     }
     catch (Exception ex)
     {
         Logger.ErrorFormat("{0} could not handle message. Exception: {1}", satellite.GetType().Name, ex.Message);
         throw;
     }
 }
Example #53
0
 public SatelliteWindow(ISatellite satellite)
     : base(Guid, null, new Rect(0, 0, 600, 600), WindowAlign.BottomRight)
 {
     mSetSatellite = satellite;
 }
Example #54
0
        private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
        {
            FlightCtrlState delayed = new FlightCtrlState();
            while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
            {
                delayed = mFlightCtrlQueue.Dequeue().State;
            }

            fcs.CopyFrom(delayed);
        }
 private void OnSatelliteUnregister(ISatellite s)
 {
     mEdges.RemoveWhere(x => x.A == s || x.B == s);
 }
Example #56
0
 public SatelliteFragment(ISatellite sat)
 {
     Satellite = sat;
     RTCore.Instance.Satellites.OnUnregister += Refresh;
 }
Example #57
0
 /// <summary>Finds the distance between an ISatellite and the target of a connection</summary>
 /// <returns>The distance in meters.</returns>
 /// <param name="sat">The satellite from which the distance is to be measured.</param>
 /// <param name="link">The network node to whose destination the distance is to be measured.</param>
 public static double DistanceTo(this ISatellite sat, NetworkLink <ISatellite> link)
 {
     return(Vector3d.Distance(sat.Position, link.Target.Position));
 }
 private void Refresh(ISatellite sat)
 {
     if (sat == Satellite) Satellite = null;
 }
Example #59
0
 private void OnLinkRemove(ISatellite a, NetworkLink <ISatellite> link)
 {
     mEdges.Remove(new BidirectionalEdge <ISatellite>(a, link.Target, link.Port));
 }
 public SatelliteFragment(ISatellite sat)
 {
     Satellite = sat;
     RTCore.Instance.Satellites.OnUnregister += Refresh;
 }