Skip to content

Commit

Permalink
Update 1.02
Browse files Browse the repository at this point in the history
  • Loading branch information
cmac994 authored and cmac994 committed Jan 12, 2021
1 parent 039ec89 commit 9091179
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 281 deletions.
Binary file modified .vs/KerbalWeatherProject/v16/.suo
Binary file not shown.
Binary file modified GameData/KerbalWeatherProject/KerbalWeatherProject.dll
Binary file not shown.
Binary file modified GameData/KerbalWeatherProject_v1.0.2.zip
Binary file not shown.
154 changes: 78 additions & 76 deletions KerbalWeatherProject/KerbalWxClimo.cs

Large diffs are not rendered by default.

150 changes: 74 additions & 76 deletions KerbalWeatherProject/KerbalWxPoint.cs

Large diffs are not rendered by default.

63 changes: 19 additions & 44 deletions KerbalWeatherProject/ModularFI_Registerer.cs
Expand Up @@ -15,15 +15,6 @@ public class ModularFI_Registerer : MonoBehaviour
//Get Kerbin cbody
CelestialBody kerbin;

//Set weather/climate boolean
public bool wx_enabled = true;

//Booleans for type of MPAS data to use
private bool use_climo;
private bool use_point;
private bool aero;
private bool thermo;

//Detect if FAR is present
bool RegisterWithFAR()
{
Expand Down Expand Up @@ -62,48 +53,29 @@ bool RegisterWithFAR()
return false;
}

internal void SetWindBool(bool wind_bool)
{
//Util.Log("Set WindBool: " + wind_bool);
wx_enabled = wind_bool;
}

void Start()
{
//Check if KWP is enabled by default
wx_enabled = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams>().WxEnabled;
//Util.Log("MFI: wx_enabled: " + wx_enabled);
//Determine MPAS data set
use_climo = Util.useCLIM();
use_point = Util.useWX();
aero = Util.allowAero();
thermo = Util.allowThermo();

//Check if FAR is available
haveFAR = RegisterWithFAR();

Util.check_settings();
//if (!haveFAR)
//{
Vessel v = FlightGlobals.ActiveVessel;

//Override KSP's FlightIntegrator using the ModularFlightIntegrator
//Util.Log("Register Modular FlightIntegrator");
if (aero)
if (Util.allow_aero)
{
//Util.Log("Register Aero");
ModularFI.ModularFlightIntegrator.RegisterUpdateAerodynamicsOverride(UpdateAerodynamicsWx);
}
if (thermo)
if (Util.allow_thermo)
{
//Util.Log("Register Thermo");
ModularFI.ModularFlightIntegrator.RegisterUpdateThermodynamicsPre(UpdateThermodynamicsPreWx);
}

if ((aero) || (thermo))
{
//Util.Log("MFI On");
Util.setMFI(true);
}
GameObject.Destroy(this);
}

Expand All @@ -112,25 +84,27 @@ void Start()
void UpdateAerodynamicsWx(ModularFI.ModularFlightIntegrator fi, Part part)
{

Vessel v = FlightGlobals.ActiveVessel;
wx_enabled = Util.getWindBool(); //Is weather enabled?
use_climo = Util.useCLIM(); //Are we using the climatology
use_point = Util.useWX(); //Are we using MPAS point time-series
if (!Util.allow_aero)
{
return;
}

Vessel v = FlightGlobals.ActiveVessel;
//Get main vessel and get reference to Kerbin (i.e. celestial body)
kerbin = Util.getbody();

//Get wind vector (initialize to zero)
Vector3d windVec = Vector3d.zero;
if (use_climo)
if (Util.use_climo)
{
//Retrieve wind vector from climatology
windVec = KerbalWxClimo.getWSWind(); // .GetWind(FlightGlobals.currentMainBody, part, rb.position);
} else if (use_point)
} else if (Util.use_point)
{
//Retrieve wind vector from point forecast
windVec = KerbalWxPoint.getWSWind(); // .GetWind(FlightGlobals.currentMainBody, part, rb.position);
}

