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);
        }
        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);
        }
        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);
        }
Example #4
0
 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);
     }
 }
 private void SwitchControl()
 {
     if (_selected == null)
     {
         ErrorPopup.Error("No vessel selected");
         return;
     }
     FlightGlobals.SetActiveVessel(_selected);
 }
Example #6
0
 private void HostSession()
 {
     if (Network.isClient || Network.isServer)
     {
         ErrorPopup.Error("Cannot host server: Already connected");
         return;
     }
     Network.InitializeServer(10, Port, !Network.HavePublicAddress());
 }
 private void Delete()
 {
     if (_selected == null)
     {
         ErrorPopup.Error("No vessel selected");
         return;
     }
     _selected.Die();
     _selected = null;
     UpdateContents();
 }
        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");
            }
        }
        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
            };
        }
Example #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();
 }
Example #11
0
 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);
 }
Example #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;
            }
        }
Example #13
0
        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;
        }
Example #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");
            }
        }
Example #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();
        }
Example #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);
        }
Example #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);
        }
Example #18
0
 public void OnFailedToConnect(NetworkConnectionError reason)
 {
     print("Failed to connect: " + reason);
     ErrorPopup.Error("Failed to connect to server: " + reason);
     _updateGui = true;
 }