Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Wolf crew settings to configuration file #1563

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 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 @@ -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);
Expand All @@ -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;
}
Expand Down