示例#1
0
 internal Resources(global::Vessel vessel, int stage = -1, bool cumulative = true)
 {
     this.vesselId   = vessel.id;
     this.stage      = stage;
     this.cumulative = cumulative;
     this.partId     = 0;
 }
示例#2
0
        internal static bool Fly(global::Vessel vessel, PilotAddon.ControlInputs state)
        {
            // Get the auto-pilot object. Do nothing if there is no auto-pilot engaged for this vessel.
            if (!engaged.ContainsKey(vessel.id))
            {
                return(false);
            }
            var autoPilot = engaged [vessel.id];

            if (autoPilot == null)
            {
                return(false);
            }
            // If the client that engaged the auto-pilot has disconnected, disengage and reset the auto-pilot
            if (autoPilot.requestingClient != null && !autoPilot.requestingClient.Connected)
            {
                autoPilot.attitudeController.ReferenceFrame = ReferenceFrame.Surface(vessel);
                autoPilot.attitudeController.TargetPitch    = 0;
                autoPilot.attitudeController.TargetHeading  = 0;
                autoPilot.attitudeController.TargetRoll     = double.NaN;
                autoPilot.Disengage();
                return(false);
            }
            // Run the auto-pilot
            autoPilot.SAS = false;
            autoPilot.attitudeController.Update(state);
            return(true);
        }
示例#3
0
文件: Comms.cs 项目: pipi1226/krpc
 internal Comms(global::Vessel vessel)
 {
     if (!RemoteTech.IsAvailable)
     {
         throw new InvalidOperationException("RemoteTech is not installed");
     }
     vesselId = vessel.id;
 }
        private Vector3d GetSrfAtDT(global::Vessel vessel, double deltaTime, CelestialBody body)
        {
            Vector3d obti        = vessel.GetOrbit().getOrbitalVelocityAtUT(Planetarium.GetUniversalTime() + deltaTime).xzy;
            Vector3d rposFromNow = vessel.GetOrbit().getRelativePositionAtUT(Planetarium.GetUniversalTime() + deltaTime).xzy;
            Vector3d refi        = Vector3d.Cross(body.angularVelocity, rposFromNow);

            return(obti - refi);
        }
示例#5
0
 /// <summary>
 /// Construct from a KSP vessel object.
 /// </summary>
 public Vessel(global::Vessel vessel)
 {
     if (ReferenceEquals(vessel, null))
     {
         throw new ArgumentNullException(nameof(vessel));
     }
     Id = vessel.id;
 }
示例#6
0
 internal AutoPilot(global::Vessel vessel)
 {
     if (!engaged.ContainsKey(vessel.id))
     {
         engaged [vessel.id] = null;
     }
     vesselId           = vessel.id;
     attitudeController = new AttitudeController(vessel);
 }
示例#7
0
            internal static void SetGroupOverride(global::Vessel activeVessel, int set)
            {
                MethodInfo methodInfo = activeVessel.GetType().GetMethod("SetGroupOverride");

                if (null != methodInfo)
                {
                    methodInfo.Invoke(activeVessel, new object[] { set });
                }
            }
示例#8
0
 public Vessel(global::Vessel kspVessel)
 {
     this.Id         = kspVessel.id;
     this.Name       = kspVessel.vesselName;
     this.Orbit      = new Orbit(kspVessel.orbit);
     this.Height     = Math.Min(kspVessel.GetHeightFromTerrain(), (float)kspVessel.altitude);
     this.VesselType = (byte)kspVessel.vesselType; // will break if there are ever >256 vessel types
     this.Latitude   = kspVessel.latitude;
     this.Longitude  = kspVessel.longitude;
 }
示例#9
0
文件: Node.cs 项目: zentarul/krpc
        internal Node(global::Vessel vessel, double ut, double prograde, double normal, double radial)
        {
            vesselId = vessel.id;
            var node = vessel.patchedConicSolver.AddManeuverNode(ut);

            if (node.attachedGizmo == null)
            {
                node.AttachGizmo(MapView.ManeuverNodePrefab, FlightGlobals.ActiveVessel.patchedConicRenderer);
            }
            node.OnGizmoUpdated(new Vector3d(radial, normal, prograde), ut);
            InternalNode = node;
        }
示例#10
0
 ReferenceFrame(
     Type type, global::CelestialBody body = null, global::Vessel vessel = null,
     ManeuverNode node = null, Part part = null, ModuleDockingNode dockingPort = null)
 {
     this.type     = type;
     this.body     = body;
     this.vesselId = vessel != null ? vessel.id : Guid.Empty;
     this.node     = node;
     //TODO: is it safe to use a part id of 0 to mean no part?
     this.partId      = part != null ? part.flightID : 0;
     this.dockingPort = dockingPort;
 }
