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

Commit

Permalink
Merge pull request #7 from magico13/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Kerbas-ad-astra committed Oct 18, 2016
2 parents 99a9fae + 95c50d9 commit 7989d68
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 83 deletions.
8 changes: 4 additions & 4 deletions GameData/KerbalConstructionTime/.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
"URL":"http://magico13.net/KCT/.version",
"DOWNLOAD":"http://forum.kerbalspaceprogram.com/threads/92377-0-24-2-Kerbal-Construction-Time-Release-v1-0-2-%289-3-14%29",
"CHANGE_LOG_URL":"http://magico13.net/KCT/KCT_changelog",
"VERSION":"1.3.3.0",
"VERSION":"1.3.4.0",
"KSP_VERSION":{
"MAJOR":1,
"MINOR":1,
"PATCH":0
"PATCH":3
},
"KSP_VERSION_MIN":{
"MAJOR":1,
"MINOR":1,
"PATCH":0
"PATCH":3
},
"KSP_VERSION_MAX":{
"MAJOR":1,
"MINOR":1,
"PATCH":0
"PATCH":3
}
}
15 changes: 13 additions & 2 deletions GameData/KerbalConstructionTime/KCT_Presets/UpFree.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ KCT_Preset
UpgradeFundsFormula = -1
UpgradeScienceFormula = -1
ResearchFormula = [R]^2/86400
EffectivePartFormula = min([c]/([I] + ([B]*([U]+1))), [c])
ProceduralPartFormula = (([C]-[A]) + ([A]*10/max([I],1))) / max([B]*([U]+1),1)
EffectivePartFormula = min([c]/([I] + ([B]*([U]+1))), [c])*[MV]*[PV]
ProceduralPartFormula = (([C]-[A]) + ([A]*10/max([I],1))) / max([B]*([U]+1),1) *[MV]*[PV]
BPFormula = ([E]^(1/2))*2000*[O]
KSCUpgradeFormula = ([C]^(1/2))*1000*[O]
ReconditioningFormula = min([M]*[O]*[E], [X])*abs([RE]-[S])
Expand All @@ -50,4 +50,15 @@ KCT_Preset
RolloutCostFormula = 0
NewLaunchPadCostFormula = 100000*([N]^3)
}
KCT_Preset_Part_Variables
{
Part_Variables
{
//partName = multiplier
}
Module_Variables
{
//moduleName = multiplier
}
}
}
13 changes: 12 additions & 1 deletion GameData/KerbalConstructionTime/KCT_Presets/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ KCT_Preset
UpgradeFundsFormula = min(2^([N]+4) * 1000, 1024000)
UpgradeScienceFormula = min(2^([N]+2) * 1.0, 512)
ResearchFormula = [N]*0.5/86400
EffectivePartFormula = min([c]/([I] + ([B]*([U]+1))) *[MV]*[PV], [c])
EffectivePartFormula = min([c]/([I] + ([B]*([U]+1))), [c])*[MV]*[PV]
ProceduralPartFormula = (([c]-[A]) + ([A]*10/max([I],1))) / max([B]*([U]+1),1) *[MV]*[PV]
BPFormula = ([E]^(1/2))*2000*[O]
KSCUpgradeFormula = ([C]^(1/2))*1000*[O]
Expand All @@ -50,4 +50,15 @@ KCT_Preset
RolloutCostFormula = 0
NewLaunchPadCostFormula = 100000*([N]^3)
}
KCT_Preset_Part_Variables
{
Part_Variables
{
//partName = multiplier
}
Module_Variables
{
//moduleName = multiplier
}
}
}
15 changes: 13 additions & 2 deletions GameData/KerbalConstructionTime/KCT_Presets/rlowtech.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ KCT_Preset
KerbinSimCostFormula = max( 144 + ([L]/10) + ([C]/20) ^0.5, max([L]^0.5,10)*[C]/20000 )
RolloutCostFormula = 0
ReconditioningFormula = min([M]/100*[E]*3600*[O], [X]*6*3600) * abs([RE]-[S])
ProceduralPartFormula = max( 0-[A]*[I]/([I]+1)+[C] /([B]*[U]+1), [C]/([I]+1^2+([B]*[U])+1) )
EffectivePartFormula = max( [C] /([I]+1) /([B]*[U]+1), [C]/([I]+1^2+([B]*[U])+1) )
ProceduralPartFormula = max( 0-[A]*[I]/([I]+1)+[C] /([B]*[U]+1), [C]/([I]+1^2+([B]*[U])+1) )*[MV]*[PV]
EffectivePartFormula = max( [C] /([I]+1) /([B]*[U]+1), [C]/([I]+1^2+([B]*[U])+1) )*[MV]*[PV]
BPFormula = ([E]^(1/2))*(2000^3/6+([E]^2*2000))/(2000^2+([E]^2))*[O]
NewLaunchPadCostFormula = 100000*([N]^3)
}
Expand All @@ -50,4 +50,15 @@ KCT_Preset
MaxReconditioning = 16
RolloutReconSplit = 0.25
}
KCT_Preset_Part_Variables
{
Part_Variables
{
//partName = multiplier
}
Module_Variables
{
//moduleName = multiplier
}
}
}
9 changes: 9 additions & 0 deletions GameData/KerbalConstructionTime/readme-KCT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ If at all possible, please include directions about how to replicate the issue a
Issue tracker: https://github.com/magico13/KCT/issues

