Exemple #1
0
        public static ConnectionInfo connection(Vessel v)
        {
            // hard-coded transmission rate and cost
            const double ext_rate = 0.064;
            const double ext_cost = 0.1;

            // if RemoteTech is present and enabled
            if (RemoteTech.Enabled())
            {
                if (RemoteTech.Connected(v.id) && !RemoteTech.ConnectedToKSC(v.id))
                {
                    return(new ConnectionInfo(LinkStatus.indirect_link, ext_rate, ext_cost));
                }
                else if (RemoteTech.ConnectedToKSC(v.id))
                {
                    return(new ConnectionInfo(LinkStatus.direct_link, ext_rate, ext_cost));
                }
                else
                {
                    return(new ConnectionInfo(LinkStatus.no_link));
                }
            }
            // if CommNet is enabled
            else if (HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet)
            {
                return(v.connection != null && v.connection.IsConnected
                                  ? new ConnectionInfo(LinkStatus.direct_link, ext_rate * v.connection.SignalStrength, ext_cost)
                                  : new ConnectionInfo(LinkStatus.no_link));
            }
            // the simple stupid signal system
            else
            {
                return(new ConnectionInfo(LinkStatus.direct_link, ext_rate, ext_cost));
            }
        }
        static ConnectionInfo OtherComms(Vessel v, KAntennaInfo antenna, HashSet <Guid> avoid_inf_recursion)
        {
            // hard-coded transmission rate and cost
            const double ext_rate = 0.064;
            const double ext_cost = 0.1;

            // if RemoteTech is present and enabled
            if (RemoteTech.Enabled())
            {
                return(RemoteTech.Connected(v.id)
        ? new ConnectionInfo(LinkStatus.direct_link, ext_rate, ext_cost)
        : new ConnectionInfo(LinkStatus.no_link));
            }
            // if CommNet is enabled
            else if (Features.KCommNet)
            {
                return(v.connection != null && v.connection.IsConnected
        ? new ConnectionInfo(LinkStatus.direct_link, ext_rate * v.connection.SignalStrength, ext_cost)
        : new ConnectionInfo(LinkStatus.no_link));
            }
            // the simple stupid signal system
            else
            {
                return(new ConnectionInfo(LinkStatus.direct_link, ext_rate, ext_cost));
            }
        }
Exemple #3
0
 // return true if the vessel is subject to a signal blackout
 public static bool Blackout(Vessel v)
 {
     if (!RemoteTech.Enabled())
     {
         return(false);
     }
     return(Cache.VesselInfo(v).blackout);
 }
Exemple #4
0
		bool render_vessel(Panel p, Vessel v)
		{
			// get vessel info
			vessel_info vi = Cache.VesselInfo(v);

			// skip invalid vessels
			if (!vi.is_valid) return false;

			// get data from db
			VesselData vd = DB.Vessel(v);

			// determine if filter must be shown
			show_filter |= vd.group.Length > 0 && vd.group != "NONE";

			// skip filtered vessels
			if (filtered() && vd.group != filter) return false;

			// get resource handler
			vessel_resources resources = ResourceCache.Get(v);

			// get vessel crew
			List<ProtoCrewMember> crew = Lib.CrewList(v);

			// get vessel name
			string vessel_name = v.isEVA ? crew[0].name : v.vesselName;

			// get body name
			string body_name = v.mainBody.name.ToUpper();

			// render entry
			p.header
			(
			  Lib.BuildString("<b>",
			  Lib.Ellipsis(vessel_name, Styles.ScaleStringLength(((page == MonitorPage.data || page == MonitorPage.log || selected_id == Guid.Empty) && !Lib.IsFlight()) ? 50 : 30)),
			  "</b> <size=", Styles.ScaleInteger(9).ToString(),
			  "><color=#cccccc>", Lib.Ellipsis(body_name, Styles.ScaleStringLength(8)), "</color></size>"),
			  string.Empty,
			  () => { selected_id = selected_id != v.id ? v.id : Guid.Empty; }
			);

			// problem indicator
			indicator_problems(p, v, vi, crew);

			// battery indicator
			indicator_ec(p, v, vi);

			// supply indicator
			if (Features.Supplies) indicator_supplies(p, v, vi);

			// reliability indicator
			if (Features.Reliability) indicator_reliability(p, v, vi);

			// signal indicator
			if (RemoteTech.Enabled() || HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet) indicator_signal(p, v, vi);

			// done
			return true;
		}