示例#11
0
文件: Node.cs 项目: v0lat1le/krpc
        internal Node(global::Vessel vessel, double ut, double prograde, double normal, double radial)
        {
            vesselId = vessel.id;
            if (InternalVessel.patchedConicSolver == null)
            {
                throw new InvalidOperationException("Cannot add maneuver node");
            }
            var node = vessel.patchedConicSolver.AddManeuverNode(ut);

            node.DeltaV = new Vector3d(radial, normal, prograde);
            Update();
            InternalNode = node;
        }
示例#12
0
文件: Node.cs 项目: v0lat1le/krpc
 /// <summary>
 /// Construct a node from a KSP node.
 /// </summary>
 public Node(global::Vessel vessel, ManeuverNode node)
 {
     if (ReferenceEquals(vessel, null))
     {
         throw new ArgumentNullException(nameof(vessel));
     }
     if (ReferenceEquals(node, null))
     {
         throw new ArgumentNullException(nameof(node));
     }
     vesselId     = vessel.id;
     InternalNode = node;
 }
 public VesselInfo(global::Vessel kspVessel)
 {
     this.id        = kspVessel.id;
     this.name      = kspVessel.vesselName;
     this.type      = (byte)kspVessel.vesselType;
     this.landed    = kspVessel.Landed;
     this.landedAt  = kspVessel.landedAt;
     this.splashed  = kspVessel.Splashed;
     this.situation = (byte)kspVessel.situation;
     this.altitude  = kspVessel.altitude;
     this.latitude  = kspVessel.latitude;
     this.longitude = kspVessel.longitude;
     this.orbit     = new Orbit(kspVessel.orbit);
 }
示例#14
0
 internal AutoPilot(global::Vessel vessel)
 {
     if (!engaged.ContainsKey(vessel.id))
     {
         engaged [vessel.id] = null;
     }
     vesselId           = vessel.id;
     attitudeController = new AttitudeController(vessel);
     this.vessel        = new Services.Vessel(vessel);
     throttleController = new PIDController(0);
     maxAcc             = -1;
     throttleParameter  = 0.5;
     throttleController.SetParameters(0, throttleParameter, 0, -1.0d, 0.0d);
 }
示例#15
0
        Vessel PostUndock(global::Vessel preActiveVessel, global::Vessel[] preVessels, int wait = 0)
        {
            //FIXME: sometimes after undocking, KSP changes it's mind as to what the active vessel is, so we wait for 10 frames before getting the active vessel
            // Wait while the port is docked
            if (wait < 10 || State == DockingPortState.Docked)
            {
                throw new YieldException(new ParameterizedContinuation <Vessel, global::Vessel, global::Vessel[], int> (PostUndock, preActiveVessel, preVessels, wait + 1));
            }
            // Return the vessel that was undocked from
            var activeVessel = FlightGlobals.ActiveVessel;
            var newVessel    = FlightGlobals.Vessels.Except(preVessels).Select(vessel => new Vessel(vessel)).Single();

            return(activeVessel == preActiveVessel ? newVessel : new Vessel(preActiveVessel));
        }
示例#16
0
文件: Control.cs 项目: paperclip/krpc
        internal static void SetSASMode(global::Vessel vessel, SASMode value)
        {
            var mode = value.FromSASMode();

            if (!vessel.Autopilot.CanSetMode(mode))
            {
                throw new InvalidOperationException("Cannot set SAS mode of vessel");
            }
            vessel.Autopilot.SetMode(mode);
            // Update the UI buttons
            var modeIndex   = (int)vessel.Autopilot.Mode;
            var modeButtons = UnityEngine.Object.FindObjectOfType <VesselAutopilotUI> ().modeButtons;

            modeButtons [modeIndex].SetState(true);
        }
示例#17
0
        internal static bool Fly(global::Vessel vessel, PilotAddon.ControlInputs state)
        {
            // Get the auto-pilot object. Do nothing if there is no auto-pilot engaged for this vessel.
            if (!engaged.ContainsKey(vessel.id))
            {
                return(false);
            }
            var autoPilot = engaged [vessel.id];

            if (autoPilot == null)
            {
                return(false);
            }
            // If the client that engaged the auto-pilot has disconnected, disengage and reset the auto-pilot
            if (autoPilot.requestingClient != null && !autoPilot.requestingClient.Connected)
            {
                autoPilot.attitudeController.ReferenceFrame = ReferenceFrame.Surface(vessel);
                autoPilot.attitudeController.TargetPitch    = 0;
                autoPilot.attitudeController.TargetHeading  = 0;
                autoPilot.attitudeController.TargetRoll     = double.NaN;
                autoPilot.Disengage();
                return(false);
            }

            //auto shutdown engine
            if (autoPilot.Speed > autoPilot.ShutdownSpeed)
            {
                autoPilot.vessel.Control.Throttle = 0.0f;
                state.Throttle   = 0.0f;
                autoPilot.maxAcc = -1.0d;
            }

            if (autoPilot.maxAcc >= 0)
            {
                double deltaTime = Time.fixedDeltaTime;
                if (deltaTime > 0.01)
                {
                    double acc      = autoPilot.vessel.Thrust / autoPilot.vessel.Mass;
                    float  throttle = 1.0f + (float)autoPilot.throttleController.Update(autoPilot.maxAcc, acc, deltaTime);
                    state.Throttle = throttle.Clamp(0.01f, 1.0f);
                }
            }

            // Run the auto-pilot
            autoPilot.SAS = false;
            autoPilot.attitudeController.Update(state);
            return(true);
        }
