public override void OnUpdate()
        {
            base.OnUpdate();

            //If we started a survey, then watch to see when the planet is unlocked.
            //Once the planet is unlocked, hide our orbital survey button and enable
            //resource monitoring
            if (monitorSurvey)
            {
                if (ResourceMap.Instance.IsPlanetScanned(FlightGlobals.currentMainBody.flightGlobalsIndex))
                {
                    //Check to see if we should show the tooltip
                    if (WBIPathfinderScenario.Instance.HasShownToolTip(this.ClassName) == false)
                    {
                        WBIPathfinderScenario.Instance.SetToolTipShown(this.ClassName);
                        WBIToolTipWindow introWindow = new WBIToolTipWindow(kToolTipTitle, kToolTip);
                        introWindow.SetVisible(true);
                    }
                    Events["PerformOrbitalSurvey"].guiActive          = false;
                    Events["PerformOrbitalSurvey"].guiActiveUnfocused = false;
                    monitorSurvey = false;
                    SetupGUI();
                }
            }

            if (ModuleIsActive())
            {
                Fields["scienceCollected"].guiActive = true;
                scienceCollected = string.Format("{0:f2}", scienceAdded);
            }
            else
            {
                Fields["scienceCollected"].guiActive = false;
            }
        }
Exemple #2
0
        protected override bool canAffordReconfigure(string templateName, bool deflatedModulesAutoPass = true)
        {
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            bool   canAfford    = base.canAffordReconfigure(templateName, deflatedModulesAutoPass);
            string requiredName = templateManager[templateName].GetValue("requiredResource");

            //If the vessel can't afford to reconfigure the module, then maybe the distribution manager can help.
            if (canAfford == false)
            {
                ScreenMessages.PostScreenMessage("Checking distributors...", 10.0f);
                if (string.IsNullOrEmpty(requiredName))
                {
                    return(true);
                }

                double distributedAmount = WBIDistributionManager.Instance.GetDistributedAmount(requiredName);
                if (distributedAmount >= reconfigureCost)
                {
                    ScreenMessages.PostScreenMessage("Distributors have enough " + requiredName, 10.0f);
                    return(true);
                }
            }

            //Add first time for redecoration
            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
Exemple #3
0
        public override void OnStart(StartState state)
        {
            ModuleResourceHarvester harvester;

            base.OnStart(state);

            //Get the drills
            groundDrills = this.part.FindModulesImplementing <ModuleResourceHarvester>();

            //Setup the drills with the new resource to drill for.
            if (drillResources != null)
            {
                for (int index = 0; index < drillResources.Length; index++)
                {
                    harvester = groundDrills[index];
                    harvester.ResourceName    = drillResources[index];
                    harvester.StartActionName = "Start " + drillResources[index] + " Drill";
                    harvester.StopActionName  = "Stop " + drillResources[index] + " Drill";
                    harvester.Fields["ResourceStatus"].guiName = drillResources[index] + " rate";
                }
            }

            //Setup the window
            drillSwitchWindow = new DrillSwitchWindow();
            drillSwitchWindow.groundDrills     = groundDrills;
            drillSwitchWindow.part             = this.part;
            drillSwitchWindow.reconfigureCost  = reconfigureCost;
            drillSwitchWindow.requiredResource = requiredResource;
            drillSwitchWindow.requiredSkill    = requiredSkill;

            //Setup GUI
            Events["ShowDrillSwitchWindow"].guiActiveUnfocused = Utils.HasResearchedNode(PathfinderSettings.drillTechNode);

            //Tooltip
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (scenario.HasShownToolTip(this.ClassName))
            {
                return;
            }
            scenario.SetToolTipShown(this.ClassName);

            WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kToolTipTitle, kDrillSwitchTooltip);

            toolTipWindow.SetVisible(true);
        }
Exemple #4
0
        protected override void notEnoughParts()
        {
            base.notEnoughParts();

            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            //Add first time for redecoration
            if (scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }
        }
Exemple #5
0
        protected override bool canAffordReconfigure(string templateName)
        {
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            bool canAfford = base.canAffordReconfigure(templateName);

            //Add first time for redecoration
            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
Exemple #6
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(this.part.partInfo.title))
            {
                return;
            }

            string           toolTip       = kToolTipSend;
            WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(this.part.partInfo.title, toolTip);

            toolTipWindow.SetVisible(true);

            //Cleanup
            scenario.SetToolTipShown(this.part.partInfo.title);
        }
