public static float Radius(this Vessel vessel, bool fromCoM = false)
        {
            if (!vessel.loaded)
            {
                if (vessel.vesselType == VesselType.SpaceObject)
                {
                    var ast = vessel.protoVessel.protoPartSnapshots
                              .Select(p => p.FindModule("ModuleAsteroid"))
                              .FirstOrDefault();
                    if (ast != null)
                    {
                        float rho;
                        if (float.TryParse(ast.moduleValues.GetValue("density"), out rho))
                        {
                            return((float)Math.Pow(vessel.GetTotalMass() / rho, 1 / 3.0));
                        }
                    }
                }
                return((float)Math.Pow(vessel.GetTotalMass() / 2, 1 / 3.0));
            }
            var refT   = vessel.packed ? vessel.transform : vessel.ReferenceTransform;
            var bounds = vessel.BoundsWithExhaust(refT);

            if (fromCoM)
            {
                var shift = refT.TransformPoint(bounds.center) - vessel.CoM;
                return(bounds.extents.magnitude + shift.magnitude);
            }
            return(bounds.extents.magnitude);
        }
示例#2
0
        bool ComputeManeuver(Vessel v, out Vector3d maneuver)
        {
            maneuver = Vector3d.zero;
            //calculate distance
            var dir  = (v.CurrentCoM - VSL.Physics.wCoM);
            var dist = dir.magnitude;

            dir /= dist;
            //first try to get TCA from other vessel and get vessel's R and Exhaust
            var       vR  = 0f;
            var       vB  = new Bounds();
            Transform vT  = null;
            var       tca = ModuleTCA.EnabledTCA(v);

            if (tca != null)
            {
//                if(tca.CPS != null &&
//                   tca.CPS.IsActive &&
//                   VSL.Physics.M > tca.VSL.Physics.M &&
//                   VSL.vessel.srfSpeed > v.srfSpeed) //test
//                    return false;
                vR = tca.VSL.Geometry.R;
                vB = tca.VSL.Geometry.B;
                vT = tca.VSL.refT;
            }
            else //do a raycast
            {
                RaycastHit raycastHit;
                if (Physics.SphereCast(VSL.Geometry.C + dir * (VSL.Geometry.R + 0.1f), VSL.Geometry.R, dir,
                                       out raycastHit, dist, RadarMask))
                {
                    vR = (raycastHit.point - v.CurrentCoM).magnitude;
                }
                vT = v.ReferenceTransform;
                vB = v.BoundsWithExhaust(vT);
            }
            //compute course correction
            var dV         = VSL.vessel.srf_velocity - v.srf_velocity + (VSL.vessel.acceleration - v.acceleration) * C.LookAheadTime;
            var thrershold = -1f;

            if (v.LandedOrSplashed)
            {
                thrershold = 0;
            }
            else if (Dangerous.Contains(v.id))
            {
                thrershold = C.SafeDistance;
            }
            if (AvoideVessel(VSL, dir, dist, dV, vR, vB, vT, out maneuver, thrershold))
            {
                Dangerous.Add(v.id);
            }
            else
            {
                Dangerous.Remove(v.id);
            }
            return(!maneuver.IsZero());
        }