コード例 #1
0
        public void SliderUpdate(float value)
        {
            var body = FlightGlobals.Bodies.FirstOrDefault(c => c.bodyName.ToLower() == (FindField <TextBox, string>("body") ?? "").ToLower());

            if (body == null)
            {
                ErrorPopup.Error("Unknown body");
                return;
            }
            var pe    = (double)FindField <Slider, float>("pe");
            var ratio = body.sphereOfInfluence / (body.Radius + body.maxAtmosphereAltitude);

            pe  = Math.Pow(ratio, pe) / ratio;
            pe *= body.sphereOfInfluence;
            var e         = Math.Tan(FindField <Slider, float>("e"));
            var semimajor = pe / (1 - e);

            _setTo = Core.CreateOrbit(FindField <Slider, float>("inc"),
                                      e,
                                      semimajor,
                                      FindField <Slider, float>("lan"),
                                      FindField <Slider, float>("w"),
                                      FindField <Slider, float>("mEp"),
                                      FlightGlobals.ActiveVessel.orbit.epoch,
                                      body);
        }
コード例 #2
0
        private void ApplyForce()
        {
            double prgVel, nrmVel, radVel;

            if (UnitParser.Parse(FindField <TextBox, string>("prograde") ?? FindField <TextBox, string>("up"), "m/s", out prgVel) == false ||
                UnitParser.Parse(FindField <TextBox, string>("normal+") ?? FindField <TextBox, string>("north"), "m/s", out nrmVel) == false ||
                UnitParser.Parse(FindField <TextBox, string>("rad+") ?? FindField <TextBox, string>("east"), "m/s", out radVel) == false)
            {
                ErrorPopup.Error("A force parameter was not a number");
                return;
            }
            Vector3d prograde, normal, rad;

            if (_orbitReference)
            {
                prograde = FlightGlobals.ActiveVessel.orbit.GetWorldSpaceVel().normalized;
                normal   = Vector3d.Cross(prograde, FlightGlobals.ActiveVessel.upAxis);
                rad      = Vector3d.Cross(normal, prograde);
            }
            else
            {
                prograde = FlightGlobals.ActiveVessel.upAxis;
                rad      = FlightGlobals.ActiveVessel.mainBody.getRFrmVel(FlightGlobals.ActiveVessel.GetWorldPos3D()).normalized;
                normal   = Vector3d.Cross(prograde, rad);
            }
            var finalForce = prograde * prgVel + normal * nrmVel + rad * radVel;

            FlightGlobals.ActiveVessel.ChangeWorldVelocity(finalForce);
        }
コード例 #3
0
        private void SaveCoords(string s)
        {
            if (string.IsNullOrEmpty(s) || s.Contains(' '))
            {
                ErrorPopup.Error("Name cannot be empty or contain whitespace");
                return;
            }
            double latitude, longitude;

            if (UnitParser.Parse(FindField <TextBox, string>("latitude"), "", out latitude) == false || UnitParser.Parse(FindField <TextBox, string>("longitude"), "", out longitude) == false)
            {
                ErrorPopup.Error("A parameter was not a number");
                return;
            }
            var alreadyAdded = _saved.Where(saved => saved.Body == FlightGlobals.ActiveVessel.mainBody).FirstOrDefault(saved => saved.Name.ToLower() == s.ToLower());

            if (alreadyAdded == null)
            {
                alreadyAdded = new SavedLatLon();
                _saved.Add(alreadyAdded);
            }
            alreadyAdded.Body   = FlightGlobals.ActiveVessel.mainBody;
            alreadyAdded.LatLon = new LatLon {
                Latitude = latitude, Longitude = longitude
            };
            alreadyAdded.Name = s;
            SaveList();
            ErrorPopup.Error("Saved " + s);
        }