Exemple #5
0
        public static void update(Vessel v, vessel_info vi, VesselData vd, double elapsed_s)
        {
            // do nothing if signal mechanic is disabled
            if (!HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet && !RemoteTech.Enabled())
            {
                return;
            }

            // get connection info
            ConnectionInfo conn = vi.connection;

            // maintain and send messages
            // - do not send messages for vessels without an antenna
            // - do not send messages during/after solar storms
            // - do not send messages for EVA kerbals
            if (conn.status != LinkStatus.no_antenna && !v.isEVA && v.situation != Vessel.Situations.PRELAUNCH)
            {
                if (!vd.msg_signal && !conn.linked)
                {
                    vd.msg_signal = true;
                    if (vd.cfg_signal && conn.status != LinkStatus.blackout)
                    {
                        string subtext = "Data transmission disabled";
                        if (vi.crew_count == 0)
                        {
                            switch (Settings.UnlinkedControl)
                            {
                            case UnlinkedCtrl.none: subtext = Localizer.Format("#KERBALISM_UI_noctrl"); break;

                            case UnlinkedCtrl.limited: subtext = Localizer.Format("#KERBALISM_UI_limitedcontrol"); break;
                            }
                        }
                        Message.Post(Severity.warning, Lib.BuildString(Localizer.Format("#KERBALISM_UI_signallost"), " <b>", v.vesselName, "</b>"), subtext);
                    }
                }
                else if (vd.msg_signal && conn.linked)
                {
                    vd.msg_signal = false;
                    if (vd.cfg_signal && !Storm.JustEnded(v, elapsed_s))
                    {
                        var path = conn.path;
                        Message.Post(Severity.relax, Lib.BuildString("<b>", v.vesselName, "</b> ", Localizer.Format("#KERBALISM_UI_signalback")),
                                     path.Count == 0 ? Localizer.Format("#KERBALISM_UI_directlink") : Lib.BuildString(Localizer.Format("#KERBALISM_UI_relayby"), " <b>", path[path.Count - 1].vesselName, "</b>"));
                    }
                }
            }
        }
        public static void Update(Vessel v, Vessel_Info vi, VesselData vd, double elapsed_s)
        {
            // do nothing if signal mechanic is disabled
            if (!Features.Signal && !Features.KCommNet && !RemoteTech.Enabled())
            {
                return;
            }

            // get connection info
            ConnectionInfo conn = vi.connection;

            // maintain and send messages
            // - do not send messages for vessels without an antenna
            // - do not send messages during/after solar storms
            // - do not send messages for EVA kerbals
            if (conn.status != LinkStatus.no_antenna && !v.isEVA && v.situation != Vessel.Situations.PRELAUNCH)
            {
                if (!vd.msg_signal && !conn.linked)
                {
                    vd.msg_signal = true;
                    if (vd.cfg_signal && conn.status != LinkStatus.blackout)
                    {
                        string subtext = "Data transmission disabled";
                        if (vi.crew_count == 0)
                        {
                            switch (Settings.UnlinkedControl)
                            {
                            case UnlinkedCtrl.none: subtext = "Remote control disabled"; break;

                            case UnlinkedCtrl.limited: subtext = "Limited control available"; break;
                            }
                        }
                        Message.Post(Severity.warning, Lib.BuildString("Signal lost with <b>", v.vesselName, "</b>"), subtext);
                    }
                }
                else if (vd.msg_signal && conn.linked)
                {
                    vd.msg_signal = false;
                    if (vd.cfg_signal && !Storm.JustEnded(v, elapsed_s))
                    {
                        var path = conn.path;
                        Message.Post(Severity.relax, Lib.BuildString("<b>", v.vesselName, "</b> signal is back"),
                                     path.Count == 0 ? "We got a direct link with the space center" : Lib.BuildString("Relayed by <b>", path[path.Count - 1].vesselName, "</b>"));
                    }
                }
            }
        }
