public override bool FindHome(CommNode from, CommPath path = null)
        {
            bool value = true;

            for (int i = 0; i < Sequence_FindHome.Early.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindHome.Early[i].Invoke(from, path), Sequence_FindHome.MetaDict[Sequence_FindHome.Early[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            for (int i = 0; i < Sequence_FindHome.Late.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindHome.Late[i].Invoke(from, path), Sequence_FindHome.MetaDict[Sequence_FindHome.Late[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            //if (value == true)
            value &= base.FindHome(from, path);

            for (int i = 0; i < Sequence_FindHome.Post.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindHome.Post[i].Invoke(from, path), Sequence_FindHome.MetaDict[Sequence_FindHome.Post[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            return(value);
        }
Ejemplo n.º 2
0
        public bool HasConnectionToControl(Vessel vessel)
        {
            if (!IsEnabled)
            {
                return(true);
            }
            if (vessel == null) // null check to handle fringe instances where connection is checked after nullified
            {
                return(false);
            }

            // IsConnected is only set to true on the active vessel, so we have to manually
            // call the FindHome method to evaluate the home connection.

            // WARNING: In stock this will only work for vessels with a relay antenna installed.
            // This is a limitation put in place to improve performance in the stock game, and
            // there isn't a very good way around it.
            if (!vessel.isActiveVessel)
            {
                var net = CommNetNetwork.Instance.CommNet;
                tempPath = new CommPath();
                net.FindClosestControlSource(vessel.Connection.Comm, tempPath);
                return(tempPath.signalStrength > 0 || vessel.CurrentControlLevel >= Vessel.ControlLevel.PARTIAL_MANNED);
            }
            return(vessel.Connection.IsConnected || vessel.CurrentControlLevel >= Vessel.ControlLevel.PARTIAL_MANNED);
        }
Ejemplo n.º 3
0
        public bool HasConnectionToHome(Vessel vessel)
        {
            if (!IsEnabled)
            {
                return(true);
            }
            if (!IsCommnetParticipant(vessel))
            {
                return(false);
            }

            // IsConnectedHome is only set to true on the active vessel, so we have to manually
            // call the FindHome method to evaluate the home connection.

            // WARNING: In stock this will only work for vessels with a relay antenna installed.
            // This is a limitation put in place to improve performance in the stock game, and
            // there isn't a very good way around it.
            if (!vessel.isActiveVessel)
            {
                var net = CommNetNetwork.Instance.CommNet;
                tempPath = new CommPath();
                net.FindHome(vessel.Connection.Comm, tempPath);
                return(tempPath.signalStrength > 0);
            }
            return(vessel.Connection.IsConnectedHome);
        }
        public override CommNode FindClosestWhere(CommNode start, CommPath path, Func <CommNode, CommNode, bool> where)
        {
            CommNode value;

            for (int i = 0; i < Sequence_FindClosestWhere.Early.Count; i++)
            {
                try { Sequence_FindClosestWhere.Early[i].Invoke(start, path, where); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            for (int i = 0; i < Sequence_FindClosestWhere.Late.Count; i++)
            {
                try { Sequence_FindClosestWhere.Late[i].Invoke(start, path, where); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            value = base.FindClosestWhere(start, path, where);

            for (int i = 0; i < Sequence_FindClosestWhere.Post.Count; i++)
            {
                try { Sequence_FindClosestWhere.Post[i].Invoke(start, path, where); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            return(value);
        }
        public override bool FindPath(CommNode start, CommPath path, CommNode end)
        {
            bool value = true;

            for (int i = 0; i < Sequence_FindPath.Early.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindPath.Early[i].Invoke(start, path, end), Sequence_FindPath.MetaDict[Sequence_FindPath.Early[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            for (int i = 0; i < Sequence_FindPath.Late.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindPath.Late[i].Invoke(start, path, end), Sequence_FindPath.MetaDict[Sequence_FindPath.Late[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            //if (value == true)
            value &= base.FindPath(start, path, end);

            for (int i = 0; i < Sequence_FindPath.Post.Count; i++)
            {
                try { value = AndOr(value, Sequence_FindPath.Post[i].Invoke(start, path, end), Sequence_FindPath.MetaDict[Sequence_FindPath.Post[i]]); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            return(value);
        }
Ejemplo n.º 6
0
        public static bool IsCommReachable(ModuleTCA A, ModuleTCA B)
        {
            if (A == B)
            {
                return(true);
            }
            //if KerbNet is not enabled, always reachable
            if (!CommNetScenario.CommNetEnabled)
            {
                return(true);
            }
            //null checks
            if (A.vessel.Connection == null)
            {
                return(false);
            }
            if (B == null || B.vessel == null || B.vessel.Connection == null)
            {
                return(false);
            }
            //if it is locally controllable, it is also remotely controllable
            if (A.IsControllable)
            {
                return(true);
            }
            //check KerbNet path
            var start = A.vessel.Connection.Comm;
            var end   = B.vessel.Connection.Comm;
            var path  = new CommPath();

            if (A.vessel.Connection.Comm.Net.FindPath(start, path, end))
            {
                return(true);
            }
            //check direct ship2ship connection
            var sqrDist = (start.precisePosition - end.precisePosition).sqrMagnitude;
            var offset  = start.distanceOffset + end.distanceOffset;

            if (!offset.Equals(0))
            {
                offset  = Math.Sqrt(sqrDist) + offset;
                sqrDist = offset > 0 ? offset * offset : 0;
            }
            return(CommNetScenario.RangeModel
                   .InRange(Math.Max(start.antennaTransmit.power, start.antennaRelay.power),
                            Math.Max(end.antennaTransmit.power, end.antennaRelay.power),
                            sqrDist));
        }
Ejemplo n.º 7
0
        public bool HasConnection(Vessel vessel1, Vessel vessel2)
        {
            if (!IsEnabled)
            {
                return(true);
            }

            // We next need to query the network to find a connection between the two vessels.
            // I found no exposed method for accessing cached paths directly, other than the
            // control path.

            // WARNING: In stock this will only work for vessels with a relay antenna installed.
            // This is a limitation put in place to improve performance in the stock game, and
            // there isn't a very good way around it.
            var net = CommNetNetwork.Instance.CommNet;

            tempPath = new CommPath();
            return(vessel1.id == vessel2.id || net.FindPath(vessel1.Connection.Comm, tempPath, vessel2.Connection.Comm) || net.FindPath(vessel2.Connection.Comm, tempPath, vessel1.Connection.Comm));
        }
Ejemplo n.º 8
0
        protected override void UpdateDisplay()
        {
            base.UpdateDisplay();
            if (CommNetNetwork.Instance == null)
            {
                return;
            }
            if (CommNetUI.Mode == CommNetUI.DisplayMode.None)
            {
                return;
            }
            List <Vector3> targetPoints = new List <Vector3>();
            List <Vector3> cone3Points  = new List <Vector3>();
            List <Vector3> cone10Points = new List <Vector3>();

            // We COULD but do not need to rewrite how CommNetUI displays its normal link stuff.
            // Let's just get started by displaying antenna cones for now, for nodes the UI asks about.

            CommNetwork   commNet       = CommNetNetwork.Instance.CommNet;
            CommNetVessel commNetVessel = null;
            CommNode      commNode      = null;
            CommPath      commPath      = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                commNetVessel = this.vessel.connection;
                commNode      = commNetVessel.Comm;
                commPath      = commNetVessel.ControlPath;
            }
            // Big switch statement seeking cases of nothing to do.
            switch (CommNetUI.Mode)
            {
            case DisplayMode.FirstHop:
                GatherAntennaCones(commNode as RACommNode, ref targetPoints, ref cone3Points, ref cone10Points);
                break;

            case CommNetUI.DisplayMode.VesselLinks:
                GatherAntennaCones(commNode as RACommNode, ref targetPoints, ref cone3Points, ref cone10Points);
                break;

            case CommNetUI.DisplayMode.Path:
                foreach (CommLink link in commPath)
                {
                    GatherAntennaCones(link.start as RACommNode, ref targetPoints, ref cone3Points, ref cone10Points);
                }
                break;

            case CommNetUI.DisplayMode.Network:
                for (int i = 0; i < commNet.Count; i++)
                {
                    CommNode node = commNet[i];
                    GatherAntennaCones(node as RACommNode, ref targetPoints, ref cone3Points, ref cone10Points);
                }
                break;
            }
            ScaledSpace.LocalToScaledSpace(targetPoints);
            CreateLine(ref targetLine, targetPoints);
            targetLine.name = "RACommNetUIVectorToTarget";
            targetLine.SetColor(colorToTarget);
            targetLine.active = drawTarget;

            ScaledSpace.LocalToScaledSpace(cone3Points);
            CreateLine(ref cone3Line, cone3Points);
            cone3Line.name = "RACommNetUIVectorCone3dB";
//            cone3Line.material = MapView.DottedLinesMaterial;
            cone3Line.SetColor(color3dB);
            cone3Line.active = drawCone3;

            ScaledSpace.LocalToScaledSpace(cone10Points);
            CreateLine(ref cone10Line, cone10Points);
            cone10Line.name = "RACommNetUIVectorCone10dB";
            cone10Line.SetColor(color10dB);
            cone10Line.active = drawCone10;
            float width = draw3dLines ? lineWidth3D : lineWidth2D;

            targetLine.SetWidth(width);
            cone3Line.SetWidth(width);
            cone10Line.SetWidth(width);
            //Debug.LogFormat("Drawing lines in {0} with width {1} cone3Color {2}", draw3dLines ? "3D" : "2D", width, cone3Line.GetColor(0));
            if (this.draw3dLines)
            {
                // Why do these calls NOT work?  Nothing renders.
                targetLine.Draw3D();
                cone3Line.Draw3D();
                cone10Line.Draw3D();
            }
            else
            {
                targetLine.Draw();
                cone3Line.Draw();
                cone10Line.Draw();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), 5f);
                    }
                }
            }

            if (this.useTSBehavior)
            {
                CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int count    = this.points.Count;//save previous value
            int numLinks = 0;

            switch (CNVCommNetUI.CustomMode)
            {
            case CNVCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNVCommNetUI.CustomDisplayMode.FirstHop:
            case CNVCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal ||
                    path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    if (CNVCommNetUI.CustomMode == CNVCommNetUI.CustomDisplayMode.FirstHop)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                    }
                    else
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                    }
                }
                break;

            case CNVCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNVCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(this.points);
                }
                break;

            case CNVCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    CommPath newPath = new CommPath();

                    var nodes   = net;
                    var vessels = FlightGlobals.fetch.vessels;
                    for (int i = 0; i < vessels.Count; i++)
                    {
                        var commnetvessel = vessels[i].connection;
                        if (commnetvessel == null)    // like flag
                        {
                            continue;
                        }

                        SetPrivatePropertyValue <CommNetVessel>(commnetvessel, "unloadedDoOnce", true);   //network update is done only once for unloaded vessels so need to manually re-trigger every time
                        //don't want to override CommNetVessel to just set the boolean flag

                        if (!(commnetvessel.ControlState == VesselControlState.Probe || commnetvessel.ControlState == VesselControlState.Kerbal ||
                              commnetvessel.ControlPath == null || commnetvessel.ControlPath.Count == 0))
                        {
                            for (int pathIndex = 0; pathIndex < commnetvessel.ControlPath.Count; pathIndex++)
                            {
                                var link = commnetvessel.ControlPath[pathIndex];
                                if (newPath.Find(x => x.a.precisePosition == link.a.precisePosition && x.b.precisePosition == link.b.precisePosition) == null) //not found in list of links to be displayed
                                {
                                    newPath.Add(link);                                                                                                         //laziness wins
                                    //KSP techincally does not care if path is consisted of non-continuous links or not
                                }
                            }
                        }
                    }

                    path = newPath;
                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important

            if (this.refreshLines || MapView.Draw3DLines != this.draw3dLines || count != this.points.Count || this.line == null)
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNVCommNetUI.CustomMode)
            {
            case CNVCommNetUI.CustomDisplayMode.FirstHop:
            {
                float lvl = Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower);
                if (this.swapHighLow)
                {
                    this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), 0);
                }
                else
                {
                    this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), 0);
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.Path:
            case CNVCommNetUI.CustomDisplayMode.MultiPaths:
            {
                int linkIndex = numLinks;
                for (int i = linkIndex - 1; i >= 0; i--)
                {
                    float lvl = Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i);
                    }
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.VesselLinks:
            {
                var itr       = node.Values.GetEnumerator();
                int linkIndex = 0;
                while (itr.MoveNext())
                {
                    CommLink link = itr.Current;
                    float    lvl  = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), linkIndex++);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), linkIndex++);
                    }
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.Network:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    CommLink commLink = net.Links[i];
                    float    lvl      = Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i);
                    }
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), CNCSettings.ScreenMessageDuration);
                    }
                }
            }

            if (CommNetNetwork.Instance == null)
            {
                return;
            }
            if (this.useTSBehavior)
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int  count    = this.points.Count;//save previous value
            int  numLinks = 0;
            bool pathLinkExist;

            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.FirstHop:
                if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null)
                {
                    if (path.Count != 0)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                        break;
                    }
                }
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null)
                {
                    if (path.Count != 0)
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                        break;
                    }
                }
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNCCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    //net.GetLinkPoints(this.points);
                    //numLinks = net.Links.Count;
                    //KSP 1.8: Likely shader changes led to stackup of 2 or more lines illustrating overall brighter line
                    //Workaround: collect unqiue lines as path
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    for (int i = 0; i < net.Links.Count; i++)
                    {
                        pathLinkExist = false;
                        for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if path has this link already
                        {
                            if (CNCCommNetwork.AreSame(path[overallpathIndex].a, net.Links[i].a) &&
                                CNCCommNetwork.AreSame(path[overallpathIndex].b, net.Links[i].b))
                            {
                                pathLinkExist = true;
                                break;
                            }
                        }
                        if (!pathLinkExist)
                        {
                            path.Add(net.Links[i]);
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    for (int i = 0; i < net.Count; i++)
                    {
                        if (net[i].isControlSource)     //is it ground station/remote-control pilot?
                        {
                            continue;
                        }

                        var thisPath = new CommPath();
                        net.FindHome(net[i], thisPath);
                        for (int controlpathIndex = 0; controlpathIndex < thisPath.Count; controlpathIndex++)
                        {
                            pathLinkExist = false;
                            for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if overall path has this link already
                            {
                                if (CNCCommNetwork.AreSame(path[overallpathIndex].a, thisPath[controlpathIndex].a) &&
                                    CNCCommNetwork.AreSame(path[overallpathIndex].b, thisPath[controlpathIndex].b))
                                {
                                    pathLinkExist = true;
                                    break;
                                }
                            }
                            if (!pathLinkExist)
                            {
                                path.Add(thisPath[controlpathIndex]);
                            }
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important
            if (!(!this.refreshLines && MapView.Draw3DLines == this.draw3dLines && count == this.points.Count && this.line != null))
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            {
                this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b),
                                                 this.colorLow,
                                                 Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)),
                                   0);
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Path:
            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
            {
                CommLink[] links = new CommLink[node.Count];
                node.Values.CopyTo(links, 0);
                for (int i = 0; i < links.Length; i++)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Network:
            {
                //for (int i = numLinks - 1; i >= 0; i--)
                //{
                //    this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b),
                //                                     this.colorLow,
                //                                     Mathf.Pow((float) net.Links[i].GetBestSignal(), this.colorLerpPower)),
                //                                     i);
                //}
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].GetBestSignal(), this.colorLerpPower)),
                                       i);
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
 bool IPublicCommNet.FindClosestControlSource(CommNode from, CommPath path)
 {
     return(this.FindClosestControlSource(from, path));
 }
