public static float GetHCUCost(Vessel vessel, IEnumerable <Part> HCUParts = null, float multiplier = 1f) { float HCUCost = 0f; if (HCUParts == null) { HCUParts = HailerGUI.GetHCUParts(vessel).Keys.ToList(); } foreach (Part HCUPart in HCUParts) { foreach (PartResource resource in HCUPart.Resources) { if (HailerGUI.highEnergyResources.ContainsKey(resource.resourceName) && resource.amount > 0.0) { HCUCost += resource.info.density * (float)resource.amount * 0.1f / 0.0058f * HailerGUI.highEnergyResources[resource.resourceName]; } } } HCUCost += (float)vessel.GetCrewCount() * 0.9f / 1.13f; return(HCUCost * multiplier); }
public void Warp(Vessel target, Vessel destination, float precision, List <Part> unsafeParts = null) { float tripdist = Vector3.Distance(base.vessel.GetWorldPos3D(), destination.GetWorldPos3D()); float totalMass = target.GetTotalMass(); float cost = GetTripFinalCost(GetTripBaseCost(tripdist, totalMass), target, destination, totalMass, unsafeParts); HailerGUI.PathCheck pathCheck = new HailerGUI.PathCheck(base.vessel, destination, gLimitEff); if (pathCheck.clear) { if (jumpResources.All(res => RequireResource(res.resID, (double)(res.ratio * cost), false))) { jumpResources.All(res => RequireResource(res.resID, (double)(res.ratio * cost), true)); HailerButton.Instance.Dazzle(); Vector3d transferVelOffset = GetJumpVelOffset(target, destination); if (hasAMU) { transferVelOffset = destination.orbit.vel; } Vector3d vector3d = (UnityEngine.Random.onUnitSphere + UnityEngine.Random.insideUnitSphere) / 2f * precision; // Making the spread less likely to throw you outside the SoI of the body. if ((destination.orbit.pos + vector3d).magnitude > destination.mainBody.sphereOfInfluence) { vector3d = -vector3d; // Negative random is equally random. } OrbitDriver orbitDriver = target.orbitDriver; Orbit orbit = orbitDriver.orbit; Orbit orbit2 = new Orbit(orbit.inclination, orbit.eccentricity, orbit.semiMajorAxis, orbit.LAN, orbit.argumentOfPeriapsis, orbit.meanAnomalyAtEpoch, orbit.epoch, orbit.referenceBody); orbit2.UpdateFromStateVectors(destination.orbit.pos + vector3d, transferVelOffset, destination.mainBody, Planetarium.GetUniversalTime()); target.Landed = false; target.Splashed = false; target.landedAt = string.Empty; OrbitPhysicsManager.HoldVesselUnpack(60); List <Vessel> vessels = FlightGlobals.Vessels; foreach (Vessel item in vessels.AsEnumerable()) { if (!item.packed) { item.GoOnRails(); } } CelestialBody referenceBody = target.orbitDriver.orbit.referenceBody; orbit.inclination = orbit2.inclination; orbit.eccentricity = orbit2.eccentricity; orbit.semiMajorAxis = orbit2.semiMajorAxis; orbit.LAN = orbit2.LAN; orbit.argumentOfPeriapsis = orbit2.argumentOfPeriapsis; orbit.meanAnomalyAtEpoch = orbit2.meanAnomalyAtEpoch; orbit.epoch = orbit2.epoch; orbit.referenceBody = orbit2.referenceBody; orbit.Init(); orbit.UpdateFromUT(Planetarium.GetUniversalTime()); if ((UnityEngine.Object)orbit.referenceBody != (UnityEngine.Object)orbit2.referenceBody) { orbitDriver.OnReferenceBodyChange?.Invoke(orbit2.referenceBody); } target.orbitDriver.pos = target.orbit.pos.xzy; target.orbitDriver.vel = target.orbit.vel; if ((UnityEngine.Object)target.orbitDriver.orbit.referenceBody != (UnityEngine.Object)referenceBody) { GameEvents.onVesselSOIChanged.Fire(new GameEvents.HostedFromToAction <Vessel, CelestialBody>(target, referenceBody, target.orbitDriver.orbit.referenceBody)); } if (UnsafeTransfer) { if (unsafeParts == null) { unsafeParts = HailerGUI.GetHCUParts(target).Keys.ToList(); } for (int i = unsafeParts.Count - 1; i >= 0; i--) { unsafeParts[i].explosionPotential = Mathf.Max(1f, unsafeParts[i].explosionPotential); unsafeParts[i].explode(); } for (int i = base.vessel.parts.Count - 1; i >= 0; i--) { Part part = base.vessel.parts[i]; for (int j = part.protoModuleCrew.Count - 1; j >= 0; j--) { ProtoCrewMember protoCrewMember = part.protoModuleCrew[j]; ScreenMessages.PostScreenMessage(protoCrewMember.name + " was killed in transit!", 5f, ScreenMessageStyle.UPPER_CENTER); base.vessel.parts[i].RemoveCrewmember(protoCrewMember); protoCrewMember.Die(); } } } } else { ScreenMessages.PostScreenMessage("Jump failed! Origin beacon did not have enough fuel to execute transfer.", 5f, ScreenMessageStyle.UPPER_CENTER); } } }