Exemple #7
0
        public static void config(this Panel p, Vessel v)
        {
            // avoid corner-case when this is called in a lambda after scene changes
            v = FlightGlobals.FindVessel(v.id);

            // if vessel doesn't exist anymore, leave the panel empty
            if (v == null)
            {
                return;
            }

            // get info from the cache
            vessel_info vi = Cache.VesselInfo(v);

            // if not a valid vessel, leave the panel empty
            if (!vi.is_valid)
            {
                return;
            }

            // set metadata
            p.title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), " <color=#cccccc>VESSEL CONFIG</color>"));
            p.width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.config;

            // time-out simulation
            if (p.timeout(vi))
            {
                return;
            }

            // get data from db
            VesselData vd = DB.Vessel(v);

            // toggle rendering
            string tooltip;

            if (Features.Reliability)
            {
                p.section("RENDERING");
            }
            if (Features.Reliability)
            {
                tooltip = "Highlight failed components";
                p.content("highlight malfunctions", string.Empty, tooltip);
                p.icon(vd.cfg_highlights ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_highlights));
            }

            // toggle messages
            p.section("MESSAGES");
            tooltip = "Receive a message when\nElectricCharge level is low";
            p.content("battery", string.Empty, tooltip);
            p.icon(vd.cfg_ec ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_ec));
            if (Features.Supplies)
            {
                tooltip = "Receive a message when\nsupply resources level is low";
                p.content("supply", string.Empty, tooltip);
                p.icon(vd.cfg_supply ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_supply));
            }
            if (RemoteTech.Enabled() || HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet)
            {
                tooltip = "Receive a message when signal is lost or obtained";
                p.content("signal", string.Empty, tooltip);
                p.icon(vd.cfg_signal ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_signal));
            }
            if (Features.Reliability)
            {
                tooltip = "Receive a message\nwhen a component fail";
                p.content("reliability", string.Empty, tooltip);
                p.icon(vd.cfg_malfunction ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_malfunction));
            }
            if (Features.SpaceWeather)
            {
                tooltip = "Receive a message\nduring CME events";
                p.content("storm", string.Empty, tooltip);
                p.icon(vd.cfg_storm ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_storm));
            }
            if (Features.Automation)
            {
                tooltip = "Receive a message when\nscripts are executed";
                p.content("script", string.Empty, tooltip);
                p.icon(vd.cfg_script ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_script));
            }
        }
