Skip to content

Commit

Permalink
Expose Wolf crew settings to configuration file
Browse files Browse the repository at this point in the history
This patch allows users to configure crew settings.
  • Loading branch information
mhoram-kerbin committed Aug 4, 2022
1 parent ed0f6aa commit f1c3e3a
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 15 deletions.
8 changes: 8 additions & 0 deletions FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/WOLF.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
142 changes: 142 additions & 0 deletions Source/WOLF/WOLF/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,13 +47,29 @@ 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<string> _allowedHarvestableResources;
private List<string> _allowedHarvestableResourcesOnHomeworld;
private List<string> _blacklistedHomeworldResources;
private List<string> _refinedResourcesFilter;
private List<string> _assembledResourcesFilter;
private List<string> _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<string> AllowedHarvestableResources
{
get
Expand Down Expand Up @@ -114,6 +137,90 @@ public List<string> 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<string> ParseHarvestableResources(string resources)
{
if (string.IsNullOrEmpty(resources))
Expand Down Expand Up @@ -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;
}
}
}
26 changes: 11 additions & 15 deletions Source/WOLF/WOLF/Modules/WOLF_CrewModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ 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";
private static readonly string RESOURCE_NAME_MULCH = "Mulch";
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()
{
Expand All @@ -27,7 +23,7 @@ public static IRecipe GetCrewRecipe(List<ProtoCrewMember> roster)
{
if (roster.Count < 1)
return new Recipe();

_scenario = FindObjectOfType<WOLF_ScenarioModule>();
var inputs = new Dictionary<string, int>
{
{ RESOURCE_NAME_LIFESUPPORT, 0 },
Expand All @@ -41,18 +37,18 @@ public static IRecipe GetCrewRecipe(List<ProtoCrewMember> 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))
{
Expand Down
21 changes: 21 additions & 0 deletions Source/WOLF/WOLF/Modules/WOLF_ScenarioModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ private Configuration GetConfiguration()
var assembledResourcesFilter = new List<string>();
var lifeSupportResourcesFilter = new List<string>();
var refinedResourcesFilter = new List<string>();
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)
{
Expand All @@ -34,6 +41,13 @@ private Configuration GetConfiguration()
var assembledResources = Configuration.ParseHarvestableResources(configFromFile.AssembledResourcesFilter);
var lifeSupportResources = Configuration.ParseHarvestableResources(configFromFile.LifeSupportResourcesFilter);
var refinedResources = Configuration.ParseHarvestableResources(configFromFile.RefinedResourcesFilter);
crewRequiredLifeSupport = configFromFile.CrewRequiredLifeSupport;
crewRequiredHabitation = configFromFile.CrewRequiredHabitation;
crewCO2Output = configFromFile.CrewCO2Output;
crewMulchOutput = configFromFile.CrewMulchOutput;
crewWasteWaterOutput = configFromFile.CrewWasteWaterOutput;
crewMinimumEffectiveStars = configFromFile.CrewMinimumEffectiveStars;
crewStarMultiplier = configFromFile.CrewStarMultiplier;

allowedResources.AddRange(harvestableResources);
blacklistedResources.AddRange(blacklist);
Expand All @@ -48,6 +62,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;
}
Expand Down

0 comments on commit f1c3e3a

Please sign in to comment.