public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (originalCriticalFail == -1)
            {
                originalCriticalFail = criticalFail;
                currentCriticalFail  = criticalFail;
            }

            criticalFail = currentCriticalFail;

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            float efficiencyModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biomeName, harvestID, efficiencyType);

            if (this.EfficiencyBonus != efficiencyModifier)
            {
                this.EfficiencyBonus = efficiencyModifier;
            }

            SetupGUI();
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }
            infoView = new InfoView();
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            moduleSwitcher = this.part.FindModuleImplementing <WBIModuleSwitcher>();

            GameEvents.onCrewOnEva.Add(this.onCrewEVA);
            GameEvents.onCrewTransferred.Add(this.onCrewTransfer);
            GameEvents.onCrewBoardVessel.Add(this.onCrewBoardVessel);

            originalCriticalSuccess = criticalSuccess;
            setupModuleInfo();
        }
Esempio n. 3
0
        public void ResetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.efficiencyModifier = 1.0f;
                efficiencyData.attemptsRemaining = kMaxCoreSamples;
            }

            else
            {
                //Create a new entry.
                efficiencyData = new EfficiencyData();
                efficiencyData.planetID = planetID;
                efficiencyData.biomeName = biomeName;
                efficiencyData.harvestType = harvestType;
                efficiencyData.efficiencyModifier = 1.0f;
                efficiencyData.attemptsRemaining = kMaxCoreSamples;

                efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
            }
        }
Esempio n. 4
0
        public float GetEfficiencyModifier(int planetID, string biomeName, HarvestTypes harvestType, string modifierName)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                if (efficiencyData.modifiers.ContainsKey(modifierName))
                {
                    return(efficiencyData.modifiers[modifierName]);
                }
                else
                {
                    return(1.0f);
                }
            }

            else
            {
                //Create a new entry.
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            return(1.0f);
        }
        public void SetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType, string modifierName, float modifierValue)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            //Create a new entry if needed.
            if (!efficiencyDataMap.ContainsKey(key))
            {
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            //If we already have the efficiency data then just update the value
            efficiencyData = efficiencyDataMap[key];
            if (efficiencyData.modifiers.ContainsKey(modifierName))
            {
                efficiencyData.modifiers[modifierName] = modifierValue;
            }
            else
            {
                efficiencyData.modifiers.Add(modifierName, modifierValue);
            }

            //Update interested parties
            if (onEfficiencyUpdate != null)
            {
                onEfficiencyUpdate(planetID, biomeName, harvestType, modifierName, modifierValue);
            }
        }
Esempio n. 6
0
        public void ResetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.efficiencyModifier = 1.0f;
                efficiencyData.attemptsRemaining  = kMaxCoreSamples;
            }

            else
            {
                //Create a new entry.
                efficiencyData                    = new EfficiencyData();
                efficiencyData.planetID           = planetID;
                efficiencyData.biomeName          = biomeName;
                efficiencyData.harvestType        = harvestType;
                efficiencyData.efficiencyModifier = 1.0f;
                efficiencyData.attemptsRemaining  = kMaxCoreSamples;

                efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
            }
        }
        public override void OnUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            //Get the current biome
            string biomeName = Utils.GetCurrentBiomeName(this.part.vessel);

            //Determine the harvest type from the current vessel situation
            HarvestTypes situationType = getHarvestSituation();

            //If our harvest types are mismatched then rebuild the resource ratios
            if (currentHarvestType != situationType)
            {
                currentHarvestType = situationType;
                setupHarvester();
            }

            //Check the biome
            else if (currentBiome != biomeName)
            {
                currentBiome = biomeName;
                setupHarvester();
            }

            //And make sure our abundance summary is up to date
            else if (resourceRatios.Count == 0)
            {
                setupHarvester();
            }

            base.OnUpdate();
        }
