예제 #1
0
        // Checks if the vessel can perform the given mission:
        public bool CanPerformMission(MissionProfileType missionType)
        {
            if (this.currentStats == null)
            {
                return(false);                           // This should not happen.
            }
            switch (missionType)
            {
            case MissionProfileType.TRANSPORT:
                if (this.currentStats.hasDockingPort && this.currentStats.hasRCS)
                {
                    return(true);
                }
                break;

            case MissionProfileType.DEPLOY:
                if (this.currentStats.payloadAssemblies.Count > 0)
                {
                    return(true);
                }
                break;

            default:
                throw new Exception("invalid mission-type");
            }
            return(false);
        }
예제 #2
0
        public void DeployPayloadAssembly(List <PayloadAssembly> payloadAssemblies)
        {
            if (payloadAssemblies.Count < 1)
            {
                return;
            }

            // Sort the assemblies from largest to smallest, to avoid problems with detaching assemblies that contain other assemblies on the list:
            payloadAssemblies.Sort((x, y) => y.partCount.CompareTo(x.partCount));

            // Deploy all selected payloads:
            double deployedMass  = 0;
            double deployedFunds = 0;

            foreach (PayloadAssembly payloadAssembly in payloadAssemblies)
            {
                if (!payloadAssembly.detachmentPart || !this.vessel)
                {
                    continue;
                }
                if (!this.vessel.parts.Contains(payloadAssembly.detachmentPart))
                {
                    continue;                     // The subassembly was probably already detached together with a bigger one.
                }
                payloadAssembly.Highlight(false); // Turn off highlighting, in case it was on.

                foreach (ModuleDockingNode dockingModule in payloadAssembly.detachmentPart.FindModulesImplementing <ModuleDockingNode>())
                {
                    dockingModule.Decouple();
                }
                foreach (ModuleDecouple decoupleModule in payloadAssembly.detachmentPart.FindModulesImplementing <ModuleDecouple>())
                {
                    decoupleModule.Decouple();
                }
                foreach (ModuleAnchoredDecoupler decoupleModule in payloadAssembly.detachmentPart.FindModulesImplementing <ModuleAnchoredDecoupler>())
                {
                    decoupleModule.Decouple();
                }

                deployedMass  += payloadAssembly.mass;
                deployedFunds += payloadAssembly.value;
            }

            // If there was something deployed, we can move on to the next stage:
            if (deployedMass > 0)
            {
                this.payloadMass      = deployedMass;
                this.missionType      = MissionProfileType.DEPLOY;
                this.deploymentTime   = Planetarium.GetUniversalTime();
                this.status           = FlightRecordingStatus.DESCENDING;
                this.dockingPortTypes = this.currentStats.dockingPortTypes; // This mission-type doesn't need docking ports, but this way it's not inconsistent.

                // The weight and value of the payload should not counted in the vessel's stats:
                this.launchMass -= deployedMass;
                this.launchCost -= Math.Round(deployedFunds);
            }
        }
예제 #3
0
 public static string GetMissionProfileTypeName(MissionProfileType type)
 {
     if (type == MissionProfileType.DEPLOY)
     {
         return("deployment");
     }
     if (type == MissionProfileType.TRANSPORT)
     {
         return("transport");
     }
     return("N/A");
 }
예제 #4
0
        public void DeployPayloadResources(Dictionary <string, double> requestedResources)
        {
            double dumpedMass  = 0;
            double dumpedFunds = 0;

            if (!this.CanPerformMission(MissionProfileType.TRANSPORT))
            {
                return;
            }

            // Try to dump the requested amount of resources from the vessel:
            foreach (var item in requestedResources)
            {
                string requestedName   = item.Key;
                double requestedAmount = item.Value;

                PayloadResource payloadResource = null;
                if (!this.currentStats.payloadResources.TryGetValue(requestedName, out payloadResource))
                {
                    continue;
                }
                if (requestedAmount > payloadResource.amount)
                {
                    requestedAmount = payloadResource.amount;
                }
                if (requestedAmount < 0)
                {
                    requestedAmount = 0;
                }

                // Find parts to dump the resources from:
                double amountToDump = requestedAmount;
                foreach (Part part in vessel.parts)
                {
                    if (amountToDump <= 0)
                    {
                        break;
                    }
                    double dumpedAmount = part.RequestResource(requestedName, amountToDump);
                    if (dumpedAmount == 0)
                    {
                        continue;
                    }
                    Debug.Log("[KSTS] dumped " + dumpedAmount.ToString() + " of " + requestedName.ToString() + " from " + part.name.ToString());
                    amountToDump -= dumpedAmount;
                    dumpedMass   += dumpedAmount * payloadResource.mass;
                    if (KSTS.resourceDictionary.ContainsKey(payloadResource.name))
                    {
                        dumpedFunds += dumpedAmount * KSTS.resourceDictionary[payloadResource.name].unitCost;
                    }
                }
            }

            // If there was something dumped, we can move on to the next stage:
            if (dumpedMass > 0)
            {
                this.payloadMass      = dumpedMass;
                this.missionType      = MissionProfileType.TRANSPORT;
                this.deploymentTime   = Planetarium.GetUniversalTime();
                this.status           = FlightRecordingStatus.DESCENDING;
                this.dockingPortTypes = this.currentStats.dockingPortTypes;

                // The weight and value of the payload should not counted in the vessel's stats:
                this.launchMass -= dumpedMass;
                this.launchCost -= Math.Round(dumpedFunds);
            }
        }