示例#18
0
 internal AutoPilot(global::Vessel vessel)
 {
     if (!engaged.ContainsKey(vessel.id))
     {
         engaged [vessel.id] = null;
     }
     vesselId = vessel.id;
     rotationRateController  = new RotationRateController(vessel);
     ReferenceFrame          = ReferenceFrame.Surface(vessel);
     TargetDirection         = null;
     TargetRoll              = float.NaN;
     RotationSpeedMultiplier = 1f;
     RollSpeedMultiplier     = 1f;
     MaxRollSpeed            = 1f;
     MaxRotationSpeed        = 1f;
 }
        private double getBrakingDistanceForDT(global::Vessel vessel, double t, CelestialBody body, out double shipalt, out double burntime, out Vector3d srf, bool debug)
        {
            Vector3d posFromNow = vessel.GetOrbit().getRelativePositionAtUT(Planetarium.GetUniversalTime() + t);
            double   shipradius = posFromNow.magnitude;

            shipalt = shipradius - body.Radius;

            //hmm. use instant or surface gravity? instant will underestimate brake dist. Surface will overestimate.
            double m_Gravity = body.gravParameter / Math.Pow(shipradius - shipalt / 2, 2.0);

            //use the average!

            srf = GetSrfAtDT(vessel, t, body);
            var    upAxis      = posFromNow.normalized.xzy;
            double ivertDeltaV = -Vector3d.Dot(srf, upAxis);

            if (ivertDeltaV <= 0)
            {
                if (debug)
                {
                    Debug.Log("calc brake: going up (land) " + srf + " " + upAxis + " " + posFromNow + " " + ivertDeltaV);
                }
                burntime = 0;
                return(0);
            }

            double ihDeltaV = Math.Sqrt(srf.sqrMagnitude - ivertDeltaV * ivertDeltaV);
            double loss     = ivertDeltaV == 0 ? 0 : Math.Cos(Math.Atan(ihDeltaV / ivertDeltaV)); //assume ship is always surface retrograde
            double accel    = Vessel.SimulationProcessor.LastStage.totalMass > 0 ? Vessel.SimulationProcessor.LastStage.thrust / Vessel.SimulationProcessor.LastStage.totalMass : 0;
            double vaccel   = accel * loss - m_Gravity;
            double haccel   = accel * (1 - loss);
            double netaccel = Math.Sqrt(vaccel * vaccel + haccel * haccel);

            burntime = srf.magnitude / netaccel;
            double vburnTime = ivertDeltaV / vaccel;
            double bdist     = ivertDeltaV * vburnTime - (0.5) * (vaccel) * vburnTime * vburnTime;

            if (debug)
            {
                Debug.Log("calc brake " + " g " + m_Gravity + " a " + accel + " loss " + loss + " vi " + ivertDeltaV + " hi " + ihDeltaV + " b " + burntime + " vb " + vburnTime);
            }
            return(bdist);
        }
示例#20
0
        internal static bool Fly(global::Vessel vessel, PilotAddon.ControlInputs state)
        {
            // Get the auto-pilot object. Do nothing if there is no auto-pilot engaged for this vessel.
            if (!engaged.ContainsKey(vessel.id))
            {
                return(false);
            }
            var autoPilot = engaged [vessel.id];

            if (autoPilot == null)
            {
                return(false);
            }
            // If the client that engaged the auto-pilot has disconnected, disengage the auto-pilot
            if (autoPilot.requestingClient != null && !autoPilot.requestingClient.Connected)
            {
                autoPilot.Disengage();
                return(false);
            }
            // Run the auto-pilot
            autoPilot.DoAutoPiloting(state);
            return(true);
        }