Esempio n. 8
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

                biomeName = biome.name;
                harvestID = (HarvestTypes)harvestType;
                planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            converters = this.part.FindModulesImplementing <ModuleResourceConverter>();

            originalEfficiencyType = efficiencyType;
            originalHarvestType    = harvestType;

            switcher = this.part.FindModuleImplementing <WBIResourceSwitcher>();
            if (switcher != null)
            {
                switcher.onModuleRedecorated += new ModuleRedecoratedEvent(switcher_onModuleRedecorated);
            }
        }
Esempio n. 9
0
        protected int getSamplesLeft()
        {
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            HarvestTypes harvestType            = (HarvestTypes)resourceType;
            int          samplesLeft            = WBIPathfinderScenario.Instance.GetCoreSamplesRemaining(this.part.vessel.mainBody.flightGlobalsIndex, biome.name, harvestType);

            return(samplesLeft);
        }
Esempio n. 10
0
        public void SetCoreSamplesRemaining(int planetID, string biomeName, HarvestTypes harvestType, int attemptsRemaining)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.attemptsRemaining = attemptsRemaining;
            }
        }
Esempio n. 11
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestType = HarvestTypes.Planetary;
                planetID    = this.part.vessel.mainBody.flightGlobalsIndex;
            }
        }
Esempio n. 12
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestType = HarvestTypes.Planetary;
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
            }
        }
Esempio n. 13
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

                biomeName = biome.name;
                harvestID = (HarvestTypes)harvestType;
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            converters = this.part.FindModulesImplementing<ModuleResourceConverter>();
        }
Esempio n. 14
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            converters = this.part.FindModulesImplementing <ModuleResourceConverter>();
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            Fields["efficiencyDisplayString"].guiName = efficiencyGUIName;

            //Get our biome, planet, and harvest ID.
            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

                if (biome != null)
                {
                    biomeName = biome.name;
                    harvestID = (HarvestTypes)harvestType;
                    planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
                }
            }

            //Get our converters
            converters = this.part.FindModulesImplementing <BaseConverter>();

            //Make sure we know the original efficiency and harvest type since these can change.
            originalEfficiencyType = efficiencyType;
            originalHarvestType    = harvestType;

            //Hook into the switcher's events
            switcher = this.part.FindModuleImplementing <WBIResourceSwitcher>();
            if (switcher != null)
            {
                switcher.onModuleRedecorated += switcher_onModuleRedecorated;
            }

            //Hook into the scenario's events
            WBIPathfinderScenario.Instance.onEfficiencyUpdate += onEfficiencyUpdate;

            //Make sure that we set up efficiency
            if (!string.IsNullOrEmpty(biomeName))
            {
                onEfficiencyUpdate(planetID, biomeName, harvestID, efficiencyType,
                                   WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biomeName, harvestID, efficiencyType));
            }
        }
        protected void createNewEfficencyEntry(int planetID, string biomeName, HarvestTypes harvestType)
        {
            EfficiencyData efficiencyData = new EfficiencyData();

            efficiencyData.planetID          = planetID;
            efficiencyData.biomeName         = biomeName;
            efficiencyData.harvestType       = harvestType;
            efficiencyData.attemptsRemaining = kMaxCoreSamples;

            //Standard modifiers
            efficiencyData.modifiers.Add(EfficiencyData.kExtractionMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kIndustryMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kHabitationMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kScienceMod, 1.0f);

            efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
        }
Esempio n. 17
0
        public void Load(ConfigNode node)
        {
            string value;
            string modifierName;

            value = node.GetValue("planetID");
            if (string.IsNullOrEmpty(value) == false)
            {
                planetID = int.Parse(value);
            }

            biomeName = node.GetValue("biomeName");

            value = node.GetValue("harvestType");
            if (string.IsNullOrEmpty(value) == false)
            {
                harvestType = (HarvestTypes)int.Parse(value);
            }

            value = node.GetValue("attemptsRemaining");
            if (string.IsNullOrEmpty(value) == false)
            {
                attemptsRemaining = int.Parse(value);
            }

            //Modifiers
            modifiers.Clear();
            ConfigNode[] modifierNodes = node.GetNodes("MODIFIER");
            if (modifierNodes != null)
            {
                foreach (ConfigNode modNode in modifierNodes)
                {
                    modifierName = modNode.GetValue("name");
                    value        = modNode.GetValue("value");
                    modifiers.Add(modifierName, float.Parse(value));
                }
            }

            //Backwards compatibility
            value = node.GetValue("efficiencyModifier");
            if (string.IsNullOrEmpty(value) == false)
            {
                modifiers.Add("extractionModifier", float.Parse(value));
            }
        }
        public void ResetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            //Create a new entry if needed.
            if (!efficiencyDataMap.ContainsKey(key))
            {
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            efficiencyData = efficiencyDataMap[key];
            foreach (string modifierKey in efficiencyData.modifiers.Keys)
            {
                efficiencyData.modifiers[modifierKey] = 1.0f;
            }
            efficiencyData.attemptsRemaining = kMaxCoreSamples;
        }
