Ejemplo n.º 1
0
        protected void updateScienceLab()
        {
            bool enableMPLModules = false;

            if (CurrentTemplate.HasValue("enableMPLModules"))
            {
                enableMPLModules = bool.Parse(CurrentTemplate.GetValue("enableMPLModules"));
            }

            ModuleScienceLab sciLab = this.part.FindModuleImplementing <ModuleScienceLab>();

            if (sciLab != null)
            {
                if (HighLogic.LoadedSceneIsEditor)
                {
                    sciLab.isEnabled = false;
                    sciLab.enabled   = false;
                }

                else if (enableMPLModules)
                {
                    sciLab.isEnabled     = true;
                    sciLab.enabled       = true;
                    sciLab.crewsRequired = originalCrewsRequired;
                }
                else
                {
                    sciLab.crewsRequired = 2000.0f;
                    sciLab.isEnabled     = false;
                    sciLab.enabled       = false;
                }
            }
        }
Ejemplo n.º 2
0
 public string GetCheckSkill()
 {
     if (CurrentTemplate.HasValue("reconfigureSkill"))
     {
         return(CurrentTemplate.GetValue("reconfigureSkill"));
     }
     else
     {
         return("RepairSkill");
     }
 }
Ejemplo n.º 3
0
        public override void RedecorateModule(bool loadTemplateResources = true)
        {
            base.RedecorateModule(loadTemplateResources);
            bool enableMPLModules = false;

            if (CurrentTemplate.HasValue("enableMPLModules"))
            {
                enableMPLModules = bool.Parse(CurrentTemplate.GetValue("enableMPLModules"));
            }

            ModuleScienceLab sciLab = this.part.FindModuleImplementing <ModuleScienceLab>();

            if (sciLab != null)
            {
                if (HighLogic.LoadedSceneIsEditor)
                {
                    sciLab.isEnabled = false;
                    sciLab.enabled   = false;
                }

                else if (enableMPLModules)
                {
                    sciLab.isEnabled     = true;
                    sciLab.enabled       = true;
                    sciLab.crewsRequired = originalCrewsRequired;
                }
                else
                {
                    sciLab.crewsRequired = 2000.0f;
                    sciLab.isEnabled     = false;
                    sciLab.enabled       = false;
                }
            }

            ModuleScienceConverter converter = this.part.FindModuleImplementing <ModuleScienceConverter>();

            if (converter != null)
            {
                if (HighLogic.LoadedSceneIsEditor)
                {
                    converter.isEnabled = enableMPLModules;
                    converter.enabled   = enableMPLModules;
                }

                else
                {
                    converter.isEnabled = enableMPLModules;
                    converter.enabled   = enableMPLModules;
                }
            }
        }
Ejemplo n.º 4
0
        public void showAssemblyRequirements()
        {
            StringBuilder requirementsList = new StringBuilder();
            string        templateName     = "";

            //If we have a template then be sure to list its requirements.
            //Template name
            if (CurrentTemplate.HasValue("title"))
            {
                templateName = CurrentTemplate.GetValue("title");
            }
            else
            {
                templateName = CurrentTemplate.GetValue("name");
            }
            if (templateName.ToLower() != "empty")
            {
                requirementsList.AppendLine("Configuration: " + templateName);
            }

            //Resource Requirements.
            buildInputList(templateName);
            string[] keys = inputList.Keys.ToArray();
            for (int index = 0; index < keys.Length; index++)
            {
                requirementsList.Append(keys[index]);
                requirementsList.Append(": ");
                requirementsList.AppendLine(string.Format("{0:f2}", inputList[keys[index]]));
            }

            if (keys.Length == 0)
            {
                requirementsList.AppendLine("No resource requirements");
            }

            InfoView infoView = new InfoView();

            infoView.ModuleInfo = requirementsList.ToString();
            infoView.SetVisible(true);
        }
