Skip to content

Commit

Permalink
OMNIRESOURCECOMBO update
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-125 committed Jun 30, 2020
1 parent f78619b commit a689fd2
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 44 deletions.
Binary file modified .vs/WildBlueTools/v15/.suo
Binary file not shown.
Binary file modified .vs/WildBlueTools/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/WildBlueTools/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/WildBlueTools/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions GameData/WildBlueIndustries/000WildBlueTools/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ A KSP mod that provides common functionality for mods by Wild Blue Industries.

Copy the contents of the mod's GameData directory into your GameData folder.

1.79
- WBIOmniStorage now supports its own set of OMNIRESOURCECOMBO nodes. If a combo is defined within the part module and a combo with the same resources is defined as a global OMNIRESOURCECOMBO, then the part's OMNIRESOURCECOMBO will be used.

1.78
- Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,52 @@ OMNICONVERTER
}
}

OMNICONVERTER
{
templateTags = lab
TechRequired = advScienceTech
ConverterName = Cryofuels Maker
description = Split Water into Propellium and Oxidizer
StartActionName = Start Making Cryofuels
StopActionName = Stop Making Cryofuels
AutoShutdown = false
UseSpecialistBonus = true
SpecialistEfficiencyFactor = 0.2
SpecialistBonusBase = 0.05
ExperienceEffect = ScienceSkill
EfficiencyBonus = 1

INPUT_RESOURCE
{
ResourceName = Water
Ratio = 1
FlowMode = ALL_VESSEL
}

INPUT_RESOURCE
{
ResourceName = ElectricCharge
Ratio = 22
FlowMode = ALL_VESSEL
}

OUTPUT_RESOURCE
{
ResourceName = Oxidizer
Ratio = 0.779
DumpExcess = true
FlowMode = ALL_VESSEL
}

OUTPUT_RESOURCE
{
ResourceName = Propellium
Ratio = 1.56
DumpExcess = true
FlowMode = ALL_VESSEL
}
}

OMNICONVERTER
{
templateTags = lab
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
STORAGE_TEMPLATE
//Resource combos make sure that the resources added stay in the correct ratios despite where the sliders are. For instance,
//many rocket engines use a ratio of 0.45/0.55 for LiquidFuel and Oxidizer. No matter where the sliders are, the omni storage
//will ensure that the resource units are automatically adjusted to follow the ratios.
//You can add any number of resources, but make sure that the ratios all add up to 1.0. It also helps if the resource volumes are all the same
//so that the unit volumes are also the same (5-liter units is the stock standard).
//NOTE: For now, only the first combo pattern to match the resources in the omni storage will be applied.
OMNIRESOURCECOMBO
{
name = Omni Storage
author = Angel-125
logoPanel = WildBlueIndustries/000WildBlueTools/Decals/Omni
glowPanel = WildBlueIndustries/000WildBlueTools/Decals/OmniGlow
description = This kit can store a wide variety of resources in varying amounts.
templateTags = stowage

MODULE
RESOURCE
{
name = WBIOmniStorage

//In liters, how much can the part store.
//Note: this is a standard size for a switcher capacity of 1.0 and based on
//the Titan 1800 fuel tank standard (on which the templates were originally based).
//Actual volume depends upon switcher's capacityFactor.
storageVolume = 9000
//Adjust storage volume to account for resource switcher's capacity factor.
accountForSwitcherCapacity = true

//Skill required to reconfigure the container.
reconfigureSkill = ConverterSkill

//Minimum rank to reconfigure the container.
reconfigureRank = 1

//Resource required to reconfigure the container.
requiredResource = Equipment

//Amount of the required resource to reconfigure the container.
requiredAmount = 0
name = RHK1
ratio = 0.45
}

//Blacklisted resources that can't be added to the container.
//Separate by semicolon. Below is the default.
resourceBlacklist = GeoEnergy;ElectroPlasma;CoreHeat;Atmosphere;CompressedAtmosphere;LabTime;ExposureTime;ScopeTime;SolarReports;SimulatorTime;GravityWaves;IntakeAir;StaticCharge;EVA Propellant;Plants
RESOURCE
{
name = Oxidizer
ratio = 0.55
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,60 @@ OMNIRESOURCECOMBO
ratio = 0.45
maxAmountMultiplier = 1.0 //Multiplies the max storage capacity of the combo resource by this amount. Default is 1.0 so you can omit this.
}

RESOURCE
{
name = Oxidizer
ratio = 0.55
maxAmountMultiplier = 1.0 //Multiplies the max storage capacity of the combo resource by this amount. Default is 1.0 so you can omit this.
}
}
OMNIRESOURCECOMBO
{
RESOURCE
{
name = RHK1
ratio = 0.45
}
RESOURCE
{
name = Oxidizer
ratio = 0.55
}
}
OMNIRESOURCECOMBO
{
RESOURCE
{
name = LqdHydrogen
ratio = 0.9375
maxAmountMultiplier = 1.0
}

RESOURCE
{
name = Oxidizer
ratio = 0.0625
maxAmountMultiplier = 1.0
}
}

OMNIRESOURCECOMBO
{
RESOURCE
{
name = Propellium
ratio = 0.75
maxAmountMultiplier = 1.5
}

RESOURCE
{
name = Oxidizer
ratio = 0.25
maxAmountMultiplier = 1.5
}
}


//The amount of resource in a part depends upon the size of the storage in liters, the number of resources in the container, the number of liters allocated per resource,
//and the volume of the resource. Most stock and Classic Stock resources have a volume of 5, meaning that one unit of resource takes up 5 liters. For the OmniStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"VERSION":
{
"MAJOR":1,
"MINOR":78,
"MINOR":79,
"PATCH":0
},
"KSP_VERSION_MIN":
Expand Down
4 changes: 2 additions & 2 deletions Notes/WildBlueTools.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
{
"USERNAME":"Angel-125",
"REPOSITORY":"WildBlueTools",
"ALLOW_PRE_RELEASE":false,
"ALLOW_PRE_RELEASE":false
},
"VERSION":
{
"MAJOR":1,
"MINOR":77,
"MINOR":78,
"PATCH":0
},
"KSP_VERSION_MIN":
Expand Down
77 changes: 71 additions & 6 deletions Omni/WBIOmniStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,19 @@ public override void OnStart(StartState state)
}
}

