Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
                    }
                }
            }
        }