ResourceTransfer(Part fromPart, Part toPart, PartResourceDefinition resource, float amount) { internalFromPart = fromPart; internalToPart = toPart; internalResource = resource; FromPart = new Parts.Part(fromPart); ToPart = new Parts.Part(toPart); Resource = resource.name; TotalAmount = amount; // Compute the transfer rate (in units/sec) as one tenth the size of the destination tank (determined experimentally from the KSP transfer UI) var totalStorage = (float)toPart.Resources.GetAll(resource.id).Sum(r => r.maxAmount); transferRate = 0.1f * totalStorage; ResourceTransferAddon.AddTransfer(this); }
public static ResourceTransfer Start(Parts.Part fromPart, Parts.Part toPart, string resource, float maxAmount) { if (ReferenceEquals(fromPart, null)) { throw new ArgumentNullException("fromPart"); } if (ReferenceEquals(toPart, null)) { throw new ArgumentNullException("toPart"); } // Get the internal part objects var internalFromPart = fromPart.InternalPart; var internalToPart = toPart.InternalPart; // Check the parts are in the same vessel if (internalFromPart.vessel.id != internalToPart.vessel.id) { throw new ArgumentException("Parts are not on the same vessel"); } // Check the parts are different if (internalFromPart.flightID == internalToPart.flightID) { throw new ArgumentException("Source and destination parts are the same"); } // Get the resource info object var resourceInfo = PartResourceLibrary.Instance.resourceDefinitions .FirstOrDefault(r => r.name == resource); if (resourceInfo == null) { throw new ArgumentException("Resource '" + resource + "' does not exist"); } // Check the parts contain the required resource if (internalFromPart.Resources.Get(resourceInfo.id) == null) { throw new ArgumentException("Source part does not contain '" + resource + "'"); } if (internalToPart.Resources.Get(resourceInfo.id) == null) { throw new ArgumentException("Destination part cannot store '" + resource + "'"); } // Create the resource transfer return(new ResourceTransfer(internalFromPart, internalToPart, resourceInfo, maxAmount)); }
/// <summary> /// Hash code for the object. /// </summary> public override int GetHashCode() { return(Part.GetHashCode() ^ transmitter.GetHashCode()); }
internal static bool Is(Part part) { return(part.InternalPart.HasModule <ModuleDataTransmitter> ()); }
internal static bool Is(Part part) { return(part.InternalPart.HasModule <ModuleParachute> ()); }
/// <summary> /// Hash code for the object. /// </summary> public override int GetHashCode () { return Part.GetHashCode () ^ rcs.GetHashCode (); }
internal static bool Is (Part part) { return Is (part.InternalPart); }
/// <summary> /// Hash code for the object. /// </summary> public override int GetHashCode() { return(Part.GetHashCode() ^ wheel.GetHashCode()); }
internal static bool Is(Part part) { return (part.InternalPart.HasModule <ModuleResourceHarvester> () && part.InternalPart.HasModule <ModuleAnimationGroup> ()); }
/// <summary> /// Hash code for the object. /// </summary> public override int GetHashCode() { return(Part.GetHashCode() ^ parachute.GetHashCode()); }