コード例 #4
0
ファイル: Kestrel.cs プロジェクト: net-lisias-ksph/Khylib
 public void VersionCheck(int kspMajor, int kspMinor, int kspRev, int kestrel)
 {
     if (Network.isServer)
     {
         print("Warning: VersionCheck called on server");
         return;
     }
     if (FlightState.lastCompatibleMajor != kspMajor || FlightState.lastCompatibleMinor != kspMinor || FlightState.lastCompatibleRev != kspRev)
     {
         ErrorPopup.Error("Incompatible KSP versions, disconnected");
         print("Incompatible KSP versions\nMine: " + FlightState.lastCompatibleMajor + "." + FlightState.lastCompatibleMinor + "." + FlightState.lastCompatibleRev + "\nTheirs: " + kspMajor + "." + kspMinor + "." + kspRev);
         Network.Disconnect(200);
     }
     else if (NetworkVersion != kestrel)
     {
         ErrorPopup.Error("Incompatible Kestrel versions, disconnected");
         print("Incompatible Kestrel versions\nMine: " + NetworkVersion + "\nTheirs: " + kestrel);
         Network.Disconnect(200);
     }
     else
     {
         print("Saving : " + GamePersistence.SaveGame("kestrel", HighLogic.SaveFolder, SaveMode.OVERWRITE));
         foreach (var vessel in FlightGlobals.Vessels.ToArray())
         {
             vessel.Die();
         }
         networkView.RPC("Handshake", RPCMode.Server);
     }
 }
コード例 #5
0
 private void SwitchControl()
 {
     if (_selected == null)
     {
         ErrorPopup.Error("No vessel selected");
         return;
     }
     FlightGlobals.SetActiveVessel(_selected);
 }
コード例 #6
0
ファイル: Kestrel.cs プロジェクト: net-lisias-ksph/Khylib
 private void HostSession()
 {
     if (Network.isClient || Network.isServer)
     {
         ErrorPopup.Error("Cannot host server: Already connected");
         return;
     }
     Network.InitializeServer(10, Port, !Network.HavePublicAddress());
 }
コード例 #7
0
 private void Delete()
 {
     if (_selected == null)
     {
         ErrorPopup.Error("No vessel selected");
         return;
     }
     _selected.Die();
     _selected = null;
     UpdateContents();
 }
コード例 #8
0
        private void ForceDownChange(string s)
        {
            double newForce;

            if (UnitParser.Parse(s, "m/s/s", out newForce))
            {
                _upForce = newForce;
            }
            else
            {
                ErrorPopup.Error("Force down was not a number");
            }
        }
コード例 #9
0
        private void Land()
        {
            double latitude, longitude;

            if (UnitParser.Parse(FindField <TextBox, string>("latitude"), "", out latitude) == false || UnitParser.Parse(FindField <TextBox, string>("longitude"), "", out longitude) == false)
            {
                ErrorPopup.Error("A parameter was not a number");
                return;
            }
            _toLandAt = new LatLon {
                Latitude = latitude, Longitude = longitude
            };
        }
