示例#1
0
 public static void Teleport(this Krakensbane krakensbane, Vector3d offset)
 {
     foreach (var vessel in FlightGlobals.Vessels.Where(v => v.packed == false && v != FlightGlobals.ActiveVessel))
     {
         vessel.GoOnRails();
     }
     krakensbane.setOffset(offset);
 }
示例#2
0
        public void FixedUpdate()
        {
            try
            {
                if (vessel == null || part == null || _state == StartState.Editor)
                {
                    return;
                }

                if (enhancerPoll <= 0)
                {
                    IsEnhanced        = false;
                    BubbleEnhancement = 0;
                    enhancerPoll      = 25;

                    var enhancer = FindEnhancer();
                    if (enhancer != null)
                    {
                        BubbleEnhancement = enhancer.GetEffectiveness(this);
                        IsEnhanced        = true;
                    }
                }
                else
                {
                    enhancerPoll--;
                }

                if (IsDeployed != IsActivated)
                {
                    IsDeployed = IsActivated;
                    CheckBubbleDeployment(3);
                    SetPartState(IsActivated);
                }

                if (!IsDeployed)
                {
                    part.Effect(idleEffectName, 0.0f);
                }

                if (alertCondition)
                {
                    SetupAlertEvents();
                    alertTimer -= TimeWarp.fixedDeltaTime;
                    if (alertTimer <= 0.0)
                    {
                        CancelRedAlert();
                    }
                    return;
                }

                if (IsDeployed)
                {
                    float currentThrottle = vessel.ctrlState.mainThrottle * (displayWarpFactor / 10.0f);

                    //Failsafe
                    if (deployTimer <= 0.0)
                    {
                        // The Kraken tends to eat things that get close to the bubble
                        if (currentThrottle < MinThrottle)
                        {
                            if (!CheckBubbleDistances())
                            {
                                return;
                            }
                        }

                        if (!CheckAltitude())
                        {
                            ShutdownDrive(false);
                            return;
                        }
                    }

                    if (IsActivated && plasma_gauge == null)
                    {
                        CreateAllGauges();
                    }

                    double dt = (double)TimeWarp.fixedDeltaTime;

                    if (deployTimer > 0.0)
                    {
                        deployTimer -= (float)dt;
                        PlayWarpAnimation(currentThrottle);
                        UpdateAllGauges();
                        return;
                    }


                    part.Effect(idleEffectName, 1.0f);
                    part.Effect(powerEffectName, currentThrottle);

                    bool flameout = false;

                    if (currentThrottle >= MinThrottle)
                    {
                        // Use up Plasma and Electricity to maintain the warp field
                        float plasmaNeeded = (float)(PlasmaMultiply * WarpFactor * currentThrottle * dt);
                        float elecNeeded   = (float)(ElectricMultiply * WarpFactor * currentThrottle * dt);

                        float plasmaUsed = part.RequestResource("WarpPlasma", plasmaNeeded);
                        float elecUsed   = part.RequestResource("ElectricCharge", elecNeeded);
                        if (plasmaUsed < plasmaNeeded || elecUsed < elecNeeded)
                        {
                            flameout = true;
                            SetPlasmaPowerError(plasmaUsed, plasmaNeeded);
                        }
                    }
                    if (UpdateAllGauges())
                    {
                        flameout = true;
                        SetPlasmaPowerError((float)currentPlasma, 1.0f);
                    }

                    //OH NO FLAMEOUT!
                    // (actually it isn't all that bad anymore)
                    if (flameout)
                    {
                        WarningSound();
                        BubbleCollapse();
                        ShutdownDrive(true);
                        return;
                    }

                    PlayWarpAnimation(currentThrottle);

                    if (currentThrottle < MinThrottle)
                    {
                        return;
                    }

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

                    //Then if throttle is over our threshold, go linear
                    if (currentThrottle > SUBLIGHT_THROTTLE)
                    {
                        //How much headroom do we have
                        double maxSpeed = (LIGHTSPEED / 50 * WarpFactor) - distance;
                        //How much of this can we use?
                        var upperThrottle = 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 c = (distance * 50) / LIGHTSPEED;
                    status = String.Format("{1:n0} m/s [{0:0}%c]", c * 100f, distance * 50);
                    if (currentThrottle >= MinThrottle)
                    {
                        // Translate through space on the back of a Kraken!
                        Vector3d    ps          = vessel.transform.position + (transform.up * (float)(distance));
                        Krakensbane krakensbane = (Krakensbane)FindObjectOfType(typeof(Krakensbane));
                        krakensbane.setOffset(ps);
                        //AngularMomentum Block
                        if (AMConservationMode == true)
                        {
                            ApplyAngularMomentum();
                        }
                    }
                    if (AMConservationMode == true && currentThrottle == 0)
                    {
                        SetAMStartStateVars();
                    }
                }
            }
            catch (Exception ex)
            {
                print(String.Format("[WSXWARP] Error in OnFixedUpdate - {0}", ex.Message));
            }
        }