From 57065e1e7b9ee9684e7941d99f43cbe1050f251a Mon Sep 17 00:00:00 2001 From: Mhoram Kerbin Date: Thu, 4 Aug 2022 17:08:46 +0200 Subject: [PATCH] Expose Wolf crew settings to configuration file This patch allows users to configure crew settings. --- .../UmbraSpaceIndustries/WOLF/WOLF.cfg | 8 + Source/WOLF/WOLF/Configuration.cs | 142 ++++++++++++++++++ Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs | 26 ++-- .../WOLF/WOLF/Modules/WOLF_ScenarioModule.cs | 44 ++++++ 4 files changed, 205 insertions(+), 15 deletions(-) diff --git a/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/WOLF.cfg b/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/WOLF.cfg index d5b77f9cb..6d841fc46 100644 --- a/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/WOLF.cfg +++ b/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/WOLF.cfg @@ -5,4 +5,12 @@ WOLF_CONFIGURATION RefinedResourcesFilter = Chemicals,Fertilizer,Fuel,Metals,Polymers,Power,RefinedExotics,Silicon AssembledResourcesFilter = Alloys,Electronics,Machinery,Maintenance,MaterialKits,Power,Prototypes,Robotics,SpecializedParts,Synthetics,TransportCredits LifeSupportResourcesFilter = CarbonDioxide,ColonySupplies,Food,Habitation,Lab,LifeSupport,Mulch,Oxygen,Power,WasteWater,Water + + CrewRequiredLifeSupport = 1 + CrewRequiredHabitation = 1 + CrewCO2Output = 0 + CrewMulchOutput = 0 + CrewWasteWaterOutput = 0 + CrewStarMultiplier = 2 + CrewMinimumEffectiveStars = 1 } diff --git a/Source/WOLF/WOLF/Configuration.cs b/Source/WOLF/WOLF/Configuration.cs index d3c6bf3f9..f79414e42 100644 --- a/Source/WOLF/WOLF/Configuration.cs +++ b/Source/WOLF/WOLF/Configuration.cs @@ -11,6 +11,13 @@ public class ConfigurationFromFile public string RefinedResourcesFilter { get; set; } public string AssembledResourcesFilter { get; set; } public string LifeSupportResourcesFilter { get; set; } + public int CrewRequiredLifeSupport { get; set; } + public int CrewRequiredHabitation { get; set; } + public int CrewCO2Output { get; set; } + public int CrewMulchOutput { get; set; } + public int CrewWasteWaterOutput { get; set; } + public int CrewMinimumEffectiveStars { get; set; } + public int CrewStarMultiplier { get; set; } } public class Configuration @@ -40,6 +47,14 @@ public class Configuration "Oxygen", "Power", "WasteWater", "Water" }; + public static readonly int DefaultCrewRequiredLifeSupport = 1; + public static readonly int DefaultCrewRequiredHabitation = 1; + public static readonly int DefaultCrewCO2Output = 0; + public static readonly int DefaultCrewMulchOutput = 0; + public static readonly int DefaultCrewWasteWaterOutput = 0; + public static readonly int DefaultCrewMinimumEffectiveStars = 1; + public static readonly int DefaultCrewStarMultiplier = 2; + private List _allowedHarvestableResources; private List _allowedHarvestableResourcesOnHomeworld; private List _blacklistedHomeworldResources; @@ -47,6 +62,14 @@ public class Configuration private List _assembledResourcesFilter; private List _lifeSupportResourcesFilter; + private int _crewRequiredLifeSupport = -1; + private int _crewRequiredHabitation = -1; + private int _crewCO2Output = -1; + private int _crewMulchOutput = -1; + private int _crewWasteWaterOutput = -1; + private int _crewMinimumEffectiveStars = -1; + private int _crewStarMultiplier = -1; + public List AllowedHarvestableResources { get @@ -114,6 +137,90 @@ public List LifeSupportResourcesFilter } } + public int CrewRequiredLifeSupport + { + get + { + if (_crewRequiredLifeSupport < 0) + { + _crewRequiredLifeSupport = DefaultCrewRequiredLifeSupport; + } + return _crewRequiredLifeSupport; + } + } + + public int CrewRequiredHabitation + { + get + { + if (_crewRequiredHabitation < 0) + { + _crewRequiredHabitation = DefaultCrewRequiredHabitation; + } + return _crewRequiredHabitation; + } + } + + public int CrewCO2Output + { + get + { + if (_crewCO2Output < 0) + { + _crewCO2Output = DefaultCrewCO2Output; + } + return _crewCO2Output; + } + } + + public int CrewMulchOutput + { + get + { + if (_crewMulchOutput < 0) + { + _crewMulchOutput = DefaultCrewMulchOutput; + } + return _crewMulchOutput; + } + } + + public int CrewWasteWaterOutput + { + get + { + if (_crewWasteWaterOutput < 0) + { + _crewWasteWaterOutput = DefaultCrewWasteWaterOutput; + } + return _crewWasteWaterOutput; + } + } + + public int CrewMinimumEffectiveStars + { + get + { + if (_crewMinimumEffectiveStars < 0) + { + _crewMinimumEffectiveStars = DefaultCrewMinimumEffectiveStars; + } + return _crewMinimumEffectiveStars; + } + } + + public int CrewStarMultiplier + { + get + { + if (_crewStarMultiplier < 0) + { + _crewStarMultiplier = DefaultCrewStarMultiplier; + } + return _crewStarMultiplier; + } + } + public static List ParseHarvestableResources(string resources) { if (string.IsNullOrEmpty(resources)) @@ -215,5 +322,40 @@ public void SetRefinedResourcesFilter(string resourceList) { _refinedResourcesFilter = ParseHarvestableResources(resourceList); } + + public void SetCrewRequiredLifeSupport(int lifeSupport) + { + _crewRequiredLifeSupport = lifeSupport; + } + + public void SetCrewRequiredHabitation(int habitation) + { + _crewRequiredHabitation = habitation; + } + + public void SetCrewCO2Output(int co2Output) + { + _crewCO2Output = co2Output; + } + + public void SetCrewMulchOutput(int mulchOutput) + { + _crewMulchOutput = mulchOutput; + } + + public void SetCrewWasteWaterOutput(int wasteWaterOutput) + { + _crewWasteWaterOutput = wasteWaterOutput; + } + + public void SetCrewMinimumEffectiveStars(int minimumEffectiveStars) + { + _crewMinimumEffectiveStars = minimumEffectiveStars; + } + + public void SetCrewStarMultiplier(int resourceMultiplier) + { + _crewStarMultiplier = resourceMultiplier; + } } } diff --git a/Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs b/Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs index e1610daa6..b75ca6446 100644 --- a/Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs +++ b/Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs @@ -4,11 +4,8 @@ namespace WOLF { public class WOLF_CrewModule : VesselModule { - private static readonly int REQUIRED_LIFE_SUPPORT = 1; - private static readonly int REQUIRED_HABITATION = 1; - private static readonly int CO2_OUTPUT = 0; - private static readonly int MULCH_OUTPUT = 0; - private static readonly int WASTEWATER_OUTPUT = 0; + protected static WOLF_ScenarioModule _scenario; + private static readonly string RESOURCE_NAME_LIFESUPPORT = "LifeSupport"; private static readonly string RESOURCE_NAME_HABITATION = "Habitation"; private static readonly string RESOURCE_NAME_CO2 = "CarbonDioxide"; @@ -16,7 +13,6 @@ public class WOLF_CrewModule : VesselModule private static readonly string RESOURCE_NAME_WASTEWATER = "WasteWater"; public static readonly string CREW_RESOURCE_SUFFIX = "CrewPoint"; - public static readonly int CREW_RESOURCE_MULTIPLIER = 2; public IRecipe GetCrewRecipe() { @@ -27,7 +23,7 @@ public static IRecipe GetCrewRecipe(List roster) { if (roster.Count < 1) return new Recipe(); - + _scenario = FindObjectOfType(); var inputs = new Dictionary { { RESOURCE_NAME_LIFESUPPORT, 0 }, @@ -41,18 +37,18 @@ public static IRecipe GetCrewRecipe(List roster) }; foreach (var kerbal in roster) { - inputs[RESOURCE_NAME_LIFESUPPORT] += REQUIRED_LIFE_SUPPORT; - inputs[RESOURCE_NAME_HABITATION] += REQUIRED_HABITATION; + inputs[RESOURCE_NAME_LIFESUPPORT] += _scenario.Configuration.CrewRequiredLifeSupport; + inputs[RESOURCE_NAME_HABITATION] += _scenario.Configuration.CrewRequiredHabitation; - outputs[RESOURCE_NAME_CO2] += CO2_OUTPUT; - outputs[RESOURCE_NAME_MULCH] += MULCH_OUTPUT; - outputs[RESOURCE_NAME_WASTEWATER] += WASTEWATER_OUTPUT; + outputs[RESOURCE_NAME_CO2] += _scenario.Configuration.CrewCO2Output; + outputs[RESOURCE_NAME_MULCH] += _scenario.Configuration.CrewMulchOutput; + outputs[RESOURCE_NAME_WASTEWATER] += _scenario.Configuration.CrewWasteWaterOutput; var resourceName = kerbal.trait + CREW_RESOURCE_SUFFIX; - var stars = kerbal.experienceLevel * CREW_RESOURCE_MULTIPLIER; - if (stars < 1) + var stars = kerbal.experienceLevel * _scenario.Configuration.CrewStarMultiplier; + if (stars < _scenario.Configuration.CrewMinimumEffectiveStars) { - stars = 1; + stars = _scenario.Configuration.CrewMinimumEffectiveStars; } if (!outputs.ContainsKey(resourceName)) { diff --git a/Source/WOLF/WOLF/Modules/WOLF_ScenarioModule.cs b/Source/WOLF/WOLF/Modules/WOLF_ScenarioModule.cs index 20b994578..21c47424f 100644 --- a/Source/WOLF/WOLF/Modules/WOLF_ScenarioModule.cs +++ b/Source/WOLF/WOLF/Modules/WOLF_ScenarioModule.cs @@ -25,6 +25,13 @@ private Configuration GetConfiguration() var assembledResourcesFilter = new List(); var lifeSupportResourcesFilter = new List(); var refinedResourcesFilter = new List(); + var crewRequiredLifeSupport = 1; + var crewRequiredHabitation = 1; + var crewCO2Output = 0; + var crewMulchOutput = 0; + var crewWasteWaterOutput = 0; + var crewMinimumEffectiveStars = 1; + var crewStarMultiplier = 2; foreach (var node in configNodes) { @@ -35,6 +42,36 @@ private Configuration GetConfiguration() var lifeSupportResources = Configuration.ParseHarvestableResources(configFromFile.LifeSupportResourcesFilter); var refinedResources = Configuration.ParseHarvestableResources(configFromFile.RefinedResourcesFilter); + int newValue; + if (node.HasValue("CrewRequiredLifeSupport") && int.TryParse(node.GetValue("CrewRequiredLifeSupport"), out newValue)) + { + crewRequiredLifeSupport = newValue; + } + if (node.HasValue("CrewRequiredHabitation") && int.TryParse(node.GetValue("CrewRequiredHabitation"), out newValue)) + { + crewRequiredHabitation = newValue; + } + if (node.HasValue("CrewCO2Output") && int.TryParse(node.GetValue("CrewCO2Output"), out newValue)) + { + crewCO2Output = newValue; + } + if (node.HasValue("CrewMulchOutput") && int.TryParse(node.GetValue("CrewMulchOutput"), out newValue)) + { + crewMulchOutput = newValue; + } + if (node.HasValue("CrewWasteWaterOutput") && int.TryParse(node.GetValue("CrewWasteWaterOutput"), out newValue)) + { + crewWasteWaterOutput = newValue; + } + if (node.HasValue("CrewMinimumEffectiveStars") && int.TryParse(node.GetValue("CrewMinimumEffectiveStars"), out newValue)) + { + crewMinimumEffectiveStars = newValue; + } + if (node.HasValue("CrewStarMultiplier") && int.TryParse(node.GetValue("CrewStarMultiplier"), out newValue)) + { + crewStarMultiplier = newValue; + } + allowedResources.AddRange(harvestableResources); blacklistedResources.AddRange(blacklist); assembledResourcesFilter.AddRange(assembledResources); @@ -48,6 +85,13 @@ private Configuration GetConfiguration() config.SetAssembledResourcesFilter(assembledResourcesFilter); config.SetLifeSupportResourcesFilter(lifeSupportResourcesFilter); config.SetRefinedResourcesFilter(refinedResourcesFilter); + config.SetCrewRequiredLifeSupport(crewRequiredLifeSupport); + config.SetCrewRequiredHabitation(crewRequiredHabitation); + config.SetCrewCO2Output(crewCO2Output); + config.SetCrewMulchOutput(crewMulchOutput); + config.SetCrewWasteWaterOutput(crewWasteWaterOutput); + config.SetCrewMinimumEffectiveStars(crewMinimumEffectiveStars); + config.SetCrewStarMultiplier(crewStarMultiplier); return config; }