/// <summary>
        /// Add a resource to the transfer request.
        /// </summary>
        /// <param name="resource">The <see cref="OrbitalLogisticsResource"/> to transfer from the source <see cref="Vessel"/>.</param>
        /// <param name="amount">The amount to transfer to the destination <see cref="Vessel"/>.</param>
        /// <returns></returns>
        public OrbitalLogisticsTransferRequestResource AddResource(OrbitalLogisticsResource resource, double amount)
        {
            // Determine if requested transfer amount is feasible
            double available = resource.GetAvailableAmount();

            if (amount > available)
            {
                amount = available;
            }

            // Check if there is already a transfer setup for the selected resource
            var transferResource = ResourceRequests.Where(r => r.ResourceDefinition.id == resource.ResourceDefinition.id).SingleOrDefault();

            if (transferResource == null)
            {
                // Add the resource to the transfer request
                transferResource = new OrbitalLogisticsTransferRequestResource(resource.ResourceDefinition, amount);
                ResourceRequests.Add(transferResource);
            }
            else
            {
                transferResource.TransferAmount = amount;
            }

            // Update duration
            CalculateDuration();

            return(transferResource);
        }
예제 #2
0
        /// <summary>
        /// Gets the current available amount of the currency used for transporting goods via Orbital Logistics.
        /// </summary>
        /// <param name="vessel"></param>
        /// <returns></returns>
        public static double GetTransportCapacity(this Vessel vessel)
        {
            PartResourceDefinition transportCredits = PartResourceLibrary.Instance.GetDefinition("TransportCredits");

            if (transportCredits == null || !vessel.HasResource(transportCredits))
            {
                return(0);
            }

            OrbitalLogisticsResource transportCreditsResource = new OrbitalLogisticsResource(transportCredits, vessel);

            return(transportCreditsResource.GetAvailableAmount());
        }