Esempio n. 19
0
        public int GetCoreSamplesRemaining(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                return efficiencyData.attemptsRemaining;
            }

            else
            {
                //Create a new entry.
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            return kMaxCoreSamples;
        }
        public int GetCoreSamplesRemaining(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                return(efficiencyData.attemptsRemaining);
            }

            else
            {
                //Create a new entry.
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            return(kMaxCoreSamples);
        }
Esempio n. 21
0
        protected bool situationIsValid()
        {
            HarvestTypes harvestType = (HarvestTypes)resourceType;
            bool         isValid     = true;
            string       message     = null;

            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }

            switch (this.part.vessel.situation)
            {
            case Vessel.Situations.LANDED:
            case Vessel.Situations.PRELAUNCH:
                if (harvestType != HarvestTypes.Planetary && harvestType != HarvestTypes.Atmospheric)
                {
                    isValid = false;
                    message = kNeedVesselLanded;
                }
                break;

            case Vessel.Situations.SPLASHED:
                if (harvestType != HarvestTypes.Oceanic)
                {
                    isValid = false;
                    message = kNeedVesselSplashed;
                }
                break;

            default:
                return(false);
            }

            //Inform the player if needed
            if (message != null)
            {
                ScreenMessages.PostScreenMessage(message, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            }

            return(isValid);
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            //Setup info view
            infoView                 = new HarvestView();
            infoView.WindowTitle     = this.part.partInfo.title;
            infoView.part            = this.part;
            infoView.onBiomeUnlocked = setupHarvester;

            //Setup the resource ratio list
            resourceRatios = new List <ResourceRatio>();

            //Setup supplementary output ratios
            setupSupplementaryOutputs();

            //Setup the harvest types
            harvestTypeList = new List <HarvestTypes>();
            if (!string.IsNullOrEmpty(harvestTypes))
            {
                HarvestTypes type;
                string[]     types = harvestTypes.Split(new char[] { ';' });
                for (int index = 0; index < types.Length; index++)
                {
                    type = (HarvestTypes)Enum.Parse(typeof(HarvestTypes), types[index]);
                    harvestTypeList.Add(type);
                }
            }

            //Use HarvesterType
            else
            {
                harvestTypeList.Add((HarvestTypes)this.HarvesterType);
            }

            //If in flight then setup the harvester
            if (HighLogic.LoadedSceneIsFlight)
            {
                this.currentHarvestType = getHarvestSituation();
                setupHarvester();
            }
        }
Esempio n. 23
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            //Setup the resource ratio list
            resourceRatios = new List <ResourceRatio>();

            //Setup the harvest types
            harvestTypeList = new List <HarvestTypes>();
            HarvestTypes type;

            string[] types = harvestTypes.Split(new char[] { ';' });
            for (int index = 0; index < types.Length; index++)
            {
                type = (HarvestTypes)Enum.Parse(typeof(HarvestTypes), types[index]);
                harvestTypeList.Add(type);
            }
            currentHarvestType = (HarvestTypes)HarvesterType;
            HarvesterType      = (int)currentHarvestType;
        }
