Ejemplo n.º 1
0
        public void FixedUpdate()
        {
            if (_doBoost == false)
            {
                return;
            }
            if (FlightGlobals.fetch == null || FlightGlobals.ActiveVessel == null)
            {
                _doBoost = false;
                return;
            }
            var vessel = FlightGlobals.ActiveVessel;
            var toAdd  = vessel.transform.up;

            toAdd *= (float)Speed;
            vessel.ChangeWorldVelocity(toAdd);
            RateLimitedLogger.Log(_boostLogObject,
                                  $"Booster changed vessel's velocity by {toAdd.x},{toAdd.y},{toAdd.z} (mag {toAdd.magnitude})");
        }
Ejemplo n.º 2
0
 private static void SetResource(Vessel vessel, string key, double value)
 {
     if (vessel.parts == null)
     {
         return;
     }
     foreach (var part in vessel.parts)
     {
         foreach (PartResource resource in part.Resources)
         {
             if (resource.resourceName == key)
             {
                 part.TransferResource(resource.info.id, resource.maxAmount * value - resource.amount);
                 RateLimitedLogger.Log(SetResourceLogObject,
                                       $"Set part \"{part.partName}\"'s resource \"{resource.resourceName}\" to {value*100}% by requesting {resource.maxAmount*value - resource.amount} from it");
             }
         }
     }
 }
Ejemplo n.º 3
0
        private static void HardsetOrbit(OrbitDriver orbitDriver, Orbit newOrbit)
        {
            var orbit = orbitDriver.orbit;

            orbit.inclination         = newOrbit.inclination;
            orbit.eccentricity        = newOrbit.eccentricity;
            orbit.semiMajorAxis       = newOrbit.semiMajorAxis;
            orbit.LAN                 = newOrbit.LAN;
            orbit.argumentOfPeriapsis = newOrbit.argumentOfPeriapsis;
            orbit.meanAnomalyAtEpoch  = newOrbit.meanAnomalyAtEpoch;
            orbit.epoch               = newOrbit.epoch;
            orbit.referenceBody       = newOrbit.referenceBody;
            orbit.Init();
            orbit.UpdateFromUT(Planetarium.GetUniversalTime());
            if (orbit.referenceBody != newOrbit.referenceBody)
            {
                orbitDriver.OnReferenceBodyChange?.Invoke(newOrbit.referenceBody);
            }
            RateLimitedLogger.Log(HardsetOrbitLogObject,
                                  $"Orbit \"{orbitDriver.OrbitDriverToString()}\" changed to: inc={orbit.inclination} ecc={orbit.eccentricity} sma={orbit.semiMajorAxis} lan={orbit.LAN} argpe={orbit.argumentOfPeriapsis} mep={orbit.meanAnomalyAtEpoch} epoch={orbit.epoch} refbody={orbit.referenceBody.CbToString()}");
        }
