예제 #1
0
        private void travelAtWarp()
        {
            if (throttleLevel <= 0f)
            {
                return;
            }

            // Calculate offset position
            warpDistance = kLightSpeed * maxWarpSpeed * throttleLevel * TimeWarp.fixedDeltaTime;
            Transform refTransform   = this.part.vessel.transform;
            Vector3   warpVector     = refTransform.up * warpDistance;
            Vector3d  offsetPosition = refTransform.position + warpVector;

            // Make sure that we won't run into a celestial body.
            if (previousBody != this.part.orbit.referenceBody)
            {
                previousBody = this.part.orbit.referenceBody;
                bodyBounds   = previousBody.getBounds();
            }
            if (bodyBounds.Contains(offsetPosition))
            {
                ScreenMessages.PostScreenMessage(kTerrainWarning, 3.0f, ScreenMessageStyle.UPPER_CENTER);
                FlightInputHandler.state.mainThrottle = 0;
                return;
            }

            // Apply translation.
            FloatingOrigin.SetOutOfFrameOffset(offsetPosition);
        }
        public void FixedUpdate()
        {
            try
            {
                if (!HighLogic.LoadedSceneIsFlight)
                {
                    return;
                }

                if (eModule == null)
                {
                    SetupDrive();
                }

                if (IsDeployed != eModule.getIgnitionState)
                {
                    IsDeployed = eModule.getIgnitionState;
                    CheckBubbleDeployment(3);
                    SetPartState(eModule.getIgnitionState);
                }

                if (IsDeployed)
                {
                    //Failsafe
                    if (!CheckAltitude())
                    {
                        eModule.Shutdown();
                        return;
                    }

                    //Snip parts
                    DecoupleBubbleParts();

                    //OH NO FLAMEOUT!
                    if (eModule.flameout)
                    {
                        print("Flameout");
                        BubbleCollapse(eModule.currentThrottle);
                        FlightInputHandler.state.mainThrottle = 0;
                        IsDeployed = false;
                        return;
                    }

                    PlayWarpAnimation(eModule.currentThrottle);
                    GravityBrake();
                    //Start by adding in our subluminal speed which is exponential
                    double lowerThrottle = (Math.Min(eModule.currentThrottle, SUBLIGHT_THROTTLE) * SUBLIGHT_MULT);
                    double distance      = Math.Pow(lowerThrottle, SUBLIGHT_POWER);

                    //Then if throttle is over our threshold, go linear
                    if (eModule.currentThrottle > SUBLIGHT_THROTTLE)
                    {
                        //How much headroom do we have
                        double maxSpeed = ((LIGHTSPEED * WarpFactor) - distance);
                        //How much of this can we use?
                        var upperThrottle = eModule.currentThrottle - SUBLIGHT_THROTTLE;
                        //How much of this headroom have we used?
                        var throttlePercent = upperThrottle / (1 - SUBLIGHT_THROTTLE);
                        //Add it to our current throttle calculation
                        var additionalDistance = maxSpeed * throttlePercent;
                        distance += additionalDistance;
                    }


                    //Take into acount safe accelleration/decelleration
                    //if (distance > CurrentSpeed + Math.Pow(10,MaxAccelleration))
                    //	distance = CurrentSpeed + Math.Pow(10, MaxAccelleration);
                    //if (distance < CurrentSpeed - Math.Pow(10, MaxAccelleration))
                    //	distance = CurrentSpeed - Math.Pow(10, MaxAccelleration);
                    //CurrentSpeed = distance;

                    //if (distance > 1000)
                    //{
                    //Let's see if we can get rid of precision issues with distance.
                    //	Int32 precision = Math.Round(distance, 0).ToString().Length - 1;
                    //	if (precision > MaxAccelleration) precision = MaxAccelleration;
                    //	var magnitude = Math.Round((distance / Math.Pow(10, precision)),0);
                    //	var jumpDistance = Math.Pow(10,precision) * magnitude;
                    //	distance = jumpDistance;
                    //}

                    double maxspeeddisp = Math.Pow(LIGHTSPEED * WarpFactor, GravityBrakes) / LIGHTSPEED;
                    double ts           = WarpFactor * (TurboPoint / 100d);
                    if (maxspeeddisp >= ts)
                    {
                        distance     = distance / (Math.Log(1 / GravityBrakes) + (1 / (TurboFactor * TurboMult)));
                        maxspeeddisp = maxspeeddisp / (Math.Log(1 / GravityBrakes) + (1 / (TurboFactor * TurboMult)));
                    }
                    if (eModule.currentThrottle > MinThrottle)
                    {
                        // Translate through space on the back of a Kraken!
                        if (maxspeeddisp >= minMaxSpeed)
                        {
                            distance = Math.Pow(distance, GravityBrakes) * TimeWarp.fixedDeltaTime;
                        }
                        else
                        {
                            distance     = minMaxSpeed * LIGHTSPEED * TimeWarp.fixedDeltaTime;
                            maxspeeddisp = minMaxSpeed;
                        }
                        Vector3d ps = FlightGlobals.ActiveVessel.transform.position + (transform.up * (float)distance);
                        //krakensbane.setOffset(ps);
                        FloatingOrigin.SetOutOfFrameOffset(ps);

                        //AngularMomentum Block
                        if (AMConservationMode == true)
                        {
                            ApplyAngularMomentum();
                        }
                    }
                    if (AMConservationMode == true && eModule.currentThrottle == 0)
                    {
                        SetAMStartStateVars();
                    }
                    double speedcdisp = (distance) / (LIGHTSPEED * TimeWarp.fixedDeltaTime);
                    status = String.Format("{0:g3}c [Max {1:f3}c] T@{2:f3}c", speedcdisp, maxspeeddisp, ts);
                }
            }
            catch (Exception ex)
            {
                print(String.Format("[WARP] Error in OnFixedUpdate - {0}", ex.Message));
            }
        }