Esempio n. 24
0
        void switcher_onModuleRedecorated(ConfigNode templateNode)
        {
            if (templateNode.HasValue("efficiencyType"))
            {
                efficiencyType = templateNode.GetValue("efficiencyType");
            }
            else
            {
                efficiencyType = originalEfficiencyType;
            }

            if (templateNode.HasValue("harvestType"))
            {
                harvestID = (HarvestTypes)int.Parse(templateNode.GetValue("harvestType"));
            }
            else
            {
                harvestID = (HarvestTypes)originalHarvestType;
            }
        }
Esempio n. 25
0
        protected void applyResults(float efficiencyModifier, string resultsPreamble)
        {
            int          planetID    = this.part.vessel.mainBody.flightGlobalsIndex;
            HarvestTypes harvestType = HarvestTypes.Planetary;

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            string biomeName      = biome.name;
            string modifierName   = "";
            string processChanged = "";

            switch (currentExperiment)
            {
            case GeologyLabExperiments.SoilAnalysis:
                modifierName   = EfficiencyData.kHabitationMod;
                processChanged = kLifeSupport;
                break;

            case GeologyLabExperiments.MetallurgyAnalysis:
                modifierName   = EfficiencyData.kIndustryMod;
                processChanged = kManufacturing;
                break;

            default:
            case GeologyLabExperiments.ChemicalAnalysis:
                modifierName   = EfficiencyData.kScienceMod;
                processChanged = kChemicalProducts;
                break;
            }

            //Get existing modifier
            float currentModifer = WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biome.name, harvestType, modifierName);

            //Add improvement
            currentModifer += efficiencyModifier;
            WBIPathfinderScenario.Instance.SetEfficiencyData(planetID, biome.name, harvestType, modifierName, currentModifer);

            //Inform user
            string message = string.Format(resultsPreamble, efficiencyModifier * 100f) + processChanged + "</color>";

            ScreenMessages.PostScreenMessage(message, 8.0f, ScreenMessageStyle.UPPER_CENTER);
        }
Esempio n. 26
0
        public float GetEfficiencyModifier(int planetID, string biomeName, HarvestTypes harvestType, string modifierName)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                if (efficiencyData.modifiers.ContainsKey(modifierName))
                    return efficiencyData.modifiers[modifierName];
                else
                    return 1.0f;
            }

            else
            {
                //Create a new entry.
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }

            return 1.0f;
        }
Esempio n. 27
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            ResourceRatio[] outputs = outputList.ToArray();
            ResourceRatio   output;

            for (int index = 0; index < outputs.Length; index++)
            {
                output = outputs[index];
                if (output.ResourceName == "ElectricCharge")
                {
                    ecBaseOutput = output.Ratio;
                    break;
                }
            }

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID  = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            float efficiencyModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biomeName, harvestID, efficiencyType);

            if (this.EfficiencyBonus != efficiencyModifier)
            {
                this.EfficiencyBonus = efficiencyModifier;
            }
        }
Esempio n. 28
0
        public void SetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType, float efficiencyModifier)
        {
            string         key            = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            //If we already have the efficiency data then just update the value
            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.efficiencyModifier = efficiencyModifier;
                return;
            }

            //Create a new entry.
            efficiencyData                    = new EfficiencyData();
            efficiencyData.planetID           = planetID;
            efficiencyData.biomeName          = biomeName;
            efficiencyData.harvestType        = harvestType;
            efficiencyData.efficiencyModifier = efficiencyModifier;
            efficiencyData.attemptsRemaining  = kMaxCoreSamples;

            efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
        }
Esempio n. 29
0
        public void Load(ConfigNode node)
        {
            string value;
            string modifierName;

            value = node.GetValue("planetID");
            if (string.IsNullOrEmpty(value) == false)
                planetID = int.Parse(value);

            biomeName = node.GetValue("biomeName");

            value = node.GetValue("harvestType");
            if (string.IsNullOrEmpty(value) == false)
                harvestType = (HarvestTypes)int.Parse(value);

            value = node.GetValue("attemptsRemaining");
            if (string.IsNullOrEmpty(value) == false)
                attemptsRemaining = int.Parse(value);

            //Modifiers
            modifiers.Clear();
            ConfigNode[] modifierNodes = node.GetNodes("MODIFIER");
            if (modifierNodes != null)
            {
                foreach (ConfigNode modNode in modifierNodes)
                {
                    modifierName = modNode.GetValue("name");
                    value = modNode.GetValue("value");
                    modifiers.Add(modifierName, float.Parse(value));
                }
            }

            //Backwards compatibility
            value = node.GetValue("efficiencyModifier");
            if (string.IsNullOrEmpty(value) == false)
                modifiers.Add("extractionModifier", float.Parse(value));
        }
