示例#1
0
        public void ReloadDishRange()
        {
            if (isLoaded)
            {
                try
                {
                    if (RTUtils.containsField(partModule, "dishRange"))
                    {
                        this.dishRange = (float)partModule.Fields.GetValue("dishRange");
                    }
                    else
                    {
                        this.dishRange = 0;
                    }
                }
                catch (Exception)
                { }
            }
            else
            {
                ConfigNode n = new ConfigNode();
                protoPartModule.Save(n);

                if (n.HasValue("dishRange"))
                {
                    this.dishRange = float.Parse(n.GetValue("dishRange"));
                }
                else
                {
                    this.dishRange = 0;
                }
            }
        }
示例#2
0
 public static bool IsComsat(Vessel v)
 {
     if (v.loaded)
     {
         foreach (Part p in v.parts)
         {
             foreach (PartModule m in p.Modules)
             {
                 if (RTUtils.containsField(m, "isRemoteCommand"))
                 {
                     return(true);
                 }
             }
         }
     }
     else
     {
         foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
         {
             foreach (ProtoPartModuleSnapshot s in p.modules)
             {
                 ConfigNode n = new ConfigNode();
                 s.Save(n);
                 if (n.HasValue("isRemoteCommand"))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
        public void SaveAndClose()
        {
            this.Close();

            try
            {
                if (FlightGlobals.ActiveVessel.isEVA ? (Vector3d.Distance(module.vessel.transform.position, FlightGlobals.ActiveVessel.transform.position) > 50) : !RTGlobals.coreList[module.vessel].InControl)
                {
                    return;
                }
            }
            catch { return; }

            if (settingNode != null && module.vessel.loaded)
            {
                if (RTUtils.containsField(module, "antennaName"))
                {
                    module.Fields.SetValue("antennaName", antennaName);
                }

                settingNode.save();

                RTGlobals.network = new RelayNetwork();
                RTGlobals.coreList[module.vessel].path = RTGlobals.network.GetCommandPath(RTGlobals.coreList[module.vessel].Rnode);
            }
        }
示例#4
0
        void ConstructFromLoaded()
        {
            foreach (Part p in vessel.parts)
            {
                foreach (PartModule m in p.Modules)
                {
                    if (RTUtils.containsField(m, "isRemoteCommand") && (bool)m.Fields.GetValue("isRemoteCommand"))
                    {
                        this.hasCommand = true;
                        break;
                    }
                }
                if (hasCommand)
                {
                    break;
                }
            }

            float sumRange = 0f; // NK allow multiple antennae

            foreach (Part p in vessel.parts)
            {
                foreach (PartModule m in p.Modules)
                {
                    if (RTUtils.containsField(m, "antennaRange"))
                    {
                        float lngth = (float)m.Fields.GetValue("antennaRange");
                        if (lngth > this.antennaRange)
                        {
                            this.hasAntenna   = true;
                            this.antennaRange = lngth;
                        }
                        sumRange += lngth; // NK allow multiple antennae
                    }

                    if (RTUtils.containsField(m, "dishRange"))
                    {
                        DishData tmp = new DishData();

                        tmp.dishRange = m.Fields.GetValue("dishRange") == null ? 0 : (float)m.Fields.GetValue("dishRange");

                        tmp.pointedAt = m.Fields.GetValue("pointedAt") == null ? "None" : (string)m.Fields.GetValue("pointedAt");

                        if (tmp.dishRange > 0)
                        {
                            this.hasDish = true;
                            this.dishData.Add(tmp);
                        }
                    }
                }
            }
            // NK allow multiple antennae
            if (this.hasAntenna && RTGlobals.useMultiple)
            {
                this.antennaRange = (float)Math.Round(this.antennaRange + (sumRange - this.antennaRange) * 0.25f);
            }
        }
        public override string GetInfo()
        {
            string text = "";

            if (antennaRange0 != antennaRange1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Antenna range: " + RTUtils.length(this.antennaRange0 * 1000) + "m / " + RTUtils.length(this.antennaRange1 * 1000) + "m";
            }
            else if (antennaRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Antenna range: " + RTUtils.length(antennaRange * 1000) + "m";
            }

            if (dishRange0 != dishRange1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Dish range: " + RTUtils.length(dishRange0 * 1000) + "m / " + RTUtils.length(dishRange1 * 1000) + "m";
            }
            else if (dishRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Dish range: " + RTUtils.length(dishRange * 1000) + "m";
            }

            if (EnergyDrain0 != EnergyDrain1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Energy req.: " + (EnergyDrain0 * 60).ToString("0.00") + "/min. / " + (EnergyDrain1 * 60).ToString("0.00") + "/min.";
            }
            else if (this.EnergyDrain > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
            }

            return(text);
        }
示例#6
0
        public override string GetInfo()
        {
            string text = "";

            if (antennaRange0 != antennaRange1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Antenna range: " + RTUtils.length(this.antennaRange0 * 1000) + "m / " + RTUtils.length(this.antennaRange1 * 1000) + "m";
            }
            else if (antennaRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Antenna range: " + RTUtils.length(antennaRange * 1000) + "m";
            }

            if (dishRange0 != dishRange1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Dish range: " + RTUtils.length(dishRange0 * 1000) + "m / " + RTUtils.length(dishRange1 * 1000) + "m";
            }
            else if (dishRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Dish range: " + RTUtils.length(dishRange * 1000) + "m";
            }

            if (EnergyDrain0 != EnergyDrain1)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Energy req.: " + RTUtils.eCost(EnergyDrain0) + " / " + RTUtils.eCost(EnergyDrain1); // NK
            }
            else if (this.EnergyDrain > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
            }

            return(text);
        }
        public void Update()
        {
            if (HighLogic.fetch == null)
            {
                return;
            }

            try
            {
                if (HighLogic.LoadedSceneIsFlight)
                {
                    doOnce = true;
                    if (RTGlobals.Manager == null)
                    {
                        RTGlobals.Manager = (OrbitPhysicsManager)GameObject.FindObjectOfType(typeof(OrbitPhysicsManager));
                    }

                    try
                    {
                        if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(RTGlobals.settingsKey))
                        {
                            coreSettings.Toggle();
                        }
                    }
                    catch { }

                    if (this.vessels != FlightGlobals.Vessels.Count)
                    {
                        RTGlobals.network = new RelayNetwork();
                        this.vessels      = FlightGlobals.Vessels.Count;
                    }

                    RTGlobals.coreList.update();

                    if (RTGlobals.coreList.activeVesselIsRemoteTech)
                    {
                        RTUtils.applyLocks();
                    }
                    else
                    {
                        RTUtils.removeLocks();
                    }
                }
                else if (doOnce)
                {
                    RTGlobals.coreList.Clear();
                    RTGlobals.coreList.activeVesselIsRemoteTech = doOnce = false;
                    RTUtils.removeLocks();
                }
            }
            catch { }

            if (GUIcreated && !HighLogic.LoadedSceneIsFlight)
            {
                destroyGUI();
            }
        }
示例#8
0
 void LoadFromLoaded()
 {
     foreach (Part p in node.Vessel.parts)
     {
         foreach (PartModule m in p.Modules)
         {
             if (RTUtils.containsField(m, "dishRange") && (float)m.Fields.GetValue("dishRange") > 0)
             {
                 settingNodes.Add(new SatSettingNode(m));
             }
         }
     }
     vesselName = node.Vessel.vesselName;
 }
示例#9
0
        void ConstructFromLoaded()
        {
            foreach (Part p in vessel.parts)
            {
                foreach (PartModule m in p.Modules)
                {
                    if (RTUtils.containsField(m, "isRemoteCommand") && (bool)m.Fields.GetValue("isRemoteCommand"))
                    {
                        this.hasCommand = true;
                        break;
                    }
                }
                if (hasCommand)
                {
                    break;
                }
            }

            foreach (Part p in vessel.parts)
            {
                foreach (PartModule m in p.Modules)
                {
                    if (RTUtils.containsField(m, "antennaRange"))
                    {
                        float lngth = (float)m.Fields.GetValue("antennaRange");
                        if (lngth > this.antennaRange)
                        {
                            this.hasAntenna   = true;
                            this.antennaRange = lngth;
                        }
                    }

                    if (RTUtils.containsField(m, "dishRange"))
                    {
                        DishData tmp = new DishData();

                        tmp.dishRange = m.Fields.GetValue("dishRange") == null ? 0 : (float)m.Fields.GetValue("dishRange");

                        tmp.pointedAt = m.Fields.GetValue("pointedAt") == null ? "None" : (string)m.Fields.GetValue("pointedAt");

                        if (tmp.dishRange > 0)
                        {
                            this.hasDish = true;
                            this.dishData.Add(tmp);
                        }
                    }
                }
            }
        }
示例#10
0
        public override string GetInfo()
        {
            string text;

            if (isRemoteCommand)
            {
                text = "Remote Command";
            }
            else
            {
                text = "Remote Control";
            }

            text += "\nEnergy req.: " + RTUtils.eCost(EnergyDrain); // NK

            return(text);
        }
示例#11
0
        public void update()
        {
            if (sending && states.Peek().ActTime <= Planetarium.GetUniversalTime())
            {
                state = states.Dequeue();
                if (state.Bt)
                {
                    state.Target = state.Target + Planetarium.GetUniversalTime();
                }
                else
                {
                    speedT0 = RTUtils.ForwardSpeed(computer.core.vessel);
                }
            }

            if (burning)
            {
                if (!RTUtils.PhysicsActive)
                {
                    TimeWarp.SetRate(0, true);
                }
                doOnce = true;
                if (ThrottleIncrement < state.Throttle)
                {
                    ThrottleIncrement = Mathf.Clamp(ThrottleIncrement + 0.1F, 0, 1);
                    computer.core.computer.SetThrottle(ThrottleIncrement);
                }
                else
                {
                    computer.core.computer.SetThrottle(Mathf.Clamp(state.Throttle, 0, 1));
                }
            }
            else
            if (doOnce)
            {
                ThrottleIncrement = 0;
                computer.core.computer.SetThrottle(ThrottleIncrement);
                doOnce = false;
                if (!state.Bt)
                {
                    state.Target = -10;
                    state.Bt     = true;
                }
            }
        }
示例#12
0
        public SatSettingNode(PartModule m)
        {
            this.partModule = m;
            isLoaded        = true;


            if (RTUtils.containsField(partModule, "pointedAt"))
            {
                this.pointedAt = new Target((string)partModule.Fields.GetValue("pointedAt"));
            }
            else
            {
                this.pointedAt = new Target();
            }

            if (RTUtils.containsField(partModule, "dishRange"))
            {
                this.dishRange = (float)partModule.Fields.GetValue("dishRange");
            }
            else
            {
                this.dishRange = 0;
            }

            if (RTUtils.containsField(partModule, "antennaName"))
            {
                this.antennaName = (string)partModule.Fields.GetValue("antennaName");
            }


            for (int i = 0; i < RTGlobals.targets.Count; i++)
            {
                if (pointedAt.Equals(RTGlobals.targets[i]))
                {
                    selectedTarget = i; break;
                }
            }
        }
示例#13
0
        public RelayNetwork()
        {
            all             = new List <RelayNode>();
            comSats         = new List <RelayNode>();
            commandStations = new List <RelayNode>();


            foreach (Vessel v in FlightGlobals.Vessels)
            {
                if (RTUtils.IsComsat(v))
                {
                    all.Add(new RelayNode(v));
                }
            }

            foreach (RelayNode node in all)
            {
                if (node.HasCommand)
                {
                    commandStations.Add(node);
                }
                else
                {
                    comSats.Add(node);
                }
            }
            all.Add(new RelayNode());
            commandStations.Add(new RelayNode());

            foreach (KeyValuePair <Vessel, RemoteCore> pair in RTGlobals.coreList)
            {
                try
                {
                    pair.Value.Rnode = new RelayNode(pair.Key);
                }
                catch { }
            }
        }
示例#14
0
        public void recalculate()
        {
            HashSet <Vessel> toDelete = new HashSet <Vessel>();

            foreach (KeyValuePair <Vessel, RemoteCore> pair in this)
            {
                if (!(pair.Key.loaded && RTUtils.IsComsat(pair.Key)))
                {
                    try
                    {
                        pair.Key.OnFlyByWire -= pair.Value.drive;
                    }
                    catch { }

                    toDelete.Add(pair.Key);
                }
            }
            foreach (Vessel v in toDelete)
            {
                this.Remove(v);
            }
            toDelete.Clear();
        }
示例#15
0
        public void Open(PartModule moduleIn)
        {
            if (!moduleIn.vessel.loaded)
            {
                Close();
                return;
            }
            this.module = moduleIn;

            RTGlobals.targets = new List <Target>();

            CBOrV SortNetwork = new CBOrV(Planetarium.fetch.Sun, new RelayNode(moduleIn.vessel));

            SortNetwork.createTargets(ref RTGlobals.targets);



            RTGlobals.targets.Add(new Target());
            RTGlobals.targets[RTGlobals.targets.Count - 1].GUIListname = RTGlobals.targets[RTGlobals.targets.Count - 1].Name;
            RTGlobals.targets[RTGlobals.targets.Count - 1].color       = Color.red;


            if (RTUtils.containsField(module, "dishRange") && (float)module.Fields.GetValue("dishRange") > 0)
            {
                settingNode = new SatSettingNode(module);
                if (RTUtils.containsField(module, "antennaName"))
                {
                    antennaName = (string)module.Fields.GetValue("antennaName");
                }
                else
                {
                    antennaName = "Dish";
                }

                this.show = true;
            }
        }
示例#16
0
        public override string GetInfo()
        {
            string text = "";

            if (this.antennaRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Antenna range: " + RTUtils.length(this.antennaRange * 1000) + "m";
            }
            if (this.dishRange > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Dish range: " + RTUtils.length(this.dishRange * 1000) + "m";
            }
            if (this.EnergyDrain > 0)
            {
                if (text.Length > 0)
                {
                    text += "\n";
                }
                text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
            }

            //if (this.EnergyDrain0 > 0)
            //    text += "\nInactive energy req.: " + (Math.Round(this.EnergyDrain0 * 60, 1) == 0 ? Math.Round(this.EnergyDrain0 * 60, 2) : Math.Round(this.EnergyDrain0 * 60, 1)) + "/min.";
            //if (this.EnergyDrain1 > 0)
            //    text += "\nEnergy req.: " + (Math.Round(this.EnergyDrain1 * 60, 1) == 0 ? Math.Round(this.EnergyDrain1 * 60, 2) : Math.Round(this.EnergyDrain1 * 60, 1)) + "/min.";

            return(text);
        }
示例#17
0
        public void UpdatePA()
        {
            target = new Target(pointedAt);

            string targetName = target.GUIname;

            if (this.dishRange > 0)
            {
                if (Events["setTarget"].active)
                {
                    Events["setTarget2"].guiName      = "Target: " + targetName;
                    Events["OverrideTarget2"].guiName = "Override " + Events["setTarget2"].guiName;
                    Events["setTarget"].active        = Events["OverrideTarget"].active = false;
                    Events["setTarget2"].active       = Events["OverrideTarget2"].active = true;
                }
                else
                {
                    Events["setTarget"].guiName      = "Target: " + targetName;
                    Events["OverrideTarget"].guiName = "Override " + Events["setTarget"].guiName;
                    Events["setTarget"].active       = Events["OverrideTarget"].active = true;
                    Events["setTarget2"].active      = Events["OverrideTarget2"].active = false;
                }
            }
            else
            {
                Events["setTarget"].active = Events["OverrideTarget"].active = Events["setTarget2"].active = Events["OverrideTarget2"].active = false;
            }


            if (!showStats)
            {
                Fields["Dish_Range"].guiActive = Fields["Antenna_Range"].guiActive = false;
                return;
            }

            if (dishRange > 0)
            {
                Dish_Range = RTUtils.length(dishRange * 1000) + "m";

                Fields["Dish_Range"].guiName = "";

                if (showAntennaName)
                {
                    Fields["Dish_Range"].guiName += antennaName;
                }
                if (showType)
                {
                    Fields["Dish_Range"].guiName += showAntennaName ? " dish " : "Dish ";
                }
                Fields["Dish_Range"].guiName += (showAntennaName || showType) ? "range" : "Range";

                Fields["Dish_Range"].guiActive = true;
            }
            else
            {
                Fields["Dish_Range"].guiActive = false;
            }


            if (this.antennaRange > 0)
            {
                Antenna_Range = RTUtils.length(antennaRange * 1000) + "m";

                Fields["Antenna_Range"].guiName = "";

                if (showAntennaName)
                {
                    Fields["Antenna_Range"].guiName += antennaName;
                }
                if (showType)
                {
                    Fields["Antenna_Range"].guiName += showAntennaName ? " antenna " : "Antenna ";
                }
                Fields["Antenna_Range"].guiName += (showAntennaName || showType) ? "range" : "Range";

                Fields["Antenna_Range"].guiActive = true;
            }
            else
            {
                Fields["Antenna_Range"].guiActive = false;
            }
        }
示例#18
0
        void WindowGUI(int windowID)
        {
            Color    savedColor        = GUI.color;
            Color    savedContentColor = GUI.contentColor;
            bool     CrewControl       = vessel.GetCrewCount() > 0;
            GUIStyle Alarm             = new GUIStyle(GUI.skin.label);

            Alarm.fontStyle        = FontStyle.Bold;
            Alarm.normal.textColor = Color.red;

            if (!powered)
            {
                GUI.DragWindow();

                string alarmMessage = "Out of power";
                if (AlarmTime < Time.time)
                {
                    AlarmTime = Time.time + 1;
                    alarmShow = !alarmShow;
                }
                if (alarmShow)
                {
                    alarmMessage += " !";
                }
                GUILayout.Label(alarmMessage, Alarm);
                return;
            }

            try
            {
                if (InContact)
                {
                    if (GUILayout.Button("Path length: " + RTUtils.length(path.Length) + "m, delay: " + RTUtils.time(path.ControlDelay) +
                                         (RTGlobals.AdvInfo ?
                                          "\nRelay path: " + path.ToString() :
                                          ""),
                                         GUI.skin.label, GUILayout.ExpandWidth(true)))
                    {
                        RTGlobals.AdvInfo = !RTGlobals.AdvInfo;
                    }
                }
                else
                {
                    string alarmMessage = "Out of contact";
                    if (AlarmTime < Time.time)
                    {
                        AlarmTime = Time.time + 1;
                        alarmShow = !alarmShow;
                    }
                    if (alarmShow)
                    {
                        alarmMessage += " !";
                    }
                    GUILayout.Label(alarmMessage, Alarm);
                }
            }
            catch (NullReferenceException)
            {
                RTGlobals.network = new RelayNetwork();
                path = RTGlobals.network.GetCommandPath(Rnode);
            }
            GUI.color = savedColor;

            GUILayout.BeginHorizontal();

            RTGlobals.listComsats = GUILayout.Toggle(RTGlobals.listComsats, "List comsats", GUI.skin.button, GUILayout.Height(20));


            if (!CrewControl && !(MechJeb && InContact))
            {
                GUI.contentColor = Color.red;
            }
            localControl = GUILayout.Toggle(localControl, (!CrewControl && MechJeb) ? "MechJeb Control" : "Local Control", GUI.skin.button, GUILayout.Height(20));
            if (!CrewControl && !(MechJeb && InContact))
            {
                localControl     = false;
                GUI.contentColor = savedContentColor;
            }


            RTGlobals.showPathInMapView = GUILayout.Toggle(RTGlobals.showPathInMapView, "Show path on map", GUI.skin.button, GUILayout.Height(20));

            RTGlobals.showFC = GUILayout.Toggle(RTGlobals.showFC, "Flight Computer", GUI.skin.button, GUILayout.Height(20));

            GUILayout.EndHorizontal();

            if (RTGlobals.listComsats)
            {
                if (!LCoLF)
                {
                    Thread thread = new Thread(new ThreadStart(GetCommandPath));
                    thread.Start();
                    LCoLF = true;
                }


                if (!InControl)
                {
                    GUI.contentColor = Color.red;
                }
                if (GUILayout.Button(Rnode.descript, new GUIStyle(GUI.skin.button)) && InControl)
                {
                    settings.Open(Rnode);
                }
                if (!InControl)
                {
                    GUI.contentColor = savedContentColor;
                }

                RTGlobals.comsatListScroll = GUILayout.BeginScrollView(RTGlobals.comsatListScroll, false, true);

                //compiles a list of comsat vessels that are in the current RelayNetwork, Coloring the ones in the current RelayPath green.
                if (InContact || Rnode.HasCommand)
                {
                    foreach (RelayNode node in RTGlobals.network.all)
                    {
                        if (!node.Equals(Rnode) && node.Vessel != null)
                        {
                            GUILayout.BeginHorizontal();
                            bool connection = InContactWith(node);

                            if (!connection)
                            {
                                if (GUI.contentColor != Color.red)
                                {
                                    GUI.contentColor = Color.red;
                                }
                            }
                            else
                            if (InContact && path.nodes.Contains(node))
                            {
                                if (GUI.contentColor != Color.green)
                                {
                                    GUI.contentColor = Color.green;
                                }
                            }
                            else if (GUI.contentColor != Color.white)
                            {
                                GUI.contentColor = Color.white;
                            }
                            if (GUILayout.Button(node.descript, new GUIStyle(GUI.skin.button), GUILayout.Height(50.0F)) && connection)
                            {
                                settings.Open(node);
                            }
                            if ((InContact || Rnode.HasCommand) && connection && node.Vessel.loaded && (RTGlobals.extPack ? Vector3d.Distance(vessel.transform.position, node.Vessel.transform.position) < 2000 : !node.Vessel.packed))
                            {
                                if (GUILayout.Button("Ctrl", new GUIStyle(GUI.skin.button), GUILayout.Width(50.0F), GUILayout.Height(50.0F)))
                                {
                                    bool isThere        = false;
                                    int  ATid           = this.flightComputerGUI.ATTITUDE_ID + 1,
                                         THid           = this.flightComputerGUI.THROTTLE_ID + 1;
                                    GUIcontainer remove = new GUIcontainer();
                                    foreach (GUIcontainer c in this.otherGUI)
                                    {
                                        if (c.gui == RTGlobals.coreList[node.Vessel].flightComputerGUI)
                                        {
                                            isThere = true;
                                            remove  = c;
                                            break;
                                        }
                                        ATid = c.ATTITUDE_ID + 1;
                                        THid = c.THROTTLE_ID + 1;
                                    }

                                    if (isThere)
                                    {
                                        otherGUI.Remove(remove);
                                        if (RTGlobals.extPack && otherGUI.Count == 0 && RTGlobals.Manager != null)
                                        {
                                            RTGlobals.Manager.distantLandedPartPackThreshold   = 350;
                                            RTGlobals.Manager.distantLandedPartUnpackThreshold = 200;
                                            RTGlobals.Manager.distantPartPackThreshold         = 5000;
                                            RTGlobals.Manager.distantPartUnpackThreshold       = 200;
                                        }
                                    }
                                    else
                                    {
                                        otherGUI.Add(new GUIcontainer(RTGlobals.coreList[node.Vessel].flightComputerGUI, ATid, THid));
                                    }
                                }
                            }

                            GUILayout.EndHorizontal();
                        }
                    }
                }
                else
                {
                    GUI.contentColor = Color.red;
                    foreach (RelayNode node in RTGlobals.network.all)
                    {
                        if (!node.Equals(Rnode) && node.Vessel != null)
                        {
                            GUILayout.Label(node.descript, new GUIStyle(GUI.skin.button));
                        }
                    }
                }

                GUI.color        = savedColor;
                GUI.contentColor = savedContentColor;
                GUILayout.EndScrollView();
            }

            GUI.DragWindow();
        }
示例#19
0
        public void drive(FlightCtrlState s)
        {
            if (attitideActive)
            {
                updateAvailableTorque();

                attitudeError = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(Reference) * Target * Vector3d.forward, vessel.ReferenceTransform.up));
                // Used in the drive_limit calculation
                double precision = Math.Max(0.5, Math.Min(10.0, (torquePYAvailable + torqueThrustPYAvailable * s.mainThrottle) * 20.0 / MoI.magnitude));

                // Direction we want to be facing
                Quaternion target = attitudeGetReferenceRotation(Reference) * Target;
                Quaternion delta  = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.ReferenceTransform.rotation) * target);

                Vector3d deltaEuler = new Vector3d(
                    (delta.eulerAngles.x > 180) ? (delta.eulerAngles.x - 360.0F) : delta.eulerAngles.x,
                    -((delta.eulerAngles.y > 180) ? (delta.eulerAngles.y - 360.0F) : delta.eulerAngles.y),
                    (delta.eulerAngles.z > 180) ? (delta.eulerAngles.z - 360.0F) : delta.eulerAngles.z
                    );

                Vector3d torque = new Vector3d(
                    torquePYAvailable + torqueThrustPYAvailable * s.mainThrottle,
                    torqueRAvailable,
                    torquePYAvailable + torqueThrustPYAvailable * s.mainThrottle
                    );

                Vector3d inertia = Vector3d.Scale(
                    RTUtils.Sign(angularMomentum) * 1.8f,
                    Vector3d.Scale(
                        Vector3d.Scale(angularMomentum, angularMomentum),
                        RTUtils.Invert(Vector3d.Scale(torque, MoI))
                        )
                    );

                // Determine the current level of error, this is then used to determine what act to apply
                Vector3d err = deltaEuler * Math.PI / 180.0F;
                err += RTUtils.Reorder(inertia, 132);
                err.Scale(Vector3d.Scale(MoI, RTUtils.Invert(torque)));
                prev_err = err;

                // Make sure we are taking into account the correct timeframe we are working with
                integral += err * TimeWarp.fixedDeltaTime;

                // The inital value of act
                // Act is ultimately what determines what the pitch, yaw and roll will be set to
                // We make alterations to act between here and passing it into the pod controls
                Vector3d act = Mathf.Clamp((float)attitudeError, 1.0F, 3.0F) * Kp * err;
                //+ Ki * integral + Kd * deriv; //Ki and Kd are always 0 so they have been commented out

                // The maximum value the controls may be
                float drive_limit = Mathf.Clamp01((float)(err.magnitude * 450 / precision));

                // Reduce z by reduceZfactor, z seems to act far too high in relation to x and y
                act.z = act.z / 18.0F;

                // Reduce all 3 axis to a maximum of drive_limit
                act.x = Mathf.Clamp((float)act.x, drive_limit * -1, drive_limit);
                act.y = Mathf.Clamp((float)act.y, drive_limit * -1, drive_limit);
                act.z = Mathf.Clamp((float)act.z, drive_limit * -1, drive_limit);

                // Met is the time in seconds from take off
                double met = Planetarium.GetUniversalTime() - vessel.launchTime;

                // Reduce effects of controls after launch and returns them gradually
                // This helps to reduce large wobbles experienced in the first few seconds
                if (met < 3.0F)
                {
                    act = act * ((met / 3.0F) * (met / 3.0F));
                }

                // Averages out the act with the last few results, determined by the size of the a_avg_act array
                act = RTUtils.averageVector3d(a_avg_act, act);

                // Looks for rapid toggling of each axis and if found, then rest that axis for a while
                // This helps prevents wobbles from getting larger
                rapidRestX = RTUtils.restForPeriod(rapidToggleX, act.x, rapidRestX);
                rapidRestY = RTUtils.restForPeriod(rapidToggleY, act.y, rapidRestY);
                rapidRestZ = RTUtils.restForPeriod(rapidToggleZ, act.z, rapidRestZ);

                // Reduce axis by rapidToggleRestFactor if rapid toggle rest has been triggered
                if (rapidRestX > 0)
                {
                    act.x = act.x / rapidToggleRestFactor;
                }
                if (rapidRestY > 0)
                {
                    act.y = act.y / rapidToggleRestFactor;
                }
                if (rapidRestZ > 0)
                {
                    act.z = act.z / rapidToggleRestFactor;
                }

                // Sets the SetFlightCtrlState for pitch, yaw and roll
                if (!double.IsNaN(act.z))
                {
                    s.roll = Mathf.Clamp((float)(act.z), -1, 1);
                }
                if (!double.IsNaN(act.x))
                {
                    s.pitch = Mathf.Clamp((float)(act.x), -1, 1);
                }
                if (!double.IsNaN(act.y))
                {
                    s.yaw = Mathf.Clamp((float)(act.y), -1, 1);
                }
            }
            if (throttleActive)
            {
                s.mainThrottle = throttle;
                if (throttle == 0)
                {
                    throttleActive = false;
                }
            }

            if (roverActive)
            {
                if (roverState.Steer)
                {
                    if (Quaternion.Angle(roverState.roverRotation, core.vessel.ReferenceTransform.rotation) < roverState.Target)
                    {
                        s.wheelThrottle = roverState.reverse ? -throttlePID.Control(roverState.Speed - (float)vessel.horizontalSrfSpeed) : throttlePID.Control(roverState.Speed - (float)vessel.horizontalSrfSpeed);
                        s.wheelSteer    = roverState.Steering;
                    }
                    else
                    {
                        s.wheelThrottle = 0;
                        s.wheelSteer    = 0;
                        roverActive     = false;
                        core.vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
                    }
                }
                else
                {
                    if ((float)Vector3d.Distance(core.vessel.mainBody.position + altitude * core.vessel.mainBody.GetSurfaceNVector(roverState.latitude, roverState.longitude), core.vessel.transform.position) < roverState.Target)
                    {
                        s.wheelThrottle = roverState.reverse ? -throttlePID.Control(roverState.Speed - (float)vessel.horizontalSrfSpeed) : throttlePID.Control(roverState.Speed - (float)vessel.horizontalSrfSpeed);
                        s.wheelSteer    = roverState.Steering;
                    }
                    else
                    {
                        s.wheelThrottle = 0;
                        s.wheelSteer    = 0;
                        roverActive     = false;
                        core.vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
                    }
                }
            }
        }
        public override void OnUpdate()
        {
            if (!flightStarted || broken)
            {
                return;
            }

            if (EnergyDrain1 > 0)
            {
                RequestPower();
            }

            if (vessel != null && RTUtils.PhysicsActive)
            {
                if (willWakeInPanic && animState == 0 && !InControl && !anim.IsPlaying(Animation))
                {
                    SetMode1();
                    UpdateGUI();
                }

                if (explodeMe && Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, part.transform.position) > 250)
                {
                    explodeMe = false;
                    part.explode();
                }

                if (MaxQ > 0 && animState == 1 && (Math.Pow(vessel.srf_velocity.magnitude, 2) * vessel.atmDensity * 0.5) > MaxQ)
                {
                    if (BreakTransformName == "")
                    {
                        part.decouple(0f);
                        explodeMe = true;
                    }
                    else
                    {
                        broken = true;
                        RTUtils.findTransformsWithCollider(part.FindModelTransform(BreakTransformName), ref toRemove);

                        foreach (Transform t in toRemove)
                        {
                            Rigidbody rb = t.gameObject.AddComponent <Rigidbody>();

                            rb.angularDrag     = part.rigidbody.angularDrag;
                            rb.angularVelocity = part.rigidbody.angularVelocity;
                            rb.drag            = 0;
                            rb.mass            = part.mass / 5;
                            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.tf      = t;
                            dm.rb      = rb;
                            dm.dc      = DragCoeff;
                            dm.mb      = vessel.mainBody;
                        }

                        if (this.MaximumDrag > 0)
                        {
                            part.minimum_drag = this.MinimumDrag;
                            part.maximum_drag = this.MaximumDrag;
                        }
                        EnergyDrain = antennaRange = dishRange = 0;
                        part.SendMessage("UpdateGUI");
                        UpdatePA();
                        RTGlobals.network = new RelayNetwork();
                    }
                }
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (broken)
            {
                RTUtils.findTransformsWithCollider(part.FindModelTransform(BreakTransformName), ref toRemove);
                foreach (Transform t in toRemove)
                {
                    Destroy(t.gameObject);
                }
                toRemove.Clear();

                if (this.MaximumDrag > 0)
                {
                    part.minimum_drag = this.MinimumDrag;
                    part.maximum_drag = this.MaximumDrag;
                }

                EnergyDrain = antennaRange = dishRange = 0;
                part.SendMessage("UpdateGUI");
                UpdatePA();
                RTGlobals.network = new RelayNetwork();
                return;
            }


            Actions["Mode1Action"].guiName  = Events["Mode1Event"].guiName = Mode1Name;
            Actions["Mode0Action"].guiName  = Events["Mode0Event"].guiName = Mode0Name;
            Actions["ActionToggle"].guiName = ToggleName;

            Events["OverrideMode1Event"].guiName = "Override " + Mode1Name;
            Events["OverrideMode0Event"].guiName = "Override " + Mode0Name;

            if (animState == 1)
            {
                act1();
            }
            else
            {
                act0();
            }

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

            anim[Animation].normalizedTime = this.animState;

            anim[Animation].wrapMode = WrapMode.Clamp;

            if (state == StartState.Editor)
            {
                if (animPlayStart == 1)
                {
                    SetMode1();
                }
                else if (animPlayStart == -1)
                {
                    SetMode0();
                }
            }

            base.OnStart(state);
        }
