public override void OnLoad(ConfigNode configFile) { Log.Info("OnLoad"); ConfigNode configFileNode = new ConfigNode(); try { ConfigNode[] configDataNodes; Dictionary <string, kerbalEVAFueldata> kerbalEVAList = new Dictionary <string, kerbalEVAFueldata>(); configFileNode = configFile.GetNode(TT_NODENAME); if (configFileNode != null) { configDataNodes = configFileNode.GetNodes("EvaData"); foreach (var dataNode in configDataNodes) { kerbalEVAFueldata ked = new kerbalEVAFueldata(); dataNode.TryGetValue("name", ref ked.name); ked.evaPropAmt = Double.Parse(dataNode.GetValue("evaPropAmt")); kerbalEVAList.Add(ked.name, ked); } } EvaFuelManager.kerbalEVAlist = kerbalEVAList; return; } catch (Exception e) { Debug.LogError("[EvaFuel] OnLoad(): " + e.ToString()); } }
private void onBoardHandler(GameEvents.FromToAction <Part, Part> data, double fuelLeft) { Log.Info("onBoardHandler, fuelLeft: " + fuelLeft.ToString()); if (data.to == null || data.from == null) { return; } Log.Info("onBoardHandler, from: " + data.from.partInfo.title + " to: " + data.to.partInfo.title); Log.Info("onBoardHandler, from: " + data.from.partInfo.name + " to: " + data.to.partInfo.name); if (fuelLeft == 0) { return; } KerbalEVA kEVA = data.from.FindModuleImplementing <KerbalEVA>(); // resourceName = kEVA.propellantResourceName; var fromResource = data.from.Resources.Where(p => p.info.name == resourceName).First(); if (fromResource == null) { Log.Info("Resource not found: " + resourceName + " in part: " + data.from.partInfo.title); return; } kerbalEVAFueldata ked; if (kerbalEVAlist.TryGetValue(data.from.partInfo.title, out ked)) { ked.evaPropAmt = fuelLeft; } else { Log.Info("Adding new kerbal on EVA (not found in kerbalEVAList: " + data.to.partInfo.title); // This is needed here in case the mod is added to an existing game while a kerbal is // already on EVA ked = new kerbalEVAFueldata(); ked.name = data.from.partInfo.title; ked.evaPropAmt = fuelLeft; kerbalEVAlist.Add(ked.name, ked); } Log.Info("Storing EVA fuel: " + ked.evaPropAmt.ToString()); //FileOperations.Instance.saveKerbalEvaData(kerbalEVAlist); #if false if (HighLogic.CurrentGame.Parameters.CustomParams <EvaFuelDifficultySettings>().fillFromPod) { double sentAmount = data.to.RequestResource(this.resourceName, -fromResource.amount); fromResource.amount += sentAmount; Log.Info(string.Format("Returned {0} {1} to {2}", -sentAmount, this.resourceName, data.to.partInfo.title)); } #endif }
/// <summary> /// Load data from a file /// </summary> /// <returns>Dictionary with the data</returns> public Dictionary <string, kerbalEVAFueldata> loadKerbalEvaData() { ConfigNode configFile = new ConfigNode(); ConfigNode configFileNode = new ConfigNode(); ConfigNode[] configDataNodes; Dictionary <string, kerbalEVAFueldata> kerbalEVAList = new Dictionary <string, kerbalEVAFueldata>(); string fname = getKerbalEvaFile(); if (fname != "" && File.Exists(fname)) { try { configFile = ConfigNode.Load(fname); configFileNode = configFile.GetNode(TT_NODENAME); if (configFileNode != null) { configDataNodes = configFileNode.GetNodes("EvaData"); foreach (var dataNode in configDataNodes) { kerbalEVAFueldata ked = new kerbalEVAFueldata(); dataNode.TryGetValue("name", ref ked.name); ked.evaPropAmt = Double.Parse(dataNode.GetValue("evaPropAmt")); kerbalEVAList.Add(ked.name, ked); } } } catch { } } return(kerbalEVAList); }
private double onEvaHandler(GameEvents.FromToAction <Part, Part> data) { Log.Info("onEvaHandler"); double fuelTaken = 0; if (data.to == null || data.from == null) { return(0); } Log.Info("onEvaHandler, from: " + data.from.partInfo.title + " to: " + data.to.partInfo.title); Log.Info("onEvaHandler, from: " + data.from.partInfo.name + " to: " + data.to.partInfo.name); Log.Info("data.from.name: " + data.from.name); Log.Info("data.to.name: " + data.to.name); char[] delimiterChars = { '(', ')' }; string[] words = data.to.name.Split(delimiterChars); string foundName = words[1]; Log.Info("Detected name: " + foundName); PartResource kerbalResource = null; // // The following is in case different kerbals have different eva propellant // KerbalEVA kEVA = data.to.FindModuleImplementing <KerbalEVA>(); var kerbalResourceList = data.to.Resources.Where(p => p.resourceName == shipPropName); if (kerbalResourceList.Count() > 0) { kerbalResource = kerbalResourceList.First(); } else { Log.Info("Kerbal Resource not found: " + shipPropName); } if (kerbalEVAlist == null) { Log.Error("kerbalEVAlist is null"); return(0); } else { kerbalEVAFueldata ked; Log.Info("Searching list for Kerbal: " + foundName); if (!kerbalEVAlist.TryGetValue(foundName, out ked)) { ked = new kerbalEVAFueldata(); ked.name = foundName; ked.evaPropAmt = 0; // kerbalResource.maxAmount; // New kerbals always get the maxAmount kerbalEVAlist.Add(ked.name, ked); Log.Info("Adding full amount to new kerbal on EVA (not found in kerbalEVAList: " + data.to.partInfo.title); } fuelTaken = ked.evaPropAmt; ked.evaPropAmt = 0; // fillFromPod controls whether the Kerbal has a fixed amount of fuel for the entire mission or not. // if false, then the kerbal is not able to fill from the pod #if false if (HighLogic.CurrentGame.Parameters.CustomParams <EvaFuelDifficultySettings>().fillFromPod) { double giveBack = kerbalResource.maxAmount - ked.evaPropAmt; double sentBackAmount = data.from.RequestResource(this.resourceName, -1 * giveBack); kerbalResource.amount = ked.evaPropAmt; Log.Info(string.Format("Returned {0} {1} to {2}", sentBackAmount, this.resourceName, data.from.partInfo.title)); } #endif //FileOperations.Instance.saveKerbalEvaData(kerbalEVAlist); } // lastPart = data.to; Log.Info( string.Format("[{0}] Caught OnCrewOnEva event to part ({1}) containing this resource ({2})", this.GetType().Name, data.to.partInfo.title, this.resourceName)); Log.Info("Kerbal had stored: " + fuelTaken.ToString()); return(fuelTaken); }