Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
allista committed May 9, 2019
2 parents 3a78b72 + 956fd56 commit bfc1247
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 47 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Ground Construction ChangeLog
* **v2.3 -- Part Construction**

* **v2.3.1**
* Excluded some pure-technical part modules (like ModuleTestSubject and ModuleOverheatDisplay) from DIY kit complexity calculation, which decreases both SpecializedParts and SKH build costs of many kits. _**Note** for modders: the excluded part modules are listed in the IgnoreModules.cfg and could be added/changed using MM._

* v2.3 -- **Part Construction**
* Compatible with KSP-1.7
* Added "Add Part" option to **create kit from a single part**.

Expand Down
8 changes: 4 additions & 4 deletions DIYKits/PartKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public PartKit(Part part, bool assembled = true)
}
else
{
Complexity = 1 - 1 / ((dry_cost / part.mass + part.Modules.Count * 1000) * GLB.ComplexityFactor + 1);
Complexity = 1 - 1 / ((dry_cost / part.mass + GLB.IgnoreModules.SizeOfDifference(part.Modules) * 1000) * GLB.ComplexityFactor + 1);
var structure_mass = part.mass * (1 - Complexity);
var structure_cost = Mathf.Min(structure_mass / GLB.ConstructionResource.def.density * GLB.ConstructionResource.def.unitCost, dry_cost);
var kit_mass = part_mass - structure_mass;
var kit_cost = part_cost - structure_cost;
Construction.TotalWork = total_work(Construction, structure_mass);
Assembly.TotalWork = total_work(Assembly, kit_mass);
update_total_work();
var frac = (float)(Assembly.TotalWork/TotalWork);
var frac = (float)(Assembly.TotalWork / TotalWork);
//Utils.Log("frac {}, kit_mass {}, kit_cost {}", frac, kit_mass, kit_cost);//debug
Mass.Add(frac, kit_mass);
Cost.Add(frac, kit_cost);
SetStageComplete(ASSEMBLY, true);
}
}

double total_work(JobStage task, double end_mass) =>
double total_work(JobStage task, double end_mass) =>
(Complexity * task.Resource.ComplexityWork + Construction.Resource.WorkPerMass) * end_mass * 3600;

//deprecated config conversion
Expand All @@ -75,7 +75,7 @@ public override void Load(ConfigNode node)
Assembly.TotalWork = Assembly.WorkDone = Construction.TotalWork;
update_total_work();
float v;
var frac = (float)(Assembly.TotalWork/TotalWork);
var frac = (float)(Assembly.TotalWork / TotalWork);
var val = node.GetValue("Title");
if(!string.IsNullOrEmpty(val))
Name = val;
Expand Down
2 changes: 1 addition & 1 deletion DIYKits/VesselKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void strip_resources(IShipconstruct ship, bool assembled)
if(r.info.isTweakable &&
r.info.density > 0 &&
r.info.id != Utils.ElectricCharge.id &&
!GLB.KeepResourcesIDs.Contains(r.info.id))
!GLB.KeepResourcesIDs.Values.Contains(r.info.id))
AdditionalResources.Strip(r);
}));
else
Expand Down
2 changes: 1 addition & 1 deletion GameData/GroundConstruction/GroundConstruction.version
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"MAJOR":2,
"MINOR":3,
"PATCH":0,
"PATCH":1,
"BUILD":0
},
"KSP_VERSION_MIN":
Expand Down
24 changes: 24 additions & 0 deletions GameData/GroundConstruction/IgnoreModules.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GC_IGNORE_MODULES
{
// stock
ignore = ModuleTestSubject
ignore = ModulePartVariants
ignore = FlagDecal
ignore = ModuleOverheatDisplay
ignore = ModuleLiftingSurface
ignore = ModuleSurfaceFX
ignore = FXModuleAnimateThrottle
ignore = ModuleDragModifier
ignore = ModuleColorChanger
ignore = ModuleAblator

// mods
ignore = KOSNameTag
ignore = ModuleB9PropagateCopyEvents
ignore = ModuleB9PartSwitch
ignore = ModuleB9PartInfo
ignore = ModuleConnectedLivingSpace
ignore = ModuleKISItem
ignore = TCAEngineInfo
ignore = ResourceHack
}
133 changes: 94 additions & 39 deletions Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,126 @@