Ejemplo n.º 12
0
        public bool HasConnection(Vessel vessel1, Vessel vessel2)
        {
            if (!IsEnabled)
                return true;

            // We next need to query the network to find a connection between the two vessels.
            // I found no exposed method for accessing chached paths directly, other than the
            // control path.

            // WARNING: In stock this will only work for vessels with a relay antenna installed.
            // This is a limitation put in place to improve performance in the stock game, and
            // there isn't a very good way around it.
            var net = CommNetNetwork.Instance.CommNet;
            tempPath = new CommPath();
            return net.FindPath(vessel1.Connection.Comm, tempPath, vessel2.Connection.Comm) || net.FindPath(vessel2.Connection.Comm, tempPath, vessel1.Connection.Comm);
        }
Ejemplo n.º 13
0
        public bool HasConnectionToControl(Vessel vessel)
        {
            if (!IsEnabled)
                return true;

            // IsConnected is only set to true on the active vessel, so we have to manually
            // call the FindHome method to evaluate the home connection.

            // WARNING: In stock this will only work for vessels with a relay antenna installed.
            // This is a limitation put in place to improve performance in the stock game, and
            // there isn't a very good way around it.
            if (!vessel.isActiveVessel)
            {
                var net = CommNetNetwork.Instance.CommNet;
                tempPath = new CommPath();
                net.FindClosestControlSource(vessel.Connection.Comm, tempPath);
                return tempPath.signalStrength > 0 || vessel.CurrentControlLevel >= Vessel.ControlLevel.PARTIAL_MANNED;
            }
            return vessel.Connection.IsConnected || vessel.CurrentControlLevel >= Vessel.ControlLevel.PARTIAL_MANNED;
        }