Esempio n. 30
0
        private void onEfficiencyUpdate(int planetID, string biomeName, HarvestTypes harvestID, string efficiencyType, float modifier)
        {
            //Are we interested in this update?
            if (this.planetID != planetID)
            {
                return;
            }
            if (this.biomeName != biomeName)
            {
                return;
            }
            if (this.harvestID != harvestID)
            {
                return;
            }
            if (this.efficiencyType != efficiencyType)
            {
                return;
            }

            //Record the modifier
            efficiencyModifier = modifier;

            //Find all the efficiency modifier parts and add their modifiers.
            List <WBIEfficiencyBonus> bonusModifiers = this.part.vessel.FindPartModulesImplementing <WBIEfficiencyBonus>();
            WBIEfficiencyBonus        bonusModifier;
            int totalMultipliers = bonusModifiers.Count;

            for (int index = 0; index < totalMultipliers; index++)
            {
                bonusModifier       = bonusModifiers[index];
                efficiencyModifier += bonusModifier.Bonus;
            }

            //Update efficiency
            UpdateEfficiency();
        }
Esempio n. 31
0
        protected void setupHarvestTypes()
        {
            if (this.part.vessel.situation == Vessel.Situations.LANDED ||
                this.part.vessel.situation == Vessel.Situations.SPLASHED ||
                this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                currentBiome = Utils.GetCurrentBiome(this.part.vessel).name;
            }

            string[]            types       = harvestTypes.Split(new char[] { ';' });
            HarvestTypes        harvestType = HarvestTypes.Planetary;
            List <HarvestTypes> typeList    = new List <HarvestTypes>();

            for (int index = 0; index < types.Length; index++)
            {
                harvestType = (HarvestTypes)Enum.Parse(typeof(HarvestTypes), types[index]);
                typeList.Add(harvestType);
            }
            harvestEnvironments = typeList.ToArray();
            if (harvestEnvironments == null)
            {
                harvestEnvironments = new HarvestTypes[] { HarvestTypes.Planetary };
            }
        }
Esempio n. 32
0
        protected IEnumerable <ResourceCache.AbundanceSummary> getAbundances(Vessel vessel, HarvestTypes harvestType)
        {
            string biomeName          = getCurrentBiomeName(vessel);
            int    flightGlobalsIndex = vessel.mainBody.flightGlobalsIndex;
            IEnumerable <ResourceCache.AbundanceSummary> abundanceCache;

            //First, try getting from the current biome.
            abundanceCache = ResourceCache.Instance.AbundanceCache.
                             Where(a => a.HarvestType == harvestType && a.BodyId == flightGlobalsIndex && a.BiomeName == biomeName);

            //No worky? Try using vessel situation.
            if (abundanceCache.Count() == 0)
            {
                switch (harvestType)
                {
                case HarvestTypes.Atmospheric:
                    biomeName = "FLYING";
                    break;

                case HarvestTypes.Oceanic:
                    biomeName = "SPLASHED";
                    break;

                case HarvestTypes.Exospheric:
                    biomeName = "ORBITING";
                    break;

                default:
                    biomeName = "Planetary";
                    break;
                }

                //Give it another shot.
                abundanceCache = ResourceCache.Instance.AbundanceCache.
                                 Where(a => a.HarvestType == harvestType && a.BodyId == flightGlobalsIndex && a.BiomeName == biomeName);
            }

            return(abundanceCache);
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (originalCriticalFail == -1)
            {
                originalCriticalFail = criticalFail;
                currentCriticalFail = criticalFail;
            }

            criticalFail = currentCriticalFail;

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);

            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            float efficiencyModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biomeName, harvestID, efficiencyType);
            if (this.EfficiencyBonus != efficiencyModifier)
                this.EfficiencyBonus = efficiencyModifier;

            SetupGUI();
        }