namespace GroundConstruction
{
public class Globals : PluginGlobals<Globals>
{
#region Resources
[Persistent] public ResourceUsageInfo AssemblyResource = new ResourceUsageInfo("SpecializedParts");
[Persistent] public ResourceUsageInfo ConstructionResource = new ResourceUsageInfo("MaterialKits");

public ResourceIdSet KeepResourcesIDs = new ResourceIdSet("GC_KIT_RESOURCES");
#endregion

public ModuleNamesSet IgnoreModules = new ModuleNamesSet("GC_IGNORE_MODULES");

[Persistent] public bool UseStockAppLauncher = true;

[Persistent] public float WorkshopShutdownThreshold = 0.99f;
[Persistent] public float MaxDistanceToWorkshop = 300f;
[Persistent] public float MinDistanceToWorkshop = 50f;
[Persistent] public float MaxDistanceEfficiency = 0.2f;

[Persistent] public float VolumePerKerbal = 3;
[Persistent] public float PartVolumeFactor = 0.3f;
[Persistent] public float MinGenericEfficiency = 0.05f;
[Persistent] public float MaxGenericEfficiency = 0.5f;

[Persistent] public float ComplexityFactor = 1e-4f;

[Persistent] public float ComplexityWeight = 110;
[Persistent] public float MetalworkWeight = 100;

[Persistent] public float VesselKitDensity = 0.5f; //t/m3
[Persistent] public float MinKitVolume = 0.02f; //m3

[Persistent] public float DeployMaxSpeed = 0.5f; //m/s
[Persistent] public float DeployMaxAV = 5e-6f; //(rad/s)2
[Persistent] public float MaxDeploymentMomentum = 1; //t*m/s
[Persistent] public float MinDeploymentTime = 3; //s

[Persistent] public int EasingFrames = 120;
}

public class ResourceUsageInfo : ResourceInfo
{
[Persistent] public float ComplexityWork = 0;
[Persistent] public float EnergyPerMass = 0;
[Persistent] public float WorkPerMass = 0;

public ResourceUsageInfo(string name = "") : base(name) {}
public ResourceUsageInfo(string name = "") : base(name) { }
}

public class Globals : PluginGlobals<Globals>
public abstract class ConfigValueSet<T>
{
#region Resources
[Persistent] public ResourceUsageInfo AssemblyResource = new ResourceUsageInfo("SpecializedParts");
[Persistent] public ResourceUsageInfo ConstructionResource = new ResourceUsageInfo("MaterialKits");
protected string node_name = string.Empty;
HashSet<T> values;

protected abstract bool transform_value(ConfigNode.Value val, out T value);

const string RESOURCES_NODE = "GC_KIT_RESOURCES";
HashSet<int> keep_res_ids;
public HashSet<int> KeepResourcesIDs
protected ConfigValueSet(string nodeName)
{
node_name = nodeName;
}

public HashSet<T> Values
{
get
{
if(keep_res_ids == null)
if(values == null)
{
keep_res_ids = new HashSet<int>();
var nodes = GameDatabase.Instance.GetConfigNodes(RESOURCES_NODE);
values = new HashSet<T>();
T value;
var nodes = GameDatabase.Instance.GetConfigNodes(node_name);
foreach(var node in nodes)
{
foreach(ConfigNode.Value val in node.values)
{
var res = PartResourceLibrary.Instance.GetDefinition(val.value);
if(res != null) keep_res_ids.Add(res.id);
if(transform_value(val, out value))
values.Add(value);
}
}
}
return keep_res_ids;
return values;
}
}
#endregion

[Persistent] public bool UseStockAppLauncher = true;

[Persistent] public float WorkshopShutdownThreshold = 0.99f;
[Persistent] public float MaxDistanceToWorkshop = 300f;
[Persistent] public float MinDistanceToWorkshop = 50f;
[Persistent] public float MaxDistanceEfficiency = 0.2f;

[Persistent] public float VolumePerKerbal = 3;
[Persistent] public float PartVolumeFactor = 0.3f;
[Persistent] public float MinGenericEfficiency = 0.05f;
[Persistent] public float MaxGenericEfficiency = 0.5f;

[Persistent] public float ComplexityFactor = 1e-4f;

[Persistent] public float ComplexityWeight = 110;
[Persistent] public float MetalworkWeight = 100;
public static implicit operator HashSet<T>(ConfigValueSet<T> configValueSet)
=> configValueSet.Values;
}

[Persistent] public float VesselKitDensity = 0.5f; //t/m3
[Persistent] public float MinKitVolume = 0.02f; //m3
public class ModuleNamesSet : ConfigValueSet<string>
{
public ModuleNamesSet(string nodeName) : base(nodeName) { }
protected override bool transform_value(ConfigNode.Value val, out string value)
{
value = val.value;
return true;
}

[Persistent] public float DeployMaxSpeed = 0.5f; //m/s
[Persistent] public float DeployMaxAV = 5e-6f; //(rad/s)2
[Persistent] public float MaxDeploymentMomentum = 1; //t*m/s
[Persistent] public float MinDeploymentTime = 3; //s
public int SizeOfDifference(PartModuleList modules)
{
int size = 0;
for(int i = 0, modulesCount = modules.Count; i < modulesCount; i++)
{
if(!Values.Contains(modules[i].ClassName))
size++;
}
return size;
}
}

[Persistent] public int EasingFrames = 120;
public class ResourceIdSet : ConfigValueSet<int>
{
public ResourceIdSet(string nodeName) : base(nodeName) { }
protected override bool transform_value(ConfigNode.Value val, out int value)
{
value = 0;
var res = PartResourceLibrary.Instance.GetDefinition(val.value);
if(res != null)
{
value = res.id;
return true;
}
return false;
}
}
}

12 changes: 12 additions & 0 deletions GroundConstruction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@
<Folder Include="Containers\" />
<Folder Include="Workshops\" />
</ItemGroup>
<ItemGroup>
<None Include="GameData\GroundConstruction\IgnoreModules.cfg" />
<None Include="GameData\GroundConstruction\KitResources.cfg" />
<None Include="GameData\GroundConstruction\Engineer.cfg" />
<None Include="GameData\GroundConstruction\Patches\ISRU_Patch.cfg" />
<None Include="GameData\GroundConstruction\Patches\EPL.cfg" />
<None Include="ChangeLog.md" />
<None Include="GroundConstruction.netkan" />
<None Include="GroundConstruction-Core.netkan" />
<None Include="make-release.sh" />
<None Include="README.md" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#if NIGHTBUILD
[assembly: AssemblyVersion("2.3.*")]
#else
[assembly: AssemblyVersion("2.3.0")]
[assembly: AssemblyVersion("2.3.1")]
#endif
[assembly: KSPAssembly("GroundConstruction", 2, 3)]

Expand Down

0 comments on commit bfc1247

Please sign in to comment.