protected bool canAffordReconfigure()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!WBIMainSettings.PayToReconfigure)
            {
                return(true);
            }
            bool   canAffordCost = false;
            string notEnoughPartsMsg;

            calculateRemodelCostModifier();
            double amount         = resourceCost * (1.0 - reconfigureCostModifier);
            double totalResources = ResourceHelper.GetTotalResourceAmount(resourceRequired, this.part.vessel);

            //An inflatable part that hasn't been inflated yet is an automatic pass.
            if (switcher.isInflatable && !switcher.isDeployed)
            {
                return(true);
            }

            //now check to make sure the vessel has enough parts.
            if (totalResources >= amount)
            {
                canAffordCost = true;
            }

            if (!canAffordCost)
            {
                notEnoughPartsMsg = string.Format(kInsufficientParts, amount, resourceRequired);
                ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            return(true);
        }
示例#2
0
        public string GetMissingRequiredResource()
        {
            PartResourceDefinition            definition;
            Dictionary <string, PartResource> resourceMap = new Dictionary <string, PartResource>();

            foreach (PartResource res in this.part.Resources)
            {
                resourceMap.Add(res.resourceName, res);
            }

            //If we have required resources, make sure we have them.
            if (reqList.Count > 0)
            {
                foreach (ResourceRatio resRatio in reqList)
                {
                    //Do we have a definition?
                    definition = ResourceHelper.DefinitionForResource(resRatio.ResourceName);
                    if (definition == null)
                    {
                        return(resRatio.ResourceName);
                    }

                    //Do we have the resource aboard?
                    if (resourceMap.ContainsKey(resRatio.ResourceName) == false)
                    {
                        return(resRatio.ResourceName);
                    }

                    //Do we have enough?
                    if (resourceMap[resRatio.ResourceName].amount < resRatio.Ratio)
                    {
                        return(resRatio.ResourceName);
                    }
                }
            }

            return(null);
        }
示例#3
0
        protected override void recoverResourceCost(string resourceName, double recycleAmount)
        {
            double availableStorage = ResourceHelper.GetTotalResourceSpaceAvailable(resourceName, this.part.vessel);

            //Do we have sufficient space in the vessel to store the recycled parts?
            //If not, distrubute what we don't have space for.
            if (availableStorage < recycleAmount)
            {
                double amountRemaining = recycleAmount - availableStorage;
                string recycleMessage;

                //We'll only recycle what we have room to store aboard the vessel.
                recycleAmount = availableStorage;

                //Distribute the rest.
                List <DistributedResource> recycledResources = new List <DistributedResource>();
                recycleMessage = string.Format(kResourceDistributed, amountRemaining, resourceName);
                recycledResources.Add(new DistributedResource(resourceName, amountRemaining, recycleMessage));
                WBIDistributionManager.Instance.DistributeResources(recycledResources);
            }

            //Store what we have space for.
            this.part.RequestResource(resourceName, -recycleAmount, ResourceFlowMode.ALL_VESSEL);
        }
示例#4
0
 protected void getMaxTotalFuel()
 {
     maxTotalFuelGaugeResource = (float)ResourceHelper.GetTotalResourceMaxAmount(fuelGaugeResource, this.part.vessel);
 }
