diff --git a/KMPManager.cs b/KMPManager.cs index 7cf3c1e..010a441 100644 --- a/KMPManager.cs +++ b/KMPManager.cs @@ -2664,7 +2664,7 @@ private bool checkOrbitForCollision(Orbit orbit, double tick, double fromTick) private void addRemoteVessel(ProtoVessel protovessel, Guid vessel_id, KMPVessel kvessel = null, KMPVesselUpdate update = null, double distance = 501d) { if (vessel_id == FlightGlobals.ActiveVessel.id && (serverVessels_InUse.ContainsKey(vessel_id) ? !serverVessels_InUse.ContainsKey(vessel_id) : false)) return; - if (serverVessels_LoadDelay.ContainsKey(vessel_id) ? serverVessels_LoadDelay[vessel_id] <= UnityEngine.Time.realtimeSinceStartup : false) return; + if (serverVessels_LoadDelay.ContainsKey(vessel_id) ? serverVessels_LoadDelay[vessel_id] >= UnityEngine.Time.realtimeSinceStartup : false) return; serverVessels_LoadDelay[vessel_id] = UnityEngine.Time.realtimeSinceStartup + 5f; Log.Debug("addRemoteVessel: " + vessel_id.ToString()); Vector3 newWorldPos = Vector3.zero, newOrbitVel = Vector3.zero; @@ -2732,7 +2732,7 @@ private void addRemoteVessel(ProtoVessel protovessel, Guid vessel_id, KMPVessel } } - if (isInSafetyBubble(protovessel.position, body, protovessel.altitude)) //refuse to load anything too close to the KSC + if (isProtoVesselInSafetyBubble(protovessel)) //refuse to load anything too close to the KSC { Log.Debug("Tried to load vessel too close to KSC"); return; @@ -5211,6 +5211,30 @@ private bool isInSafetyBubble(Vector3d pos, CelestialBody body, double altitude) return Vector3d.Distance(kscPosition, projectedPos) < safetyBubbleRadius; } + + private bool isProtoVesselInSafetyBubble(ProtoVessel protovessel) { + //When vessels are landed, position is 0,0,0 - So we need to check lat/long + ConfigNode protoVesselNode = new ConfigNode(); + protovessel.Save(protoVesselNode); + CelestialBody kerbinBody = FlightGlobals.Bodies.Find (b => b.name == "Kerbin"); + //If not kerbin, we aren't in the safety bubble. + if (protoVesselNode.GetNode("ORBIT").GetValue("REF") != "1") { + return false; + } + //If we aren't landed, use the vector3 check above. + if (!protovessel.landed) { + return isInSafetyBubble (protovessel.position, kerbinBody, protovessel.altitude); + } + //Check our distance + double protoVesselLat; + double protoVesselLong; + Double.TryParse(protoVesselNode.GetValue("lat"), out protoVesselLat); + Double.TryParse(protoVesselNode.GetValue("long"), out protoVesselLong); + Vector3d kscPosition = kerbinBody.GetWorldSurfacePosition(-0.102668048654,-74.5753856554,60); + Vector3d protoVesselPosition = kerbinBody.GetWorldSurfacePosition(protoVesselLat, protoVesselLong, protovessel.altitude); + double vesselDistance = Vector3d.Distance(kscPosition, protoVesselPosition); + return vesselDistance < safetyBubbleRadius; + } public double horizontalDistanceToSafetyBubbleEdge() { diff --git a/KMPVesselUpdate.cs b/KMPVesselUpdate.cs index 03db079..23a4738 100644 --- a/KMPVesselUpdate.cs +++ b/KMPVesselUpdate.cs @@ -257,6 +257,8 @@ private void InitKMPVesselUpdate(Vessel _vessel, bool includeProtoVessel) { crewMember.KerbalRef = null; } + proto.position = _vessel.mainBody.transform.InverseTransformPoint(_vessel.GetWorldPos3D()); + Log.Debug("Protovessel: " + _vessel.id + ", x: " + proto.position.x + ", y: " + proto.position.y + ", z: " + proto.position.z); proto.Save(protoVesselNode); } }