Esempio n. 34
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                harvestID = (HarvestTypes)harvestType;
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
            }

            moduleSwitcher = this.part.FindModuleImplementing<WBIModuleSwitcher>();
            setupModuleInfo();
        }
Esempio n. 35
0
        public void ExperimentRequirementsMet(string experimentID, float chanceOfSuccess, float resultRoll)
        {
            float        efficiencyModifier = 0.1f;
            int          planetID           = this.part.vessel.mainBody.flightGlobalsIndex;
            HarvestTypes harvestType        = HarvestTypes.Planetary;

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            string biomeName       = biome.name;
            string modifierName    = "";
            string processChanged  = "";
            string resultsPreamble = string.Empty;

            switch (experimentID)
            {
            case "WBISoilAnalysis":
                modifierName   = EfficiencyData.kHabitationMod;
                processChanged = kLifeSupport;
                break;

            case "WBIMetallurgyAnalysis":
                modifierName   = EfficiencyData.kIndustryMod;
                processChanged = kManufacturing;
                break;

            case "WBIExtractionAnalysis":
                modifierName        = EfficiencyData.kExtractionMod;
                processChanged      = kExtraction;
                efficiencyModifier /= 2.0f;
                break;

            default:
            case "WBIChemicalAnalysis":
                modifierName   = EfficiencyData.kScienceMod;
                processChanged = kChemicalProducts;
                break;
            }

            //Factor success/fail
            if (resultRoll >= chanceOfSuccess)
            {
                resultsPreamble = kBetterEfficiency;
            }

            else //Worse results
            {
                resultsPreamble    = kWorseEfficiency;
                efficiencyModifier = efficiencyModifier * -1.0f;
            }

            //Get existing modifier
            float currentModifer = WBIPathfinderScenario.Instance.GetEfficiencyModifier(planetID, biome.name, harvestType, modifierName);

            //Add improvement
            currentModifer += efficiencyModifier;
            WBIPathfinderScenario.Instance.SetEfficiencyData(planetID, biome.name, harvestType, modifierName, currentModifer);

            //Inform user
            string message = string.Format(resultsPreamble, efficiencyModifier * 100f) + processChanged;

            ScreenMessages.PostScreenMessage(message, 8.0f, ScreenMessageStyle.UPPER_CENTER);
        }
Esempio n. 36
0
 private static string GetDefaultSituation(HarvestTypes type)
 {
     switch (type)
     {
         case HarvestTypes.Atmospheric:
             return Vessel.Situations.FLYING.ToString();
         case HarvestTypes.Oceanic:
             return Vessel.Situations.SPLASHED.ToString();
         case HarvestTypes.Planetary:
             return Vessel.Situations.LANDED.ToString();
         default:
             return Vessel.Situations.ORBITING.ToString();
     }
 }
Esempio n. 37
0
        public void SetCoreSamplesRemaining(int planetID, string biomeName, HarvestTypes harvestType, int attemptsRemaining)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.attemptsRemaining = attemptsRemaining;
            }
        }
Esempio n. 38
0
        protected void createNewEfficencyEntry(int planetID, string biomeName, HarvestTypes harvestType)
        {
            EfficiencyData efficiencyData = new EfficiencyData();
            efficiencyData.planetID = planetID;
            efficiencyData.biomeName = biomeName;
            efficiencyData.harvestType = harvestType;
            efficiencyData.attemptsRemaining = kMaxCoreSamples;

            //Standard modifiers
            efficiencyData.modifiers.Add(EfficiencyData.kExtractionMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kIndustryMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kHabitationMod, 1.0f);
            efficiencyData.modifiers.Add(EfficiencyData.kScienceMod, 1.0f);

            efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
        }