示例#5
0
        public void ScrapVessel()
        {
            //Make sure the vessel isn't occupied.
            if (this.part.vessel.GetCrewCount() > 0)
            {
                ScreenMessages.PostScreenMessage(kVesselIsOccupied, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Check for confirmation
            if (PathfinderSettings.ConfirmScrap && !scrapConfirmed)
            {
                scrapConfirmed = true;
                ScreenMessages.PostScreenMessage(kConfirmScrap, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            scrapConfirmed = false;

            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                //Check for skill & experience.
                if (astronaut.HasEffect(scrapSkill) == false)
                {
                    ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, Utils.GetTraitsWithEffect(scrapSkill)), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
                if (Utils.IsExperienceEnabled())
                {
                    //Check for experience level
                    if (astronaut.experienceLevel < minimumVesselRecycleSkill)
                    {
                        ScreenMessages.PostScreenMessage(string.Format(kInsufficientExperienceVessel, minimumVesselRecycleSkill), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }

                //Ok, we're good to go, get the resource definition for the recycleResource.
                PartResourceDefinition def = ResourceHelper.DefinitionForResource(recycleResource);
                if (def == null)
                {
                    Debug.Log("[WBIPartScrapper] - Definition not found for " + recycleResource);
                    return;
                }

                //Recycle all parts in the vessel.
                List <Part> doomedParts = new List <Part>();
                foreach (Part doomed in this.part.vessel.parts)
                {
                    if (doomed != this.part)
                    {
                        doomedParts.Add(doomed);
                    }
                }
                foreach (Part doomed in doomedParts)
                {
                    recyclePart(doomed, def, astronaut);
                }

                //Final recycle
                recyclePart(this.part, def, astronaut);
            }
        }
示例#6
0
        public void ScrapPart(Part doomedPart)
        {
            //Make sure that there are no kerbals on the part.
            if (doomedPart.protoModuleCrew.Count > 0)
            {
                ScreenMessages.PostScreenMessage(kPartIsOccupied, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Check for confirmation
            if (PathfinderSettings.ConfirmScrap && !scrapConfirmed)
            {
                scrapConfirmed = true;
                ScreenMessages.PostScreenMessage(kConfirmScrap, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            scrapConfirmed = false;

            //Check for skill & experience.
            List <ProtoCrewMember> crewMembers      = this.part.vessel.GetVesselCrew();
            bool            hasSufficientSkill      = false;
            bool            hasSufficientExperience = false;
            ProtoCrewMember highestRankingAstronaut = null;

            foreach (ProtoCrewMember astronaut in crewMembers)
            {
                //Check skill
                if (astronaut.HasEffect(scrapSkill))
                {
                    hasSufficientSkill = true;
                }

                //Check for experience level
                if (Utils.IsExperienceEnabled())
                {
                    if (astronaut.experienceLevel >= minimumPartRecycleSkill)
                    {
                        hasSufficientExperience = true;

                        if (highestRankingAstronaut == null)
                        {
                            highestRankingAstronaut = astronaut;
                        }

                        if (astronaut.experienceLevel > highestRankingAstronaut.experienceLevel)
                        {
                            highestRankingAstronaut = astronaut;
                        }
                    }
                }
            }

            if (!hasSufficientSkill)
            {
                ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, Utils.GetTraitsWithEffect(scrapSkill)), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            if (!hasSufficientExperience)
            {
                ScreenMessages.PostScreenMessage(string.Format(kInsufficientExperiencePart, minimumPartRecycleSkill), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Ok, we're good to go, get the resource definition for the recycleResource.
            PartResourceDefinition def = ResourceHelper.DefinitionForResource(recycleResource);

            if (def == null)
            {
                Debug.Log("[WBIPartScrapper] - Definition not found for " + recycleResource);
                return;
            }

            //Recycle the part and its resources
            recyclePart(doomedPart, def, highestRankingAstronaut);
        }
示例#7
0
        protected void rebuildResourceRatios()
        {
            PartResourceDefinition resourceDef = null;
            float         abundance            = 0f;
            float         harvestEfficiency;
            ResourceRatio ratio;

            if (!ResourceMap.Instance.IsPlanetScanned(this.part.vessel.mainBody.flightGlobalsIndex) && !ResourceMap.Instance.IsBiomeUnlocked(this.part.vessel.mainBody.flightGlobalsIndex, currentBiome))
            {
                return;
            }

            abundanceCache = Utils.GetAbundances(this.part.vessel, currentHarvestType);

            debugLog("Rebuilding resource ratios... ");
            debugLog("abundanceCache count: " + abundanceCache.ToArray().Length);
            resourceRatios.Clear();
            this.recipe.Outputs.Clear();
            foreach (ResourceCache.AbundanceSummary summary in abundanceCache)
            {
                //Get the resource definition
                debugLog("Getting abundance for " + summary.ResourceName);
                resourceDef = ResourceHelper.DefinitionForResource(summary.ResourceName);
                if (resourceDef == null)
                {
                    debugLog("No definition found!");
                    continue;
                }

                //Get the abundance
                abundance = ResourceMap.Instance.GetAbundance(new AbundanceRequest()
                {
                    Altitude     = this.vessel.altitude,
                    BodyId       = FlightGlobals.currentMainBody.flightGlobalsIndex,
                    CheckForLock = true,
                    Latitude     = this.vessel.latitude,
                    Longitude    = this.vessel.longitude,
                    ResourceType = currentHarvestType,
                    ResourceName = summary.ResourceName
                });
                if (abundance < HarvestThreshold || abundance < 0.001f)
                {
                    debugLog("Abundance is below HarvestThreshold or minimum abundance (0.001)");
                    continue;
                }

                //Now determine the harvest efficiency
                harvestEfficiency = abundance * Efficiency;

                //Setup the resource ratio
                ratio = new ResourceRatio();
                ratio.ResourceName = summary.ResourceName;
                ratio.Ratio        = harvestEfficiency;
                ratio.DumpExcess   = true;
                ratio.FlowMode     = ResourceFlowMode.NULL;

                resourceRatios.Add(ratio);
                debugLog("Added resource ratio for " + summary.ResourceName + " abundance: " + abundance);
            }
            debugLog("Found abundances for " + resourceRatios.Count + " resources");
        }
示例#8
0
        protected virtual void prepareOutputsByLocale()
        {
//            Debug.Log("FRED prepareOutputsByLocale called");
            ResourceRatio          outputSource;
            string                 biomeName = Utils.GetCurrentBiome(this.part.vessel).name;
            PartResourceDefinition outputDef = null;
            float totalAbundance             = 0f;
            float abundance   = 0f;
            float outputMass  = 0f;
            float outputUnits = 0f;
            IEnumerable <ResourceCache.AbundanceSummary> abundanceCache = ResourceCache.Instance.AbundanceCache.
                                                                          Where(a => a.HarvestType == HarvestTypes.Planetary && a.BodyId == this.part.vessel.mainBody.flightGlobalsIndex && a.BiomeName == biomeName);

            foreach (ResourceCache.AbundanceSummary summary in abundanceCache)
            {
//                Debug.Log("FRED checking " + summary.ResourceName);
                outputDef   = ResourceHelper.DefinitionForResource(summary.ResourceName);
                abundance   = summary.Abundance;
                outputMass  = abundance * yieldMass;
                outputUnits = outputMass / outputDef.density;

                //If the resource is an input resource then add its output mass to the byproductMass.
                if (inputSources.Contains(summary.ResourceName))
                {
//                    Debug.Log("FRED " + summary.ResourceName + " added to byproductMass");
                    byproductMass += outputMass;
                }

                //If the resource is on our ignore list, then add the output mass to the byproductMass.
                else if (!string.IsNullOrEmpty(ignoreResources) && ignoreResources.Contains(summary.ResourceName))
                {
//                    Debug.Log("FRED " + summary.ResourceName + " ignored and added to byproductMass");
                    byproductMass += outputMass;
                }

                //Legit!
                else if (summary.Abundance > 0.001f)
                {
                    totalAbundance += abundance;
//                    Debug.Log("FRED " + summary.ResourceName + " abundance: " + abundance + " Ratio: " + outputUnits);
                    outputSource = new ResourceRatio {
                        ResourceName = summary.ResourceName, Ratio = outputUnits, FlowMode = ResourceFlowMode.ALL_VESSEL_BALANCE, DumpExcess = true
                    };
                    outputList.Add(outputSource);
                }
            }

            //Leftovers
            if (!string.IsNullOrEmpty(byproduct))
            {
                byproductMass += (1.0f - totalAbundance) * yieldMass;
                outputUnits    = byproductMass / byproductDef.density;
                outputSource   = new ResourceRatio {
                    ResourceName = byproduct, Ratio = outputUnits, FlowMode = ResourceFlowMode.ALL_VESSEL_BALANCE, DumpExcess = true
                };
                outputList.Add(outputSource);
//                Debug.Log("FRED added " + byproduct + " to output list");
            }

//            Debug.Log("FRED totalAbundance: " + totalAbundance);
//            Debug.Log("FRED Slag Units: " + outputUnits);
//            Debug.Log("FRED output resources added: " + outputList.Count);
        }