Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
godarklight committed Feb 23, 2014
1 parent a2bca95 commit 3d1c2d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions KMPManager.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions KMPVesselUpdate.cs
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 3d1c2d8

Please sign in to comment.