Ejemplo n.º 14
0
        // Render the CommNet presentation
        // This method has been created to modify line color
        private void UpdateView()
        {
            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (vessel != null && vessel.connection != null && vessel.connection.Comm.Net != null)
            {
                cnvessel = vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            // Work out how many connections to paint
            int numLinks = 0;
            int count    = points.Count;

            switch (Mode)
            {
            case DisplayMode.None:
            {
                numLinks = 0;
                break;
            }

            case DisplayMode.FirstHop:
            {
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path.First.GetPoints(points);
                    numLinks = 1;
                }
                break;
            }

            case DisplayMode.Path:
            {
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path.GetPoints(points, true);
                    numLinks = path.Count;
                }
                break;
            }

            case DisplayMode.VesselLinks:
            {
                numLinks = node.Count;
                node.GetLinkPoints(points);
                break;
            }

            case DisplayMode.Network:
            {
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(points);
                }
                break;
            }
            }

            // Check if nothing to draw
            if (numLinks == 0)
            {
                if (line != null)
                {
                    line.active = false;
                }
                points.Clear();
                return;
            }
            else
            {
                // TODO: I'm not sure if I need the commented part below.
                //if (line != null) line.active = true;
                //else refreshLines = true;
                //ScaledSpace.LocalToScaledSpace(points);
                //if (refreshLines || MapView.Draw3DLines != draw3dLines || (count != points.Count || line == null))
                //{
                //  CreateLine(ref line, points);
                //  draw3dLines = MapView.Draw3DLines;
                //  refreshLines = false;
                //}

                //paint eligible connections

                // Sample to create a customHighColor :
                //    Color customHighColor = getConstellationColor(path.First.a, path.First.b);
                //      If want custom color, alter colorHigh for customHighColor
                switch (Mode)
                {
                case DisplayMode.FirstHop:
                {
                    float lvl = Mathf.Pow((float)path.First.signalStrength, colorLerpPower);
                    if (swapHighLow)
                    {
                        line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), 0);
                    }
                    else
                    {
                        line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), 0);
                    }
                    break;
                }

                case DisplayMode.Path:
                {
                    int linkIndex = numLinks;
                    for (int i = linkIndex - 1; i >= 0; i--)
                    {
                        float lvl = Mathf.Pow((float)path[i].signalStrength, colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), i);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), i);
                        }
                    }
                    break;
                }

                case DisplayMode.VesselLinks:
                {
                    var itr       = node.Values.GetEnumerator();
                    int linkIndex = 0;
                    while (itr.MoveNext())
                    {
                        CommLink link = itr.Current;
                        float    lvl  = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), linkIndex++);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), linkIndex++);
                        }
                    }
                    break;
                }

                case DisplayMode.Network:
                {
                    int linkIndex = numLinks;
                    while (linkIndex-- > 0)
                    {
                        CommLink commLink = net.Links[linkIndex];
                        float    t2       = Mathf.Pow((float)net.Links[linkIndex].GetBestSignal(), colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, t2), linkIndex);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, t2), linkIndex);
                        }
                    }
                    break;
                }
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), CNCSettings.ScreenMessageDuration);
                    }
                }
            }

            if (this.useTSBehavior)
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int  count    = this.points.Count;//save previous value
            int  numLinks = 0;
            bool pathLinkExist;

            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            case CNCCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal ||
                    path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    if (CNCCommNetUI.CustomMode == CNCCommNetUI.CustomDisplayMode.FirstHop)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                    }
                    else
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                    }
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNCCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(this.points);
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    var vessels = CNCCommNetScenario.Instance.getCommNetVessels();    //TODO: replace it with CNM
                    for (int i = 0; i < vessels.Count; i++)
                    {
                        vessels[i].computeUnloadedUpdate();    //network update is done only once for unloaded vessels so need to manually re-trigger every time

                        //is vessel real/alive?
                        if (!(vessels[i].ControlState == VesselControlState.Probe || vessels[i].ControlState == VesselControlState.Kerbal ||
                              vessels[i].ControlPath == null || vessels[i].ControlPath.Count == 0))
                        {
                            //add each link in control path to overall path
                            for (int controlpathIndex = 0; controlpathIndex < vessels[i].ControlPath.Count; controlpathIndex++)
                            {
                                pathLinkExist = false;
                                for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if overall path has this link already
                                {
                                    if (CNCCommNetwork.AreSame(path[overallpathIndex].a, vessels[i].ControlPath[controlpathIndex].a) &&
                                        CNCCommNetwork.AreSame(path[overallpathIndex].b, vessels[i].ControlPath[controlpathIndex].b))
                                    {
                                        pathLinkExist = true;
                                        break;
                                    }
                                }
                                if (!pathLinkExist)
                                {
                                    path.Add(vessels[i].ControlPath[controlpathIndex]);     //laziness wins
                                    //KSP techincally does not care if path is consisted of non-continuous links or not
                                }
                            }
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important

            if (this.refreshLines || MapView.Draw3DLines != this.draw3dLines || count != this.points.Count || this.line == null)
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            {
                this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b),
                                                 this.colorLow,
                                                 Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)),
                                   0);
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Path:
            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
            {
                CommLink[] links = new CommLink[node.Count];
                node.Values.CopyTo(links, 0);
                for (int i = 0; i < links.Length; i++)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Network:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower)),
                                       i);
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
 CommNode IPublicCommNet.FindClosestWhere(CommNode start, CommPath path, Func <CommNode, CommNode, bool> where)
 {
     return(this.FindClosestWhere(start, path, where));
 }
 bool IPublicCommNet.FindHome(CommNode from, CommPath path)
 {
     return(this.FindHome(from, path));
 }
 bool IPublicCommNet.FindPath(CommNode start, CommPath path, CommNode end)
 {
     return(this.FindPath(start, path, end));
 }