Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Hash code for the object.
 /// </summary>
 public override int GetHashCode()
 {
     return(Part.GetHashCode() ^ transmitter.GetHashCode());
 }
Ejemplo n.º 4
0
 internal static bool Is(Part part)
 {
     return(part.InternalPart.HasModule <ModuleDataTransmitter> ());
 }
Ejemplo n.º 5
0
 internal static bool Is(Part part)
 {
     return(part.InternalPart.HasModule <ModuleParachute> ());
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Hash code for the object.
 /// </summary>
 public override int GetHashCode ()
 {
     return Part.GetHashCode () ^ rcs.GetHashCode ();
 }
Ejemplo n.º 7
0
 internal static bool Is (Part part)
 {
     return Is (part.InternalPart);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Hash code for the object.
 /// </summary>
 public override int GetHashCode()
 {
     return(Part.GetHashCode() ^ wheel.GetHashCode());
 }
Ejemplo n.º 9
0
 internal static bool Is(Part part)
 {
     return
         (part.InternalPart.HasModule <ModuleResourceHarvester> () &&
          part.InternalPart.HasModule <ModuleAnimationGroup> ());
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Hash code for the object.
 /// </summary>
 public override int GetHashCode()
 {
     return(Part.GetHashCode() ^ parachute.GetHashCode());
 }