Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jwvanderbeck committed Aug 13, 2022
2 parents 765e1e6 + 61a515e commit 9985201
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
20 changes: 20 additions & 0 deletions TestFlightAPI/TestFlightAPI/EngineModuleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ public float requestedThrust
}
}

public float commandedThrust
{
get
{
if (engineType == EngineModuleType.UNKNOWN)
return 0f;
// current thrust / maxThrust * vac_Isp / current_Isp / ispMult / flowMult
// var currentThrust = moduleEngine.finalThrust;
// var maxThrust = moduleEngine.maxThrust;
// var vac_Isp = moduleEngine.atmCurveIsp.Evaluate(0f);
// var current_Isp = moduleEngine.realIsp;
// var ispMult = moduleEngine.multIsp;
// var flowMult = moduleEngine.flowMultiplier;

return moduleEngine.finalThrust / moduleEngine.maxThrust * moduleEngine.atmCurveIsp.Evaluate(0f) /
moduleEngine.realIsp / moduleEngine.multIsp / moduleEngine.flowMultiplier;
}
}

public float finalThrust
{
get
Expand Down Expand Up @@ -300,6 +319,7 @@ public void Shutdown()
if (engineType == EngineModuleType.UNKNOWN)
return;

moduleEngine.allowShutdown = true;
moduleEngine.Shutdown();
moduleEngine.DeactivateRunningFX();
moduleEngine.DeactivatePowerFX();
Expand Down
1 change: 1 addition & 0 deletions TestFlightAPI/TestFlightAPI/TestFlightAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ bool DebugEnabled
List<string> GetTestFlightInfo();

float GetTechTransfer();
void LogCareerFailure(Vessel vessel, string failureTitle);
}
}

1 change: 1 addition & 0 deletions TestFlightAPI/TestFlightAPI/TestFlightFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public virtual void DoFailure()

}
FlightLogger.eventLog.Add(failMessage);
core.LogCareerFailure(vessel, failureTitle);
}
}

Expand Down
51 changes: 51 additions & 0 deletions TestFlightCore/TestFlightCore/TestFlight.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Profiling;
using TestFlightCore.KSPPluginFramework;
Expand Down Expand Up @@ -406,12 +408,60 @@ public class TestFlightManagerScenario : ScenarioModule
public bool SettingsEnabled { get { return settingsEnabled; } set { settingsEnabled = value; } }
public bool SettingsAlwaysMaxData { get { return settingsAlwaysMaxData; } set { settingsAlwaysMaxData = value; } }

private bool rp1Available = false;
private bool careerLogging = false;
private PropertyInfo careerLoggingInstanceProperty;
private MethodInfo careerLogFailureMethod;

internal void Log(string message)
{
TestFlightUtil.Log($"[TestFlightManagerScenario] {message}", Instance.userSettings.debugLog);
}

internal void LogCareerFailure(Vessel vessel, string part, string failureType)
{
if (!rp1Available || !careerLogging)
{
Log("Unable to log career failure. RP1 or Career Logging is unavailable");
return;
}

var instance = careerLoggingInstanceProperty.GetValue(null);
Log("Logging career failure");
careerLogFailureMethod.Invoke(instance, new object[] { vessel, part, failureType });
}

private void InitRP1Connection()
{
Assembly a = AssemblyLoader.loadedAssemblies.FirstOrDefault(la => string.Equals(la.name, "RP-0", StringComparison.OrdinalIgnoreCase))?.assembly;
if (a == null)
{
Log("RP1 Assembly not found");
rp1Available = false;
return;
}
rp1Available = true;
Type t = a.GetType("RP0.CareerLog");

careerLogFailureMethod =
t?.GetMethod("AddFailureEvent", new[] { typeof(Vessel), typeof(string), typeof(string) });
if (careerLogFailureMethod == null)
{
careerLogging = false;
return;
}
careerLoggingInstanceProperty = t.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
if (careerLoggingInstanceProperty != null)
{
careerLogging = true;
Log("RP1 Career Logging enabled");
}
else
{
careerLogging = false;
}
}

private void InitDataStore()
{
saveData.Clear();
Expand Down Expand Up @@ -498,6 +548,7 @@ public override void OnAwake()
userSettings.Save();

InitDataStore();
InitRP1Connection();
base.OnAwake();

if (RandomGenerator == null)
Expand Down
6 changes: 6 additions & 0 deletions TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,12 @@ public float GetTechTransfer()
return AttemptTechTransfer();
}

public void LogCareerFailure(Vessel vessel, string failureTitle)
{
if (!initialized) return;
TestFlightManagerScenario.Instance.LogCareerFailure(vessel, Title, failureTitle);
}

internal float AttemptTechTransfer()
{
// attempts to transfer data from a predecessor part
Expand Down
20 changes: 17 additions & 3 deletions TestFlightReliability_EngineCycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public class TestFlightReliability_EngineCycle : TestFlightReliabilityBase
/// </summary>
[KSPField]
public float ratedBurnTime = 0f;


/// <summary>
/// Multiplier to how much time is added to the engine's runTime based on set throttle position
/// </summary>
[KSPField]
public FloatCurve thrustModifier = null;

/// <summary>
/// maximum rated continuous burn time between restarts
/// </summary>
Expand Down Expand Up @@ -94,8 +100,10 @@ protected void UpdateCycle()
// engine is running

// increase both continuous and cumulative run times
currentRunTime += deltaTime; // continuous
engineOperatingTime += deltaTime; // cumulative
// add burn time based on time passed, optionally modified by the thrust
float actualThrustModifier = thrustModifier.Evaluate(engine.commandedThrust);
currentRunTime += deltaTime * actualThrustModifier; // continuous
engineOperatingTime += deltaTime * actualThrustModifier; // cumulative


// calculate total failure rate modifier
Expand Down Expand Up @@ -278,6 +286,12 @@ public override void OnAwake()
continuousCycle.Add(0f, 1f);
}

if (thrustModifier == null)
{
thrustModifier = new FloatCurve();
thrustModifier.Add(0f, 1f);
}

}

public override List<string> GetTestFlightInfo(float reliabilityAtTime)
Expand Down
2 changes: 1 addition & 1 deletion makeMeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def error(self, message):
}
}
with open("TestFlight.version", "w") as f:
f.write(json.dumps(avc))
f.write(json.dumps(avc, indent=4))

0 comments on commit 9985201

Please sign in to comment.