Ejemplo n.º 5
0
        protected void checkAndShowToolTip()
        {
            //Now we can check to see if the tooltip for the current template has been shown.
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (scenario.HasShownToolTip(CurrentTemplateName) && scenario.HasShownToolTip(getMyPartName()))
            {
                return;
            }
            if (!CurrentTemplate.HasValue("toolTipTitle") && !CurrentTemplate.HasValue("toolTip"))
            {
                return;
            }

            //Tooltip for the current template has never been shown. Show it now.
            string toolTipTitle = CurrentTemplate.GetValue("toolTipTitle");
            string toolTip      = CurrentTemplate.GetValue("toolTip");

            if (string.IsNullOrEmpty(toolTipTitle))
            {
                toolTipTitle = partToolTipTitle;
            }

            //Add the very first part's tool tip.
            if (scenario.HasShownToolTip(getMyPartName()) == false)
            {
                toolTip = partToolTip + "\r\n\r\n" + toolTip;

                scenario.SetToolTipShown(getMyPartName());
            }

            if (string.IsNullOrEmpty(toolTip) == false)
            {
                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(toolTipTitle, toolTip);
                toolTipWindow.SetVisible(true);

                //Cleanup
                scenario.SetToolTipShown(CurrentTemplateName);
            }
        }
Ejemplo n.º 6
0
        protected void updateWorkshop()
        {
            PartModule oseWorkshop    = null;
            PartModule oseRecycler    = null;
            bool       enableWorkshop = false;

            //See if the drill is enabled.
            if (CurrentTemplate.HasValue("enableWorkshop"))
            {
                enableWorkshop = bool.Parse(CurrentTemplate.GetValue("enableWorkshop"));
            }

            //Find the workshop modules
            foreach (PartModule pm in this.part.Modules)
            {
                if (pm.moduleName == "OseModuleWorkshop")
                {
                    oseWorkshop = pm;
                }
                else if (pm.moduleName == "OseModuleRecycler")
                {
                    oseRecycler = pm;
                }
            }

            if (oseWorkshop != null)
            {
                oseWorkshop.enabled   = enableWorkshop;
                oseWorkshop.isEnabled = enableWorkshop;
            }

            if (oseRecycler != null)
            {
                oseRecycler.enabled   = enableWorkshop;
                oseRecycler.isEnabled = enableWorkshop;
            }
        }
Ejemplo n.º 7
0
        protected virtual void updatePartMass()
        {
            if (CurrentTemplate.HasValue("mass"))
            {
                partMass = float.Parse(CurrentTemplate.GetValue("mass"));
            }

            else
            {
                PartResourceDefinition definition;
                buildInputList(CurrentTemplateName);
                string[] keys = inputList.Keys.ToArray();
                string   resourceName;

                partMass = 0;
                for (int index = 0; index < keys.Length; index++)
                {
                    resourceName = keys[index];
                    definition   = ResourceHelper.DefinitionForResource(resourceName);

                    partMass += definition.density * (float)inputList[resourceName];
                }
            }
        }
Ejemplo n.º 8
0
        protected override bool canAffordReconfigure(string templateName)
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!payForReconfigure)
            {
                return(true);
            }
            string value;
            bool   canAffordCost = false;

            requriredResource = templatesModel[templateName].GetValue("rocketParts");
            if (string.IsNullOrEmpty(requriredResource) == false)
            {
                float reconfigureAmount           = float.Parse(requriredResource);
                PartResourceDefinition definition = ResourceHelper.DefinitionForResource("RocketParts");
                Vessel.ActiveResource  resource   = this.part.vessel.GetActiveResource(definition);

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

                //Get the current template's rocket part cost.
                value = CurrentTemplate.GetValue("rocketParts");
                if (string.IsNullOrEmpty(value) == false)
                {
                    float recycleAmount = float.Parse(value);

                    //calculate the amount of parts that we can recycle.
                    recycleAmount *= calculateRecycleAmount();

                    //Now recalculate rocketPartCost, accounting for the parts we can recycle.
                    //A negative value means we'll get parts back, a positive number means we pay additional parts.
                    //Ex: current configuration takes 1200 parts. new configuration takes 900.
                    //We recycle 90% of the current configuration (1080 parts).
                    //The reconfigure cost is: 900 - 1080 = -180 parts
                    //If we reverse the numbers so new configuration takes 1200: 1200 - (900 * .9) = 390
                    reconfigureCost = reconfigureAmount - recycleAmount;
                }

                //now check to make sure the vessel has enough parts.
                if (resource == null)
                {
                    canAffordCost = false;
                }

                else if (resource.amount < reconfigureCost)
                {
                    canAffordCost = false;
                }

                else
                {
                    canAffordCost = true;
                }
            }

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

            return(true);
        }