Exemple #8
0
		void indicator_signal(Panel p, Vessel v, vessel_info vi)
		{
			ConnectionInfo conn = vi.connection;
			if (RemoteTech.Enabled())
			{
				double signal_delay = RemoteTech.GetShortestSignalDelay(v.id);
				string signal_str = "";
				if (signal_delay < Double.Epsilon)
				{
					signal_str = "none";
				}
				else
				{
					signal_str = KSPUtil.dateTimeFormatter.PrintTimeStampCompact(signal_delay, false, false);
				}
				string tooltip_rt = Lib.BuildString(
				  "<align=left />",
				  "connected\t<b>", conn.linked ? "yes" : "no", "</b>\n",
				  "delay\t\t<b>", conn.linked ? signal_str : "no connection", "</b>\n",
				  "rate\t\t<b>", Lib.HumanReadableDataRate(vi.connection.rate), "</b>"
				);
				Texture image_rt = Icons.signal_red;
				if (RemoteTech.Connected(v.id)) image_rt = Icons.signal_white;
				if (RemoteTech.Connected(v.id) && !RemoteTech.ConnectedToKSC(v.id)) image_rt = Icons.signal_yellow;
				if (vi.blackout || RemoteTech.GetCommsBlackout(v.id))
				{
					image_rt = Icons.signal_red;
					tooltip_rt += "\n\n<color=red><i>Blackout</i></color>";
				}
				p.icon(image_rt, tooltip_rt);
				return;
			}

			// target name
			string target_str = string.Empty;
			switch (vi.connection.status)
			{
				case LinkStatus.direct_link: target_str = ("DSN"); break;
				case LinkStatus.indirect_link: target_str = vi.connection.path[vi.connection.path.Count - 1].vesselName; break;
				default: target_str = "none"; break;
			}

			// transmitted label, content and tooltip
			string comms_label = vi.relaying.Length == 0 ? "transmitting" : "relaying";
			string comms_str = vi.connection.linked ? "telemetry" : "nothing";
			string comms_tooltip = string.Empty;
			if (vi.relaying.Length > 0)
			{
				ExperimentInfo exp = Science.experiment(vi.relaying);
				comms_str = exp.name;
				comms_tooltip = exp.fullname;
			}
			else if (vi.transmitting.Length > 0)
			{
				ExperimentInfo exp = Science.experiment(vi.transmitting);
				comms_str = exp.name;
				comms_tooltip = exp.fullname;
			}

			string tooltip = Lib.BuildString
			(
			  "<align=left />",
			  "connected\t<b>", vi.connection.linked ? "yes" : "no", "</b>\n",
			  "rate\t\t<b>", Lib.HumanReadableDataRate(vi.connection.rate), "</b>\n",
			  "target\t\t<b>", target_str, "</b>\n",
			  comms_label, "\t<b>", comms_str, "</b>"
			);

			Texture image = Icons.signal_red;
			switch (conn.status)
			{
				case LinkStatus.direct_link:
					image = vi.connection.rate > 0.005 ? Icons.signal_white : Icons.signal_yellow;
					break;

				case LinkStatus.indirect_link:
					image = vi.connection.rate > 0.005 ? Icons.signal_white : Icons.signal_yellow;
					tooltip += "\n\n<color=yellow>Signal relayed</color>";
					break;

				case LinkStatus.no_link:
					image = Icons.signal_red;
					break;

				case LinkStatus.no_antenna:
					image = Icons.signal_red;
					tooltip += "\n\n<color=red>No antenna</color>";
					break;

				case LinkStatus.blackout:
					image = Icons.signal_red;
					tooltip += "\n\n<color=red><i>Blackout</i></color>";
					break;
			}

			p.icon(image, tooltip);
		}
        bool Render_Vessel(Panel p, Vessel v)
        {
            // get vessel info
            Vessel_Info vi = Cache.VesselInfo(v);

            // skip invalid vessels
            if (!vi.is_valid)
            {
                return(false);
            }

            if (!Lib.IsVessel(v))
            {
                return(false);
            }

            // get data from db
            VesselData vd = DB.Vessel(v);

            // determine if filter must be shown
            show_filter |= vd.group.Length > 0 && vd.group != "NONE";

            // skip filtered vessels
            if (Filtered() && vd.group != filter)
            {
                return(false);
            }

            // get resource handler
            Vessel_Resources resources = ResourceCache.Get(v);

            // get vessel crew
            List <ProtoCrewMember> crew = Lib.CrewList(v);

            // get vessel name
            string vessel_name = v.isEVA ? crew[0].name : v.vesselName;

            // get body name
            string body_name = v.mainBody.name.ToUpper();

            // render entry
            p.SetHeader
            (
                Lib.BuildString("<b>", Lib.Ellipsis(vessel_name, 20), "</b> <size=9><color=#cccccc>", Lib.Ellipsis(body_name, 8), "</color></size>"),
                string.Empty,
                () => { selected_id = selected_id != v.id ? v.id : Guid.Empty; }
            );

            // problem indicator
            Indicator_Problems(p, v, vi, crew);

            // battery indicator
            Indicator_EC(p, v, vi);

            // supply indicator
            if (Features.Supplies)
            {
                Indicator_Supplies(p, v, vi);
            }

            // reliability indicator
            if (Features.Reliability)
            {
                Indicator_Reliability(p, v, vi);
            }

            // signal indicator
            if (Features.Signal || Features.KCommNet || RemoteTech.Enabled())
            {
                Indicator_Signal(p, v, vi);
            }

            // done
            return(true);
        }