Skip to content

Commit

Permalink
Merge pull request #18 from tobitege/master
Browse files Browse the repository at this point in the history
Some calculation, recipe and program fixes. Daily production rate as link.
  • Loading branch information
Dimencia authored Sep 9, 2022
2 parents d7ef7f9 + 813c76f commit 9c498c4
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 1,881 deletions.
2 changes: 1 addition & 1 deletion DU-Industry-Tool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_SaveFilesImmediatelyUponChange = False
SolutionGuid = {FC9CE6EA-20C1-4940-86AB-CCF7B75FB2BA}
RESX_SaveFilesImmediatelyUponChange = False
EndGlobalSection
EndGlobal
14 changes: 1 addition & 13 deletions DU-Industry-Tool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="8fb06cb64d019a17" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.17.1.0" newVersion="2.17.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="ExcelNumberFormat" publicKeyToken="23c6f5d73be07eca" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
75 changes: 32 additions & 43 deletions DU-Industry-Tool/DU-Industry-Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,12 @@
<ApplicationIcon>reshot-icon-factory.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="ClosedXML, Version=0.96.0.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b, processorArchitecture=MSIL">
<HintPath>..\packages\ClosedXML.0.96.0\lib\net46\ClosedXML.dll</HintPath>
</Reference>
<Reference Include="DocumentFormat.OpenXml, Version=2.17.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.2.17.1\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
</Reference>
<Reference Include="Krypton.Docking">
<HintPath>..\packages\Krypton.Docking.65.22.6.152\lib\net472\Krypton.Docking.dll</HintPath>
</Reference>
<Reference Include="Krypton.Navigator">
<HintPath>..\packages\Krypton.Navigator.65.22.6.152\lib\net472\Krypton.Navigator.dll</HintPath>
</Reference>
<Reference Include="Krypton.Ribbon, Version=65.22.6.152, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Krypton.Ribbon.65.22.6.152\lib\net472\Krypton.Ribbon.dll</HintPath>
</Reference>
<Reference Include="Krypton.Toolkit">
<HintPath>..\packages\Krypton.Toolkit.65.22.6.152\lib\net472\Krypton.Toolkit.dll</HintPath>
</Reference>
<Reference Include="Krypton.Workspace">
<HintPath>..\packages\Krypton.Workspace.65.22.6.152\lib\net472\Krypton.Workspace.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.IO.Packaging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Packaging.6.0.0\lib\net461\System.IO.Packaging.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -194,10 +158,6 @@
<None Include="KryptonToolkit.license">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="oreValues.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -213,9 +173,6 @@
<None Include="schematicValues.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="talentSettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -238,5 +195,37 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="ClosedXML">
<Version>0.96.0</Version>
</PackageReference>
<PackageReference Include="DocumentFormat.OpenXml">
<Version>2.16.0</Version>
</PackageReference>
<PackageReference Include="ExcelNumberFormat">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Krypton.Docking">
<Version>65.22.6.152</Version>
</PackageReference>
<PackageReference Include="Krypton.Ribbon">
<Version>65.22.6.152</Version>
</PackageReference>
<PackageReference Include="Microsoft.CSharp">
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="System.IO.FileSystem.Primitives">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.IO.Packaging">
<Version>6.0.0</Version>
</PackageReference>
<PackageReference Include="System.Runtime.Serialization.Primitives">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
97 changes: 52 additions & 45 deletions DU-Industry-Tool/IndustryManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -8,8 +7,6 @@
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DocumentFormat.OpenXml.Drawing.ChartDrawing;
using Krypton.Toolkit;

namespace DU_Industry_Tool
{
Expand Down Expand Up @@ -975,19 +972,22 @@ public IndustryManager(ProgressBar progressBar = null)
*/
}

//SaveRecipes();
// 1st check:
// Is this a "part", but not an ingredient in any recipe?
// Could also be just an API category. Unly uncomment when needed!
//var removalEntries = (from kvp in Recipes.Values.Where(x =>
// x.ParentGroupName.EndsWith(" parts", StringComparison.InvariantCultureIgnoreCase))
// let found = Recipes.Values.Any(x => x.Ingredients?.Any(
// y => y.Name.Equals(kvp.Name, StringComparison.InvariantCultureIgnoreCase)) == true)
// where !found select kvp.Key).ToList();
//foreach (var removalEntry in removalEntries)
//{
// Recipes.Remove(removalEntry);
//}
// 2nd check: any ingredient has circular reference to Key?
//var removalEntries = Recipes.Where(x => x.Value.Ingredients?.Any(y => y.Type == x.Key) == true).ToList();

// Is this a "part", but not in any recipe?
foreach (var kvp in Recipes.Values.Where(x =>
x.ParentGroupName.EndsWith(" parts", StringComparison.InvariantCultureIgnoreCase)))
{
var found = Recipes.Values.Any(x => x.Ingredients?.Any(y =>
y.Name.Equals(kvp.Name, StringComparison.InvariantCultureIgnoreCase)) == true);
if (!found)
{
kvp.Name += " (!)";
}
}
//SaveRecipes();

if (progressBar != null)
progressBar.Value = 70;
Expand Down Expand Up @@ -1467,11 +1467,12 @@ public double GetBaseCost(string key)
// -> Chemical 562.50 q * 5 = 2812,50 q
// -> SUM for schematics: 4500 quanta
// :grimace:

