private static void LoadValue(ConfigNode node, string key, ref Vector3[] param) { if (node.HasNode(key)) { ConfigNode subnode = node.GetNode(key); if (subnode.HasValue("size")) { string[] values = subnode.GetValues("size"); Vector3[] result = new Vector3[values.Length]; for (int i = 0; i < values.Length; i++) { result[i] = ConfigNode.ParseVector3(values[i]); if (result[i].x < 0 && result[i].y < 0 && result[i].z < 0) { result[i] = maxVector3d; } if (result[i] == Vector3.zero) { CustomBarnKit.log("Fail to parse into a Vector array for key " + key + " the node\n" + subnode.ToString()); return; } } param = result; } } else if (debug) { CustomBarnKit.log("No node " + key); } }
private static void LoadValue(ConfigNode node, string key, ref int[] param) { if (node.HasValue(key)) { string s = node.GetValue(key); string[] split = s.Split(','); int[] result = new int[split.Length]; for (int i = 0; i < split.Length; i++) { string v = split[i]; int val; if (int.TryParse(v, out val)) { result[i] = val >= 0 ? val : int.MaxValue; } else { CustomBarnKit.log("Fail to parse \"" + s + "\" into an int array for key " + key); return; } } param = result; } else if (debug) { CustomBarnKit.log("No value " + key); } }
private void debugLog(string s) { if (debug) { CustomBarnKit.log(s); } }
private static void LoadValue(ConfigNode node, string key, ref DoubleCurve param) { if (node.HasNode(key)) { ConfigNode subNode = node.GetNode(key); param = new DoubleCurve(); param.Load(subNode); } else if (debug) { CustomBarnKit.log("No node " + key); } }
private static void LoadValue(ConfigNode node, string key, ref int param) { if (node.HasValue(key)) { string s = node.GetValue(key); int val; if (int.TryParse(s, out val)) { param = val != -1 ? val : int.MaxValue; } else { CustomBarnKit.log("Fail to parse \"" + s + "\" into an int for key " + key); } } else if (debug) { CustomBarnKit.log("No value " + key); } }
private static void LoadValue(ConfigNode node, string key, ref bool param) { if (node.HasValue(key)) { string s = node.GetValue(key); bool val; if (bool.TryParse(s, out val)) { param = val; } else { CustomBarnKit.log("Fail to parse \"" + s + "\" into a param for key " + key); } } else if (debug) { CustomBarnKit.log("No value " + key); } }
public void Load(GameVariables orig) { CustomBarnKit.log("Loading new career/science config"); #if DEBUG debug = true; #endif original = orig; // Init our values with the one from the default config reputationAddition = orig.reputationAddition; reputationSubtraction = orig.reputationSubtraction; ConfigNode[] configs = GameDatabase.Instance.GetConfigNodes("CUSTOMBARNKIT"); if (configs == null || configs.Length == 0) { CustomBarnKit.log("No config to load"); return; } if (configs.Length > 1) { CustomBarnKit.log("More than 1 CustomBarnKit node found. Loading the first one"); } ConfigNode config = configs[0]; ConfigNode node = new ConfigNode(); if (config.TryGetNode("VAB", ref node)) { LoadValue(node, "levels", ref levelsVAB); LoadValue(node, "upgrades", ref upgradesVAB); LoadValue(node, "upgradesVisual", ref upgradesVisualVAB); LoadValue(node, "actionGroupsCustomUnlock", ref actionGroupsCustomUnlockVAB); LoadValue(node, "actionGroupsStockUnlock", ref actionGroupsStockUnlockVAB); LoadValue(node, "partCountLimit", ref partCountLimitVAB); } if (config.TryGetNode("SPH", ref node)) { LoadValue(node, "levels", ref levelsSPH); LoadValue(node, "upgrades", ref upgradesSPH); LoadValue(node, "upgradesVisual", ref upgradesVisualSPH); LoadValue(node, "actionGroupsCustomUnlock", ref actionGroupsCustomUnlockSPH); LoadValue(node, "actionGroupsStockUnlock", ref actionGroupsStockUnlockSPH); LoadValue(node, "partCountLimit", ref partCountLimitSPH); } if (config.TryGetNode("LAUNCHPAD", ref node)) { LoadValue(node, "levels", ref levelsLaunchPad); LoadValue(node, "upgrades", ref upgradesLaunchPad); LoadValue(node, "upgradesVisual", ref upgradesVisualLaunchPad); LoadValue(node, "craftMassLimit", ref craftMassLimitLaunchPad); LoadValue(node, "craftSizeLimit", ref craftSizeLimitLaunchPad); LoadValue(node, "useBuilding", ref useBuildingLaunchPad); } if (config.TryGetNode("RUNWAY", ref node)) { LoadValue(node, "levels", ref levelsRunway); LoadValue(node, "upgrades", ref upgradesRunway); LoadValue(node, "upgradesVisual", ref upgradesVisualRunway); LoadValue(node, "craftMassLimit", ref craftMassLimitRunway); LoadValue(node, "craftSizeLimit", ref craftSizeLimitRunway); LoadValue(node, "useBuilding", ref useBuildingRunway); } if (config.TryGetNode("ASTRONAUTS", ref node)) { LoadValue(node, "levels", ref levelsAstronauts); LoadValue(node, "upgrades", ref upgradesAstronauts); LoadValue(node, "upgradesVisual", ref upgradesVisualAstronauts); LoadValue(node, "recruitHireBaseCost", ref recruitHireBaseCost); LoadValue(node, "recruitHireFlatRate", ref recruitHireFlatRate); LoadValue(node, "recruitHireRateModifier", ref recruitHireRateModifier); LoadValue(node, "recruitHireFixedRate", ref recruitHireFixedRate); LoadValue(node, "unlockedEVA", ref unlockedEVA); LoadValue(node, "unlockedEVAClamber", ref unlockedEVAClamber); LoadValue(node, "unlockedEVAFlags", ref unlockedEVAFlags); LoadValue(node, "homebodyAtmoEVA", ref homebodyAtmoEVA); LoadValue(node, "homebodyEVA", ref homebodyEVA); LoadValue(node, "activeCrewLimit", ref activeCrewLimit); LoadValue(node, "crewLevelLimit", ref crewLevelLimit); } if (config.TryGetNode("MISSION", ref node)) { LoadValue(node, "levels", ref levelsMission); LoadValue(node, "upgrades", ref upgradesMission); LoadValue(node, "upgradesVisual", ref upgradesVisualMission); LoadValue(node, "unlockedFlightPlanning", ref unlockedFlightPlanning); LoadValue(node, "activeContractsLimit", ref activeContractsLimit); LoadValue(node, "scoreSituationHome", ref scoreSituationHome); LoadValue(node, "scoreSituationOther", ref scoreSituationOther); LoadValue(node, "partRecoveryValueFactor", ref partRecoveryValueFactor); LoadValue(node, "resourceRecoveryValueFactor", ref resourceRecoveryValueFactor); LoadValue(node, "reputationKerbalDeath", ref reputationKerbalDeath); LoadValue(node, "reputationKerbalRecovery", ref reputationKerbalRecovery); LoadValue(node, "contractPrestigeTrivial", ref contractPrestigeTrivial); LoadValue(node, "contractPrestigeSignificant", ref contractPrestigeSignificant); LoadValue(node, "contractPrestigeExceptional", ref contractPrestigeExceptional); LoadValue(node, "contractDestinationWeight", ref contractDestinationWeight); LoadValue(node, "contractFundsAdvanceFactor", ref contractFundsAdvanceFactor); LoadValue(node, "contractFundsCompletionFactor", ref contractFundsCompletionFactor); LoadValue(node, "contractFundsFailureFactor", ref contractFundsFailureFactor); LoadValue(node, "contractReputationCompletionFactor", ref contractReputationCompletionFactor); LoadValue(node, "contractReputationFailureFactor", ref contractReputationFailureFactor); LoadValue(node, "contractScienceCompletionFactor", ref contractScienceCompletionFactor); } if (config.TryGetNode("TRACKING", ref node)) { LoadValue(node, "levels", ref levelsTracking); LoadValue(node, "upgrades", ref upgradesTracking); LoadValue(node, "upgradesVisual", ref upgradesVisualTracking); LoadValue(node, "unlockedSpaceObjectDiscovery", ref unlockedSpaceObjectDiscovery); LoadValue(node, "orbitDisplayMode", ref orbitDisplayMode); LoadValue(node, "patchesAheadLimit", ref patchesAheadLimit); LoadValue(node, "trackedObjectLimit", ref trackedObjectLimit); LoadValue(node, "DSNRange", ref DSNRange); LoadValue(node, "DSNRangeCurve", ref DSNRangeCurve); LoadValue(node, "DSNPowerCurve", ref DSNPowerCurve); LoadValue(node, "DSNScienceCurve", ref DSNScienceCurve); } if (config.TryGetNode("ADMINISTRATION", ref node)) { LoadValue(node, "levels", ref levelsAdministration); LoadValue(node, "upgrades", ref upgradesAdministration); LoadValue(node, "upgradesVisual", ref upgradesVisualAdministration); LoadValue(node, "activeStrategyLimit", ref activeStrategyLimit); LoadValue(node, "strategyCommitRange", ref strategyCommitRange); } if (config.TryGetNode("RESEARCH", ref node)) { LoadValue(node, "levels", ref levelsRnD); LoadValue(node, "upgrades", ref upgradesRnD); LoadValue(node, "upgradesVisual", ref upgradesVisualRnD); LoadValue(node, "dataToScienceRatio", ref dataToScienceRatio); LoadValue(node, "scienceCostLimit", ref scienceCostLimit); LoadValue(node, "unlockedFuelTransfer", ref unlockedFuelTransfer); } }