//Check to see if root part is in list. If not do not perform aero update.
//This avoids updating aerodynamics of parts that have been decoupled and are no longer part of the active vessel.
bool hasPart = false;
Expand Down Expand Up @@ -160,9 +134,9 @@ void UpdateAerodynamicsWx(ModularFI.ModularFlightIntegrator fi, Part part)
double gamma = 1.4;
//Util.Log("MFI wx_enabled: " + wx_enabled+", use_point: "+use_point+", use_climo: "+use_climo);
bool inatmos = false;
if ((FlightGlobals.ActiveVessel.mainBody == kerbin) && (v.altitude <= 70000) && (wx_enabled))
if ((FlightGlobals.ActiveVessel.mainBody == kerbin) && (v.altitude <= 70000) && (Util.wx_enabled))
{
if (use_climo)
if (Util.use_climo)
{
//Retrieve air pressure/density at vessel location
climate_data.wx_aero ptd = climate_data.getPTD(vlat, vlng, vheight);
Expand Down Expand Up @@ -416,9 +390,10 @@ public List<Vector3> GetDragLiftForce(ModularFI.ModularFlightIntegrator fi, Part
public void UpdateThermodynamicsPreWx(ModularFI.ModularFlightIntegrator fi)
{

wx_enabled = Util.getWindBool();
use_climo = Util.useCLIM();
use_point = Util.useWX();
if (!Util.allow_thermo)
{
return;
}

//Get reference to Kerbin (i.e. celestial body)
kerbin = Util.getbody();
Expand Down Expand Up @@ -461,13 +436,13 @@ public void UpdateThermodynamicsPreWx(ModularFI.ModularFlightIntegrator fi)
return;
}
//Check if in atmosphere
if (wx_enabled)
if (Util.wx_enabled)
{
//Define gamma (ratio of cp/cv)
double gamma = 1.4;

double sqrMag = v.srf_velocity.sqrMagnitude; //Square magnitude of vessel surface velocity
if (use_climo)
if (Util.use_climo)
{
climate_data.wx_aero ptd = climate_data.getPTD(vlat, vlng, vheight); //Retrieve pressure,temperature,and density from climate API
//Adjust atmospheric constants
Expand Down
17 changes: 0 additions & 17 deletions KerbalWeatherProject/Settings.cs
Expand Up @@ -61,12 +61,6 @@ public override bool Enabled(MemberInfo member, GameParameters parameters)
}
return true;
}


public override bool Interactible(MemberInfo member, GameParameters parameters)
{
return true;
}
}

public class KerbalWxCustomParams_Sec2 : GameParameters.CustomParameterNode
Expand Down Expand Up @@ -131,12 +125,6 @@ public override bool Enabled(MemberInfo member, GameParameters parameters)

return true;
}


public override bool Interactible(MemberInfo member, GameParameters parameters)
{
return true;
}
}

public class KerbalWxCustomParams_Sec3 : GameParameters.CustomParameterNode
Expand Down Expand Up @@ -189,11 +177,6 @@ public override bool Enabled(MemberInfo member, GameParameters parameters)
return true;
}

public override bool Interactible(MemberInfo member, GameParameters parameters)
{
return true;
}

//Provide list of unit options to chose from
public override IList ValidValues(MemberInfo member)
{
Expand Down
63 changes: 40 additions & 23 deletions KerbalWeatherProject/Util.cs
Expand Up @@ -3,7 +3,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using Debug = UnityEngine.Debug;

Expand All @@ -20,9 +19,13 @@ internal static class Util
public static bool use_point = false;
public static bool allow_aero = true;
public static bool allow_thermo = true;
public static bool old_aero = false;
public static bool use_mfi = false;

public static bool disable_surface_wind;
public static bool cnst_wnd;
public static int wspd_prof;
public static int wdir_prof;

//Atmospheric Constants
public static double g = 9.80665; //Gravitational constant m/s^2
public static double md = 28.9655; //Molar mass, dry air (kg/kmol)
Expand Down Expand Up @@ -56,20 +59,35 @@ public struct aero_stats

};