Changelog:
v1.3.4.0 (06/25/16)
- Update to KSP 1.1.3

v 1.3.3.7 (05/09/16)
- Update for KSP 1.1.2
- Now requires MagiCore for math and time parsing
- Added Part Variables and Module Variables to alter the EffectivePart and ProceduralPart formulas for specific parts/modules
- Several bug fixes

v1.3.3.0-pre (04/22/16)
- Pre-release update for KSP v1.1

Expand Down
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
3 changes: 2 additions & 1 deletion Kerbal_Construction_Time/KCT_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void addEvents()

public void HideAllGUIs()
{
KCT_GUI.hideAll();
//KCT_GUI.hideAll();
KCT_GUI.ClickOff();
}
/* public void LevelLoadedEvent(GameScenes scene)
{
Expand Down
21 changes: 13 additions & 8 deletions Kerbal_Construction_Time/KCT_GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,14 @@ private static void CheckEditorLock()

public static void ClickOff()
{
KCTDebug.Log("ClickOff");
clicked = false;
onClick();
}

public static void ClickOn()
{
KCTDebug.Log("ClickOn");
clicked = true;
onClick();
}
Expand All @@ -224,7 +226,7 @@ public static void onClick()

if (PrimarilyDisabled && (HighLogic.LoadedScene == GameScenes.SPACECENTER))
{
if (!showSettings)
if (clicked)
ShowSettings();
else
showSettings = false;
Expand Down Expand Up @@ -257,12 +259,12 @@ public static void onClick()
}
else if (HighLogic.LoadedScene == GameScenes.FLIGHT && KCT_GameStates.flightSimulated)
{
showSimulationWindow = !showSimulationWindow;
showSimulationWindow = clicked;
simulationWindowPosition.height = 1;
}
else if ((HighLogic.LoadedScene == GameScenes.EDITOR) && !PrimarilyDisabled)
{
showEditorGUI = !showEditorGUI;
showEditorGUI = clicked;
KCT_GameStates.showWindows[1] = showEditorGUI;
}
else if ((HighLogic.LoadedScene == GameScenes.SPACECENTER) || (HighLogic.LoadedScene == GameScenes.TRACKSTATION) && !PrimarilyDisabled)
Expand Down Expand Up @@ -293,6 +295,7 @@ public static void onClick()

public static void onHoverOn()
{
KCTDebug.Log("onHoverOn: Clicked = " + clicked);
if (!PrimarilyDisabled)
{
if (HighLogic.LoadedScene == GameScenes.SPACECENTER || (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated))
Expand All @@ -305,6 +308,7 @@ public static void onHoverOn()
}
public static void onHoverOff()
{
KCTDebug.Log("onHoverOff: Clicked = " + clicked);
if (!PrimarilyDisabled && !clicked)
{
if (HighLogic.LoadedScene == GameScenes.SPACECENTER || (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated))
Expand Down Expand Up @@ -339,15 +343,16 @@ public static void hideAll()
showSimLengthChooser = false;
showPresetSaver = false;
showLaunchSiteSelector = false;


if (!KCT_GameStates.settings.PreferBlizzyToolbar)
//ClickOff();

/* if (!KCT_GameStates.settings.PreferBlizzyToolbar)
{
if (KCT_Events.instance != null && KCT_Events.instance.KCTButtonStock != null)
{
KCT_Events.instance.KCTButtonStock.SetFalse(true);
KCT_Events.instance.KCTButtonStock.SetFalse(false);
}
}
}*/
clicked = false;