示例#21
0
文件: Vessel.cs 项目: sopindm/bjeb
        public void update(global::Vessel vessel)
        {
            body.update(vessel);
            orbit.update(vessel.orbit, Planetarium.GetUniversalTime());

            _rootRotation = new Quaternion(vessel.GetTransform().rotation);

            _rotatingFrameVelocity = new Vector3(vessel.mainBody.getRFrmVel(position.unity));

            gravity = new Vector3(FlightGlobals.getGeeForceAtPosition(position.unity));

            altitude = vessel.mainBody.GetAltitude(position.unity);

            UnityEngine.RaycastHit sfc;
            if (UnityEngine.Physics.Raycast(position.unity, -up.unity, out sfc, (float)altitude + 10000.0F, 1 << 15))
            {
                altitude = sfc.distance;
            }
            else if (vessel.mainBody.pqsController != null)
            {
                altitude -= (vessel.mainBody.pqsController.GetSurfaceHeight(UnityEngine.QuaternionD.AngleAxis(vessel.mainBody.GetLongitude(position.unity), Vector3d.down) * UnityEngine.QuaternionD.AngleAxis(vessel.mainBody.GetLatitude(position.unity), Vector3d.forward) * Vector3d.right) - vessel.mainBody.pqsController.radius);
            }

            double altitudeASL = vessel.mainBody.GetAltitude(position.unity);

            double atmosphericPressure = FlightGlobals.getStaticPressure(altitudeASL, vessel.mainBody);

            if (atmosphericPressure < vessel.mainBody.atmosphereMultiplier * 1e-6)
            {
                atmosphericPressure = 0;
            }

            atmosphericDensity = FlightGlobals.getAtmDensity(atmosphericPressure);

            //parts (info for rcs, engines, intakes, tanks)
        }
示例#22
0
 ReferenceFrame(
     ReferenceFrameType type, global::CelestialBody body = null, global::Vessel vessel = null,
     ManeuverNode node             = null, Part part             = null, ModuleDockingNode dockingPort = null,
     Thruster thruster             = null, ReferenceFrame parent = null,
     ReferenceFrame hybridPosition = null, ReferenceFrame hybridRotation        = null,
     ReferenceFrame hybridVelocity = null, ReferenceFrame hybridAngularVelocity = null)
 {
     this.type = type;
     this.body = body;
     vesselId  = vessel != null ? vessel.id : Guid.Empty;
     this.node = node;
     //TODO: is it safe to use a part id of 0 to mean no part?
     if (part != null)
     {
         partId = part.flightID;
     }
     this.dockingPort           = dockingPort;
     this.thruster              = thruster;
     this.parent                = parent;
     this.hybridPosition        = hybridPosition;
     this.hybridRotation        = hybridRotation;
     this.hybridVelocity        = hybridVelocity;
     this.hybridAngularVelocity = hybridAngularVelocity;
 }
示例#23
0
文件: Orbit.cs 项目: pipi1226/krpc
 internal Orbit(global::Vessel vessel)
 {
     InternalOrbit = vessel.GetOrbit();
 }
示例#24
0
文件: Control.cs 项目: paperclip/krpc
 internal static SASMode GetSASMode(global::Vessel vessel)
 {
     return(vessel.Autopilot.Mode.ToSASMode());
 }
示例#25
0
文件: Control.cs 项目: paperclip/krpc
 internal Control(global::Vessel vessel)
 {
     vesselId = vessel.id;
 }
示例#26
0
文件: Flight.cs 项目: lucaelin/krpc
 internal Flight(global::Vessel vessel, ReferenceFrame referenceFrame)
 {
     vesselId            = vessel.id;
     this.referenceFrame = referenceFrame;
 }
示例#27
0
        static string getKSCBiome(global::Vessel vessel)
        {
            var at = vessel.landedAt;

            return(at == "KSC" ? at : at.Replace("KSC", string.Empty).Replace("Grounds", string.Empty).Replace("_", string.Empty));
        }
示例#28
0
 public RotationRateController(global::Vessel vessel)
 {
     this.vessel = vessel;
 }
示例#29
0
 internal static ReferenceFrame SurfaceVelocity(global::Vessel vessel)
 {
     return(new ReferenceFrame(ReferenceFrameType.VesselSurfaceVelocity, vessel: vessel));
 }
示例#30
0
 internal static ReferenceFrame Orbital(global::Vessel vessel, ManeuverNode node)
 {
     return(new ReferenceFrame(ReferenceFrameType.ManeuverOrbital, vessel: vessel, node: node));
 }
示例#31
0
        /// <summary>
        /// Vector from given vessel to north pole of body being orbited, in world space.
        /// </summary>
        static Vector3d ToNorthPole(global::Vessel vessel)
        {
            var parent = vessel.mainBody;

            return(parent.position + ((Vector3d)parent.transform.up) * parent.Radius - (vessel.findWorldCenterOfMass()));
        }