// node parsing private static void Nodeparse(ConfigNode profile_node) { // parse all rules foreach (ConfigNode rule_node in profile_node.GetNodes("Rule")) { try { // parse rule Rule rule = new Rule(rule_node); // ignore duplicates if (rules.Find(k => k.name == rule.name) == null) { // add the rule rules.Add(rule); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load rule (reason: ", e.Message, ")")); } } // parse all supplies foreach (ConfigNode supply_node in profile_node.GetNodes("Supply")) { try { // parse supply Supply supply = new Supply(supply_node); // ignore duplicates if (supplies.Find(k => k.resource == supply.resource) == null) { // add the supply supplies.Add(supply); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load supply (reason: ", e.Message, ")")); } } // parse all processes foreach (ConfigNode process_node in profile_node.GetNodes("Process")) { try { // parse process Process process = new Process(process_node); // ignore duplicates if (processes.Find(k => k.name == process.name) == null) { // add the process processes.Add(process); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load process (reason: ", e.Message, ")")); } } }
// trigger a random breakdown event public static void Breakdown(Vessel v, ProtoCrewMember c) { // constants const double res_penalty = 0.1; // proportion of food lost on 'depressed' and 'wrong_valve' // get a supply resource at random resource_info res = null; if (Profile.supplies.Count > 0) { Supply supply = Profile.supplies[Lib.RandomInt(Profile.supplies.Count)]; res = ResourceCache.Info(v, supply.resource); } // compile list of events with condition satisfied List <KerbalBreakdown> events = new List <KerbalBreakdown>(); events.Add(KerbalBreakdown.mumbling); //< do nothing, here so there is always something that can happen if (Lib.HasData(v)) { events.Add(KerbalBreakdown.fat_finger); } if (Reliability.CanMalfunction(v)) { events.Add(KerbalBreakdown.rage); } if (res != null && res.amount > double.Epsilon) { events.Add(KerbalBreakdown.wrong_valve); } // choose a breakdown event KerbalBreakdown breakdown = events[Lib.RandomInt(events.Count)]; // generate message string text = ""; string subtext = ""; switch (breakdown) { case KerbalBreakdown.mumbling: text = "$ON_VESSEL$KERBAL has been in space for too long"; subtext = "Mumbling incoherently"; break; case KerbalBreakdown.fat_finger: text = "$ON_VESSEL$KERBAL is pressing buttons at random on the control panel"; subtext = "Science data has been lost"; break; case KerbalBreakdown.rage: text = "$ON_VESSEL$KERBAL is possessed by a blind rage"; subtext = "A component has been damaged"; break; case KerbalBreakdown.wrong_valve: text = "$ON_VESSEL$KERBAL opened the wrong valve"; subtext = res.resource_name + " has been lost"; break; } // post message first so this one is shown before malfunction message Message.Post(Severity.breakdown, Lib.ExpandMsg(text, v, c), subtext); // trigger the event switch (breakdown) { case KerbalBreakdown.mumbling: break; // do nothing case KerbalBreakdown.fat_finger: Lib.RemoveData(v); break; case KerbalBreakdown.rage: Reliability.CauseMalfunction(v); break; case KerbalBreakdown.wrong_valve: res.Consume(res.amount * res_penalty); break; } // remove reputation if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { Reputation.Instance.AddReputation(-Settings.BreakdownReputation, TransactionReasons.Any); } }
public static void parse() { // initialize data rules = new List <Rule>(); supplies = new List <Supply>(); processes = new List <Process>(); // if a profile is specified if (Settings.Profile.Length > 0) { // for each profile config foreach (ConfigNode profile_node in Lib.ParseConfigs("Profile")) { // get the name string name = Lib.ConfigValue(profile_node, "name", string.Empty); // if this is the one choosen in settings if (name == Settings.Profile) { // log profile name Lib.Log(Lib.BuildString("using profile: ", Settings.Profile)); // parse all rules foreach (ConfigNode rule_node in profile_node.GetNodes("Rule")) { try { // parse rule Rule rule = new Rule(rule_node); // ignore duplicates if (rules.Find(k => k.name == rule.name) == null) { // add the rule rules.Add(rule); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load rule (reason: ", e.Message, ")")); } } // parse all supplies foreach (ConfigNode supply_node in profile_node.GetNodes("Supply")) { try { // parse supply Supply supply = new Supply(supply_node); // ignore duplicates if (supplies.Find(k => k.resource == supply.resource) == null) { // add the supply supplies.Add(supply); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load supply (reason: ", e.Message, ")")); } } // parse all processes foreach (ConfigNode process_node in profile_node.GetNodes("Process")) { try { // parse process Process process = new Process(process_node); // ignore duplicates if (processes.Find(k => k.name == process.name) == null) { // add the process processes.Add(process); } } catch (Exception e) { Lib.Log(Lib.BuildString("warning: failed to load process (reason: ", e.Message, ")")); } } // log info Lib.Log("supplies:"); foreach (Supply supply in supplies) { Lib.Log(Lib.BuildString("- ", supply.resource)); } if (supplies.Count == 0) { Lib.Log("- none"); } Lib.Log("rules:"); foreach (Rule rule in rules) { Lib.Log(Lib.BuildString("- ", rule.name)); } if (rules.Count == 0) { Lib.Log("- none"); } Lib.Log("processes:"); foreach (Process process in processes) { Lib.Log(Lib.BuildString("- ", process.name)); } if (processes.Count == 0) { Lib.Log("- none"); } // we are done here return; } } // if we reach this point, the profile was not found Lib.Log(Lib.BuildString("warning: profile '", Settings.Profile, "' was not found")); } }