//VABSelected = false;
Expand Down Expand Up @@ -723,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
5 changes: 3 additions & 2 deletions Kerbal_Construction_Time/KCT_PresetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public KCT_Preset(KCT_Preset Source)
ConfigNode.LoadObjectFromConfig(generalSettings, Source.generalSettings.AsConfigNode());
ConfigNode.LoadObjectFromConfig(timeSettings, Source.timeSettings.AsConfigNode());
ConfigNode.LoadObjectFromConfig(formulaSettings, Source.formulaSettings.AsConfigNode());
partVariables.FromConfigNode(Source.partVariables.ToConfigNode());
partVariables.FromConfigNode(Source.partVariables.AsConfigNode());
}

public ConfigNode AsConfigNode()
Expand All @@ -302,6 +302,7 @@ public ConfigNode AsConfigNode()
node.AddNode(generalSettings.AsConfigNode());
node.AddNode(timeSettings.AsConfigNode());
node.AddNode(formulaSettings.AsConfigNode());
node.AddNode(partVariables.AsConfigNode());
return node;
}

Expand Down Expand Up @@ -415,7 +416,7 @@ private Dictionary<string, double> NodeToDictionary(ConfigNode node)
return dict;
}

public ConfigNode ToConfigNode()
public ConfigNode AsConfigNode()
{
ConfigNode node = new ConfigNode("KCT_Preset_Part_Variables");
node.AddNode(DictionaryToNode(Part_Variables, "Part_Variables"));
Expand Down
64 changes: 30 additions & 34 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 All @@ -434,7 +439,8 @@ public static double GetBuildTime(List<ConfigNode> parts, bool useTracker, Dicti


effectiveCost = KCT_MathParsing.GetStandardFormulaValue("EffectivePart", new Dictionary<string, string>() { {"C", cost.ToString()}, {"c", dryCost.ToString()}, {"M",wetMass.ToString()},
{"m", dryMass.ToString()}, {"U", used.ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()}, {"I", InvEff.ToString()}, {"B", KCT_PresetManager.Instance.ActivePreset.timeSettings.BuildEffect.ToString()}});
{"m", dryMass.ToString()}, {"U", used.ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()}, {"I", InvEff.ToString()}, {"B", KCT_PresetManager.Instance.ActivePreset.timeSettings.BuildEffect.ToString()},
{"PV", PartMultiplier.ToString()}, {"MV", ModuleMultiplier.ToString()}});

if (InvEff != 0)
{
Expand Down Expand Up @@ -474,7 +480,8 @@ public static double GetBuildTime(List<ConfigNode> parts, bool useTracker, Dicti
int used = (useTracker && KCT_GameStates.PartTracker.ContainsKey(name)) ? KCT_GameStates.PartTracker[name] : 0;

effectiveCost = KCT_MathParsing.GetStandardFormulaValue("ProceduralPart", new Dictionary<string, string>() { {"A", costRemoved.ToString()},{"C", cost.ToString()}, {"c", dryCost.ToString()}, {"M",wetMass.ToString()},
{"m", dryMass.ToString()}, {"U", used.ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()}, {"I", InvEff.ToString()}, {"B", KCT_PresetManager.Instance.ActivePreset.timeSettings.BuildEffect.ToString()}});
{"m", dryMass.ToString()}, {"U", used.ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()}, {"I", InvEff.ToString()}, {"B", KCT_PresetManager.Instance.ActivePreset.timeSettings.BuildEffect.ToString()},
{"PV", PartMultiplier.ToString()}, {"MV", ModuleMultiplier.ToString()}});

if (InvEff != 0)
{
Expand Down Expand Up @@ -752,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 @@ -1040,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 @@ -1094,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 @@ -1114,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 Expand Up @@ -1938,6 +1932,8 @@ public static string GetActiveRSSKSC()
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "regexKSP.KSCLoader");
object LoaderInstance = GetMemberInfoValue(Loader.GetMember("instance")[0], null);
if (LoaderInstance == null)
return "Stock";
object SitesObj = GetMemberInfoValue(Loader.GetMember("Sites")[0], LoaderInstance);
string lastSite = (string)GetMemberInfoValue(SitesObj.GetType().GetMember("lastSite")[0], SitesObj);

Expand Down
Loading

0 comments on commit 7989d68

Please sign in to comment.