public override Vector GetPositionAtUT(TimeSpan timeStamp)
{
string blockingTech;
if (!Career.CanMakeNodes(out blockingTech))
throw new KOSLowTechException("use POSITIONAT on a vessel", blockingTech);
double desiredUT = timeStamp.ToUnixStyleTime();
Orbit patch = GetOrbitAtUT(desiredUT);
Vector3d pos = patch.getPositionAtUT(desiredUT);
// This is an ugly workaround to fix what is probably a bug in KSP's API:
// If looking at a future orbit patch around a child body of the current body, then
// the various get{Thingy}AtUT() methods return numbers calculated incorrectly as
// if the child body was going to remain stationary where it is now, rather than
// taking into account where it will be later when the intercept happens.
// This corrects for that case:
if (Utils.BodyOrbitsBody(patch.referenceBody, Vessel.orbit.referenceBody))
{
Vector3d futureSOIPosNow = patch.referenceBody.position;
Vector3d futureSOIPosLater = patch.referenceBody.getPositionAtUT(desiredUT);
Vector3d offset = futureSOIPosLater - futureSOIPosNow;
pos = pos + offset;
}
return new Vector(pos - Shared.Vessel.CoMD); // Convert to ship-centered frame.
}