コード例 #10
0
 public override void Update()
 {
     if (_landing)
     {
         if (FlightGlobals.ActiveVessel.LandedOrSplashed)
         {
             _landing = false;
         }
         else
         {
             var accel = FlightGlobals.ActiveVessel.srf_velocity * -0.5 + FlightGlobals.ActiveVessel.upAxis * -0.5;
             FlightGlobals.ActiveVessel.ChangeWorldVelocity(accel);
         }
     }
     if (_toLandAt != null)
     {
         double raisedAlt;
         if (UnitParser.Parse(FindField <TextBox, string>("altitude"), "m", out raisedAlt) == false)
         {
             ErrorPopup.Error("Altitude was not a number");
             _toLandAt = null;
             return;
         }
         var alt = FlightGlobals.ActiveVessel.mainBody.pqsController.GetSurfaceHeight(
             QuaternionD.AngleAxis(_toLandAt.Longitude, Vector3d.down) *
             QuaternionD.AngleAxis(_toLandAt.Latitude, Vector3d.forward) * Vector3d.right) -
                   FlightGlobals.ActiveVessel.mainBody.pqsController.radius;
         alt = Math.Max(alt, 0); // Underwater!
         var diff = FlightGlobals.ActiveVessel.mainBody.GetWorldSurfacePosition(_toLandAt.Latitude, _toLandAt.Longitude, alt + raisedAlt) - FlightGlobals.ActiveVessel.GetWorldPos3D();
         if (FlightGlobals.ActiveVessel.Landed)
         {
             FlightGlobals.ActiveVessel.Landed = false;
         }
         else if (FlightGlobals.ActiveVessel.Splashed)
         {
             FlightGlobals.ActiveVessel.Splashed = false;
         }
         foreach (var part in FlightGlobals.ActiveVessel.parts.ToArray().Where(part => part.Modules.OfType <LaunchClamp>().Any()))
         {
             part.Die();
         }
         Krakensbane.Teleport(diff);
         FlightGlobals.ActiveVessel.ChangeWorldVelocity(-FlightGlobals.ActiveVessel.obt_velocity);
         //var up = (FlightGlobals.ActiveVessel.CoM - FlightGlobals.ActiveVessel.mainBody.position).normalized;
         //var forward = Vector3.Cross(up, Vector3.down);
         //var targetRot = Quaternion.LookRotation(forward, up);
         _toLandAt = null;
         _landing  = true;
     }
     base.Update();
 }
コード例 #11
0
ファイル: Kestrel.cs プロジェクト: net-lisias-ksph/Khylib
 private void ConnectToIp()
 {
     if (Network.isClient || Network.isServer)
     {
         ErrorPopup.Error("Cannot connect: Already connected");
         return;
     }
     if (FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null)
     {
         ErrorPopup.Error("Cannot connect while in flight mode, please go to KSC.");
         return; // best solution would be main menu option, but I'm not Squad
     }
     Network.Connect(((TextBox)_kestrelWindow.Contents[0]).Value, Port);
 }
コード例 #12
0
        private void Stiffness(string s)
        {
            float n;

            if (float.TryParse(s, out n) == false)
            {
                ErrorPopup.Error("Stiffness was not a number");
            }
            foreach (var collider in FlightGlobals.ActiveVessel.parts.Select(p => p.Modules.OfType <ModuleLandingGear>().FirstOrDefault()).Where(m => m != null).Select(w => w.wheelCollider))
            {
                var curve = collider.sidewaysFriction;
                curve.stiffness           = n;
                collider.sidewaysFriction = curve;
            }
        }
コード例 #13
0
ファイル: Kestrel.cs プロジェクト: net-lisias-ksph/Khylib
        public void OnDisconnectedFromServer(NetworkDisconnection reason)
        {
            print("Disconnected: " + reason);
            ErrorPopup.Error("Disconnected from server: " + reason);
            var game = GamePersistence.LoadGame("kestrel", HighLogic.SaveFolder, false, false);

            if (game == null)
            {
                print("ERROR: Kestrel.sfs persistence file not found! Not reverting to original state!");
            }
            else
            {
                HighLogic.CurrentGame = game;
                HighLogic.CurrentGame.flightState.Load();
            }
            _updateGui = true;
        }
コード例 #14
0
        private void LeadTimeChange(string s)
        {
            double newLeadTime;

            if (UnitParser.Parse(s, "s", out newLeadTime))
            {
                _leadTime = newLeadTime;
            }
            else if (s == "TO THE BOULDER")
            {
                _target = GameObject.Find("Magic Boulder").GetComponent <OrbitDriver>().orbit;
            }
            else
            {
                ErrorPopup.Error("Lead time was not a number");
            }
        }