private string _currentRecipe;
public double GetTotalCost(string key, double amount = 0, string level = "", int depth = 0, bool silent = false)
{
if (depth == 0)
{
_currentRecipe = key;
amount = ProductQuantity;
CostResults = new StringBuilder();
_sumParts = new SortedDictionary<string, double>();
Expand All @@ -1483,6 +1484,11 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
_schematicsCost = 0;
ApplicableTalents = new List<string>(160);
}
else
if (depth > 10 || key == _currentRecipe) // faulty recipe?!
{
return 0;
}

double totalCost = 0;
if (key.StartsWith("Catalyst"))
Expand Down Expand Up @@ -1528,31 +1534,21 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
var qty = 0d;
double factor = 1;
var myRecipe = Recipes[ingredient.Type];
var isOre = myRecipe.ParentGroupName.Equals("Ore", StringComparison.InvariantCultureIgnoreCase);
var isPure = myRecipe.ParentGroupName.Equals("Pure", StringComparison.InvariantCultureIgnoreCase) ||
myRecipe.ParentGroupName.Equals("Refined Materials", StringComparison.InvariantCultureIgnoreCase);
var isOre = myRecipe.ParentGroupName.Equals("Ore");
var isPure = myRecipe.ParentGroupName.Equals("Pure") ||
myRecipe.ParentGroupName.Equals("Refined Materials");
var isPart = myRecipe.ParentGroupName.EndsWith("parts", StringComparison.InvariantCultureIgnoreCase);
var isProduct = myRecipe.ParentGroupName.Equals("Product", StringComparison.InvariantCultureIgnoreCase);
var isProduct = myRecipe.ParentGroupName.Equals("Product");
var isPlasma = myRecipe.ParentGroupName.Equals("Consumables") &&
myRecipe.Key.StartsWith("Plasma", StringComparison.InvariantCultureIgnoreCase);
myRecipe.Key.StartsWith("plasma", StringComparison.InvariantCultureIgnoreCase);
var ingName = ingredient.Name;
var ingKey = ingName;
if (!isPlasma)
{
ingKey = "T" + (myRecipe.Level < 2 ? "1" : myRecipe.Level.ToString()) + " " + ingKey;
}

if (!isOre && !isPure)
{
if (isPart || isProduct)
{
ingName = (isProduct ? " " : " ") + ingKey;
}

AddIngredient(ingName, ingredient.Quantity * amount);
}

if (depth > 0 && ingredient.Quantity > productQty && (isOre || isPure))
if (isOre || isPure || isProduct)
{
factor = ((productQty + outputAdder) * outputMultiplier) /
((ingredient.Quantity + inputAdder) * inputMultiplier);
Expand All @@ -1574,6 +1570,7 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
else
_sumOres.Add(ingKey, qty);
Debug.WriteLineIf(!silent && qty > 0, $"{curLevel} ({ingredient.Name}: {qty:N2} = {cost:N2}q)");
AddIngredient(ingKey, qty);
continue;
}

Expand All @@ -1586,22 +1583,34 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
_sumPures[ingKey] += qty;
else
_sumPures.Add(ingKey, qty);
ingName = " " + ingKey;
ingName = " " + ingKey;
AddIngredient(ingName, qty);
continue;
}

// Any other part or product
if (depth < 1)
{
qty = factor;
}
else
if (isPart || isProduct)
{
if (isProduct)
if (isPart)
{
ingName = " " + ingKey;
qty = amount * ingredient.Quantity;
AddIngredient(ingName, qty);
}
else
qty = amount * factor;
if (isProduct)
{
ingName = " " + ingKey;
qty = amount / factor;
AddIngredient(ingName, amount / factor);
}
}
else
{
qty = amount * factor;
}

cost = GetTotalCost(ingredient.Type, qty, level, depth + 1, silent);
Expand Down Expand Up @@ -1636,12 +1645,11 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
}

CostResults.AppendLine("");
_schematicsCost += CalculateItemCost(_sumOres, "U", amount, "Ores");
_schematicsCost += CalculateItemCost(_sumPures, "U", amount, "Pures");
_schematicsCost += CalculateItemCost(_sumProducts, "P", amount, "Products");
_schematicsCost += CalculateItemCost(_sumParts, "P", amount, "Parts");
_schematicsCost += CalculateItemCost(_sumOres, "U", 1, "Ores");
_schematicsCost += CalculateItemCost(_sumPures, "U", 1, "Pures");
_schematicsCost += CalculateItemCost(_sumProducts, "P", 1, "Products");
_schematicsCost += CalculateItemCost(_sumParts, "P", 1, "Parts");
CostResults.AppendLine("Schematics:".PadRight(16) + $"{_schematicsCost:N1}q".PadLeft(20));
totalCost *= amount;
CostResults.AppendLine("Pures/Products:".PadRight(16) + $"{totalCost:N1}q".PadLeft(20));
totalCost += _schematicsCost;
var costx1 = totalCost / amount;
Expand Down Expand Up @@ -1674,10 +1682,9 @@ public double GetTotalCost(string key, double amount = 0, string level = "", int
var maxlen = 2 + _sumIngredients.Max(x => x.Key.Length);
foreach (var item in _sumIngredients)
{
CostResults.AppendLine(item.Key.PadRight(maxlen) + $"{item.Value:N0}".PadLeft(9));
CostResults.AppendLine(item.Key.PadRight(maxlen) + $"{item.Value:N2}".PadLeft(12));
}
}

return costx1;
}

Expand Down Expand Up @@ -1745,7 +1752,7 @@ private double CalculateItemCost(SortedDictionary<string, double> itemPrices, st
var orePrice = 0d;
if (listType == "U" && (isPlasma || isOre))
{
orePrice = Ores.FirstOrDefault(o => o.Key == key)?.Value ?? 0;
orePrice = Ores.FirstOrDefault(o => o.Name == key)?.Value ?? 0;
}

var tmp = item.Value * quantity;
Expand Down
6 changes: 5 additions & 1 deletion DU-Industry-Tool/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c498c4

Please sign in to comment.