Esempio n. 39
0
        public void ResetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                foreach (string modifierKey in efficiencyData.modifiers.Keys)
                    efficiencyData.modifiers[modifierKey] = 1.0f;
                efficiencyData.attemptsRemaining = kMaxCoreSamples;
            }

            else
            {
                //Create a new entry.
                createNewEfficencyEntry(planetID, biomeName, harvestType);
            }
        }
Esempio n. 40
0
        public void SetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType, string modifierName, float modifierValue)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            //If we already have the efficiency data then just update the value
            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                if (efficiencyData.modifiers.ContainsKey(modifierName))
                    efficiencyData.modifiers[modifierName] = modifierValue;
                else
                    efficiencyData.modifiers.Add(modifierName, modifierValue);
                return;
            }

            //Create a new entry.
            createNewEfficencyEntry(planetID, biomeName, harvestType);
        }
Esempio n. 41
0
        public void SetEfficiencyData(int planetID, string biomeName, HarvestTypes harvestType, float efficiencyModifier)
        {
            string key = planetID.ToString() + biomeName + harvestType.ToString();
            EfficiencyData efficiencyData = null;

            //If we already have the efficiency data then just update the value
            if (efficiencyDataMap.ContainsKey(key))
            {
                efficiencyData = efficiencyDataMap[key];
                efficiencyData.efficiencyModifier = efficiencyModifier;
                return;
            }

            //Create a new entry.
            efficiencyData = new EfficiencyData();
            efficiencyData.planetID = planetID;
            efficiencyData.biomeName = biomeName;
            efficiencyData.harvestType = harvestType;
            efficiencyData.efficiencyModifier = efficiencyModifier;
            efficiencyData.attemptsRemaining = kMaxCoreSamples;

            efficiencyDataMap.Add(efficiencyData.Key, efficiencyData);
        }
Esempio n. 42
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            SetGuiVisible(false);
            showResults = false;

            resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody);

            gps          = this.part.FindModuleImplementing <ModuleGPS>();
            biomeScanner = this.part.FindModuleImplementing <ModuleBiomeScanner>();
            hideStockGUI();

            //Grab the seismometer (if any)
            foreach (PartModule mod in this.part.Modules)
            {
                if (mod.moduleName == "Seismometer")
                {
                    impactSeismometer = mod;
                    impactSensor      = (IScienceDataContainer)impactSeismometer;
                    break;
                }
            }

            //Create swizzler
            swizzler            = new WBIResultsDialogSwizzler();
            swizzler.onTransmit = transmitData;

            //Setup the science container
            scienceContainer = this.part.FindModuleImplementing <ModuleScienceContainer>();
            scienceContainer.Events["ReviewDataEvent"].guiActiveUnfocused = false;
            scienceContainer.Events["ReviewDataEvent"].guiActive          = false;

            if (impactSensor != null)
            {
                ScienceData[] impactData = impactSensor.GetData();

                foreach (ScienceData data in impactData)
                {
                    scienceContainer.AddData(data);
                }
                foreach (ScienceData doomed in impactData)
                {
                    impactSensor.DumpData(doomed);
                }
            }

            //Terrain uplink
            terrainUplinkView.part             = this.part;
            terrainUplinkView.scienceContainer = scienceContainer;

            //Elapsed time for current experiment
            if (ModuleIsActive())
            {
                //Get the new elapsed time.
                int elapsedTimeIndex = (int)currentExperiment;
                elapsedTime = elapsedTimes[elapsedTimeIndex];

                //Reset the research start time.
                cycleStartTime = Planetarium.GetUniversalTime() - elapsedTime;
            }

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                planetID    = this.part.vessel.mainBody.flightGlobalsIndex;
                harvestType = (HarvestTypes)harvestID;
            }
        }
