|
| 1 | +using System; |
| 2 | + |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +namespace RealScience.Conditions |
| 6 | +{ |
| 7 | + class RealScienceCondition_GeeForce : RealScienceCondition |
| 8 | + { |
| 9 | + // common properties |
| 10 | + public string conditionType = "GeeForce"; |
| 11 | + public bool restriction = false; |
| 12 | + public string exclusion = ""; |
| 13 | + public float dataRateModifier = 1f; |
| 14 | + // specific properties |
| 15 | + public float gMin = 0f; |
| 16 | + public float gMax = float.MaxValue; |
| 17 | + |
| 18 | + public override float DataRateModifier |
| 19 | + { |
| 20 | + get { return dataRateModifier; } |
| 21 | + } |
| 22 | + public override bool IsRestriction |
| 23 | + { |
| 24 | + get { return restriction; } |
| 25 | + } |
| 26 | + public override string Exclusion |
| 27 | + { |
| 28 | + get { return exclusion; } |
| 29 | + } |
| 30 | + |
| 31 | + public override bool Evaluate(Part part, float deltaTime) |
| 32 | + { |
| 33 | + return FlightGlobals.ship_geeForce >= gMin && FlightGlobals.ship_geeForce <= gMax; |
| 34 | + } |
| 35 | + public override void Load(ConfigNode node) |
| 36 | + { |
| 37 | + // Load common properties |
| 38 | + if (node.HasValue("conditionType")) |
| 39 | + conditionType = node.GetValue("conditionType"); |
| 40 | + if (node.HasValue("exclusion")) |
| 41 | + exclusion = node.GetValue("exclusion"); |
| 42 | + if (node.HasValue("restriction")) |
| 43 | + { |
| 44 | + try |
| 45 | + { |
| 46 | + restriction = bool.Parse(node.GetValue("restriction")); |
| 47 | + } |
| 48 | + catch (FormatException) |
| 49 | + { |
| 50 | + restriction = false; |
| 51 | + } |
| 52 | + } |
| 53 | + if (node.HasValue("dataRateModifier")) |
| 54 | + { |
| 55 | + try |
| 56 | + { |
| 57 | + dataRateModifier = float.Parse(node.GetValue("dataRateModifier")); |
| 58 | + } |
| 59 | + catch (FormatException) |
| 60 | + { |
| 61 | + dataRateModifier = 1f; |
| 62 | + } |
| 63 | + } |
| 64 | + // Load specific properties |
| 65 | + if (node.HasValue("gMin")) |
| 66 | + gMin = float.Parse(node.GetValue("gMin")); |
| 67 | + if (node.HasValue("gMax")) |
| 68 | + gMax = float.Parse(node.GetValue("gMax")); |
| 69 | + } |
| 70 | + public override void Save(ConfigNode node) |
| 71 | + { |
| 72 | + // Save common properties |
| 73 | + node.AddValue("conditionType", conditionType); |
| 74 | + node.AddValue("restriction", restriction); |
| 75 | + node.AddValue("exclusion", exclusion); |
| 76 | + node.AddValue("dataRateModifier", dataRateModifier); |
| 77 | + node.AddValue("gMin", gMin); |
| 78 | + node.AddValue("gMax", gMax); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments