public static double CalculateBP(double cost) { var variables = new Dictionary <string, string>() { { "C", cost.ToString() }, { "O", PresetManager.Instance.ActivePreset.TimeSettings.OverallMultiplier.ToString() }, { "Adm", "0" }, { "AC", "0" }, { "LP", "1" }, { "MC", "0" }, { "RD", "0" }, { "RW", "0" }, { "TS", "0" }, { "SPH", "0" }, { "VAB", "0" }, { "Other", "0" } }; double bp = MathParser.GetStandardFormulaValue("KSCUpgrade", variables); if (bp <= 0) { bp = 1; } return(bp); }
private static void RenderPointResetSection() { //TODO: Calculate the cost of resetting int ResetCost = (int)MathParser.GetStandardFormulaValue("UpgradeReset", new Dictionary <string, string> { { "N", KCTGameStates.UpgradesResetCounter.ToString() } }); if (ResetCost >= 0) { GUILayout.BeginHorizontal(); GUILayout.Label("Reset Upgrades: "); bool canAfford = AvailablePoints >= ResetCost; var style = canAfford ? GUI.skin.button : GetCannotAffordStyle(); if (GUILayout.Button($"{ResetCost} Points", style, GUILayout.ExpandWidth(false))) { if (SpentPoints > 0 && canAfford) //you have to spend some points before resetting does anything { KCTGameStates.ActiveKSC.VABUpgrades = new List <int>() { 0 }; KCTGameStates.ActiveKSC.SPHUpgrades = new List <int>() { 0 }; KCTGameStates.ActiveKSC.RDUpgrades = new List <int>() { 0, 0 }; KCTGameStates.TechUpgradesTotal = 0; foreach (KSCItem ksc in KCTGameStates.KSCs) { ksc.RDUpgrades[1] = 0; } _nodeRate = int.MinValue; _upNodeRate = int.MinValue; _researchRate = int.MinValue; _upResearchRate = int.MinValue; KCTGameStates.ActiveKSC.RecalculateBuildRates(); KCTGameStates.ActiveKSC.RecalculateUpgradedBuildRates(); foreach (TechItem tech in KCTGameStates.TechList) { tech.UpdateBuildRate(KCTGameStates.TechList.IndexOf(tech)); } KCTGameStates.UpgradesResetCounter++; } } GUI.enabled = true; GUILayout.EndHorizontal(); } }
private static double CalcPointCost(ref int pointDelta, double maxCost, string formulaName, int gameStateIndex) { int purchasedUpgrades = KCTGameStates.PurchasedUpgrades[gameStateIndex]; var variables = new Dictionary <string, string> { { "N", purchasedUpgrades.ToString() } }; double cumulativeCost = 0; double nextCost = MathParser.GetStandardFormulaValue(formulaName, variables); if (nextCost < 0) { return(-1); } if (pointDelta < 0) { pointDelta = 0; do { pointDelta++; cumulativeCost += nextCost; variables["N"] = (purchasedUpgrades + pointDelta).ToString(); nextCost = MathParser.GetStandardFormulaValue(formulaName, variables); }while (cumulativeCost + nextCost <= maxCost); } else { for (int i = 0; i < pointDelta; i++) { variables["N"] = (purchasedUpgrades + i).ToString(); cumulativeCost += MathParser.GetStandardFormulaValue(formulaName, variables); } } return(cumulativeCost); }
public static double CalculateBP(double cost, SpaceCenterFacility?facilityType) { int isAdm = 0, isAC = 0, isLP = 0, isMC = 0, isRD = 0, isRW = 0, isTS = 0, isSPH = 0, isVAB = 0, isOther = 0; switch (facilityType) { case SpaceCenterFacility.Administration: isAdm = 1; break; case SpaceCenterFacility.AstronautComplex: isAC = 1; break; case SpaceCenterFacility.LaunchPad: isLP = 1; break; case SpaceCenterFacility.MissionControl: isMC = 1; break; case SpaceCenterFacility.ResearchAndDevelopment: isRD = 1; break; case SpaceCenterFacility.Runway: isRW = 1; break; case SpaceCenterFacility.TrackingStation: isTS = 1; break; case SpaceCenterFacility.SpaceplaneHangar: isSPH = 1; break; case SpaceCenterFacility.VehicleAssemblyBuilding: isVAB = 1; break; default: isOther = 1; break; } var variables = new Dictionary <string, string>() { { "C", cost.ToString() }, { "O", PresetManager.Instance.ActivePreset.TimeSettings.OverallMultiplier.ToString() }, { "Adm", isAdm.ToString() }, { "AC", isAC.ToString() }, { "LP", isLP.ToString() }, { "MC", isMC.ToString() }, { "RD", isRD.ToString() }, { "RW", isRW.ToString() }, { "TS", isTS.ToString() }, { "SPH", isSPH.ToString() }, { "VAB", isVAB.ToString() }, { "Other", isOther.ToString() } }; double bp = MathParser.GetStandardFormulaValue("KSCUpgrade", variables); if (bp <= 0) { bp = 1; } return(bp); }
private static void RenderRnDSection(bool isCostCacheInvalid, KSCItem KSC) { if (Config == null) { Config = new LRTRHomeWorldParameters(); foreach (ConfigNode stg in GameDatabase.Instance.GetConfigNodes("HOMEWORLDPARAMETERS")) { Config.Load(stg); } } double secondsPerDay = Config.hoursPerDay * 3600; int labelDelta = _buyModifier < 0 ? AvailablePoints : _buyModifier; GUILayout.BeginHorizontal(); GUILayout.Label("R&D Upgrades"); GUILayout.Label($"+{labelDelta} Point{(labelDelta == 1 ? "" : "s")}", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (_researchRate == int.MinValue || isCostCacheInvalid) { _researchDelta = _buyModifier < 0 ? AvailablePoints : _buyModifier; var variables = new Dictionary <string, string>() { { "N", KSC.RDUpgrades[0].ToString() }, { "R", Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.ResearchAndDevelopment).ToString() } }; MathParser.AddCrewVariables(variables); _researchRate = MathParser.GetStandardFormulaValue("Research", variables); variables["N"] = (KSC.RDUpgrades[0] + _researchDelta).ToString(); _upResearchRate = MathParser.GetStandardFormulaValue("Research", variables); } if (_researchRate >= 0) { GUILayout.BeginHorizontal(); GUILayout.Label("Research"); GUILayout.Label($"{Math.Round(_researchRate * secondsPerDay, 2)} sci/{secondsPerDay} BP"); if (AvailablePoints > 0) { bool canAfford = AvailablePoints >= _researchDelta; GUIStyle style = canAfford ? GUI.skin.button : GetCannotAffordStyle(); if (GUILayout.Button($"+{Math.Round((_upResearchRate - _researchRate) * secondsPerDay, 2)}", style, GUILayout.Width(45)) && canAfford) { KSC.RDUpgrades[0] += _researchDelta; _researchRate = int.MinValue; _fundsCost = _spentPoints = _totalPoints = int.MinValue; } } GUILayout.EndHorizontal(); } double days = GameSettings.KERBIN_TIME ? 4 : 1; if (_nodeRate == int.MinValue || isCostCacheInvalid) { _nodeDelta = _buyModifier < 0 ? AvailablePoints : _buyModifier; _nodeRate = MathParser.ParseNodeRateFormula(0); _upNodeRate = MathParser.ParseNodeRateFormula(0, 0, _nodeDelta); } double sci = secondsPerDay * _nodeRate; double sciPerDay = sci / days; GUILayout.BeginHorizontal(); GUILayout.Label("Rate"); bool usingPerYear = false; if (sciPerDay > 0.1) { GUILayout.Label(Math.Round(sciPerDay * 1000) / 1000 + " sci/day"); } else { //Well, looks like we need sci/year instead GUILayout.Label(Math.Round(sciPerDay * Config.daysPerYear * 1000) / 1000 + " sci/yr"); usingPerYear = true; } if (_upNodeRate != _nodeRate && AvailablePoints > 0) { bool everyKSCCanUpgrade = true; foreach (KSCItem ksc in KCTGameStates.KSCs) { if (TotalPoints - Utilities.GetTotalSpentUpgrades(ksc) <= 0) { everyKSCCanUpgrade = false; break; } } if (everyKSCCanUpgrade) { double upSciPerDay = secondsPerDay * _upNodeRate / days; string buttonText = $"{Math.Round(1000 * upSciPerDay) / 1000} sci/day"; if (usingPerYear) { buttonText = $"{Math.Round(upSciPerDay * Config.daysPerYear * 1000) / 1000} sci/yr"; } bool canAfford = AvailablePoints >= _nodeDelta; GUIStyle style = canAfford ? GUI.skin.button : GetCannotAffordStyle(); if (GUILayout.Button(buttonText, style, GUILayout.ExpandWidth(false)) && canAfford) { KCTGameStates.TechUpgradesTotal += _nodeDelta; foreach (KSCItem ksc in KCTGameStates.KSCs) { ksc.RDUpgrades[1] = KCTGameStates.TechUpgradesTotal; } _nodeRate = _upNodeRate = int.MinValue; _fundsCost = _spentPoints = _totalPoints = int.MinValue; foreach (TechItem tech in KCTGameStates.TechList) { tech.UpdateBuildRate(KCTGameStates.TechList.IndexOf(tech)); } } } } GUILayout.EndHorizontal(); }