public override void OnStart(StartState state) { base.OnStart(state); harvester = this.part.FindModuleImplementing <ModuleResourceHarvester>(); drillSwitcher = this.part.FindModuleImplementing <WBIDrillSwitcher>(); if (drillSwitcher != null) { drillSwitcher.Events["ShowDrillSwitchWindow"].guiActive = false; drillSwitcher.Events["ShowDrillSwitchWindow"].guiActiveUnfocused = false; } extractionMonitor = this.part.FindModuleImplementing <WBIExtractionMonitor>(); if (extractionMonitor != null) { extractionMonitor.Fields["extractionRateChange"].guiActive = false; } overheatDisplay = this.part.FindModuleImplementing <ModuleOverheatDisplay>(); }
public void PartUnpacked(Part part) { if (HighLogic.LoadedSceneIsFlight == false) { return; } WBIExtractionMonitor extractionMonitor = null; if (part.FindModuleImplementing <ModuleResourceHarvester>() == null) { return; } //Add an extraction monitor if needed. extractionMonitor = part.FindModuleImplementing <WBIExtractionMonitor>(); if (extractionMonitor == null) { extractionMonitor = (WBIExtractionMonitor)part.AddModule("WBIExtractionMonitor"); extractionMonitor.OnActive(); extractionMonitor.OnStart(PartModule.StartState.Landed); extractionMonitor = null; } }
public void UpdateHarvesterEfficiencies(Vessel vessel) { CBAttributeMapSO.MapAttribute biome = null; List <ModuleResourceHarvester> harvesters = null; Dictionary <string, EfficiencyData> efficiencyMap = null; WBIExtractionMonitor extractionMonitor = null; string key; int harvestID; //If the vessel has landed, find out what biome it is located in. if (vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH || vessel.situation == Vessel.Situations.SPLASHED) { biome = Utils.GetCurrentBiome(vessel); } //TODO: No biome? We need to figure out what to do about asteroids. //For now, we're done if (biome == null) { return; } //If our Scenario has efficiency data for the biome, then retrieve it. efficiencyMap = WBIPathfinderScenario.Instance.GetEfficiencyDataForBiome(vessel.mainBody.flightGlobalsIndex, biome.name); if (efficiencyMap == null) { return; } //Go through the vessel's parts and find all the parts that implement ModuleResourceHarvester. foreach (Part part in vessel.parts) { harvesters = part.FindModulesImplementing <ModuleResourceHarvester>(); if (harvesters.Count == 0) { continue; } //Add an extraction monitor if needed. extractionMonitor = part.FindModuleImplementing <WBIExtractionMonitor>(); if (extractionMonitor == null) { extractionMonitor = (WBIExtractionMonitor)part.AddModule("WBIExtractionMonitor"); extractionMonitor.OnActive(); extractionMonitor.OnStart(PartModule.StartState.Landed); extractionMonitor = null; } //For each ModuleResourceHarvester, multiply the harvester's Efficiency by the biome's EfficiencyModifier. //Note that the efficiency modifier applies to all drills of the specified harvest type regardless of resource. //Mostly because I don't see a need to modify individual resources and just knowing that your drills are ###% better or worse //is all a player really cares about. foreach (ModuleResourceHarvester harvester in harvesters) { harvestID = (int)harvester.HarvesterType; key = biome.name + harvestID.ToString(); if (efficiencyMap.ContainsKey(key)) { //It's possible that the player may repeatedly take core samples until getting a different result. //We want the modified result to always be based on the original efficiency. if (originalHarvesterEfficiencies.ContainsKey(harvester)) { harvester.Efficiency = originalHarvesterEfficiencies[harvester] * efficiencyMap[key].modifiers[EfficiencyData.kExtractionMod]; } //Multiply the harvester's efficiency by the modifier, and add the orignal value to the map. else { originalHarvesterEfficiencies.Add(harvester, harvester.Efficiency); harvester.Efficiency *= efficiencyMap[key].modifiers[EfficiencyData.kExtractionMod]; } //Dirty the harvester harvester.DirtyFlag = true; } } } }
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; } WBIExtractionMonitor extractionMonitor = this.part.FindModuleImplementing <WBIExtractionMonitor>(); 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); } }