Example #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (isOnPlanet)
        {
            return;
        }

        CelestialBody cb = other.gameObject.GetComponent <CelestialBody>();

        if (cb != null && cb.Equals(targetPlanet))
        {
            cb.TroopArrival(this);
            SetCurrentCelestialBody(cb);
        }
    }
Example #2
0
            // BROKEN: needs to b fixed
            public static CelestialBody GetOutermostPlanet()
            {
                CelestialBody result          = null;
                double        distanceFromSun = 0;

                CelestialBody center = GetKerbol();

                if (center == null)
                {
                    Log.Error("no central star found; cant get outermost planet");
                    return(null);
                }

                if (PSystemManager.Instance == null || PSystemManager.Instance.localBodies == null)
                {
                    return(null);
                }
                foreach (CelestialBody body in PSystemManager.Instance.localBodies)
                {
                    //Log.Test("testing "+body.name);
                    if (body.orbit != null)
                    {
                        Orbit orbit = body.orbit;
                        if (center.Equals(orbit.referenceBody))
                        {
                            //Log.Test("OUTMOST " + body.name + " " + body.orbit);
                            //Log.Test("ORBIT");
                            double d = body.orbit.ApA;
                            //Log.Test("outmost APA=" + d);
                            if (d > distanceFromSun)
                            {
                                result          = body;
                                distanceFromSun = d;
                            }
                        }
                    }
                }
                if (result == null)
                {
                    Log.Error("no outmost celestial body found");
                }
                return(result);
            }
Example #3
0
    public void SetCelestialBody(CelestialBody cb, bool initializeAnyways = false)
    {
        if (cb.Equals(circularBody) && !initializeAnyways)
        {
            return;
        }

        circularBody = cb;

        // Calculate new coordinates
        Vector2 dist = new Vector2(transform.position.x - circularBody.transform.position.x, transform.position.y - circularBody.transform.position.y);

        theta  = Mathf.Atan2(dist.x, dist.y);
        radius = dist.magnitude;

        curGravity = -circularBody.gravity;

        positionUpdate = updateAll;

        enabled = true;
    }
Example #4
0
            // TODO: move to EventObserver
            private void FireCustomEvents()
            {
                // detect events only in flight
                if (HighLogic.LoadedScene != GameScenes.FLIGHT)
                {
                    return;
                }
                //
                Vessel vessel = FlightGlobals.ActiveVessel;

                if (vessel != null)
                {
                    // undetected SOI change (caused by hyperedit or other mods)
                    if (currentSphereOfInfluence == null || !currentSphereOfInfluence.Equals(vessel.mainBody))
                    {
                        OnVesselSOIChanged(new GameEvents.HostedFromToAction <Vessel, CelestialBody>(vessel, currentSphereOfInfluence, vessel.mainBody));
                    }
                    // Orbit closed
                    bool inOrbit = vessel.isInStableOrbit();
                    if (inOrbit && !orbitClosed)
                    {
                        Log.Info("orbit closed detected for vessel " + vessel.name);
                        OnVesselOrbitClosed(vessel);
                    }
                    orbitClosed = inOrbit;
                    //
                    // deep atmosphere
                    double atmDensity = vessel.atmDensity;
                    if (!deepAthmosphere && atmDensity >= 10.0)
                    {
                        Log.Trace("vessel entering deep athmosphere");
                        deepAthmosphere = true;
                        OnEnteringDeepAthmosphere(vessel);
                    }
                    else if (deepAthmosphere && atmDensity < 10.0)
                    {
                        deepAthmosphere = false;
                    }
                }
                else
                {
                    orbitClosed     = false;
                    deepAthmosphere = false;
                }
                //
                // G-force increased
                bool geeForceStateChanged = geeForceObserver.StateHasChanged();

                if (geeForceStateChanged)
                {
                    VesselObserver.Instance().SetGeeForceSustained(vessel, geeForceObserver.GetGeeNumber());
                }
                // Mach increased
                // AtmosphereChanged
                // Orbit changed
                // gee force changed
                if (machObserver.StateHasChanged() || atmosphereObserver.StateHasChanged() || orbitObserver.StateHasChanged() || geeForceStateChanged)
                {
                    CheckAchievementsForVessel(vessel);
                }
            }