Exemplo n.º 1
0
        public static void Update()
        {
            _update = false;

            if (FlightGlobals.ActiveVessel == null ||
                FlightGlobals.ActiveVessel.targetObject == null ||
                FlightGlobals.ActiveVessel.targetObject.GetOrbit() == null ||
                FlightGlobals.ActiveVessel.targetObject.GetOrbit().referenceBody == null ||
                FlightGlobals.ActiveVessel.orbit == null ||
                FlightGlobals.ActiveVessel.orbit.referenceBody == null)
            {
                _updated = false;
                return;
            }

            _updated = true;

            _targetOrbit = FlightGlobals.ActiveVessel.targetObject.GetOrbit();

            Orbit active = FlightGlobals.ActiveVessel.orbit;

            _trueShipOrbit = active;

            if (active.referenceBody == Planetarium.fetch.Sun || active.referenceBody == FlightGlobals.ActiveVessel.targetObject.GetOrbit().referenceBody)
            {
                _shipOrbit = active;
            }
            else
            {
                _shipOrbit = FlightGlobals.ActiveVessel.orbit.referenceBody.orbit;
            }

            Vessel.Situations sit = FlightGlobals.ActiveVessel.situation;

            if ((sit |= Vessel.Situations.LANDED | Vessel.Situations.SPLASHED | Vessel.Situations.PRELAUNCH) == 0)
            {
                _vesselIntersect = false;
                _bodyIntersect   = false;
            }
            else
            {
                if (!_isVessel && !_isCelestial)
                {
                    _vesselIntersect = false;
                    _bodyIntersect   = false;
                }
                else
                {
                    OrbitTargeter      oTargeter = FlightGlobals.ActiveVessel.orbitTargeter;
                    PatchedConicSolver solver    = FlightGlobals.ActiveVessel.patchedConicSolver;

                    if (oTargeter == null || solver == null)
                    {
                        _vesselIntersect = false;
                        _bodyIntersect   = false;
                    }
                    else if (!MapView.MapIsEnabled)
                    {
                        if (_isVessel)
                        {
                            _bodyIntersect = false;

                            Orbit _refPatch = null;

                            if (solver.maneuverNodes.Count > 0)
                            {
                                _refPatch = GetReferencePatch(oTargeter, solver, _targetOrbit.referenceBody, null, true);
                            }
                            else
                            {
                                _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter);
                            }

                            Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                            _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch);
                        }
                        else
                        {
                            _vesselIntersect = false;

                            double Pe = GetLowestPeA(solver);

                            if (Pe < double.MaxValue - 1000)
                            {
                                _closestDist   = Pe;
                                _bodyIntersect = true;
                            }
                            else
                            {
                                Orbit _refPatch = null;

                                if (solver.maneuverNodes.Count > 0)
                                {
                                    _refPatch = GetReferencePatch(oTargeter, solver, _targetBody, _targetOrbit.referenceBody, false);
                                }
                                else
                                {
                                    _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter);
                                }

                                Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                                _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch);
                            }
                        }
                    }
                    else
                    {
                        if (_markers == null || _markers.Count <= 0)
                        {
                            _markers = BasicOrbitReflection.GetOrbitMarkers(oTargeter);
                        }

                        if (_markers == null || _markers.Count <= 0)
                        {
                            _vesselIntersect = false;
                            _bodyIntersect   = false;
                        }
                        else if (_isVessel)
                        {
                            _bodyIntersect = false;

                            if (solver.maneuverNodes.Count > 0)
                            {
                                Orbit _refPatch    = GetReferencePatch(oTargeter, solver, _targetOrbit.referenceBody, null, true);
                                Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                                _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch);
                            }
                            else
                            {
                                OrbitTargeter.ISectMarker _intersectOne = null;
                                OrbitTargeter.ISectMarker _intersectTwo = null;

                                for (int i = _markers.Count - 1; i >= 0; i--)
                                {
                                    OrbitTargeter.Marker m = _markers[i];

                                    if (m == null)
                                    {
                                        continue;
                                    }

                                    if (!(m is OrbitTargeter.ISectMarker))
                                    {
                                        continue;
                                    }

                                    int num = ((OrbitTargeter.ISectMarker)m).num;

                                    if (num == 1)
                                    {
                                        _intersectOne = m as OrbitTargeter.ISectMarker;
                                    }
                                    else if (num == 2)
                                    {
                                        _intersectTwo = m as OrbitTargeter.ISectMarker;
                                    }
                                }

                                OrbitTargeter.ISectMarker _closestIntersect = null;

                                if (_intersectOne != null && _intersectTwo != null)
                                {
                                    _closestIntersect = _intersectOne.separation > _intersectTwo.separation ? _intersectTwo : _intersectOne;
                                }
                                else if (_intersectOne != null)
                                {
                                    _closestIntersect = _intersectOne;
                                }
                                else if (_intersectTwo != null)
                                {
                                    _closestIntersect = _intersectTwo;
                                }
                                else
                                {
                                    _closestIntersect = null;
                                }

                                if (_closestIntersect == null)
                                {
                                    _vesselIntersect = false;
                                }
                                else
                                {
                                    _vesselIntersect = true;
                                    _closestDist     = _closestIntersect.separation * 1000;
                                    _closestRelVel   = _closestIntersect.relSpeed;
                                    _closestTime     = _closestIntersect.UT;
                                }
                            }
                        }
                        else
                        {
                            _vesselIntersect = false;

                            double Pe = GetLowestPeA(solver);

                            if (Pe < double.MaxValue - 1000)
                            {
                                _closestDist   = Pe;
                                _bodyIntersect = true;
                            }
                            else
                            {
                                if (solver.maneuverNodes.Count > 0)
                                {
                                    Orbit _refPatch    = GetReferencePatch(oTargeter, solver, _targetBody, _targetOrbit.referenceBody, false);
                                    Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                                    _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch);
                                }
                                else
                                {
                                    OrbitTargeter.ClApprMarker _approach = null;

                                    for (int i = _markers.Count - 1; i >= 0; i--)
                                    {
                                        OrbitTargeter.Marker m = _markers[i];

                                        if (m == null)
                                        {
                                            continue;
                                        }

                                        if (!(m is OrbitTargeter.ClApprMarker))
                                        {
                                            continue;
                                        }

                                        _approach = m as OrbitTargeter.ClApprMarker;
                                    }

                                    if (_approach == null)
                                    {
                                        _bodyIntersect = false;
                                    }
                                    else
                                    {
                                        _bodyIntersect = true;
                                        _closestDist   = _approach.separation * 1000;
                                        _closestTime   = (_approach.dT * -1) + Planetarium.GetUniversalTime();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void Update(bool target)
        {
            _update = false;

            if (FlightGlobals.ActiveVessel == null ||
                FlightGlobals.ActiveVessel.patchedConicSolver == null)
            {
                _updated = false;
                return;
            }

            PatchedConicSolver solver = FlightGlobals.ActiveVessel.patchedConicSolver;

            _node = solver.maneuverNodes[0];

            if (_node != null || _node.patch == null)
            {
                _maneuverTotal = _node.DeltaV.magnitude;

                _maneuverRemaining = _node.GetBurnVector(_node.patch).magnitude;

                if (BasicOrbitReflection.BetterBurnTimeLoaded)
                {
                    if (_bbVesselModule == null || _bbVesselReference != FlightGlobals.ActiveVessel)
                    {
                        for (int i = FlightGlobals.ActiveVessel.vesselModules.Count - 1; i >= 0; i--)
                        {
                            VesselModule vMod = FlightGlobals.ActiveVessel.vesselModules[i];

                            if (vMod == null)
                            {
                                continue;
                            }

                            if (vMod.GetType().Name != _bbModuleName)
                            {
                                continue;
                            }

                            _bbVesselModule    = vMod;
                            _bbVesselReference = FlightGlobals.ActiveVessel;
                            break;
                        }
                    }

                    if (_bbVesselModule != null)
                    {
                        string type = _bbVesselModule.Fields[_bbTypeName].GetValue(_bbVesselModule).ToString();

                        if (type == "Maneuver")
                        {
                            _burnLength = _bbVesselModule.Fields[_bbLengthName].GetValue <double>(_bbVesselModule);
                            _burnTime   = _bbVesselModule.Fields[_bbTimeName].GetValue <double>(_bbVesselModule);

                            if (double.IsNaN(_burnLength) || double.IsNaN(_burnTime))
                            {
                                _bbTimeLoaded = false;
                                _burnTime     = _node.UT;
                                _burnLength   = 0;
                            }
                            else
                            {
                                double half = _burnLength / 2;
                                _burnTime    -= half;
                                _bbTimeLoaded = true;
                            }
                        }
                        else
                        {
                            _bbTimeLoaded = false;
                            _burnTime     = _node.UT;
                        }
                    }
                    else
                    {
                        _bbTimeLoaded = false;
                        _burnTime     = _node.UT;
                    }
                }
                else
                {
                    _burnTime = _node.UT;
                }

                _showAngle         = false;
                _showPhasing       = false;
                _targetInclination = false;

                if (target)
                {
                    if (!BasicTargetting.IsVessel && !BasicTargetting.IsCelestial)
                    {
                        _vesselIntersect = false;
                        _bodyIntersect   = false;
                    }
                    else
                    {
                        Orbit targetOrbit = FlightGlobals.ActiveVessel.targetObject.GetOrbit();

                        Orbit active = FlightGlobals.ActiveVessel.orbit;

                        _targetPhasingOrbit = null;

                        if (active.referenceBody == targetOrbit.referenceBody)
                        {
                            _phasingNodePatch   = active;
                            _targetPhasingOrbit = targetOrbit;
                            _targetInclination  = true;
                        }
                        else
                        {
                            if (active.referenceBody != Planetarium.fetch.Sun)
                            {
                                _showAngle = true;
                            }

                            _showPhasing = true;

                            DrillDownOrbits(_node.patch, targetOrbit);
                        }

                        Vessel.Situations sit = FlightGlobals.ActiveVessel.situation;

                        if ((sit |= Vessel.Situations.LANDED | Vessel.Situations.SPLASHED | Vessel.Situations.PRELAUNCH) == 0)
                        {
                            _vesselIntersect = false;
                            _bodyIntersect   = false;
                        }
                        else
                        {
                            OrbitTargeter oTargeter = FlightGlobals.ActiveVessel.orbitTargeter;

                            if (oTargeter == null || solver == null)
                            {
                                _vesselIntersect = false;
                                _bodyIntersect   = false;
                            }
                            else if (!MapView.MapIsEnabled)
                            {
                                if (BasicTargetting.IsVessel)
                                {
                                    _bodyIntersect = false;

                                    Vessel tgt = FlightGlobals.ActiveVessel.targetObject.GetVessel();

                                    if (tgt == null || tgt.LandedOrSplashed)
                                    {
                                        _vesselIntersect = false;
                                        return;
                                    }

                                    Orbit _refPatch    = BasicOrbitReflection.GetRefPatch(oTargeter);
                                    Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                                    _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch);
                                }
                                else
                                {
                                    _vesselIntersect = false;

                                    double Pe = GetLowestPeA(solver, BasicTargetting.TargetBody, _node.patch);

                                    if (Pe < BasicExtensions.AlmostMaxValue)
                                    {
                                        _closestDist   = Pe;
                                        _bodyIntersect = true;
                                    }
                                    else
                                    {
                                        Orbit _refPatch    = BasicOrbitReflection.GetRefPatch(oTargeter);
                                        Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter);

                                        if (_refPatch != null && _refPatch.closestTgtApprUT <= 0)
                                        {
                                            _bodyIntersect = false;
                                            return;
                                        }

                                        _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch);
                                    }
                                }
                            }
                            else
                            {
                                if (BasicTargetting.Markers == null || BasicTargetting.Markers.Count <= 0)
                                {
                                    BasicTargetting.Markers = BasicOrbitReflection.GetOrbitMarkers(oTargeter);
                                }

                                if (BasicTargetting.IsVessel)
                                {
                                    _bodyIntersect = false;

                                    OrbitTargeter.ISectMarker _intersectOne = null;
                                    OrbitTargeter.ISectMarker _intersectTwo = null;

                                    for (int i = BasicTargetting.Markers.Count - 1; i >= 0; i--)
                                    {
                                        OrbitTargeter.Marker m = BasicTargetting.Markers[i];

                                        if (m == null)
                                        {
                                            continue;
                                        }

                                        if (!(m is OrbitTargeter.ISectMarker))
                                        {
                                            continue;
                                        }

                                        int num = ((OrbitTargeter.ISectMarker)m).num;

                                        if (num == 1)
                                        {
                                            _intersectOne = m as OrbitTargeter.ISectMarker;
                                        }
                                        else if (num == 2)
                                        {
                                            _intersectTwo = m as OrbitTargeter.ISectMarker;
                                        }
                                    }

                                    OrbitTargeter.ISectMarker _closestIntersect = null;

                                    if (_intersectOne != null && _intersectTwo != null)
                                    {
                                        _closestIntersect = _intersectOne.separation > _intersectTwo.separation ? _intersectTwo : _intersectOne;
                                    }
                                    else if (_intersectOne != null)
                                    {
                                        _closestIntersect = _intersectOne;
                                    }
                                    else if (_intersectTwo != null)
                                    {
                                        _closestIntersect = _intersectTwo;
                                    }
                                    else
                                    {
                                        _closestIntersect = null;
                                    }

                                    if (_closestIntersect == null)
                                    {
                                        _vesselIntersect = false;
                                    }
                                    else
                                    {
                                        _vesselIntersect = true;
                                        _closestDist     = _closestIntersect.separation * 1000;
                                        _closestRelVel   = _closestIntersect.relSpeed;
                                        _closestTime     = _closestIntersect.UT;
                                    }
                                }
                                else
                                {
                                    _vesselIntersect = false;

                                    double Pe = GetLowestPeA(solver, BasicTargetting.TargetBody, _node.patch);

                                    if (Pe < BasicExtensions.AlmostMaxValue)
                                    {
                                        _closestDist   = Pe;
                                        _bodyIntersect = true;
                                    }
                                    else
                                    {
                                        OrbitTargeter.ClApprMarker _approach = null;

                                        for (int i = BasicTargetting.Markers.Count - 1; i >= 0; i--)
                                        {
                                            OrbitTargeter.Marker m = BasicTargetting.Markers[i];

                                            if (m == null)
                                            {
                                                continue;
                                            }

                                            if (!(m is OrbitTargeter.ClApprMarker))
                                            {
                                                continue;
                                            }

                                            _approach = m as OrbitTargeter.ClApprMarker;
                                        }

                                        if (_approach == null)
                                        {
                                            _bodyIntersect = false;
                                        }
                                        else
                                        {
                                            _bodyIntersect = true;
                                            _closestDist   = _approach.separation * 1000;
                                            _closestTime   = (_approach.dT * -1) + Planetarium.GetUniversalTime();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                _updated = true;
            }
        }