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

Commit

Permalink
Add LM for launchsite max level and ELM for max editor level to the r…
Browse files Browse the repository at this point in the history
…econditioning, rollout cost, build rate, and node rate (as RM) formulas, where appropriate.
  • Loading branch information
magico13 committed Aug 23, 2017
1 parent 91d7218 commit a9c5ea1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion GameData/KerbalConstructionTime/KCT_Presets/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ KCT_Preset
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]) / (3-[L])
ReconditioningFormula = min([M]*[O]*[E], [X])*abs([RE]-[S]) / ([LM]-[L])
BuildRateFormula = (([I]+1)*0.05*[N] + max(0.1-[I], 0))*sign(2*[L]-[I]+1)
SimCostFormula = max([C]/50000 * min([PM]/[KM], 80) * ([S]/10 + 1) * ([A]/10 + 1) * ([L]^0.5) * 100, 500)
KerbinSimCostFormula = max([C]/50000 * ([L]^0.5) * 10, 100)
Expand Down
24 changes: 21 additions & 3 deletions Kerbal_Construction_Time/KCT_MathParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ public static double GetStandardFormulaValue(string formulaName, Dictionary<stri
public static double ParseBuildRateFormula(KCT_BuildListVessel.ListType type, int index, KCT_KSC KSC, bool UpgradedRates = false)
{
//N = num upgrades, I = rate index, L = VAB/SPH upgrade level, R = R&D level
int level = 0, upgrades = 0;
int level = 0, upgrades = 0, levelMax = 0;
Dictionary<string, string> variables = new Dictionary<string, string>();
if (type == KCT_BuildListVessel.ListType.VAB)
{
level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
levelMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
if (KSC.VABUpgrades.Count > index)
upgrades = KSC.VABUpgrades[index];
}
else if (type == KCT_BuildListVessel.ListType.SPH)
{
level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
levelMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
if (KSC.SPHUpgrades.Count > index)
upgrades = KSC.SPHUpgrades[index];
}
if (UpgradedRates)
upgrades++;
variables.Add("L", level.ToString());
variables.Add("LM", level.ToString());
variables.Add("N", upgrades.ToString());
variables.Add("I", index.ToString());
variables.Add("R", KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.ResearchAndDevelopment).ToString());
Expand All @@ -68,12 +71,14 @@ public static double ParseBuildRateFormula(KCT_BuildListVessel.ListType type, in
public static double ParseNodeRateFormula(double ScienceValue, int index = 0, bool UpgradedRates = false)
{
int RnDLvl = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.ResearchAndDevelopment);
int RnDMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.ResearchAndDevelopment);
int upgrades = KCT_GameStates.TechUpgradesTotal;
if (UpgradedRates) upgrades++;
Dictionary<string, string> variables = new Dictionary<string, string>();
variables.Add("S", ScienceValue.ToString());
variables.Add("N", upgrades.ToString());
variables.Add("R", RnDLvl.ToString());
variables.Add("RM", RnDMax.ToString());
variables.Add("O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString());
variables.Add("I", index.ToString());

Expand All @@ -93,20 +98,24 @@ public static double ParseRolloutCostFormula(KCT_BuildListVessel vessel)
loadedMass = vessel.GetTotalMass();
emptyMass = vessel.emptyMass;

int EditorLevel = 0, LaunchSiteLvl = 0;
int EditorLevel = 0, LaunchSiteLvl = 0, EditorMax = 0, LaunchSiteMax = 0;
int isVABVessel = 0;
if (vessel.type == KCT_BuildListVessel.ListType.None)
vessel.FindTypeFromLists();
if (vessel.type == KCT_BuildListVessel.ListType.VAB)
{
EditorLevel = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
LaunchSiteLvl = KCT_GameStates.ActiveKSC.ActiveLPInstance.level;//KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
EditorMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.LaunchPad);
isVABVessel = 1;
}
else if (vessel.type == KCT_BuildListVessel.ListType.SPH)
{
EditorLevel = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
LaunchSiteLvl = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.Runway);
EditorMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.Runway);
}
double BP = vessel.buildPoints;

Expand All @@ -118,7 +127,9 @@ public static double ParseRolloutCostFormula(KCT_BuildListVessel vessel)
variables.Add("VAB", isVABVessel.ToString());
variables.Add("BP", BP.ToString());
variables.Add("L", LaunchSiteLvl.ToString());
variables.Add("LM", LaunchSiteMax.ToString());
variables.Add("EL", EditorLevel.ToString());
variables.Add("ELM", EditorMax.ToString());