示例#22
0
        public void Draw()
        {
            bool locked = on;

            GUILayout.BeginHorizontal();

            Color savedContentColor = GUI.contentColor;

            if (state.Active)
            {
                if (mode == AttitudeMode.MANEUVERNODE)
                {
                    if (state.Active)
                    {
                        if (FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count > 0)
                        {
                            GUI.contentColor = Color.green;
                        }
                        else
                        {
                            GUI.contentColor = Color.yellow;
                        }
                    }
                }
                else
                if (state.Active)
                {
                    GUI.contentColor = Color.green;
                }
            }
            else
            if (mode == AttitudeMode.MANEUVERNODE && FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0)
            {
                GUI.contentColor = Color.red;
            }

            on = GUILayout.Toggle(on,
                                  (RTGlobals.ColFriend && state.Active ? name + "<" : name)
                                  , GUI.skin.textField, GUILayout.Width(100));
            GUI.contentColor = savedContentColor;

            if (!(computer.core.localControl || computer.core.InContact) || (mode == AttitudeMode.MANEUVERNODE && FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0 && !state.Active))
            {
                on = locked;
            }

            GUILayout.Label(sending ? computer.arrows : "", GUI.skin.textField, GUILayout.Width(50));
            if (sending)
            {
                GUILayout.Label(RTUtils.time((lastActTime - Planetarium.GetUniversalTime() > 0) ? lastActTime - Planetarium.GetUniversalTime() : 0), GUI.skin.textField, GUILayout.Width(90));
            }
            else
            {
                burnAts = GUILayout.TextField(burnAts, GUILayout.Width(90));
                List <String> temp = burnAts.Split(":".ToCharArray()).ToList();
                string        seconds = "", minutes = "", hours = "", days = "";

                while (temp.Count < 4)
                {
                    temp.Insert(0, "");
                }

                seconds = RTUtils.TFormat(temp[3]);
                burnAt  = Convert.ToSingle(seconds == "" ? "0" : seconds);
                burnAts = seconds;

                if (temp[2] != "")
                {
                    minutes = RTUtils.TFormat(temp[2]);
                    burnAt += Convert.ToSingle(minutes == "" ? "0" : minutes) * 60;
                    burnAts = minutes == "" ? burnAts : (minutes + ":" + burnAts);
                }

                if (temp[1] != "")
                {
                    hours   = RTUtils.TFormat(temp[1]);
                    burnAt += Convert.ToSingle(hours == "" ? "0" : hours) * 3600;
                    burnAts = hours == "" ? burnAts : (hours + ":" + burnAts);
                }

                if (temp[0] != "")
                {
                    days    = RTUtils.TFormat(temp[0]);
                    burnAt += Convert.ToSingle(days == "" ? "0" : days) * 86400;
                    burnAts = days == "" ? burnAts : (days + ":" + burnAts);
                }
            }
            GUILayout.EndHorizontal();

            if (mode != AttitudeMode.SURFACE || !on)
            {
                return;
            }
            GUILayout.BeginHorizontal();

            GUILayout.Label("Pitch:", GUI.skin.textField, GUILayout.Width(100));
            PITs = GUILayout.TextField(PITs, GUILayout.Width(50));
            PITs = RTUtils.FormatNumString(PITs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(PITs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                PITs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(PITs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                PITs = Mathf.RoundToInt(tmp).ToString();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label("Heading:", GUI.skin.textField, GUILayout.Width(100));
            HDGs = GUILayout.TextField(HDGs, GUILayout.Width(50));
            HDGs = RTUtils.FormatNumString(HDGs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(HDGs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                HDGs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(HDGs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                HDGs = Mathf.RoundToInt(tmp).ToString();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label("Roll:", GUI.skin.textField, GUILayout.Width(100));
            ROLs = GUILayout.TextField(ROLs, GUILayout.Width(50));
            ROLs = RTUtils.FormatNumString(ROLs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(ROLs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                ROLs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(ROLs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                ROLs = Mathf.RoundToInt(tmp).ToString();
            }
            USEROL = GUILayout.Toggle(USEROL, " ", GUI.skin.toggle, GUILayout.Width(21.0F));

            GUILayout.EndHorizontal();
            if (GUILayout.Button("Update", GUI.skin.textField) && (computer.core.localControl || computer.core.InContact))
            {
                if (PITs.EndsWith("."))
                {
                    PITs = PITs.Substring(0, PITs.Length - 1);
                }

                if (HDGs.EndsWith("."))
                {
                    HDGs = HDGs.Substring(0, HDGs.Length - 1);
                }
                if (ROLs.EndsWith("."))
                {
                    ROLs = ROLs.Substring(0, ROLs.Length - 1);
                }

                PIT    = Convert.ToSingle(PITs);
                HDG    = Convert.ToSingle(HDGs);
                ROL    = Convert.ToSingle(ROLs);
                lastOn = false;
            }
        }
示例#23
0
        public void draw()
        {
            GUILayout.Label((SteeringBar >= 0 ? "Right: " : "Left: ") + Math.Abs(Mathf.RoundToInt(SteeringBar * 100)) + "%", GUI.skin.textField);
            SteeringBar = GUILayout.HorizontalSlider(SteeringBar, -1, 1);

            reverse = GUILayout.Toggle(reverse, reverse ? "Reverse" : "Forward");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Speed (m/s):", GUI.skin.textField, GUILayout.Width(100));
            SpeedS = GUILayout.TextField(SpeedS, GUILayout.Width(50));
            SpeedS = RTUtils.FormatNumString(SpeedS);
            if (SpeedS == "")
            {
                SpeedS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(SpeedS);
                tmp   += 1;
                SpeedS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(SpeedS);
                tmp   -= 1;
                SpeedS = Mathf.RoundToInt(tmp).ToString();
            }

            Speed  = Mathf.Clamp(Convert.ToSingle(SpeedS), 0, float.MaxValue);
            SpeedS = Speed.ToString();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Label("Drive (m):", GUI.skin.textField, GUILayout.Width(100));
            DistS = GUILayout.TextField(DistS, GUILayout.Width(50));
            DistS = RTUtils.FormatNumString(DistS);
            if (DistS == "")
            {
                DistS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DistS);
                tmp  += 1;
                DistS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DistS);
                tmp  -= 1;
                DistS = Mathf.RoundToInt(tmp).ToString();
            }

            Distance = Mathf.Clamp(Convert.ToSingle(DistS), 0, float.MaxValue);
            DistS    = Distance.ToString();

            if (GUILayout.Button("Send", GUI.skin.textField))
            {
                RoverState r = new RoverState();
                r.Steer     = false;
                r.Target    = Distance;
                r.Speed     = Speed;
                r.reverse   = reverse;
                r.Steering  = 0;
                lastActTime = r.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? 0 : computer.core.path.ControlDelay);
                states.Enqueue(r);
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();

            GUILayout.Label("Turn (°):", GUI.skin.textField, GUILayout.Width(100));
            DegS = GUILayout.TextField(DegS, GUILayout.Width(50));
            DegS = RTUtils.FormatNumString(DegS);
            if (DegS == "")
            {
                DegS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DegS);
                tmp += 1;
                DegS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DegS);
                tmp -= 1;
                DegS = Mathf.RoundToInt(tmp).ToString();
            }

            Degrees = Mathf.Clamp(Convert.ToSingle(DegS), 0, 90);
            DegS    = Degrees.ToString();

            if (GUILayout.Button("Send", GUI.skin.textField))
            {
                RoverState r = new RoverState();
                r.Steer     = true;
                r.Target    = Degrees;
                r.Speed     = Speed;
                r.reverse   = reverse;
                r.Steering  = Mathf.RoundToInt(SteeringBar * 100) == 0 ? 0 : -SteeringBar;
                lastActTime = r.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? 0 : computer.core.path.ControlDelay);
                states.Enqueue(r);
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            GUILayout.Label(sending ? "Sending " + computer.arrows :
                            (computer.core.computer.roverActive ? DriveDescript : "")
                            , GUI.skin.textField);
            GUILayout.Label(sending ? RTUtils.time(lastActTime - Planetarium.GetUniversalTime()) : (computer.core.computer.roverActive ? TargetDescript : "")
                            , GUI.skin.textField, GUILayout.Width(100));
            GUILayout.EndHorizontal();
        }
示例#24
0
        public override void OnStart(PartModule.StartState state)
        {
            if (broken)
            {
                mode = TrackingModes.BROKEN;
                List <Transform> toRemove = new List <Transform>();
                RTUtils.findTransformsWithCollider(part.FindModelTransform(Pivot1Name), ref toRemove);
                foreach (Transform t in toRemove)
                {
                    Destroy(t.gameObject);
                }

                if (this.MaximumDrag > 0)
                {
                    part.minimum_drag = this.MinimumDrag;
                    part.maximum_drag = this.MaximumDrag;
                }

                EnergyDrain = antennaRange = dishRange = 0;
                part.SendMessage("UpdateGUI");
                UpdatePA();
                RTGlobals.network = new RelayNetwork();
                return;
            }

            Actions["Mode1Action"].guiName  = Events["Mode1Event"].guiName = Mode1Name;
            Actions["Mode0Action"].guiName  = Events["Mode0Event"].guiName = Mode0Name;
            Actions["ActionToggle"].guiName = ToggleName;

            Events["OverrideMode1Event"].guiName = "Override " + Mode1Name;
            Events["OverrideMode0Event"].guiName = "Override " + Mode0Name;

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

            if (animState == 1)
            {
                act1();

                anim[Animation].speed = Mathf.Abs(anim[Animation].speed);

                mode = TrackingModes.TRACKING;

                anim.Play(Animation);
            }
            else
            {
                act0();

                anim[Animation].speed = -Mathf.Abs(anim[Animation].speed);

                mode = TrackingModes.RETRACTED;

                anim.Play(Animation);
            }

            anim[Animation].wrapMode = WrapMode.Clamp;

            base.OnStart(state);

            if (state != StartState.Editor)
            {
                Pivot2Dir = part.FindModelTransform(Pivot2Name);

                pivot1 = new Pivot(part.FindModelTransform(Pivot1Name), Pivot1Speed, Pivot1Range);
                pivot2 = new Pivot(Pivot2Dir, Pivot2Speed, Pivot2Range);

                if (animState == 1)
                {
                    mode = TrackingModes.TRACKING;
                    if (target.isTarget)
                    {
                        pivot1.SnapToTarget(target.position);
                        pivot2.SnapToTarget(target.position);
                    }
                }
            }

            anim[Animation].normalizedTime = animState;
        }
示例#25
0
        public void SettingsGUI(int windowID)
        {
            try
            {
                this.vesselName = GUILayout.TextField(this.vesselName);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Save & Close", new GUIStyle(GUI.skin.button)))
                {
                    SaveAndClose();
                }
                if (GUILayout.Button("Close without saving", new GUIStyle(GUI.skin.button)))
                {
                    Close();
                }
                GUILayout.EndHorizontal();


                SettingListScroll = GUILayout.BeginScrollView(SettingListScroll, false, true);

                foreach (SatSettingNode setupnode in settingNodes)
                {
                    setupnode.SubmenuOpen = GUILayout.Toggle(setupnode.SubmenuOpen, setupnode.antennaName + "(" + RTUtils.length(setupnode.dishRange * 1000) + "m) Pointed At: " + setupnode.pointedAt.Name, new GUIStyle(GUI.skin.button));

                    if (setupnode.SubmenuOpen)
                    {
                        setupnode.ListTargets();
                    }
                }

                GUILayout.EndScrollView();
                GUI.DragWindow();
            }
            catch (NullReferenceException)
            { this.Close(); }
        }
示例#26
0
        public override void OnUpdate()
        {
            if (!flightStarted)
            {
                return;
            }

            switch (mode)
            {
            case TrackingModes.BROKEN:
                return;

            case TrackingModes.TRACKING:
                if (target.isTarget && powered)
                {
                    pivot1.RotToTarget(target.position);
                    pivot2.RotToTarget(target.position);
                }
                break;

            case TrackingModes.EXTENDING:
                if (!anim.IsPlaying(Animation))
                {
                    mode = TrackingModes.TRACKING;
                }
                break;

            case TrackingModes.RETRACTING:
                if (!anim.IsPlaying(Animation))
                {
                    mode = TrackingModes.RETRACTED;
                }
                break;

            case TrackingModes.RESETTING:
                if (pivot1.RotToOrigin() & pivot2.RotToOrigin())
                {
                    anim[Animation].speed = -Mathf.Abs(anim[Animation].speed);

                    anim.Play(Animation);

                    if (anim[Animation].normalizedTime == 0)
                    {
                        anim[Animation].normalizedTime = 1;
                    }
                    mode = TrackingModes.RETRACTING;
                }
                break;
            }

            if (EnergyDrain1 > 0)
            {
                RequestPower();
            }

            if (vessel != null && RTUtils.PhysicsActive)
            {
                if (willWakeInPanic && animState == 0 && !InControl && !anim.IsPlaying(Animation))
                {
                    SetMode1();
                    UpdateGUI();
                }


                if (MaxQ > 0 && mode != TrackingModes.RETRACTED && vessel.atmDensity > 0 && (Math.Pow(RTUtils.DirectionalSpeed(Pivot2Dir.up, vessel.srf_velocity), 2) * vessel.atmDensity * 0.5) > MaxQ)
                {
                    broken = true;
                    mode   = TrackingModes.BROKEN;
                    List <Transform> toRemove = new List <Transform>();
                    RTUtils.findTransformsWithCollider(part.FindModelTransform(Pivot1Name), ref toRemove);

                    foreach (Transform t in toRemove)
                    {
                        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.tf      = t;
                        dm.rb      = rb;
                        dm.dc      = ShrapnelDragCoeff;
                        dm.mb      = vessel.mainBody;
                    }

                    if (this.MaximumDrag > 0)
                    {
                        part.minimum_drag = this.MinimumDrag;
                        part.maximum_drag = this.MaximumDrag;
                    }

                    EnergyDrain = antennaRange = dishRange = 0;
                    part.SendMessage("UpdateGUI");
                    UpdatePA();
                    RTGlobals.network = new RelayNetwork();
                }
            }
        }
示例#27
0
        public void draw()
        {
            GUILayout.Label("Throttle: " + Mathf.RoundToInt(ThrottleBar * 100) + "%", GUI.skin.textField);
            ThrottleBar = GUILayout.HorizontalSlider(ThrottleBar, 0, 1);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button(BT ? "Burn time (s)" : "ΔV (m/s)", GUI.skin.textField, GUILayout.Width(100)))
            {
                BT = !BT;
            }
            BTS = GUILayout.TextField(BTS, GUILayout.Width(50));
            BTS = RTUtils.FormatNumString(BTS, false);
            if (GUILayout.Button("Send", GUI.skin.textField) && (computer.core.localControl || computer.core.InContact))
            {
                ThrottleState tmp = new ThrottleState();
                tmp.Throttle = ThrottleBar;
                if (BTS.EndsWith("."))
                {
                    BTS = BTS.Substring(0, BTS.Length - 1);
                }
                tmp.Target  = Convert.ToSingle(BTS);
                tmp.Bt      = BT;
                lastActTime = tmp.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? (double)burnAt :
                                                                              (computer.core.path.ControlDelay <= (double)burnAt ? (double)burnAt : computer.core.path.ControlDelay)
                                                                              );
                states.Enqueue(tmp);
                BTS     = "";
                burnAts = "";
                burnAt  = 0;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label(sending ? "Sending " + computer.arrows : (burning && state.Bt ? "Burning" : (BTS == "" ? "" : "in HH:MM:SS")), GUI.skin.textField, GUILayout.Width(100));

            if (BTS == "")
            {
                GUILayout.Label(sending ? RTUtils.time((lastActTime - Planetarium.GetUniversalTime() > 0) ? lastActTime - Planetarium.GetUniversalTime() : 0) :
                                (burning && state.Bt ? RTUtils.time((state.Target - Planetarium.GetUniversalTime() > 0) ? state.Target - Planetarium.GetUniversalTime() : 0) : "")
                                , GUI.skin.textField, GUILayout.Width(100));
            }
            else
            {
                burnAts = GUILayout.TextField(burnAts, GUILayout.Width(100));
                List <String> temp = burnAts.Split(":".ToCharArray()).ToList();
                string        seconds = "", minutes = "", hours = "", days = "";

                while (temp.Count < 4)
                {
                    temp.Insert(0, "");
                }

                seconds = RTUtils.TFormat(temp[3]);
                burnAt  = Convert.ToSingle(seconds == "" ? "0" : seconds);
                burnAts = seconds;

                if (temp[2] != "")
                {
                    minutes = RTUtils.TFormat(temp[2]);
                    burnAt += Convert.ToSingle(minutes == "" ? "0" : minutes) * 60;
                    burnAts = minutes == "" ? burnAts : (minutes + ":" + burnAts);
                }

                if (temp[1] != "")
                {
                    hours   = RTUtils.TFormat(temp[1]);
                    burnAt += Convert.ToSingle(hours == "" ? "0" : hours) * 3600;
                    burnAts = hours == "" ? burnAts : (hours + ":" + burnAts);
                }

                if (temp[0] != "")
                {
                    days    = RTUtils.TFormat(temp[0]);
                    burnAt += Convert.ToSingle(days == "" ? "0" : days) * 86400;
                    burnAts = days == "" ? burnAts : (days + ":" + burnAts);
                }
            }

            GUILayout.EndHorizontal();
        }