Ejemplo n.º 9
0
        protected void updateDrill()
        {
            bool   enableDrill = false;
            float  value;
            string resourceName;
            ModuleResourceHarvester harvester = this.part.FindModuleImplementing <ModuleResourceHarvester>();

            //No drill? No need to proceed.
            if (harvester == null)
            {
                return;
            }

            //See if the drill is enabled.
            if (CurrentTemplate.HasValue("enableDrill"))
            {
                enableDrill = bool.Parse(CurrentTemplate.GetValue("enableDrill"));
            }

            ModuleOverheatDisplay overheat = this.part.FindModuleImplementing <ModuleOverheatDisplay>();

            if (overheat != null)
            {
                overheat.enabled   = enableDrill;
                overheat.isEnabled = enableDrill;
            }

            ModuleCoreHeat coreHeat = this.part.FindModuleImplementing <ModuleCoreHeat>();

            if (coreHeat != null)
            {
                coreHeat.enabled   = enableDrill;
                coreHeat.isEnabled = enableDrill;
            }

            WBIDrillSwitcher drillSwitcher = this.part.FindModuleImplementing <WBIDrillSwitcher>();

            if (drillSwitcher != null)
            {
                drillSwitcher.enabled   = enableDrill;
                drillSwitcher.isEnabled = enableDrill;
            }

            WBIEfficiencyMonitor extractionMonitor = this.part.FindModuleImplementing <WBIEfficiencyMonitor>();

            if (extractionMonitor != null)
            {
                extractionMonitor.enabled   = enableDrill;
                extractionMonitor.isEnabled = enableDrill;
            }

            //Update the drill
            if (enableDrill)
            {
                harvester.EnableModule();
            }
            else
            {
                harvester.DisableModule();
            }

            //Setup drill parameters
            if (enableDrill)
            {
                if (CurrentTemplate.HasValue("converterName"))
                {
                    harvester.ConverterName = CurrentTemplate.GetValue("converterName");
                }

                if (CurrentTemplate.HasValue("drillStartAction"))
                {
                    harvester.StartActionName = CurrentTemplate.GetValue("drillStartAction");
                    harvester.Events["StartResourceConverter"].guiName = CurrentTemplate.GetValue("drillStartAction");
                }

                if (CurrentTemplate.HasValue("drillStopAction"))
                {
                    harvester.StopActionName = CurrentTemplate.GetValue("drillStopAction");
                    harvester.Events["StopResourceConverter"].guiName = CurrentTemplate.GetValue("drillStopAction");
                }

                if (CurrentTemplate.HasValue("drillEficiency"))
                {
                    harvester.Efficiency = float.Parse(CurrentTemplate.GetValue("drillEficiency"));
                }

                if (CurrentTemplate.HasValue("drillResource"))
                {
                    resourceName           = CurrentTemplate.GetValue("drillResource");
                    harvester.ResourceName = resourceName;
                    harvester.Fields["ResourceStatus"].guiName = resourceName + " rate";
                }

                if (CurrentTemplate.HasValue("drillElectricCharge"))
                {
                    if (float.TryParse(CurrentTemplate.GetValue("drillElectricCharge"), out value))
                    {
                        ResourceRatio[] inputRatios = harvester.inputList.ToArray();
                        for (int inputIndex = 0; inputIndex < inputRatios.Length; inputIndex++)
                        {
                            if (inputRatios[inputIndex].ResourceName == "ElectricCharge")
                            {
                                inputRatios[inputIndex].Ratio = value;
                            }
                        }
                    }
                }

                harvester.Fields["status"].guiName = "Drill Status";
                MonoUtilities.RefreshContextWindows(this.part);
            }
        }