AddCrewVariables(variables);

Expand All @@ -137,18 +148,22 @@ public static double ParseReconditioningFormula(KCT_BuildListVessel vessel, bool
loadedMass = vessel.GetTotalMass();
emptyMass = vessel.emptyMass;

int EditorLevel = 0, LaunchSiteLvl = 0;
int EditorLevel = 0, LaunchSiteLvl = 0, EditorMax = 0, LaunchSiteMax = 0;
int isVABVessel = 0;
if (vessel.type == KCT_BuildListVessel.ListType.VAB)
{
EditorLevel = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
LaunchSiteLvl = KCT_GameStates.ActiveKSC.ActiveLPInstance.level;//KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
EditorMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.LaunchPad);
isVABVessel = 1;
}
else
{
EditorLevel = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
LaunchSiteLvl = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.Runway);
EditorMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.Runway);
}
double BP = vessel.buildPoints;
double OverallMult = KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier;
Expand All @@ -162,14 +177,17 @@ public static double ParseReconditioningFormula(KCT_BuildListVessel vessel, bool
variables.Add("VAB", isVABVessel.ToString());
variables.Add("BP", BP.ToString());
variables.Add("L", LaunchSiteLvl.ToString());
variables.Add("LM", LaunchSiteMax.ToString());
variables.Add("EL", EditorLevel.ToString());
variables.Add("ELM", EditorMax.ToString());
variables.Add("O", OverallMult.ToString());
variables.Add("E", ReconEffect.ToString());
variables.Add("X", MaxRecon.ToString());
int isRecon = isReconditioning ? 1 : 0;
variables.Add("RE", isRecon.ToString());
variables.Add("S", KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit.ToString());


AddCrewVariables(variables);

return GetStandardFormulaValue("Reconditioning", variables);
Expand Down
42 changes: 24 additions & 18 deletions Kerbal_Construction_Time/KCT_Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1995,26 +1995,25 @@ public static bool PartIsProcedural(Part part)

public static int BuildingUpgradeLevel(SpaceCenterFacility facility)
{
int lvl = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facility);
if (lvl < 0)
int lvl = BuildingUpgradeMaxLevel(facility);
if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
{
if (!KCT_GameStates.BuildingMaxLevelCache.TryGetValue(facility.ToString(), out lvl))
{
//screw it, let's call it 2
lvl = 2;
KCTDebug.Log($"Couldn't get actual max level or cached one for {facility}. Assuming 2.");
}
lvl = (int)Math.Round((lvl * ScenarioUpgradeableFacilities.GetFacilityLevel(facility)));
}
int max = lvl;
return lvl;
}

public static int BuildingUpgradeLevel(string facilityID)
{
int lvl = BuildingUpgradeMaxLevel(facilityID);
if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
{
lvl = (int)(lvl * ScenarioUpgradeableFacilities.GetFacilityLevel(facility));
lvl = (int)Math.Round((lvl * ScenarioUpgradeableFacilities.GetFacilityLevel(facilityID))); //let's not store discrete things with integers! No! Let's use floats! -Squad
}
//KCTDebug.Log($"Facility: {facility} max: {max} lvl: {lvl}");
return lvl;
}

public static int BuildingUpgradeLevel(string facilityID)
public static int BuildingUpgradeMaxLevel(string facilityID)
{
int lvl = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facilityID);
if (lvl < 0)
Expand All @@ -2026,14 +2025,21 @@ public static int BuildingUpgradeLevel(string facilityID)
KCTDebug.Log($"Couldn't get actual max level or cached one for {facilityID}. Assuming 2.");
}
}
int max = lvl;
if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
return lvl;
}

public static int BuildingUpgradeMaxLevel(SpaceCenterFacility facility)
{
int lvl = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facility);
if (lvl < 0)
{
lvl = (int)Math.Round((lvl * ScenarioUpgradeableFacilities.GetFacilityLevel(facilityID))); //let's not store discrete things with integers! No! Let's use floats! -Squad
if (!KCT_GameStates.BuildingMaxLevelCache.TryGetValue(facility.ToString(), out lvl))
{
//screw it, let's call it 2
lvl = 2;
KCTDebug.Log($"Couldn't get actual max level or cached one for {facility}. Assuming 2.");
}
}

//KCTDebug.Log($"FacilityID: {facilityID} max: {max} lvl: {lvl}");

return lvl;
}

Expand Down

0 comments on commit a9c5ea1

Please sign in to comment.