//Load resource combos
loadResourceCombos();
//Load resource combos. Overrides first.
loadResourceCombos(getPartComboNodes());
loadResourceCombos(GameDatabase.Instance.GetConfigNodes("OMNIRESOURCECOMBO"));

//Setup default resources if needed
Debug.Log("[WBIOmniStorage] - OnStart called. resourceAmounts.Count: " + resourceAmounts.Count);
if (resourceAmounts.Count == 0 && !isEmpty)
if (isEmpty)
{
this.previewRatios.Clear();
this.previewResources.Clear();
this.part.Resources.Clear();
}
else if (resourceAmounts.Count == 0 && !isEmpty)
setupDefaultResources();
else
clearDefaultResources();
Expand Down Expand Up @@ -688,9 +695,8 @@ protected void buildOmniResourceConfigs()
}
}

protected void loadResourceCombos()
protected void loadResourceCombos(ConfigNode[] comboNodes)
{
ConfigNode[] comboNodes = GameDatabase.Instance.GetConfigNodes("OMNIRESOURCECOMBO");
ConfigNode[] resourceNodes;
ConfigNode comboNode = null;
ConfigNode resourceNode = null;
Expand All @@ -699,13 +705,34 @@ protected void loadResourceCombos()
double maxAmountMultiplier = 1.0;
ComboRatio comboRatio;
Dictionary<string, ComboRatio> comboRatios = null;
List<string> existingComboKeys = new List<string>();
string comboKey = string.Empty;

//Build the list of existing combos
int count = resourceCombos.Count;
string[] keys;
for (int index = 0; index < count; index++)
{
comboRatios = resourceCombos[index];
comboKey = string.Empty;
keys = comboRatios.Keys.ToArray();

for (int keyIndex = 0; keyIndex < keys.Length; keyIndex++)
{
comboKey += keys[keyIndex];
}

existingComboKeys.Add(comboKey);
}

//Now add the new ones
for (int index = 0; index < comboNodes.Length; index++)
{
comboNode = comboNodes[index];

resourceNodes = comboNode.GetNodes("RESOURCE");
comboRatios = new Dictionary<string, ComboRatio>();
comboKey = string.Empty;
for (int nodeIndex = 0; nodeIndex < resourceNodes.Length; nodeIndex++)
{
//Get the resource node
Expand All @@ -731,11 +758,17 @@ protected void loadResourceCombos()
comboRatio.ratio = ratio;
comboRatio.maxAmountMultiplier = maxAmountMultiplier;
comboRatios.Add(resourceName, comboRatio);

// Update the comboKey
comboKey += resourceName;
}

//Add the combo to the list.
if (comboRatios.Keys.Count > 0)
if (comboRatios.Keys.Count > 0 && !string.IsNullOrEmpty(comboKey) && !existingComboKeys.Contains(comboKey))
{
resourceCombos.Add(comboRatios);
existingComboKeys.Add(comboKey);
}
}
}

Expand Down Expand Up @@ -838,6 +871,38 @@ protected void updateResourceComboRatios(string updatedResource)
previewRatios[keys[index]] = ratio;
}

protected ConfigNode[] getPartComboNodes()
{
if (this.part.partInfo.partConfig == null)
return new ConfigNode[] { };
ConfigNode[] nodes = this.part.partInfo.partConfig.GetNodes("MODULE");
ConfigNode storageNode = null;
ConfigNode node = null;
string moduleName;

//Get the switcher config node.
for (int index = 0; index < nodes.Length; index++)
{
node = nodes[index];
if (node.HasValue("name"))
{
moduleName = node.GetValue("name");
if (moduleName == this.ClassName)
{
storageNode = node;
break;
}
}
}
if (storageNode == null)
return new ConfigNode[] { };

if (storageNode.HasNode("OMNIRESOURCECOMBO"))
return storageNode.GetNodes("OMNIRESOURCECOMBO");
else
return new ConfigNode[] { };
}

protected void clearDefaultResources()
{
if (this.part.partInfo.partConfig == null)
Expand Down
Binary file modified bin/Debug/BARISBridge.dll
Binary file not shown.
Binary file modified bin/Debug/WildBlueTools.dll
Binary file not shown.
Binary file modified bin/Debug/WildBlueTools.pdb
Binary file not shown.

0 comments on commit a689fd2

Please sign in to comment.