Ejemplo n.º 10
0
        public override void ToggleInflation()
        {
            PartResourceDefinition definition = ResourceHelper.DefinitionForResource("RocketParts");

            Vessel.ActiveResource resource = this.part.vessel.GetActiveResource(definition);
            string parts = CurrentTemplate.GetValue("rocketParts");

            if (string.IsNullOrEmpty(parts))
            {
                base.ToggleInflation();
                return;
            }
            float partCost = float.Parse(parts);

            calculateRemodelCostModifier();
            float adjustedPartCost = partCost;

            if (reconfigureCostModifier > 0f)
            {
                adjustedPartCost *= reconfigureCostModifier;
            }

            //Do we pay for resources? If so, either pay the resources if we're deploying the module, or refund the recycled parts
            if (payForReconfigure)
            {
                //If we aren't deployed then see if we can afford to pay the resource cost.
                if (!isDeployed)
                {
                    //Can we afford it?
                    if (resource == null || resource.amount < adjustedPartCost)
                    {
                        notEnoughParts();
                        string notEnoughPartsMsg = string.Format("Insufficient resources to assemble the module. You need a total of {0:f2} RocketParts to assemble.", partCost);
                        ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }

                    //Yup, we can afford it
                    //Pay the reconfigure cost
                    reconfigureCost = adjustedPartCost;
                    payPartsCost();

                    // Toggle after payment.
                    base.ToggleInflation();
                }

                //We are deployed, calculate the amount of parts that can be refunded.
                else
                {
                    // Toggle first in case deflate confirmation is needed, we'll check the state after the toggle.
                    base.ToggleInflation();

                    // deflateConfirmed's logic seems backward.
                    if (!HasResources() || (HasResources() && deflateConfirmed == false))
                    {
                        // The part came from the factory configured which represents an additional resource cost. If reconfigured in the field, the difference was paid at
                        // that time. Deflating doesn't remove any functionality, so no refund beyond the original adjusted part cost.
                        float recycleAmount = adjustedPartCost;

                        //Do we have sufficient space in the vessel to store the recycled parts?
                        float availableStorage = (float)(resource.maxAmount - resource.amount);

                        if (availableStorage < recycleAmount)
                        {
                            float amountLost = recycleAmount - availableStorage;
                            ScreenMessages.PostScreenMessage(string.Format("Module deflated, {0:f2} {1:s} lost due to insufficient storage.", amountLost, "RocketParts"), 5.0f, ScreenMessageStyle.UPPER_CENTER);

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

                        //Yup, we have the space
                        reconfigureCost = -recycleAmount;
                        payPartsCost();
                    }
                }
            }

            // Not paying for reconfiguration, check for skill requirements
            else
            {
                if (checkForSkill)
                {
                    if (hasSufficientSkill(CurrentTemplateName))
                    {
                        base.ToggleInflation();
                    }
                    else
                    {
                        return;
                    }
                }

                else
                {
                    base.ToggleInflation();
                }
            }
        }
Ejemplo n.º 11
0
        public override void ToggleInflation()
        {
            if (CurrentTemplate.HasValue("requiredResource") == false || HighLogic.LoadedSceneIsEditor)
            {
                base.ToggleInflation();
                return;
            }

            string requiredName   = CurrentTemplate.GetValue("requiredResource");
            string requiredAmount = CurrentTemplate.GetValue("requiredAmount");
            float  totalResources = (float)ResourceHelper.GetTotalResourceAmount(requiredName, this.part.vessel);

            if (string.IsNullOrEmpty(requiredAmount))
            {
                base.ToggleInflation();
                return;
            }
            float resourceCost = float.Parse(requiredAmount);

            calculateRemodelCostModifier();
            float adjustedPartCost = resourceCost;

            if (reconfigureCostModifier > 0f)
            {
                adjustedPartCost *= reconfigureCostModifier;
            }

            //Do we pay for resources? If so, either pay the resources if we're deploying the module, or refund the recycled parts
            if (WBIMainSettings.PayToReconfigure)
            {
                //If we aren't deployed then see if we can afford to pay the resource cost.
                if (!isDeployed)
                {
                    //Can we afford it?
                    if (canAffordReconfigure(CurrentTemplateName, false) == false)
                    {
                        return;
                    }

                    //Do we have the skill?
                    if (!hasSufficientSkill(CurrentTemplateName))
                    {
                        return;
                    }

                    //Yup, we can afford it
                    //Pay the reconfigure cost
                    //reconfigureCost = adjustedPartCost;
                    payPartsCost(CurrentTemplateIndex);

                    // Toggle after payment.
                    base.ToggleInflation();
                }

                //We are deployed, calculate the amount of parts that can be refunded.
                else
                {
                    // Toggle first in case deflate confirmation is needed, we'll check the state after the toggle.
                    base.ToggleInflation();

                    //Recycle what we can.

                    // deflateConfirmed's logic seems backward.
                    if (!HasResources() || (HasResources() && deflateConfirmed == false))
                    {
                        recoverResourceCost(requiredName, adjustedPartCost * recycleBase);
                    }
                }
            }

            // Not paying for reconfiguration, check for skill requirements
            else
            {
                if (WBIMainSettings.RequiresSkillCheck)
                {
                    if (hasSufficientSkill(CurrentTemplateName))
                    {
                        base.ToggleInflation();
                    }
                    else
                    {
                        return;
                    }
                }

                else
                {
                    base.ToggleInflation();
                }
            }
        }