Esempio n. 43
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            SetGuiVisible(false);
            showResults = false;

            resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody);

            gps = this.part.FindModuleImplementing<ModuleGPS>();
            biomeScanner = this.part.FindModuleImplementing<ModuleBiomeScanner>();
            hideStockGUI();

            //Grab the seismometer (if any)
            foreach (PartModule mod in this.part.Modules)
                if (mod.moduleName == "Seismometer")
                {
                    impactSeismometer = mod;
                    impactSensor = (IScienceDataContainer)impactSeismometer;
                    break;
                }

            //Create swizzler
            swizzler = new WBIResultsDialogSwizzler();
            swizzler.onTransmit = transmitData;

            //Setup the science container
            scienceContainer = this.part.FindModuleImplementing<ModuleScienceContainer>();
            scienceContainer.Events["ReviewDataEvent"].guiActiveUnfocused = false;
            scienceContainer.Events["ReviewDataEvent"].guiActive = false;

            if (impactSensor != null)
            {
                ScienceData[] impactData = impactSensor.GetData();

                foreach (ScienceData data in impactData)
                    scienceContainer.AddData(data);
                foreach (ScienceData doomed in impactData)
                    impactSensor.DumpData(doomed);
            }

            //Terrain uplink
            terrainUplinkView.part = this.part;
            terrainUplinkView.scienceContainer = scienceContainer;

            //Elapsed time for current experiment
            if (ModuleIsActive())
            {
                //Get the new elapsed time.
                int elapsedTimeIndex = (int)currentExperiment;
                elapsedTime = elapsedTimes[elapsedTimeIndex];

                //Reset the research start time.
                cycleStartTime = Planetarium.GetUniversalTime() - elapsedTime;
            }

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
                harvestType = (HarvestTypes)harvestID;
            }
        }
Esempio n. 44
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            SetGuiVisible(false);
            showResults = false;

            resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody);

            //Create swizzler
            swizzler = new WBIResultsDialogSwizzler();
            swizzler.onTransmit = transmitData;

            //Elapsed time for current experiment
            if (ModuleIsActive())
            {
                //Get the new elapsed time.
                int elapsedTimeIndex = (int)currentExperiment;
                elapsedTime = elapsedTimes[elapsedTimeIndex];

                //Reset the research start time.
                cycleStartTime = Planetarium.GetUniversalTime() - elapsedTime;
            }

            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            biomeName = biome.name;

            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                planetID = this.part.vessel.mainBody.flightGlobalsIndex;
                harvestType = (HarvestTypes)harvestID;
            }
        }
Esempio n. 45
0
        protected virtual void prepareOutputsByLocale(HarvestTypes harvestType)
        {
            Log("prepareOutputsByLocale called for harvestType: " + harvestType.ToString());
            ResourceRatio          outputSource;
            PartResourceDefinition outputDef = null;
            float totalAbundance             = 0f;
            float abundance   = 0f;
            float outputMass  = 0f;
            float outputUnits = 0f;
            IEnumerable <ResourceCache.AbundanceSummary> abundanceCache;

            if (harvestType == HarvestTypes.Planetary)
            {
                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, harvestType);
            }
            else
            {
                abundanceCache = Utils.GetAbundances(this.part.vessel, harvestType);
            }

            foreach (ResourceCache.AbundanceSummary summary in abundanceCache)
            {
                Log("checking " + summary.ResourceName);
                outputDef = ResourceHelper.DefinitionForResource(summary.ResourceName);
                if (outputDef == null)
                {
                    continue;
                }

                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 = harvestType,
                    ResourceName = summary.ResourceName
                });

                outputMass = abundance * yieldMass;
                if (outputDef.density > 0)
                {
                    outputUnits = outputMass / outputDef.density;
                }
                else
                {
                    outputUnits = outputMass;
                }
                Log("abundance: " + abundance);
                Log("outputUnits: " + outputUnits);

                //If the resource is an input resource then add its output mass to the byproductMass.
                if (inputSources.Contains(summary.ResourceName))
                {
                    Log(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))
                {
                    Log(summary.ResourceName + " ignored and added to byproductMass");
                    byproductMass += outputMass;
                }

                //Legit!
                else if (abundance > 0.0001f)
                {
                    totalAbundance += abundance;
                    Log(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);
                Log("added " + byproduct + " to output list");
            }

            Log("totalAbundance: " + totalAbundance);
            Log("Byproduct Units: " + outputUnits);
            Log("output resources added: " + outputList.Count);
        }