internal static void InitTropopauseAlts(PlanetData PD) { //kerbin's default mean troposphere height is 8815.22 CelestialBody body = PD.body; if (body == null) { Logger("[PB]: Celestial Body supplied is null"); return; } foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { double latitude = WeatherFunctions.GetCellLatitude(cell); if (!PD.TropAlts.ContainsKey((float)latitude)) { double bodyRad = body.Radius; //changes: added brackets around bodyRad nad meanTropoHeight double tropHeight = Math.Sqrt(((bodyRad + PD.meanTropoHeight * 0.63) * Math.Sin(latitude * Mathf.Deg2Rad)) * ((bodyRad + PD.meanTropoHeight * 0.63) * Math.Sin(latitude * Mathf.Deg2Rad)) + ((bodyRad + PD.meanTropoHeight * 1.2) * Math.Cos(latitude * Mathf.Deg2Rad)) * ((bodyRad + PD.meanTropoHeight * 1.2) * Math.Cos(latitude * Mathf.Deg2Rad))) - bodyRad; PD.TropAlts.Add((float)latitude, (float)tropHeight); } } Logger("[PB]: Planet Tropopause Altitudes initialized for " + PD.body.name + "!"); }
public void mainWindow(int windowid) { GUILayout.BeginVertical(); if (GUILayout.Button("Overlay")) { showOverlayWindow = !showOverlayWindow; } GUILayout.Space(1); GUILayout.Space(1); if (MapOverlay.getHoverCell().HasValue) { Cell cell = MapOverlay.getHoverCell().Value; GUILayout.Label("Temperature: " + WeatherFunctions.GetCellTemperature(PD.index, currentLayer, cell) + " °K"); GUILayout.Label("Pressure: " + WeatherFunctions.GetCellPressure(PD.index, currentLayer, cell) + " Pa"); GUILayout.Label("Rel Humidity: " + WeatherFunctions.GetCellRH(PD.index, currentLayer, cell) * 100 + " %"); GUILayout.Label("Air Density: " + String.Format("{0:0.000000}", WeatherFunctions.D_Wet(PD.index, cell, WeatherFunctions.GetCellAltitude(PD.index, currentLayer, cell))) + " Kg/m³"); GUILayout.Label("wind horz: " + String.Format("{0:0.0000}", WeatherFunctions.GetCellwindH(PD.index, currentLayer, cell)) + " m/s"); GUILayout.Label("wind Dir : " + String.Format("{0:000.0}", WeatherFunctions.GetCellwindDir(PD.index, currentLayer, cell)) + " °"); GUILayout.Label("wind vert : " + String.Format("{0:+0.00000;-0.00000}", WeatherFunctions.GetCellwindV(PD.index, currentLayer, cell)) + " m/s"); GUILayout.Label("CCN : " + WeatherFunctions.GetCellCCN(PD.index, currentLayer, cell) * 100 + " %"); GUILayout.Label("Cloud water : " + WeatherFunctions.GetCellWaterContent(PD.index, currentLayer, cell) + " Kg/m³"); int Iced = Math.Sign(WeatherFunctions.GetCelldropletSize(PD.index, currentLayer, cell)); GUILayout.Label("droplet Size: " + Math.Abs(WeatherFunctions.GetCelldropletSize(PD.index, currentLayer, cell) * 1000.0f) + " mm"); GUILayout.Label("cloud thickness: " + WeatherFunctions.GetCellthickness(PD.index, currentLayer, cell) + " m " + (Iced < 0 ? "Iced" : Iced > 0 ? "Liqd" : "None")); GUILayout.Label("rain duration: " + WeatherFunctions.GetCellrainDuration(PD.index, currentLayer, cell) + " cycles"); GUILayout.Label("rain decay: " + WeatherFunctions.GetCellrainDecay(PD.index, currentLayer, cell) / 256.0f); } GUILayout.EndVertical(); GUI.DragWindow(); }
internal static void InitBiomeMap(PlanetData PD) { foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { PD.biomes[cell] = ScienceUtil.GetExperimentBiome(PD.body, WeatherFunctions.GetCellLatitude(cell), WeatherFunctions.GetCellLongitude(cell)); } }
public void mouseWindow(int windowID) { Cell cell = hoverCell.Value; float lat = WeatherFunctions.GetCellLatitude(cell); float lon = WeatherFunctions.GetCellLongitude(cell); GUILayout.BeginVertical(); GUILayout.Label(String.Format("Cell: {0:D5} cycle: {1:D}", cell.Index, CellUpdater.run)); GUILayout.Label("Lat: " + lat + " °"); GUILayout.Label("Lon: " + lon + " °"); GUILayout.Label(String.Format("Geodesic: {0:G}", Math.Sqrt(cell.Position.x * cell.Position.x + cell.Position.y * cell.Position.y + cell.Position.z * cell.Position.z))); GUILayout.Label(String.Format("ΔT(KSP-KWS): {0:+0.000;-0.000}°", (WeatherSimulator.GetInitTemperature(PD, currentLayer, cell) - WeatherFunctions.GetCellTemperature(PD.index, currentLayer, cell)))); double DDD = 0.0; double DDD2 = 0.0; int n = 0; foreach (Cell neighbor in cell.GetNeighbors(PD.gridLevel)) { double DeltaDistance = WeatherFunctions.GetDistanceBetweenCells(PD.index, cell, neighbor, WeatherFunctions.GetCellAltitude(PD.index, currentLayer, cell)); DDD += DeltaDistance; DDD2 += DeltaDistance * DeltaDistance; n++; } DDD /= n; DDD2 /= n; GUILayout.Label(String.Format("ΔDistanceδ: {0:0.000000}", Math.Sqrt(Math.Abs(DDD2 - DDD * DDD)) / DDD)); GUILayout.Label(String.Format("flowPChange: {0:+00.000;-00.000}", PD.LiveMap[currentLayer][cell].flowPChange)); GUILayout.EndVertical(); }
public static Vector3 getCoriolisAcc(CelestialBody body, Cell cell) { //ac = -2(angularVelocity) x velocity Vector3 acc = -2 * Vector3.Cross(Vector3.Cross(body.angularVelocity, new Vector3(0, Mathf.Cos(WeatherFunctions.getLatitude(cell)), Mathf.Sin(WeatherFunctions.getLatitude(cell)))), KSPHeadMaster.PlanetMap[body].LiveMap[0][cell].WindDirection); return(acc); }
private static List <KWSCellMap <WeatherCell> > InitCalcs(PlanetData PD) { List <KWSCellMap <WeatherCell> > tempMap = new List <KWSCellMap <WeatherCell> >(); for (int i = 0; i < PD.layers; i++) { tempMap.Add(new KWSCellMap <WeatherCell>(PD.gridLevel)); } float basePressure = (float)FlightGlobals.getStaticPressure(0, PD.body) * 1000; for (int AltLayer = 0; AltLayer < PD.layers; AltLayer++) { foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { WeatherCell wCell = new WeatherCell(); wCell.temperature = GetInitTemperature(PD, AltLayer, cell); wCell.TempChange = 0; if (AltLayer == 0) { wCell.CCN = 1; wCell.pressure = basePressure; wCell.relativeHumidity = PD.biomeDatas[WeatherFunctions.GetBiome(PD.index, cell)].FLC * 0.85f; //* wCell.temperature / 288.15f } else { wCell.CCN = 0; wCell.pressure = (float)(tempMap[AltLayer - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, AltLayer * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * tempMap[AltLayer - 1][cell].temperature))); wCell.relativeHumidity = (PD.biomeDatas[WeatherFunctions.GetBiome(PD.index, cell)].FLC * wCell.temperature / 288.15f) * 0.4f; } wCell.windVector = new Vector3(0f, 0f, 0f); wCell.flowPChange = 0; tempMap[AltLayer][cell] = wCell; } } return(tempMap); }
internal static float GetInitTemperature(PlanetData PD, int AltLayer, Cell cell) { float Altitude = WeatherFunctions.GetCellAltitude(PD.index, AltLayer, cell); //get the proper f*****g temperature because the obvious answer f***s you over for 3 weeks float sunAxialDot = (float)(WeatherFunctions.GetSunriseFactor(PD.index, cell)); float latitude = Mathf.Abs(WeatherFunctions.GetCellLatitude(cell)); float diurnalRange = PD.body.latitudeTemperatureSunMultCurve.Evaluate(latitude); float latTempMod = PD.body.latitudeTemperatureBiasCurve.Evaluate(latitude); float axialTempMod = PD.body.axialTemperatureSunMultCurve.Evaluate(sunAxialDot); float atmoTempOffset = latTempMod + diurnalRange * sunAxialDot + axialTempMod; float altTempMult = PD.body.atmosphereTemperatureSunMultCurve.Evaluate(Altitude); float finalTempMod = atmoTempOffset * altTempMult; return((float)FlightGlobals.getExternalTemperature(Altitude, PD.body) + finalTempMod); }
private static List <KWSCellMap <WeatherCell> > InitStratoCalcs(PlanetData PD) { List <KWSCellMap <WeatherCell> > tempMap = new List <KWSCellMap <WeatherCell> >(); for (int i = 0; i < PD.stratoLayers; i++) { tempMap.Add(new KWSCellMap <WeatherCell>(PD.gridLevel)); } for (int layer = 0; layer < PD.stratoLayers; layer++) { foreach (Cell cell in Cell.AtLevel(PD.gridLevel)) { WeatherCell wCell = new WeatherCell(); wCell.CCN = 0; wCell.temperature = GetInitTemperature(PD, layer + layers, cell); wCell.TempChange = 0; if (layer == 0) { wCell.pressure = (float)(PD.LiveMap[layers - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, (layers + layer) * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * PD.LiveMap[layers - 1][cell].temperature))); } else { wCell.pressure = (float)(tempMap[layer - 1][cell].pressure * Math.Exp(-WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell) / (CellUpdater.UGC * PD.SH_correction / PD.atmoData.M / CellUpdater.G(PD.index, (layers + layer) * WeatherFunctions.GetDeltaLayerAltitude(PD.index, cell)) * tempMap[layer - 1][cell].temperature))); } wCell.relativeHumidity = 0; wCell.windVector = new Vector3(0f, 0f, 0f); tempMap[layer][cell] = wCell; } } return(tempMap); }
public void mouseWindow(int windowID) { Cell cell = hoverCell.Value; float lat = WeatherFunctions.GetCellLatitude(cell); float lon = WeatherFunctions.GetCellLongitude(cell); GUILayout.BeginVertical(); GUILayout.Label(String.Format("Cell: {0:D5} cycle: {1:D}", cell.Index, CellUpdater.run)); GUILayout.Label("Lat: " + lat + " °"); GUILayout.Label("Lon: " + lon + " °"); GUILayout.Label(String.Format("Geodesic: {0:G}", Math.Sqrt(cell.Position.x * cell.Position.x + cell.Position.y * cell.Position.y + cell.Position.z * cell.Position.z))); GUILayout.Label(String.Format("ΔT(KSP-KWS): {0:+0.000;-0.000}°", (WeatherSimulator.GetInitTemperature(PD, currentLayer, cell) - WeatherFunctions.GetCellTemperature(PD.index, currentLayer, cell)))); GUILayout.Label(String.Format("δ Temp: {0:+0.000000;-0.000000}°/s", currentLayer < PD.LiveMap.Count ? PD.LiveMap[currentLayer][cell].TempChange : PD.LiveStratoMap[currentLayer - PD.LiveMap.Count][cell].TempChange)); double DDD = 0.0; double DDD2 = 0.0; int n = 0; foreach (Cell neighbor in cell.GetNeighbors(PD.gridLevel)) { double DeltaDistance = WeatherFunctions.GetDistanceBetweenCells(PD.index, cell.Position, neighbor.Position, WeatherFunctions.GetCellAltitude(PD.index, currentLayer, cell)); DDD += DeltaDistance; DDD2 += DeltaDistance * DeltaDistance; n++; } DDD /= n; DDD2 /= n; GUILayout.Label(String.Format("ΔDistanceδ: {0:0.000000}", Math.Sqrt(Math.Abs(DDD2 - DDD * DDD)) / DDD)); GUILayout.Label(String.Format("CentroidΔ: {0:0.000000}", (cell.Position - PD.LiveSoilMap[cell].centroid).magnitude)); GUILayout.Label(String.Format("flowPChange: {0:+00.000;-00.000}", currentLayer < PD.LiveMap.Count ? PD.LiveMap[currentLayer][cell].flowPChange : PD.LiveStratoMap[currentLayer - PD.LiveMap.Count][cell].flowPChange)); GUILayout.Label(String.Format("Pressure Δ: {0:+000.00;-000.00}", currentLayer < PD.LiveMap.Count ? ((PD.LiveMap[0][cell].pressure - FlightGlobals.getStaticPressure(0, PD.body) * 1000) * PD.LiveMap[currentLayer][cell].pressure / PD.LiveMap[0][cell].pressure + PD.LiveMap[currentLayer][cell].flowPChange) : ((PD.LiveMap[0][cell].pressure - FlightGlobals.getStaticPressure(0, PD.body) * 1000) * PD.LiveStratoMap[currentLayer - PD.LiveMap.Count][cell].pressure / PD.LiveMap[0][cell].pressure + PD.LiveStratoMap[currentLayer - PD.LiveMap.Count][cell].flowPChange))); GUILayout.EndVertical(); }
void WeatherDataUI(int windowID) { CelestialBody body = FlightGlobals.currentMainBody; PlanetSimulator pSim = KWSKSPButtToucher.KSPHeadMaster.PlanetMap[body]; Cell cell = KSPWeatherFunctions.getCellAtLocation(body, FlightGlobals.ActiveVessel.GetWorldPos3D()); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Body Up")) { if (i < KWSKSPButtToucher.KSPHeadMaster.PlanetMap.Keys.Count - 1) { i++; } } ; if (GUILayout.Button("Body Down")) { if (i > 0) { i--; } } ; GUILayout.EndHorizontal(); CelestialBody testBody = KWSKSPButtToucher.KSPHeadMaster.PlanetMap.ElementAt(i).Key; GUILayout.BeginHorizontal(); if (GUILayout.Button("Layer Up")) { if (AltLayer < KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap.Count - 1) { AltLayer++; } } if (GUILayout.Button("Layer Down")) { if (AltLayer > 0) { AltLayer--; } } GUILayout.EndHorizontal(); //Debug.Log("1"); //GUILayout.Label("CellID: " + CellIDLabel); CellIDLabel = GUILayout.TextField(CellIDLabel, 10); CellIDInt = int.Parse(CellIDLabel); GUILayout.Label("Body: " + testBody.name); GUILayout.Label("Layer: " + AltLayer); GUILayout.Label("Current location: " + FlightGlobals.ActiveVessel.GetWorldPos3D().ToString()); //GUILayout.Label("Temperature: " + WeatherFunctions.getCellTemperature(FlightGlobals.currentMainBody, WeatherFunctions.getCellAtLocation(FlightGlobals.currentMainBody, FlightGlobals.ActiveVessel.GetWorldPos3D()))); GUILayout.Label("Temperature: " + ((KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Temperature - 273.15)).ToString("0.0000")); GUILayout.Label("Pressure: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Pressure.ToString("0.000000000")); GUILayout.Label("Density: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Density); //Debug.Log("2"); GUILayout.Label("Cell Latitude: " + WeatherFunctions.getLatitude(cell)); GUILayout.Label("Cell Longitude: " + WeatherFunctions.getLongitude(cell)); GUILayout.Label("Cell Altitude: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Altitude); GUILayout.Label("isOcean?: " + KSPWeatherFunctions.isOcean(testBody, cell)); GUILayout.Label("Albedo: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Albedo); GUILayout.Label("Daytime?: " + Heating.isSunlight(KSPHeadMaster.PlanetMap[testBody], AltLayer, cell) + " " + Heating.getSunlightAngle(KSPHeadMaster.PlanetMap[testBody], AltLayer, cell)); GUILayout.Label("Shortwave Abs: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].SWAbsorbed); GUILayout.Label("Shortwave Out: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].SWTransmitted); GUILayout.Label("Longwave In: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].LWIn); //Debug.Log("3"); //GUILayout.Label("Cell Pos: " + Cell.KWSBODY[FlightGlobals.currentMainBody][CellIDInt].CellPosition); GUILayout.EndVertical(); GUI.DragWindow(); }
private static Color32 getCellColor(int layer, Cell cell) { double?deposit = 0; double deposit2 = 0; switch (resource.Resource) { case "Temperature": deposit = PD.LiveMap[layer][cell].temperature; break; case "Delta Temp": deposit = (WeatherSimulator.GetInitTemperature(PD, currentLayer, cell) - WeatherFunctions.GetCellTemperature(PD.index, currentLayer, cell)); break; case "Temp. Change": deposit = PD.LiveMap[layer][cell].TempChange; break; case "Pressure": deposit = PD.LiveMap[layer][cell].pressure; break; case "Pressure Delta": deposit = ((PD.LiveMap[0][cell].pressure - FlightGlobals.getStaticPressure(0, PD.body) * 1000) * PD.LiveMap[layer][cell].pressure / PD.LiveMap[0][cell].pressure + PD.LiveMap[layer][cell].flowPChange); break; case "Wind H Speed": deposit = WeatherFunctions.GetCellwindH(PD.index, layer, cell); break; case "Wind H Vector": //deposit = WeatherFunctions.GetCellwindDir(PD.index, layer, cell); deposit = PD.LiveMap[layer][cell].windVector.x; deposit2 = PD.LiveMap[layer][cell].windVector.z; break; case "Wind Vertical": deposit = PD.LiveMap[layer][cell].windVector.y; break; case "Rel. Humidity": deposit = PD.LiveMap[layer][cell].relativeHumidity; break; case "Cloud water": deposit = PD.LiveMap[layer][cell].cloud.getwaterContent(); deposit2 = WeatherFunctions.GetSunriseFactor(PD.index, cell); break; case "Geodesy": // deposit = Math.Sqrt(cell.Position.x * cell.Position.x + cell.Position.y * cell.Position.y + cell.Position.z * cell.Position.z); deposit = (cell.Position - PD.LiveSoilMap[cell].centroid).magnitude; break; case "DeltaDistanceDiff": double DDD = 0.0; double DDD2 = 0.0; int n = 0; foreach (Cell neighbor in cell.GetNeighbors(PD.gridLevel)) { double DeltaDistance = WeatherFunctions.GetDistanceBetweenCells(PD.index, cell.Position, neighbor.Position, WeatherFunctions.GetCellAltitude(PD.index, layer, cell)); DDD += DeltaDistance; DDD2 += DeltaDistance * DeltaDistance; n++; } DDD /= n; DDD2 /= n; deposit = Math.Sqrt(Math.Abs(DDD2 - DDD * DDD)) / DDD; break; } var scanned = true; var color = (revealAll ? deposit != null : scanned) ? getDepositColor(resource, deposit, deposit2) : colorUnknown; return(color); }
private static Color32 getStratoCellColor(int layer, Cell cell) { double?deposit = 0; double deposit2 = 0; switch (resource.Resource) { case "Temperature": deposit = PD.LiveStratoMap[layer][cell].temperature; break; case "Delta Temp": deposit = (WeatherSimulator.GetInitTemperature(PD, currentLayer, cell) - WeatherFunctions.GetCellTemperature(PD.index, currentLayer, cell)); break; case "Temp. Change": deposit = PD.LiveStratoMap[layer][cell].TempChange; break; case "Pressure": deposit = PD.LiveStratoMap[layer][cell].pressure; break; case "Pressure Delta": deposit = ((PD.LiveMap[0][cell].pressure - FlightGlobals.getStaticPressure(0, PD.body) * 1000) * PD.LiveStratoMap[layer][cell].pressure / PD.LiveMap[0][cell].pressure + PD.LiveStratoMap[layer][cell].flowPChange); break; } var scanned = true; var color = (revealAll ? deposit != null : scanned) ? getDepositColor(resource, deposit, deposit2) : colorUnknown; return(color); }