public static void check_settings()
{

//Get surface wind boolean
disable_surface_wind = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams_Sec2>().disable_surface_wind;

//Retrieve wind profile booleans and parameters
cnst_wnd = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams_Sec2>().use_cnstprofile;
wspd_prof = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams_Sec2>().set_wspeed;
wdir_prof = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams_Sec2>().set_wdir;

//MFI Settings
allow_aero = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams>().allow_aero;
allow_thermo = HighLogic.CurrentGame.Parameters.CustomParams<KerbalWxCustomParams>().allow_thermo;
}

public static aero_stats aero_sdata;
//Log functions: Adapted from Dynamic Battery Storage
public static void Log(string toLog)
{
Debug.Log(String.Format("[{0}]: {1}", logTag, toLog));
Debug.Log(string.Format("[{0}]: {1}", logTag, toLog));
}
public static void Warn(string toLog)
{
Debug.LogWarning(String.Format("[{0}]: {1}", logTag, toLog));
Debug.LogWarning(string.Format("[{0}]: {1}", logTag, toLog));
}
public static void Error(string toLog)
{
Debug.LogError(String.Format("[{0}]: {1}", logTag, toLog));
Debug.LogError(string.Format("[{0}]: {1}", logTag, toLog));
}

public static string get_wind_card(double wdir, string wstr)
Expand Down Expand Up @@ -368,7 +386,7 @@ public static bool RegisterWithFAR()
}
catch (Exception e)
{
Debug.LogError("KerbalWeatherProject: unable to register with FerramAerospaceResearch. Exception thrown: " + e.ToString());
Debug.LogError("KerbalWeatherProject_Lite: unable to register with FerramAerospaceResearch. Exception thrown: " + e.ToString());
}
return false;
}
Expand All @@ -379,16 +397,6 @@ public static void setMAPSDtype(bool use_clim, bool use_pnt)
use_point = use_pnt;
}

public static void setMFI(bool mfi_on)
{
use_mfi = mfi_on;
}

public static bool getMFI()
{
return use_mfi;
}

public static bool allowAero()
{
return allow_thermo;
Expand Down Expand Up @@ -467,7 +475,7 @@ internal static int find_min(float[] arr1, double vval)
//Adpated from FAR
public static double StagnationPressureCalc(double M)
{
double gamma = Util.CurrentBody.atmosphereAdiabaticIndex;
double gamma = CurrentBody.atmosphereAdiabaticIndex;

double ratio;
ratio = M * M;
Expand Down Expand Up @@ -543,7 +551,8 @@ public static double toRadians(double angle)
}

//Get Kerbin cbody
public static CelestialBody getbody() {
public static CelestialBody getbody()
{
List<CelestialBody> cbodies = PSystemManager.Instance.localBodies;
return cbodies[1];
}
Expand Down Expand Up @@ -599,8 +608,12 @@ public static double getTime(double epoch)
public static double getTime_Wx(double epoch_time)
{
epoch_time = (epoch_time + 3600 * ((((180.0 - 74.724375) / 15.0) / 24.0) * 6)); //Adjust for Local kerbin time @ KSC.
double nrun = epoch_time / (NT * 3600);
epoch_time = epoch_time - (NT * 3600) * nrun;
int nrun = (int)(epoch_time / (NT * 3600));
epoch_time = epoch_time - (NT * 3600)*nrun;
if (epoch_time == NT*3600)
{
epoch_time = epoch_time - 1;
}
return epoch_time;
}

Expand All @@ -609,8 +622,12 @@ public static double getLocalTime_Wx()
{
double epoch_time = Planetarium.GetUniversalTime();
epoch_time = (epoch_time + 3600 * ((((180.0 - 74.724375) / 15.0) / 24.0) * 6)); //Adjust for Local kerbin time @ KSC.
double nrun = epoch_time / (NT * 3600);
epoch_time = epoch_time - (NT * 3600) * nrun;
int nrun = (int)(epoch_time / (NT * 3600));
epoch_time = epoch_time - (NT * 3600)*nrun;
if (epoch_time == NT*3600)
{
epoch_time = epoch_time - 1;
}
return epoch_time;
}

Expand Down Expand Up @@ -699,4 +716,4 @@ public static double round_down(double val, int prec)
}

}
}
}

0 comments on commit 9091179

Please sign in to comment.