コード例 #1
0
        /// <summary>
        /// StageRecovery handle. This is called first.
        /// </summary>
        /// <param name="data"></param>
        public static void PreRecovery(Vessel vessel)
        {
            Log.Normal("OnVesselRecoveryRequested");
            if (!KerbalKonstructs.instance.disableRemoteRecovery)
            {
                if (MiscUtils.CareerStrategyEnabled(HighLogic.CurrentGame))
                {
                    Log.Normal("OnVesselRecoveryRequested is career");
                    // Change the Space Centre to the nearest open base
                    double dist         = 0d;
                    double smallestDist = 0d;
                    string openCloseState;

                    SpaceCenter spaceCenter        = null;
                    SpaceCenter closestSpaceCenter = SpaceCenter.Instance;

                    smallestDist = SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));
                    Log.Normal("Distance to KSC is " + smallestDist);

                    foreach (CustomSpaceCenter csc in SpaceCenterManager.spaceCenters)
                    {
                        // ASH Get openclosestate of launchsite with same name as space centre
                        openCloseState = csc.staticInstance.launchSite.OpenCloseState;

                        StaticInstance myBase = csc.staticInstance;
                        if (csc.staticInstance.launchSite.RecoveryFactor == 0)
                        {
                            continue;
                        }
                        spaceCenter = csc.getSpaceCenter();
                        dist        = spaceCenter.GreatCircleDistance(spaceCenter.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));

                        if (dist < smallestDist)
                        {
                            if (csc.staticInstance.launchSite.isOpen)
                            {
                                closestSpaceCenter = spaceCenter;
                                smallestDist       = dist;
                                // Debug.Log("KK: closest updated to " + closest.SpaceCenterName + ", distance " + smallestDist);
                            }
                        }
                    }

                    // set the Spacecenter to the closest SpaceCenter, because StageRecovery uses this. We revert this later on the PostRecovery function
                    SpaceCenter.Instance = closestSpaceCenter;
                    Log.Normal("SpaceCenter set to: " + closestSpaceCenter.name);

                    if (SpaceCenter.Instance == null)
                    {
                        Log.Normal("no Spacecenter for recovery found");
                        SpaceCenter.Instance = SpaceCenterManager.KSC;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// StageRecovery handle. This is called first.
        /// </summary>
        /// <param name="data"></param>
        public static void PreRecovery(Vessel vessel)
        {
            Log.Normal("OnVesselRecoveryRequested");
            if (!KerbalKonstructs.instance.disableRemoteRecovery && CareerUtils.isCareerGame)
            {
                Log.Normal("OnVesselRecoveryRequested is career");
                // Change the Space Centre to the nearest open base
                double dist = 0d;

                SpaceCenter spaceCenter        = null;
                SpaceCenter closestSpaceCenter = SpaceCenter.Instance;

                double smallestDist = SpaceCenterManager.KSC.GreatCircleDistance(vessel.mainBody.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));
                Log.Normal("Distance to KSC is " + smallestDist);

                foreach (CustomSpaceCenter csc in SpaceCenterManager.spaceCenters)
                {
                    try
                    {
                        //Log.Normal("Checking LS: " + csc.SpaceCenterName);
                        if (!csc.isOpen)
                        {
                            //Log.Normal("Ignoring closed SC: " + csc.SpaceCenterName);
                            continue;
                        }

                        spaceCenter = csc.GetSpaceCenter();
                        dist        = spaceCenter.GreatCircleDistance(spaceCenter.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));
                        Log.Normal("distance is: " + dist);
                        if (dist < smallestDist)
                        {
                            closestSpaceCenter = spaceCenter;
                            smallestDist       = dist;
                            Log.Normal("KK: closest updated to " + csc.SpaceCenterName + ", distance " + smallestDist);
                        }
                    }
                    catch
                    {
                        Log.UserWarning("Error Processing... " + csc.SpaceCenterName);
                    }
                }

                // set the Spacecenter to the closest SpaceCenter, because StageRecovery uses this. We revert this later on the PostRecovery function
                SpaceCenter.Instance = closestSpaceCenter;
                Log.Normal("SpaceCenter set to: " + closestSpaceCenter.name);

                if (SpaceCenter.Instance == null)
                {
                    Log.Normal("no Spacecenter for recovery found");
                    SpaceCenter.Instance = SpaceCenterManager.KSC;
                }
            }
        }
コード例 #3
0
        public static void getClosestSpaceCenter(Vessel vessel, out SpaceCenter closestCenter, out float closestDistance,
                                                 out float RecoveryFactor, out float RecoveryRange, out string BaseName)
        {
            CustomSpaceCenter closest = null;
            SpaceCenter       sc      = null;

            var smallestDist = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));

            Log.Normal("Distance to KSC is " + smallestDist);

            bool isCareer = CareerUtils.isCareerGame;

            string sBaseName        = "";
            float  fMyBaseRecovFact = 0f;
            float  fMyBaseRecovRang = 0f;


            foreach (CustomSpaceCenter csc in spaceCenters)
            {
                if (csc.staticInstance.launchSite.RecoveryFactor == 0)
                {
                    continue;
                }
                sc = csc.getSpaceCenter();
                //float dist = Vector3.Distance(position, csc.getStaticObject().gameObject.transform.position);
                var dist = (float)sc.GreatCircleDistance(sc.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));

                if (dist < smallestDist)
                {
                    if (isCareer && csc.staticInstance.launchSite.isOpen)
                    {
                        closest          = csc;
                        smallestDist     = dist;
                        fMyBaseRecovFact = csc.staticInstance.launchSite.RecoveryFactor;
                        fMyBaseRecovRang = csc.staticInstance.launchSite.RecoveryRange;
                        sBaseName        = csc.staticInstance.launchSite.LaunchSiteName;
                        // Debug.Log("KK: closest updated to " + closest.SpaceCenterName + ", distance " + smallestDist);
                    }
                }
            }



            if (closest == null)
            {
                sc = null;
            }
            else
            {
                Log.Normal("closest Spacecenter is " + closest.SpaceCenterName);
                sc = closest.getSpaceCenter();
            }

            Log.Normal("smallestDist is " + smallestDist);
            Log.Normal("returning closest space centre: " + sc.name);


            if (smallestDist < 1)
            {
                smallestDist = 0;
            }
            if (sc == null)
            {
                sc = KSC;
                fMyBaseRecovFact = 100;
                sBaseName        = "KSC";
            }

            closestCenter   = sc;
            closestDistance = smallestDist;
            RecoveryFactor  = fMyBaseRecovFact;
            RecoveryRange   = fMyBaseRecovRang;
            BaseName        = sBaseName;
        }