public KethaneDeposit GetDepositUnder() { if (!PlanetDeposits.ContainsKey(Vessel.mainBody.name)) { return(null); } KethaneDeposits Deposits = KethaneController.PlanetDeposits[Vessel.mainBody.name]; double lon = Misc.clampDegrees(Vessel.mainBody.GetLongitude(Vessel.transform.position)); double lat = Vessel.mainBody.GetLatitude(Vessel.transform.position); double x = Math.Round((lon + 180d) * (Deposits.Width / 360d)); double y = Math.Round(((90d - lat) * (Deposits.Height / 180d))); Vector3 PointUnder = new Vector3((float)x, 0, (float)y); return(Deposits.GetDepositOver(PointUnder)); }
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; } }
private void DetectorWindowGUI(int windowID) { #region Detector GUILayout.BeginVertical(); if (Vessel.mainBody != null && KethaneController.PlanetTextures.ContainsKey(Vessel.mainBody.name)) { Texture2D planetTex = KethaneController.PlanetTextures[Vessel.mainBody.name]; GUILayout.Box(planetTex); Rect Last = UnityEngine.GUILayoutUtility.GetLastRect(); int x = Misc.GetXOnMap(Misc.clampDegrees(Vessel.mainBody.GetLongitude(Vessel.transform.position)), planetTex.width); int y = Misc.GetYOnMap(Vessel.mainBody.GetLatitude(Vessel.transform.position), planetTex.height); GUI.DrawTexture(new Rect(((Last.xMin + Last.xMax) / 2) - (planetTex.width / 2) + x - (youAreHereMarker.width / 2), ((Last.yMin + Last.yMax) / 2) + (planetTex.height / 2) - y - (youAreHereMarker.height / 2), 7, 7), youAreHereMarker); float xVar = ((Last.xMin + Last.xMax) / 2) - (planetTex.width / 2) + DetectorWindowPosition.x; float yVar = ((Last.yMin + Last.yMax) / 2) - (planetTex.height / 2) + DetectorWindowPosition.y; xVar = xVar - UnityEngine.Input.mousePosition.x; yVar = (Screen.height - yVar) - UnityEngine.Input.mousePosition.y; bool inbound = true; if (yVar > planetTex.height || yVar < 0) { inbound = false; } if (-xVar > planetTex.width || -xVar < 0) { inbound = false; } GUILayout.Label(String.Format(inbound ? "Mouse coordinates: {0:0.0}, {1:0.0}" : "Mouse coordinates: -", Misc.GetLatOnMap(yVar, planetTex.height), Misc.GetLonOnMap(xVar, planetTex.width))); } GUILayout.Label(String.Format("Last deposit: {0:0.000}, {1:0.000} ({2:F0}L)", LastLat, LastLon, LastQuantity)); ScanningSound = GUILayout.Toggle(ScanningSound, "Detection sound"); GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, 300, 60)); #endregion }
public void DrawMap(bool deposit) { if (Vessel.mainBody != null && PlanetTextures.ContainsKey(Vessel.mainBody.name)) { Texture2D planetTex = PlanetTextures[Vessel.mainBody.name]; if (this.Vessel != null) { int x = Misc.GetXOnMap(Misc.clampDegrees(Vessel.mainBody.GetLongitude(Vessel.transform.position)), planetTex.width); int y = Misc.GetYOnMap(Vessel.mainBody.GetLatitude(Vessel.transform.position), planetTex.height); if (deposit) { planetTex.SetPixel(x, y, XKCDColors.Green); } else { planetTex.SetPixel(x, y, XKCDColors.DarkGrey); } } planetTex.Apply(); } }
private void DrawDebugMap() { if (vessel.mainBody != null) { for (int y = 0; y < DebugTex.height; y++) { for (int x = 0; x < DebugTex.width; x++) { DebugTex.SetPixel(x, y, Color.black); } } KethaneDeposits Deposits = KethaneController.PlanetDeposits[this.vessel.mainBody.name]; float Width = Deposits.Width; float Height = Deposits.Height; foreach (KethaneDeposit KD in Deposits.Deposits) { for (int k = 0; k < KD.Vertices.Count - 1; k++) { Point p = (KD.Vertices[k] / Width) * DebugTex.width; Point p2 = (KD.Vertices[k + 1] / Height) * DebugTex.height; Line(DebugTex, (int)p.x, DebugTex.height - (int)p.y, (int)p2.x, DebugTex.height - (int)p2.y); } } if (this.vessel != null) { int x = Misc.GetXOnMap(Misc.clampDegrees(vessel.mainBody.GetLongitude(vessel.transform.position)), DebugTex.width); int y = Misc.GetYOnMap(vessel.mainBody.GetLatitude(vessel.transform.position), DebugTex.height); DebugTex.SetPixel(x, y, Color.white); } DebugTex.Apply(); } }