コード例 #15
0
        private void Set()
        {
            var editing = FlightGlobals.Bodies.FirstOrDefault(c => c.bodyName.ToLower() == (FindField <TextBox, string>("editing") ?? "").ToLower());

            if (editing == null)
            {
                ErrorPopup.Error("Unknown editing body");
                return;
            }
            double inc, e, sma, lan, w, mEp;

            if (UnitParser.Parse(FindField <TextBox, string>("inc"), "", out inc) == false ||
                UnitParser.Parse(FindField <TextBox, string>("e"), "", out e) == false ||
                UnitParser.Parse(FindField <TextBox, string>("sma"), "m", out sma) == false ||
                UnitParser.Parse(FindField <TextBox, string>("lan"), "", out lan) == false ||
                UnitParser.Parse(FindField <TextBox, string>("w"), "", out w) == false ||
                UnitParser.Parse(FindField <TextBox, string>("mEp"), "", out mEp) == false)
            {
                ErrorPopup.Error("An orbital parameter was not a number");
                return;
            }
            var body = FlightGlobals.Bodies.FirstOrDefault(c => c.bodyName.ToLower() == (FindField <TextBox, string>("body") ?? "").ToLower());

            if (body == null)
            {
                ErrorPopup.Error("Unknown body");
                return;
            }
            for (var parentCheckBody = body; ; parentCheckBody = parentCheckBody.referenceBody)
            {
                if (parentCheckBody == editing)
                {
                    ErrorPopup.Error("Error: Self-referential orbit");
                    return;
                }
                if (parentCheckBody.orbitDriver == null)
                {
                    break;
                }
            }
            var newOrbit = Core.CreateOrbit(inc, e, sma, lan, w, mEp, editing.orbit.epoch, body);

            SetPlanet(editing, newOrbit);
            Refresh();
        }
コード例 #16
0
        public void SetSimple()
        {
            double altitude;

            if (UnitParser.Parse(FindField <TextBox, string>("altitude"), "m", out altitude) == false)
            {
                ErrorPopup.Error("Altitude was not a number");
                return;
            }
            var body = FlightGlobals.Bodies.FirstOrDefault(c => c.bodyName.ToLower() == (FindField <TextBox, string>("body") ?? "").ToLower());

            if (body == null)
            {
                ErrorPopup.Error("Unknown body");
                return;
            }
            _setTo = Core.CreateOrbit(0, 0, altitude + body.Radius, 0, 0, 0, FlightGlobals.ActiveVessel.orbit.epoch, body);
        }
コード例 #17
0
        public void SetComplex()
        {
            double inc, e, sma, lan, w, mEp, epoch;
            var    epochText = FindField <TextBox, string>("epoch");

            if (epochText.ToLower() == "now")
            {
                epoch = Planetarium.GetUniversalTime();
            }
            else if (string.IsNullOrEmpty(epochText))
            {
                epoch = FlightGlobals.ActiveVessel.orbit.epoch;
            }
            else if (UnitParser.Parse(epochText, "s", out epoch) == false)
            {
                ErrorPopup.Error("An orbital parameter was not a number");
                return;
            }
            if (UnitParser.Parse(FindField <TextBox, string>("inc"), "", out inc) == false ||
                UnitParser.Parse(FindField <TextBox, string>("e"), "", out e) == false ||
                UnitParser.Parse(FindField <TextBox, string>("sma"), "m", out sma) == false ||
                UnitParser.Parse(FindField <TextBox, string>("lan"), "", out lan) == false ||
                UnitParser.Parse(FindField <TextBox, string>("w"), "", out w) == false ||
                UnitParser.Parse(FindField <TextBox, string>("mEp"), "", out mEp) == false)
            {
                ErrorPopup.Error("An orbital parameter was not a number");
                return;
            }

            var body = FlightGlobals.Bodies.FirstOrDefault(c => c.bodyName.ToLower() == (FindField <TextBox, string>("body") ?? "").ToLower());

            if (body == null)
            {
                ErrorPopup.Error("Unknown body");
                return;
            }
            _setTo = Core.CreateOrbit(inc, e, sma, lan, w, mEp, epoch, body);
        }
コード例 #18
0
ファイル: Kestrel.cs プロジェクト: net-lisias-ksph/Khylib
 public void OnFailedToConnect(NetworkConnectionError reason)
 {
     print("Failed to connect: " + reason);
     ErrorPopup.Error("Failed to connect to server: " + reason);
     _updateGui = true;
 }