Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Commit

Permalink
Updated for KSP 1.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
magico13 committed Sep 16, 2016
1 parent 5df691d commit 95c50d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 46 deletions.
5 changes: 2 additions & 3 deletions Kerbal_Construction_Time/KCT_BuildListVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ public double GetTotalMass()
emptyMass = 0;
foreach (ConfigNode p in this.ExtractedPartNodes)
{
float n1, n2;
TotalMass += ShipConstruction.GetPartTotalMass(p, KCT_Utilities.GetAvailablePartByName(KCT_Utilities.PartNameFromNode(p)), out n1, out n2);
emptyMass += n1;
TotalMass += KCT_Utilities.GetPartMassFromNode(p, true);
emptyMass += KCT_Utilities.GetPartMassFromNode(p, false);
}
if (TotalMass < 0)
TotalMass = 0;
Expand Down
2 changes: 1 addition & 1 deletion Kerbal_Construction_Time/KCT_GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ private static void DrawEditorGUI(int windowID)
{
foreach (PartResource rsc in p.Resources)
{
PartResource templateRsc = p.partInfo.partPrefab.Resources.list.Find(r => r.resourceName == rsc.resourceName);
PartResource templateRsc = p.partInfo.partPrefab.Resources.FirstOrDefault(r => r.resourceName == rsc.resourceName);
if (templateRsc != null)
rsc.amount = templateRsc.amount;
}
Expand Down
56 changes: 24 additions & 32 deletions Kerbal_Construction_Time/KCT_Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,18 @@ public static double GetBuildTime(List<ConfigNode> parts, bool useTracker, Dicti
String name = PartNameFromNode(p);
string raw_name = name;
double effectiveCost = 0;
double cost = GetPartCostFromNode(p);
double dryCost = GetPartCostFromNode(p, false);
double cost;// = GetPartCostFromNode(p);
float dryCost, fuelCost;// = GetPartCostFromNode(p, false);
//double wetmass = GetPartMassFromNode(p, true);
//double drymass = GetPartMassFromNode(p, false);
float dryMass, fuelMass;
float wetMass = ShipConstruction.GetPartTotalMass(p, GetAvailablePartByName(name), out dryMass, out fuelMass);
float wetMass; //ShipConstruction.GetPartTotalMass(p, GetAvailablePartByName(name), out dryMass, out fuelMass);

ShipConstruction.GetPartCostsAndMass(p, GetAvailablePartByName(name), out dryCost, out fuelCost, out dryMass, out fuelMass);
cost = dryCost + fuelCost;
wetMass = dryMass + fuelMass;


double PartMultiplier = KCT_PresetManager.Instance.ActivePreset.partVariables.GetPartVariable(raw_name);
List<string> moduleNames = new List<string>();
foreach (ConfigNode modNode in GetModulesFromPartNode(p))
Expand Down Expand Up @@ -754,43 +759,30 @@ public static float GetPartCostFromNode(ConfigNode part, bool includeFuel = true
AvailablePart aPart = GetAvailablePartByName(name);
if (aPart == null)
return 0;
float dry, wet;
float total = ShipConstruction.GetPartCosts(part, aPart, out dry, out wet);
float dryCost, fuelCost;
float dryMass, fuelMass;
ShipConstruction.GetPartCostsAndMass(part, aPart, out dryCost, out fuelCost, out dryMass, out fuelMass);
//float total = ShipConstruction.GetPartCosts(part, aPart, out dry, out wet);

if (includeFuel)
return total;
return dryCost+fuelCost;
else
return dry;
return dryCost;
}

public static float GetPartMassFromNode(ConfigNode part, bool includeFuel = true)
{
float dry = 0, total = 0, wet = 0;
/* if (float.TryParse(part.GetValue("mass"), out dry))
{
//mass += p.GetResourceMass();
foreach (ConfigNode rsc in part.GetNodes("RESOURCE"))
{
PartResourceDefinition def = PartResourceLibrary.Instance.GetDefinition(rsc.GetValue("name"));
wet = dry + def.density * float.Parse(rsc.GetValue("amount"));
}
}
else
{
AvailablePart p = KCT_Utilities.GetAvailablePartByName(KCT_Utilities.PartNameFromNode(part));
if (part != null)
{
dry = p.partPrefab.mass;
wet = dry + p.partPrefab.GetResourceMass();
}
}*/
AvailablePart aPart = GetAvailablePartByName(PartNameFromNode(part));
if (aPart == null)
return 0;
total = ShipConstruction.GetPartTotalMass(part, aPart, out dry, out wet);
//total = ShipConstruction.GetPartTotalMass(part, aPart, out dry, out wet);
float dryCost, fuelCost;
float dryMass, fuelMass;
ShipConstruction.GetPartCostsAndMass(part, aPart, out dryCost, out fuelCost, out dryMass, out fuelMass);
if (includeFuel)
return total;
return dryMass+fuelMass;
else
return dry;
return dryMass;
}

public static string GetTweakScaleSize(ProtoPartSnapshot part)
Expand Down Expand Up @@ -1042,7 +1034,7 @@ public static void AddPartToInventory(Part part)
{
float cost = part.partInfo.cost + part.GetModuleCosts(0);
KCTDebug.Log("PP cost: " + cost);
foreach (PartResource resource in part.Resources.list)
foreach (PartResource resource in part.Resources)
{
cost -= (float)(PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost * resource.amount);
}
Expand Down Expand Up @@ -1096,7 +1088,7 @@ public static int RemovePartFromInventory(Part part)
if (KCT_Utilities.PartIsProcedural(part))
{
float cost = part.partInfo.cost + part.GetModuleCosts(0);
foreach (PartResource resource in part.Resources.list)
foreach (PartResource resource in part.Resources)
{
cost -= (float)(PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost * resource.maxAmount);
}
Expand All @@ -1116,7 +1108,7 @@ public static int RemovePartFromInventory(Part part, Dictionary<String, int> inv
if (KCT_Utilities.PartIsProcedural(part))
{
float cost = part.partInfo.cost + part.GetModuleCosts(0);
foreach (PartResource resource in part.Resources.list)
foreach (PartResource resource in part.Resources)
{
cost -= (float)(PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost * resource.maxAmount);
}
Expand Down
6 changes: 3 additions & 3 deletions Kerbal_Construction_Time/KerbalConstructionTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private void EditorRecalculation()
}

public static bool moved = false;
private static bool updateChecked = false;
//private static bool updateChecked = false;
private static int failedLvlChecks = 0;
//private static double elapsedTimer = 0;
//private static double elapsedTicks = 0;
Expand Down Expand Up @@ -986,11 +986,11 @@ public void ShowLaunchAlert()
}

// This is how you hide tooltips.
if (EditorTooltip.Instance != null)
/*if (EditorTooltip.Instance != null)
{
EditorTooltip.Instance.HideToolTip();
GameEvents.onTooltipDestroyRequested.Fire();
}
}*/
}
}

Expand Down
7 changes: 2 additions & 5 deletions Kerbal_Construction_Time/KerbalConstructionTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@
<Reference Include="Assembly-CSharp">
<HintPath>D:\SteamLibrary\SteamApps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="KSPUtil">
<HintPath>D:\SteamLibrary\SteamApps\common\Kerbal Space Program\KSP_Data\Managed\KSPUtil.dll</HintPath>
</Reference>
<Reference Include="MagiCore">
<HintPath>..\..\MagiCore\MagiCore\obj\Debug\MagiCore.dll</HintPath>
<HintPath>..\..\MagiCore\MagiCore\obj\Release\MagiCore.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -102,4 +99,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
4 changes: 2 additions & 2 deletions Kerbal_Construction_Time/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[assembly: System.Reflection.AssemblyVersion("1.3.4.0")]
[assembly: System.Reflection.AssemblyFileVersion("1.3.4.0")]
[assembly: System.Reflection.AssemblyVersion("1.3.4.1")]
[assembly: System.Reflection.AssemblyFileVersion("1.3.4.1")]

0 comments on commit 95c50d9

Please sign in to comment.