Ejemplo n.º 1
0
        static NetworkRenderer()
        {
            RTUtil.LoadImage(out mTexMark, "mark");

            if (Versioning.version_major == 1)
            {
                switch (Versioning.version_minor)
                {
                case 4:
                    mLineWidth = 1f;     //1f is matching to CommNet's line width
                    break;

                default:
                    mLineWidth = 3f;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnStart(StartState state)
        {
            if (!String.IsNullOrEmpty(BreakTransformName))
            {
                BreakTransform = part.FindModelTransform(BreakTransformName);
            }
            if (!String.IsNullOrEmpty(ForceTransformName))
            {
                ForceTransform = part.FindModelTransform(ForceTransformName);
            }

            Animation = part.FindModelAnimators(AnimationName)[0];
            if (Animation == null || Animation[AnimationName] == null)
            {
                RTUtil.Log("ModuleRTAntennaAnimated: Animation error");
                enabled = false;
                return;
            }

            if (FixAnimLayers)
            {
                int i = 0;
                foreach (AnimationState s in Animation)
                {
                    s.layer = i++;
                }
            }

            base.OnStart(state);

            if (IsRTBroken && BreakTransform != null)
            {
                foreach (Transform t in RTUtil.FindTransformsWithCollider(BreakTransform))
                {
                    Destroy(t.gameObject);
                }
                enabled = false;
                return;
            }

            Animation[AnimationName].speed          = IsRTActive ? 1.0f : -1.0f;
            Animation[AnimationName].normalizedTime = IsRTActive ? 1.0f : 0.0f;
            Animation.Play(AnimationName);
        }
Ejemplo n.º 3
0
        public static DelayedCommand WithSurface(double pitch, double yaw, double roll)
        {
            Quaternion rotation = Quaternion.Euler(new Vector3d(Double.IsNaN(pitch) ? 0 : pitch,
                                                                Double.IsNaN(yaw) ? 0 : -yaw,
                                                                Double.IsNaN(roll) ? 0 : 180 - roll));

            return(new DelayedCommand()
            {
                AttitudeCommand = new AttitudeCommand()
                {
                    Mode = FlightMode.AttitudeHold,
                    Attitude = FlightAttitude.Surface,
                    Frame = ReferenceFrame.North,
                    Orientation = rotation,
                    Altitude = Single.NaN,
                },
                TimeStamp = RTUtil.GetGameTime()
            });
        }
Ejemplo n.º 4
0
        public void Load()
        {
            RTUtil.LoadImage(out IconCalc, "calc.png");

            ConfigNode root = ConfigNode.Load("RemoteTech.cfg");
            ConfigNode rt;

            if (root != null && root.HasNode("REMOTE_TECH"))
            {
                rt = root.GetNode("REMOTE_TECH");
            }
            else
            {
                rt = new ConfigNode();
            }
            mCore.Network.Load(rt);
            mCore.Gui.Load(rt);
            mCore.Renderer.Load(rt);
        }
        public override string GetInfo()
        {
            var info = new StringBuilder();

            if (ShowEditor_Class && Mode0OmniRange + Mode1OmniRange + Mode0DishRange + Mode1DishRange > 0)
            {
                info.AppendLine("Class: " + RTUtil.FormatClass(Math.Max(Math.Max(Mode0DishRange, Mode1DishRange), Math.Max(Mode0OmniRange, Mode1OmniRange))));
            }
            if (ShowEditor_OmniRange && Mode1OmniRange > 0)
            {
                info.Append("Omni range: ");
                info.Append(RTUtil.FormatSI(Mode0OmniRange, "m"));
                info.Append(" / ");
                info.AppendLine(RTUtil.FormatSI(Mode1OmniRange, "m"));
            }
            if (ShowEditor_DishRange && Mode1DishRange > 0)
            {
                info.Append("Dish range: ");
                info.Append(RTUtil.FormatSI(Mode0DishRange, "m"));
                info.Append(" / ");
                info.AppendLine(RTUtil.FormatSI(Mode1DishRange, "m"));
            }
            if (ShowEditor_EnergyReq && EnergyCost > 0)
            {
                info.Append("Energy req.: ");
                info.Append(RTUtil.FormatConsumption(EnergyCost));
            }
            if (ShowEditor_AllEnergyReq)
            {
                float AllEnergyReq = 0;
                foreach (ModuleRTAntenna m in part.Modules.OfType <ModuleRTAntenna>())
                {
                    AllEnergyReq += m.EnergyCost;
                }
                if (AllEnergyReq > 0)
                {
                    info.Append("Energy req.: ");
                    info.Append(RTUtil.FormatConsumption(AllEnergyReq));
                }
            }

            return(info.ToString().TrimEnd('\n'));
        }
Ejemplo n.º 6
0
        static MapViewConfigFragment()
        {
            mTextures = new Texture2D[7];
            RTUtil.LoadImage(out mTextures[0], "texBackground.png");
            RTUtil.LoadImage(out mTextures[1], "texPath.png");
            RTUtil.LoadImage(out mTextures[2], "texAll.png");
            RTUtil.LoadImage(out mTextures[3], "texDish.png");
            RTUtil.LoadImage(out mTextures[4], "texOmni.png");
            RTUtil.LoadImage(out mTextures[5], "texOmniDish.png");
            RTUtil.LoadImage(out mTextures[6], "texEmpty.png");

            mStyleButton       = GUITextureButtonFactory.CreateFromFilename("texButton.png");
            mStyleButtonGray   = GUITextureButtonFactory.CreateFromFilename("texButtonGray.png");
            mStyleButtonGreen  = GUITextureButtonFactory.CreateFromFilename("texButtonGreen.png");
            mStyleButtonRed    = GUITextureButtonFactory.CreateFromFilename("texButtonRed.png");
            mStyleButtonYellow = GUITextureButtonFactory.CreateFromFilename("texButtonYellow.png");

            RTUtil.Log("MapViewConfigFragment has loaded textures.");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Unregisters the specified signal processor.
        /// </summary>
        /// <param name="key">The key the signal processor was registered under.</param>
        /// <param name="spu">The signal processor.</param>
        public void Unregister(Guid key, ISignalProcessor spu)
        {
            RTLog.Notify("SatelliteManager: Unregister({0})", spu);
            // Return if nothing to unregister.
            if (!_loadedSpuCache.ContainsKey(key))
            {
                return;
            }
            // Find instance of the signal processor.
            var instanceId = _loadedSpuCache[key].FindIndex(x => x == spu);

            if (instanceId == -1)
            {
                return;
            }

            // Remove satellite if no signal processors remain.
            if (_loadedSpuCache[key].Count == 1)
            {
                if (_satelliteCache.ContainsKey(key))
                {
                    VesselSatellite sat = _satelliteCache[key];
                    OnUnregister(sat);
                    _satelliteCache.Remove(key);
                }
                _loadedSpuCache[key].RemoveAt(instanceId);
                _loadedSpuCache.Remove(key);

                // search vessel by id
                var vessel = RTUtil.GetVesselById(key);
                if (vessel != null)
                {
                    // trigger the onRails on more time
                    // to re-register the satellite as a protoSat
                    OnVesselOnRails(vessel);
                }
            }
            else
            {
                _loadedSpuCache[key].RemoveAt(instanceId);
            }
        }
Ejemplo n.º 8
0
        public void Unregister(Guid key, IAntenna antenna)
        {
            RTUtil.Log("AntennaManager: Unregister: " + key + ", " + antenna.Name);
            if (!mLoadedAntennaCache.ContainsKey(key))
            {
                return;
            }

            int instance_id = mLoadedAntennaCache[key].FindIndex(x => x == antenna);

            if (instance_id != -1)
            {
                mLoadedAntennaCache[key].RemoveAt(instance_id);
                if (mLoadedAntennaCache[key].Count == 0)
                {
                    mLoadedAntennaCache.Remove(key);
                }
                OnUnregister(antenna);
            }
        }
Ejemplo n.º 9
0
 private void HandleDynamicPressure()
 {
     if (vessel == null)
     {
         return;
     }
     if (!vessel.HoldPhysics && vessel.atmDensity > 0 && MaxQ > 0 && (!this.CanAnimate || this.AnimOpen))
     {
         if (GetDynamicPressure() > MaxQ && GetShieldedState() == false)
         {
             // Express flight clock in stockalike formatting
             string timestamp = RTUtil.FormatTimestamp(FlightLogger.met_years, FlightLogger.met_days,
                                                       FlightLogger.met_hours, FlightLogger.met_mins, FlightLogger.met_secs);
             FlightLogger.eventLog.Add(String.Format("[{0}]: {1} was ripped off by strong airflow.",
                                                     timestamp, part.partInfo.title));
             MaxQ = -1.0f;
             part.decouple(0.0f);
         }
     }
 }
Ejemplo n.º 10
0
        private void Coord(DriveCommand dc, FlightCtrlState fs)
        {
            float
                dist = Vector3.Distance(mVessel.CoM, TargetPos),
                deg  = RTUtil.ClampDegrees180(RoverHDG - TargetHDG);

            if (dist > Math.Abs(deg) / 36)
            {
                fs.wheelThrottle = mThrottlePID.Control(dc.speed - RoverSpeed);
                fs.wheelSteer    = mWheelPID.Control(deg);
            }
            else
            {
                fs.wheelThrottle = 0;
                fs.wheelSteer    = 0;
                mVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
                dc.mode = DriveCommand.DriveMode.Off;
                dc      = null;
            }
        }
Ejemplo n.º 11
0
 public void Draw()
 {
     mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, AbstractWindow.Frame);
     {
         Color      pushColor = GUI.contentColor;
         TextAnchor pushAlign = GUI.skin.button.alignment;
         GUI.skin.button.alignment = TextAnchor.MiddleLeft;
         foreach (var sat in RTCore.Instance.Satellites)
         {
             String text = sat.Name.Truncate(25);
             RTUtil.StateButton(text, mSelection == sat ? 1 : 0, 1, s =>
             {
                 mSelection = (s > 0) ? sat : null;
                 if (mSelection != null)
                 {
                     var newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t != null && t.gameObject.name == sat.Name);
                     if (newTarget == null)
                     {
                         var vessel                      = sat.SignalProcessor.Vessel;
                         var scaledMovement              = new GameObject().AddComponent <ScaledMovement>();
                         scaledMovement.tgtRef           = vessel.transform;
                         scaledMovement.name             = sat.Name;
                         scaledMovement.transform.parent = ScaledSpace.Instance.transform;
                         scaledMovement.vessel           = vessel;
                         scaledMovement.type             = MapObject.MapObjectType.VESSEL;
                         newTarget = scaledMovement;
                         PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
                         PlanetariumCamera.fetch.targets.Remove(newTarget);
                     }
                     else
                     {
                         PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
                     }
                 }
             });
         }
         GUI.skin.button.alignment = pushAlign;
         GUI.contentColor          = pushColor;
     }
     GUILayout.EndScrollView();
 }
Ejemplo n.º 12
0
        private void HoldAltitude(FlightCtrlState fs)
        {
            const double damping       = 1000.0f;
            Vessel       v             = mAttachedVessel;
            double       target_height = mCommand.AttitudeCommand.Altitude;
            float        target_pitch  = (float)(Math.Atan2(target_height - v.orbit.ApA, damping) / Math.PI * 180.0f);
            Vector3      up            = (v.mainBody.position - v.CoM);
            Vector3      forward       = Vector3.Exclude(up,
                                                         v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius - v.CoM
                                                         );

            Vector3.OrthoNormalize(ref forward, ref up);
            Vector3 direction      = Vector3.Exclude(up, v.obt_velocity).normalized;
            float   target_heading = Vector3.Angle(forward, direction);

            Quaternion rotationReference = Quaternion.LookRotation(forward, up);

            RTUtil.Log("Pitch: {0}, Heading: {1}", target_pitch, target_heading);
            HoldOrientation(fs, rotationReference *
                            Quaternion.Euler(new Vector3(target_pitch, target_heading, 0)));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Registers a protosatellite compiled from the unloaded vessel data.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        public void RegisterProto(Vessel vessel)
        {
            Guid key = vessel.protoVessel.vesselID;

            RTUtil.Log("SatelliteManager: RegisterProto {0} ", vessel.vesselName);
            // Return if there are still signal processors loaded.
            if (mLoadedSpuCache.ContainsKey(vessel.id))
            {
                return;
            }

            ISignalProcessor spu = vessel.GetSignalProcessor();

            if (spu != null)
            {
                List <ISignalProcessor> protos = new List <ISignalProcessor>();
                protos.Add(spu);
                mSatelliteCache[key] = new VesselSatellite(protos);
                OnRegister(mSatelliteCache[key]);
            }
        }
Ejemplo n.º 14
0
        public void Draw()
        {
            if (Satellite == null)
            {
                return;
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.TextField(Satellite.Name.Truncate(25), GUILayout.ExpandWidth(true));
                RTUtil.Button("Name", () =>
                {
                    var vessel = FlightGlobals.Vessels.First(v => v.id == Satellite.Guid);
                    if (vessel)
                    {
                        vessel.RenameVessel();
                    }
                }, GUILayout.ExpandWidth(false), GUILayout.Height(24));
            }
            GUILayout.EndHorizontal();

            mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, GUILayout.ExpandHeight(true));
            {
                Color      pushColor = GUI.contentColor;
                TextAnchor pushAlign = GUI.skin.button.alignment;
                GUI.skin.button.alignment = TextAnchor.MiddleLeft;
                foreach (var a in Satellite.Antennas.Where(a => a.CanTarget))
                {
                    GUI.contentColor = (a.Powered) ? XKCDColors.ElectricLime : XKCDColors.Scarlet;
                    String text = a.Name.Truncate(25) + Environment.NewLine + "Target: " + RTUtil.TargetName(a.Target).Truncate(18);
                    RTUtil.StateButton(text, Antenna, a, s =>
                    {
                        Antenna = (s > 0) ? a : null;
                    });
                }
                GUI.skin.button.alignment = pushAlign;
                GUI.contentColor          = pushColor;
            }
            GUILayout.EndScrollView();
        }
        public void Draw()
        {
            GUILayout.BeginVertical(GUILayout.Width(200), GUILayout.ExpandHeight(true));
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Box(mFocus.Name);
                    RTUtil.Button("Name", () => mFocus.Vessel.RenameVessel(),
                                  GUILayout.ExpandWidth(false));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginVertical(GUI.skin.box);
                {
                    mScrollPosition = GUILayout.BeginScrollView(mScrollPosition);
                    {
                        Color      pushColor = GUI.contentColor;
                        TextAnchor pushAlign = GUI.skin.button.alignment;
                        GUI.skin.button.alignment = TextAnchor.MiddleLeft;
                        for (int i = 0; i < mFocusAntennas.Count; i++)
                        {
                            GUI.contentColor =
                                (mFocusAntennas[i].DishRange > 0) ? Color.green : Color.red;
                            String text = mFocusAntennas[i].Name + '\n' +
                                          "Target: " + RTUtil.TargetName(mFocusAntennas[i].DishTarget);
                            RTUtil.StateButton(text, mSelection, i, s => {
                                mSelection = (s > 0) ? s : 0;
                                mOnClick.Invoke(mFocusAntennas[mSelection]);
                            });
                        }
                        GUI.skin.button.alignment = pushAlign;
                        GUI.contentColor          = pushColor;
                    }
                    GUILayout.EndScrollView();
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndVertical();
        }
Ejemplo n.º 16
0
        private void Break()
        {
            foreach (Transform t in RTUtil.FindTransformsWithCollider(BreakTransform))
            {
                Rigidbody rb = t.gameObject.AddComponent <Rigidbody>();

                rb.angularDrag     = 0;
                rb.angularVelocity = part.rigidbody.angularVelocity;
                rb.drag            = 0;
                rb.mass            = t.collider.bounds.size.x * t.collider.bounds.size.y * t.collider.bounds.size.z * ShrapnelDensity;
                rb.velocity        = part.rigidbody.velocity;
                rb.isKinematic     = false;
                t.parent           = null;
                rb.AddForce(UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5));
                rb.AddTorque(UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20));

                DragModel dm = t.gameObject.AddComponent <DragModel>();
                dm.enabled = true;
                dm.dc      = ShrapnelDragCoeff;
                dm.mb      = vessel.mainBody;
            }

            Events["EventOpen"].guiActive                            =
                Events["EventClose"].guiActive                       =
                    Events["EventToggle"].guiActive                  =
                        Events["EventTarget"].guiActive              =
                            Events["EventOpen"].active               =
                                Events["EventClose"].active          =
                                    Events["EventToggle"].active     =
                                        Events["EventTarget"].active = false;

            Fields["GUI_OmniRange"].guiActive         =
                Fields["GUI_DishRange"].guiActive     =
                    Fields["GUI_EnergyReq"].guiActive = false;

            IsRTBroken = true;
            base.SetState(false);
        }
Ejemplo n.º 17
0
        public void Unregister(Guid key, IAntenna antenna)
        {
            RTUtil.Log("AntennaManager: Unregister: {0}, {1}", key, antenna.Name);

            // Return if no antennas are loaded at all.
            if (!mLoadedAntennaCache.ContainsKey(key))
            {
                return;
            }

            // Find registered antenna and delete it; fire event; delete list if empty.
            int instance_id = mLoadedAntennaCache[key].FindIndex(x => x == antenna);

            if (instance_id != -1)
            {
                mLoadedAntennaCache[key].RemoveAt(instance_id);
                if (mLoadedAntennaCache[key].Count == 0)
                {
                    mLoadedAntennaCache.Remove(key);
                }
                OnUnregister(antenna);
            }
        }
        public void OnPhysicsUpdate()
        {
            int takeCount = (mCore.Satellites.Count / REFRESH_TICKS) +
                            (((mCore.Satellites.Count % REFRESH_TICKS) > mTick) ? 1 : 0);
            IEnumerable <ISatellite> commandStations = mCore.Satellites.FindCommandStations();

            foreach (VesselSatellite s in mCore.Satellites.Skip(mTickIndex).Take(takeCount))
            {
                UpdateGraph(s);
                RTUtil.Log("Status for {0}: CS?{1}, E?{2}",
                           s, commandStations.Contains(s), Graph[s.Guid].ToDebugString());
                if (s.Vessel.loaded || RTCore.Instance.IsTrackingStation)
                {
                    FindPath(s, commandStations);
                }
            }
            mTickIndex += takeCount;
            mTick       = (mTick + 1) % REFRESH_TICKS;
            if (mTick == 0)
            {
                mTickIndex = 0;
            }
        }
Ejemplo n.º 19
0
        public void Upload(String fileName)
        {
            Log("Loading program \"{0}\".", fileName);
            Int32[] newCode;
            try {
                newCode = mProgcom.Assemble(fileName);
            } catch (FormatException) {
                Log("ERROR: Compilation failed.");
                return;
            } catch (Exception) {
                Log("ERROR: Unknown error.");
                return;
            }
            Log("Successfully assembled.");
            Log("Transmitting program (ETA: {0})", RTUtil.FormatDuration(mProgcom.Delay));
            DelayedCommand dc = new DelayedCommand()
            {
                Program = newCode
            };

            dc.TimeStamp += mProgcom.Delay;
            mQueue.Enqueue(dc);
        }
Ejemplo n.º 20
0
        public void Register(Guid key, IAntenna antenna)
        {
            RTUtil.Log("AntennaManager: Register: {0}, {1}", key, antenna.Name);

            if (mProtoAntennaCache.ContainsKey(key))
            {
                // Unregister remaining proto-antennas.
                UnregisterProtos(key);
            }
            if (!mLoadedAntennaCache.ContainsKey(key))
            {
                mLoadedAntennaCache[key] = new List <IAntenna>();
            }

            // Add the antenna if no duplicate exists for that key; fire event.
            IAntenna instance = mLoadedAntennaCache[key].Find(x => x == antenna);

            if (instance == null)
            {
                mLoadedAntennaCache[key].Add(antenna);
                OnRegister(antenna);
            }
        }
        public override string GetInfo()
        {
            var info = new StringBuilder();

            if (ShowEditor_Class)
            {
                info.AppendFormat("Class: {0}", RTUtil.FormatClass(Math.Max(Math.Max(Mode0DishRange, Mode1DishRange), Math.Max(Mode0OmniRange, Mode1OmniRange)))).AppendLine();
            }
            if (ShowEditor_OmniRange && Mode1OmniRange > 0)
            {
                info.AppendFormat("Omni range: {0} / {1}", RTUtil.FormatSI(Mode0OmniRange, "m"), RTUtil.FormatSI(Mode1OmniRange, "m")).AppendLine();
            }
            if (ShowEditor_DishRange && Mode1DishRange > 0)
            {
                info.AppendFormat("Dish range: {0} / {1}", RTUtil.FormatSI(Mode0DishRange, "m"), RTUtil.FormatSI(Mode1DishRange, "m")).AppendLine();
            }
            if (ShowEditor_EnergyReq && EnergyCost > 0)
            {
                info.AppendFormat("Energy req.: {0}", RTUtil.FormatConsumption(EnergyCost)).AppendLine();
            }

            return(info.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
        }
Ejemplo n.º 22
0
        public void Draw()
        {
            if (Event.current.Equals(Event.KeyboardEvent("return")) &&
                GUI.GetNameOfFocusedControl() == "xd")
            {
                mExtraDelay = Delay.ToString();
                mFlightComputer.ExtraDelay = Delay;
            }
            GUILayout.BeginVertical(GUILayout.Width(250));
            {
                mScrollPosition = GUILayout.BeginScrollView(mScrollPosition,
                                                            GUILayout.ExpandHeight(true));
                {
                    foreach (DelayedCommand dc in mFlightComputer)
                    {
                        GUILayout.BeginHorizontal(GUI.skin.box);
                        {
                            GUILayout.Label(Format(dc));
                            RTUtil.Button("x", () => { mFlightComputer.Enqueue(DelayedCommand.Cancel(dc)); }, GUILayout.Width(21));
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndScrollView();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Artificial delay: ");
                    GUI.SetNextControlName("xd");
                    GUILayout.Label(mFlightComputer.ExtraDelay.ToString("F2"));
                    RTUtil.TextField(ref mExtraDelay, GUILayout.ExpandWidth(true));
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }
Ejemplo n.º 23
0
        private void Fine()
        {
            if (Event.current.Equals(Event.KeyboardEvent("return")) && Speed != 0)
            {
                if (GUI.GetNameOfFocusedControl() == "RC1" && mSteering != 0 && Turn != 0)
                {
                    EnqueueTurn();
                }
                else if (GUI.GetNameOfFocusedControl() == "RC2" && Dist != 0)
                {
                    EnqueueDist();
                }
                else if (GUI.GetNameOfFocusedControl() == "RC3")
                {
                    if (!distDefault && mSteering != 0 && Turn != 0)
                    {
                        EnqueueTurn();
                    }
                    else if (distDefault && Dist != 0)
                    {
                        EnqueueDist();
                    }
                }
            }


            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Wheel: ");
                GUILayout.FlexibleSpace();
                GUILayout.Label(Math.Abs(mSteering).ToString("P"));
                if (mSteering != 0)
                {
                    if (mSteering < 0)
                    {
                        GUILayout.Label("right", GUILayout.Width(40));
                    }
                    else
                    {
                        GUILayout.Label("left", GUILayout.Width(40));
                    }
                }
                else
                {
                    GUILayout.Label("", GUILayout.Width(40));
                }
            }
            GUILayout.EndHorizontal();

            RTUtil.HorizontalSlider(ref mSteering, 1, -1);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Turn", GUILayout.Width(50));
                GUI.SetNextControlName("RC1");
                RTUtil.TextField(ref mTurn, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(°)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Dist.", GUILayout.Width(50));
                GUI.SetNextControlName("RC2");
                RTUtil.TextField(ref mDist, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(m)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Speed", GUILayout.Width(50));
                GUI.SetNextControlName("RC3");
                RTUtil.TextField(ref mSpeed, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(m/s)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            mTurn  = RTUtil.ConstrictNum(mTurn, 90);
            mDist  = RTUtil.ConstrictNum(mDist, false);
            mSpeed = RTUtil.ConstrictNum(mSpeed);


            if (prevTurn != Turn)
            {
                distDefault = false;
            }
            else if (prevDist != Dist)
            {
                distDefault = true;
            }

            prevTurn = Turn;
            prevDist = Dist;
        }
Ejemplo n.º 24
0
        public void Draw()
        {
            float width3 = 156 / 3 - GUI.skin.button.margin.right * 2.0f / 3.0f;

            if (Event.current.Equals(Event.KeyboardEvent("return")))
            {
                if (GUI.GetNameOfFocusedControl().StartsWith("phr"))
                {
                    mPitch   = Pitch.ToString();
                    mHeading = Heading.ToString();
                    mRoll    = Roll.ToString();
                    if (mFlightComputer.InputAllowed)
                    {
                        mMode = 7;
                        Confirm();
                    }
                }
                else if (GUI.GetNameOfFocusedControl() == "burn")
                {
                    OnBurnClick();
                }
            }
            GUILayout.BeginVertical();
            {
                GUILayout.BeginHorizontal();
                {
                    RTUtil.StateButton(new GUIContent("KILL", "Kill rotation."),
                                       mMode, 1, OnModeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("NODE", "Prograde points in the direction of the first maneuver node."),
                                       mMode, 2, OnModeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("RVEL", "Prograde relative to target velocity."),
                                       mMode, 6, OnModeClick, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    RTUtil.StateButton(new GUIContent("ORB", "Prograde relative to orbital velocity."),
                                       mMode, 4, OnModeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("SRF", "Prograde relative to surface velocity."),
                                       mMode, 5, OnModeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("TGT", "Prograde points directly at target."),
                                       mMode, 3, OnModeClick, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();

                RTUtil.StateButton(new GUIContent("CUSTOM", "Prograde fixed as pitch, heading, roll relative to north pole."),
                                   mMode, 7, OnModeClick, GUILayout.ExpandWidth(true));
                GUILayout.Space(5);

                GUILayout.BeginHorizontal();
                {
                    RTUtil.StateButton(new GUIContent("GRD\n+", "Orient to Prograde."),
                                       mAttitude, 1, OnAttitudeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("RAD\n+", "Orient to Radial."),
                                       mAttitude, 2, OnAttitudeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("NRM\n+", "Orient to Normal."),
                                       mAttitude, 3, OnAttitudeClick, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    RTUtil.StateButton(new GUIContent("GRD\n-", "Orient to Retrograde."),
                                       mAttitude, 4, OnAttitudeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("RAD\n-", "Orient to Anti-radial."),
                                       mAttitude, 5, OnAttitudeClick, GUILayout.Width(width3));
                    RTUtil.StateButton(new GUIContent("NRM\n-", "Orient to Anti-normal."),
                                       mAttitude, 6, OnAttitudeClick, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(new GUIContent("PIT:", "Sets pitch."), GUILayout.Width(width3));
                    RTUtil.Button("+", () => Pitch++);
                    RTUtil.Button("-", () => Pitch--);
                    GUI.SetNextControlName("phr1");
                    RTUtil.TextField(ref mPitch, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(new GUIContent("HDG:", "Sets heading."), GUILayout.Width(width3));
                    RTUtil.Button("+", () => Heading++);
                    RTUtil.Button("-", () => Heading--);
                    GUI.SetNextControlName("phr2");
                    RTUtil.TextField(ref mHeading, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(new GUIContent("RLL:", "Sets roll."), GUILayout.Width(width3));
                    RTUtil.Button("+", () => Roll++);
                    RTUtil.Button("-", () => Roll--);
                    GUI.SetNextControlName("phr3");
                    RTUtil.TextField(ref mRoll, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Throttle: ");
                    GUILayout.FlexibleSpace();
                    GUILayout.Label(mThrottle.ToString("P"));
                }
                GUILayout.EndHorizontal();

                RTUtil.HorizontalSlider(ref mThrottle, 0, 1);
                GUI.SetNextControlName("burn");
                RTUtil.TextField(ref mDuration);

                GUILayout.BeginHorizontal();
                {
                    RTUtil.Button(new GUIContent("BURN", "Example: 125, 125s, 5m20s, 1d6h20m10s, 123m/s."),
                                  OnBurnClick, GUILayout.Width(width3));
                    RTUtil.Button(new GUIContent("EXEC", "Executes next maneuver node."),
                                  OnExecClick, GUILayout.Width(width3));
                    RTUtil.Button(new GUIContent(">>", "Toggles the queue and delay functionality."),
                                  mOnClickQueue, GUILayout.Width(width3));
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }
Ejemplo n.º 25
0
        public void OnGUI()
        {
            if (Event.current.type == EventType.Repaint && MapView.MapIsEnabled)
            {
                foreach (ISatellite s in RTCore.Instance.Satellites.FindCommandStations().Concat(RTCore.Instance.Network.GroundStations.Values))
                {
                    bool showOnMapview = true;
                    var  worldPos      = ScaledSpace.LocalToScaledSpace(s.Position);
                    if (MapView.MapCamera.transform.InverseTransformPoint(worldPos).z < 0f)
                    {
                        continue;
                    }
                    Vector3 pos        = PlanetariumCamera.Camera.WorldToScreenPoint(worldPos);
                    var     screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

                    // Hide the current ISatellite if it is behind its body
                    if (RTSettings.Instance.HideGroundStationsBehindBody && IsOccluded(s.Position, s.Body))
                    {
                        showOnMapview = false;
                    }

                    if (RTSettings.Instance.HideGroundStationsOnDistance && !IsOccluded(s.Position, s.Body) && this.IsCamDistanceToWide(s.Position))
                    {
                        showOnMapview = false;
                    }

                    // orbiting remote stations are always shown
                    if (s.isVessel && !s.parentVessel.Landed)
                    {
                        showOnMapview = true;
                    }

                    if (showOnMapview)
                    {
                        Color pushColor = GUI.color;
                        // tint the white mark.png into the defined color
                        GUI.color = s.MarkColor;
                        // draw the mark.png
                        GUI.DrawTexture(screenRect, mTexMark, ScaleMode.ScaleToFit, true);
                        GUI.color = pushColor;

                        // Show Mouse over informations to the ground station
                        if (RTSettings.Instance.ShowMouseOverInfoGroundStations && s is MissionControlSatellite && screenRect.ContainsMouse())
                        {
                            Rect    headline = screenRect;
                            Vector2 nameDim  = this.smallStationHead.CalcSize(new GUIContent(s.Name));

                            headline.x     -= nameDim.x + 10;
                            headline.y     -= 3;
                            headline.width  = nameDim.x;
                            headline.height = 14;
                            // draw headline of the station
                            GUI.Label(headline, s.Name, this.smallStationHead);

                            // loop antennas
                            String antennaRanges = String.Empty;
                            foreach (var antenna in s.Antennas)
                            {
                                if (antenna.Omni > 0)
                                {
                                    antennaRanges += "Omni: " + RTUtil.FormatSI(antenna.Omni, "m") + Environment.NewLine;
                                }
                                if (antenna.Dish > 0)
                                {
                                    antennaRanges += "Dish: " + RTUtil.FormatSI(antenna.Dish, "m") + Environment.NewLine;
                                }
                            }

                            if (!antennaRanges.Equals(String.Empty))
                            {
                                Rect       antennas = screenRect;
                                GUIContent content  = new GUIContent(antennaRanges);

                                Vector2 antennaDim = this.smallStationText.CalcSize(content);
                                float   maxHeight  = this.smallStationText.CalcHeight(content, antennaDim.x);

                                antennas.y     += headline.height - 3;
                                antennas.x     -= antennaDim.x + 10;
                                antennas.width  = antennaDim.x;
                                antennas.height = maxHeight;

                                // draw antenna infos of the station
                                GUI.Label(antennas, antennaRanges, this.smallStationText);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public override string GetInfo()
        {
            var info = new StringBuilder();

            if (ShowEditor_OmniRange && Mode1OmniRange > 0)
            {
                info.AppendFormat("Omni range: {0} / {1}", RTUtil.FormatSI(Mode0OmniRange * RangeMultiplier, "m"), RTUtil.FormatSI(Mode1OmniRange * RangeMultiplier, "m")).AppendLine();
            }
            if (ShowEditor_DishRange && Mode1DishRange > 0)
            {
                info.AppendFormat("Dish range: {0} / {1}", RTUtil.FormatSI(Mode0DishRange * RangeMultiplier, "m"), RTUtil.FormatSI(Mode1DishRange * RangeMultiplier, "m")).AppendLine();
            }
            if (ShowEditor_EnergyReq && EnergyCost > 0)
            {
                info.AppendFormat("Energy req.: {0}", RTUtil.FormatConsumption(EnergyCost * ConsumptionMultiplier)).AppendLine();
            }

            if (ShowEditor_DishAngle && CanTarget)
            {
                info.AppendFormat("Cone angle: {0} degrees", DishAngle.ToString("F2")).AppendLine();
            }

            if (IsRTActive)
            {
                info.AppendLine("Activated by default");
            }

            if (MaxQ > 0)
            {
                info.AppendLine("Snaps under high dynamic pressure");
            }

            return(info.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
        }
Ejemplo n.º 27
0
        private void Target()
        {
            if (Event.current.Equals(Event.KeyboardEvent("return")) && GUI.GetNameOfFocusedControl().StartsWith("RC"))
            {
                mFlightComputer.Enqueue(DriveCommand.Coord(mSteerClamp, Latitude, Longitude, Speed));
            }
            else if (GameSettings.MODIFIER_KEY.GetKey() && ((Input.GetMouseButton(0) || Input.GetMouseButton(1)) != MouseClick))
            {
                MouseClick = Input.GetMouseButton(0) || Input.GetMouseButton(1);
                Vector2 latlon;
                if (MouseClick && RTUtil.CBhit(mFlightComputer.mAttachedVessel.mainBody, out latlon))
                {
                    Latitude  = latlon.x;
                    Longitude = latlon.y;

                    if (Input.GetMouseButton(1))
                    {
                        mFlightComputer.Enqueue(DriveCommand.Coord(mSteerClamp, Latitude, Longitude, Speed));
                    }
                }
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Wheel: ");
                GUILayout.FlexibleSpace();
                GUILayout.Label(mSteerClamp.ToString("P"));
                GUILayout.Label("Clamp", GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            RTUtil.HorizontalSlider(ref mSteerClamp, 0, 1);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("LAT.", GUILayout.Width(50));
                GUI.SetNextControlName("RC1");
                RTUtil.TextField(ref mLatitude, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(°)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("LON.", GUILayout.Width(50));
                GUI.SetNextControlName("RC2");
                RTUtil.TextField(ref mLongditude, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(°)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Speed", GUILayout.Width(50));
                GUI.SetNextControlName("RC3");
                RTUtil.TextField(ref mSpeed, GUILayout.Width(50), GUILayout.ExpandWidth(false));
                GUILayout.Label("(m/s)", GUI.skin.textField, GUILayout.Width(40));
            }
            GUILayout.EndHorizontal();


            mLatitude   = RTUtil.ConstrictNum(mLatitude);
            mLongditude = RTUtil.ConstrictNum(mLongditude);
            mSpeed      = RTUtil.ConstrictNum(mSpeed, false);
        }
Ejemplo n.º 28
0
 static Texture()
 {
     RTUtil.LoadImage(out Satellite, "texSatellite.png");
 }
Ejemplo n.º 29
0
 static NetworkRenderer()
 {
     RTUtil.LoadImage(out mTexMark, "mark");
 }
Ejemplo n.º 30
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));
        }