private void DebugWindowGUI(int windowID) { var controller = KethaneController.GetInstance(this.vessel); GUILayout.BeginVertical(); DrawDebugMap(); GUILayout.Box(DebugTex); GUILayout.Label(""); if (GUILayout.Button("GEN", GUILayout.ExpandWidth(true))) { controller.GenerateKethaneDeposits(); } GUILayout.Label(""); if (GUILayout.Button("GEN HERE", GUILayout.ExpandWidth(true))) { while (controller.GetDepositUnder() == null) { controller.GenerateKethaneDeposits(); } } GUILayout.BeginHorizontal(); GUILayout.Label("Deposit: "); var DepositUnder = controller.GetDepositUnder(); GUILayout.Label(DepositUnder == null ? "-" : (DepositUnder.Depth.ToString() + " " + DepositUnder.Kethane.ToString())); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, 300, 60)); }
public override void OnFixedUpdate() { var DepositUnder = KethaneController.GetInstance(this.vessel).GetDepositUnder(); if (this.vessel != null && DepositUnder != null && this.DrillDeploymentState == KethaneExtractor.DeployState.Deployed) { if (TimeWarp.WarpMode == TimeWarp.Modes.HIGH && TimeWarp.CurrentRateIndex > 0) { CanDrill &= vessel.Landed; } else { float DrillDepth = this.DrillDepth(); CanDrill = (DrillDepth >= DepositUnder.Depth) && (DrillDepth > 0); } if (CanDrill) { var energyRequest = this.PowerConsumption * TimeWarp.fixedDeltaTime; var energy = this.part.RequestResource("ElectricCharge", energyRequest); float Amount = TimeWarp.fixedDeltaTime * ExtractionRate * (energy / energyRequest); Amount = Math.Min(Amount, DepositUnder.Kethane); DepositUnder.Kethane += this.part.RequestResource("Kethane", -Amount); } } }
public override void OnFixedUpdate() { var controller = KethaneController.GetInstance(this.vessel); double Altitude = Misc.GetTrueAltitude(vessel); if (IsDetecting && this.vessel != null && this.vessel.gameObject.activeSelf && Altitude <= this.DetectingHeight) { var energyRequest = PowerConsumption * TimeWarp.fixedDeltaTime; var energyDrawn = this.part.RequestResource("ElectricCharge", energyRequest); this.powerRatio = energyDrawn / energyRequest; TimerEcho += Time.deltaTime * (1 + Math.Log(TimeWarp.CurrentRate)) * this.powerRatio; var TimerThreshold = this.DetectingPeriod + Altitude * 0.000005d; // 0,5s delay at 100km var DepositUnder = controller.GetDepositUnder(); if (TimerEcho >= TimerThreshold) { if (DepositUnder != null && DepositUnder.Kethane >= 1.0f) { controller.DrawMap(true); controller.LastLat = vessel.latitude; controller.LastLon = Misc.clampDegrees(vessel.longitude); controller.LastQuantity = DepositUnder.Kethane; if (vessel == FlightGlobals.ActiveVessel && controller.ScanningSound) { PingDeposit.Play(); } } else { controller.DrawMap(false); if (vessel == FlightGlobals.ActiveVessel && controller.ScanningSound) { PingEmpty.Play(); } } TimerEcho = 0; } } else { this.powerRatio = 0; } }
public static KethaneController GetInstance(Vessel vessel) { foreach (var kvp in controllers.ToArray()) { var wr = kvp.Key; var v = wr.Target; if (v == null) { controllers.Remove(wr); RenderingManager.RemoveFromPostDrawQueue(3, kvp.Value.drawGui); } else if (v == vessel) { return controllers[wr]; } } var commander = new KethaneController(); controllers[new WeakReference<Vessel>(vessel)] = commander; return commander; }
public static KethaneController GetInstance(Vessel vessel) { foreach (var kvp in controllers.ToArray()) { var wr = kvp.Key; var v = wr.Target; if (v == null) { controllers.Remove(wr); RenderingManager.RemoveFromPostDrawQueue(3, kvp.Value.drawGui); } else if (v == vessel) { return(controllers[wr]); } } var commander = new KethaneController(); controllers[new WeakReference <Vessel>(vessel)] = commander; return(commander); }
public static KethaneController GetInstance(Vessel vessel) { foreach (var kvp in controllers.ToArray()) { var wr = kvp.Key; var v = wr.Target; if (v == null) { controllers.Remove(wr); } else if (v == vessel) { return controllers[wr]; } } var commander = new KethaneController(); controllers[new WeakReference<Vessel>(vessel)] = commander; return commander; }
public void HideMap() { KethaneController.GetInstance(this.vessel).ShowDetectorWindow = false; }
public void ShowMap() { KethaneController.GetInstance(this.vessel).ShowDetectorWindow = true; }
public override void OnSave(ConfigNode node) { KethaneController.GetInstance(this.vessel).SaveAndLoadState(); }
public override void OnUpdate() { Events["EnableDetection"].active = !IsDetecting; Events["DisableDetection"].active = IsDetecting; var controller = KethaneController.GetInstance(this.vessel); Events["ShowMap"].active = !controller.ShowDetectorWindow; Events["HideMap"].active = controller.ShowDetectorWindow; if (Misc.GetTrueAltitude(vessel) <= this.DetectingHeight) { if (IsDetecting) { Status = powerRatio > 0 ? "Active" : "Insufficient Power"; } else { Status = "Idle"; } } else { Status = "Out Of Range"; } CelestialBody body = this.vessel.mainBody; if (body == null) { return; } var BaseT = this.part.transform.FindChild("model"); if (!String.IsNullOrEmpty(PartTransform)) { BaseT = BaseT.FindChild(PartTransform); } BaseT = BaseT.FindChild(BaseTransform); Vector3 bodyCoords = BaseT.InverseTransformPoint(body.transform.position); Vector2 pos = Misc.CartesianToPolar(bodyCoords); var alpha = (float)Misc.NormalizeAngle(pos.x + 90); var beta = (float)Misc.NormalizeAngle(pos.y); Transform RotH = BaseT.FindChild(HeadingTransform); Transform RotV = RotH.FindChild(ElevationTransform); if (Math.Abs(RotH.localEulerAngles.y - beta) > 90) { beta += 180; alpha = 360 - alpha; } var speed = Time.deltaTime * this.powerRatio * 60; RotH.localRotation = Quaternion.RotateTowards(RotH.localRotation, Quaternion.AngleAxis(beta, new Vector3(0, 1, 0)), speed); RotV.localRotation = Quaternion.RotateTowards(RotV.localRotation, Quaternion.AngleAxis(alpha, new Vector3(1, 0, 0)), speed); if (float.IsNaN(RotH.localRotation.w)) { RotH.localRotation = Quaternion.identity; } if (float.IsNaN(RotV.localRotation.w)) { RotV.localRotation = Quaternion.identity; } }