Ejemplo n.º 4
0
        public void FixedUpdate()
        {
            //Debug.Log ("LanderAttachment.FixedUpdate");

            var vessel = GetComponent <Vessel>();

            if (vessel != FlightGlobals.ActiveVessel)
            {
                Destroy(this);
                return;
            }
            if (AlreadyTeleported)
            {
                //Debug.Log ("FixedUpdate: AlreadyTeleported");
                if (vessel.LandedOrSplashed)
                {
                    Destroy(this);
                }
                else
                {
                    var accel = (vessel.srf_velocity + vessel.upAxis) * -0.5;
                    vessel.ChangeWorldVelocity(accel);
                    RateLimitedLogger.Log(_accelLogObject,
                                          $"(Happening every frame) Soft-lander changed ship velocity this frame by vector {accel.x},{accel.y},{accel.z} (mag {accel.magnitude})");
                }
            }
            else
            {
                //Debug.Log ("FixedUpdate: not AlreadyTeleported");
                var pqs = Body.pqsController;
                if (pqs == null)
                {
                    Destroy(this);
                    return;
                }
                var alt = pqs.GetSurfaceHeight(Body.GetRelSurfaceNVector(Latitude, Longitude)) - Body.Radius;
                alt = Math.Max(alt, 0); // Underwater!
                if (TimeWarp.CurrentRateIndex != 0)
                {
                    TimeWarp.SetRate(0, true);
                    Extensions.Log("Set time warp to index 0");
                }
                // HoldVesselUnpack is in display frames, not physics frames
                //Debug.Log("alt: " + alt.ToString() + "   Altitude: " + Altitude.ToString());
                //Debug.Log ("Latitude: " + Latitude.ToString () + "   Longitude: " + Longitude.ToString ());

                //var teleportPosition = Body.GetRelSurfacePosition(Latitude, Longitude, alt +Altitude);
                Vector3d teleportPosition;
                if (!teleportedToLandingAlt)
                {
                    //Debug.Log("teleportedToLandingAlt == false, intermAltitude: " + intermAltitude.ToString() + "  Altitude: " + Altitude.ToString());
                    if (intermAltitude > Altitude)
                    {
                        if (Planetarium.GetUniversalTime() - lastUpdate >= 0.5)
                        {
                            intermAltitude = intermAltitude / 10;
                            //Debug.Log("Planetarium.GetUniversalTime (): " + Planetarium.GetUniversalTime ().ToString() + "   lastUpdate: " + lastUpdate.ToString());
                            //Debug.Log("intermAltitude: " + intermAltitude.ToString());
                            teleportPosition = Body.GetRelSurfacePosition(Latitude, Longitude, alt + intermAltitude);
                            if (lastUpdate != 0)
                            {
                                intermAltitude = Altitude;
                            }
                            lastUpdate = Planetarium.GetUniversalTime();
                        }
                        else
                        {
                            //Debug.Log("teleportPositionAltitude (no time change): alt: " + alt.ToString() + "   intermAltitude: " + intermAltitude.ToString());
                            teleportPosition = Body.GetRelSurfacePosition(Latitude, Longitude, alt + intermAltitude);
                        }
                    }
                    else
                    {
                        //Debug.Log("teleportedToLandingAlt set to true");
                        teleportedToLandingAlt = true;
                        teleportPosition       = Body.GetRelSurfacePosition(Latitude, Longitude, alt + Altitude);
                    }
                }
                else
                {
                    teleportPosition = Body.GetRelSurfacePosition(Latitude, Longitude, alt + Altitude);
                }

                var teleportVelocity = Vector3d.Cross(Body.angularVelocity, teleportPosition);
                //var teleportVelocity = Vector3d.Cross(Vector3d.down, teleportPosition.normalized)*
                //                       (Math.Cos(L atitude*(Math.PI/180))*teleportPosition.magnitude*
                //                        (Math.PI*2)/(Body.rotationPeriod));

                // convert from world space to orbit space
                teleportPosition = teleportPosition.xzy;
                teleportVelocity = teleportVelocity.xzy;
                // counter for the momentary fall when on rails (about one second)
                teleportVelocity += teleportPosition.normalized * (Body.gravParameter / teleportPosition.sqrMagnitude);

                Quaternion rotation;
                if (SetRotation)
                {
                    var from = Vector3d.up;
                    var to   = teleportPosition.xzy.normalized;
                    rotation = Quaternion.FromToRotation(from, to);
                }
                else
                {
                    var oldUp = vessel.orbit.pos.xzy.normalized;
                    var newUp = teleportPosition.xzy.normalized;
                    rotation = Quaternion.FromToRotation(oldUp, newUp) * vessel.vesselTransform.rotation;
                }

                var orbit = vessel.orbitDriver.orbit.Clone();
                orbit.UpdateFromStateVectors(teleportPosition, teleportVelocity, Body, Planetarium.GetUniversalTime());
                vessel.SetOrbit(orbit);
                vessel.SetRotation(rotation);
                if (teleportedToLandingAlt)
                {
                    AlreadyTeleported = true;
                }
            }
        }