Exemple #7
0
        protected override bool canAffordReconfigure(string templateName, bool deflatedModulesAutoPass = true)
        {
            showInsufficientResourcesMsg = false;
            bool canAfford = base.canAffordReconfigure(templateName, deflatedModulesAutoPass);

            //If the vessel can't afford to reconfigure the module, then maybe the distribution manager can help.
            if (canAfford == false)
            {
                canAfford = true;

                string[] keys = inputList.Keys.ToArray();
                string   resourceName;
                double   distributedAmount;
                for (int index = 0; index < keys.Length; index++)
                {
                    resourceName      = keys[index];
                    distributedAmount = WBIDistributionManager.Instance.GetDistributedAmount(resourceName);
                    Log("Distributors have " + distributedAmount + " units of " + resourceName);

                    if (distributedAmount < inputList[resourceName])
                    {
                        string notEnoughPartsMsg = string.Format(kInsufficientParts, inputList[resourceName], resourceName);
                        ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        ScreenMessages.PostScreenMessage("No active distributors have " + resourceName + " to share. Make sure resource distribution is turned on, and a distributor is sharing " + resourceName + ".", 10.0f);
                        canAfford = false;
                        break;
                    }
                }
            }

            //Add first time for redecoration
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
Exemple #8
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);
            }
        }
Exemple #9
0
        protected void checkAndShowToolTip()
        {
            //Check tooltips
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            string experimentName          = getExperimentName(currentExperiment);
            string experimentTip;

            //Add first time for redecoration
            if (scenario.HasShownToolTip(experimentName) == false)
            {
                scenario.SetToolTipShown(experimentName);

                switch (currentExperiment)
                {
                default:
                case GeologyLabExperiments.SoilAnalysis:
                    experimentTip = kTTSoilAnalysis;
                    break;

                case GeologyLabExperiments.MetallurgyAnalysis:
                    experimentTip = kTTMetalAnalysis;
                    break;

                case GeologyLabExperiments.ChemicalAnalysis:
                    experimentTip = kTTChemAnalysis;
                    break;

                case GeologyLabExperiments.BiomeAnalysis:
                    experimentTip = kTTBiomeAnalysis;
                    break;
                }

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kTTTitle + experimentName, experimentTip);
                toolTipWindow.SetVisible(true);
            }
        }
Exemple #10
0
        protected virtual void performAnalysis()
        {
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            float  experienceLevel = 0f;
            float  analysisRoll    = 0f;
            string analysisResultMessage;
            float  efficiencyModifier = 0f;
            float  currentModifier    = 0f;

            //Decrement the attempts remaining count
            int samplesLeft = getSamplesLeft() - 1;

            if (samplesLeft <= 0)
            {
                samplesLeft = 0;
            }
            WBIPathfinderScenario.Instance.SetCoreSamplesRemaining(this.part.vessel.mainBody.flightGlobalsIndex, biome.name, (HarvestTypes)resourceType, samplesLeft);
            coreSampleStatus = samplesLeft.ToString();

            UIPartActionWindow tweakableUI = Utils.FindActionWindow(this.part);

            if (tweakableUI != null)
            {
                tweakableUI.displayDirty = true;
            }

            //If an experienced scientist is taking the core sample, then the scientist's experience will
            //affect the analysis.
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                if (experience.TypeName == analysisSkill)
                {
                    experienceLevel = experience.CrewMemberExperienceLevel();
                }
            }

            //Add in the science lab bonus
            experienceLevel += getGeologyLabBonus();

            //Seed the random number generator
            UnityEngine.Random.seed = System.Environment.TickCount;

            //Roll 3d6 to approximate a bell curve, then convert it to a value between 1 and 100.
            analysisRoll  = UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll *= 5.5556f;

            //Now add the experience modifier
            analysisRoll += experienceLevel * kExperiencePercentModifier;

            //TODO: Did we strike gold?

            //Since we're using a bell curve, anything below maxWorsenRoll worsens the biome's extraction rates.
            //Anything above minImprovementRoll improves the biome's extraction rates.
            //A skilled scientist can affect the modifier by as much as 5%.
            if (analysisRoll <= maxWorsenRoll)
            {
                //Calculate the modifier
                efficiencyModifier = -kBaseEfficiencyModifier * (1.0f - (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionWorsened, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);

                //Modify harvesters on the active vessel
                WBIDrillManager.Instance.UpdateHarvesterEfficiencies(this.part.vessel);
            }

            //Good result!
            else if (analysisRoll >= minImprovementRoll)
            {
                //Calculate the modifier
                efficiencyModifier = kBaseEfficiencyModifier * (1.0f + (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionImproved, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);

                //Modify harvisters on the active vessel
                WBIDrillManager.Instance.UpdateHarvesterEfficiencies(this.part.vessel);
            }

            else
            {
                analysisResultMessage = kResourceExtractionUnchanged + biome.name;
            }

            //Inform the player of the result.
            ScreenMessages.PostScreenMessage(analysisResultMessage, 5.0f, ScreenMessageStyle.UPPER_CENTER);
            DeployExperiment();


            //First timers: show the tooltip.
            if (WBIPathfinderScenario.Instance.HasShownToolTip(kToolTip) == false)
            {
                WBIPathfinderScenario.Instance.SetToolTipShown(kToolTip);

                WBIToolTipWindow introWindow = new WBIToolTipWindow(kFirstCoreSampleTitle, kFirstCoreSampleMsg);
                introWindow.SetVisible(true);
            }
        }