Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/KSPCommunityPartModules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="HarmonyPatches\ModuleParachutePatch.cs" />
<Compile Include="HarmonyPatches\NameTagMigrationPatch.cs" />
<Compile Include="Modules\ModuleDecoupleAfterBurn.cs" />
<Compile Include="Modules\ModuleNameTag.cs" />
<Compile Include="Modules\NameTagWindow.cs" />
<Compile Include="Modules\ModuleAutoCutDrogue.cs" />
Expand Down
94 changes: 94 additions & 0 deletions Source/Modules/ModuleDecoupleAfterBurn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Usecase: Making a part wait for it's engine to burn out before decoupling
Example: BDB spin motors and DAXA's Epsilon spin table
Originally By: jsolson
Originally For: BluedogDesignBureau
*/
using UnityEngine;
using System.Linq;
using System.Collections.Generic;

namespace KSPCommunityPartModules
{
class ModuleDecoupleAfterBurn : ModuleDecouple
{
[KSPField(guiActive = true, isPersistant = true, guiActiveEditor = true, guiName = "Auto Jettison"), UI_Toggle()]
public bool autoDecouple = true;

private ModuleEngines engine;
private bool wasRunning = false;

public override void OnStart(StartState state)
{
base.OnStart(state);
engine = part.FindModulesImplementing<ModuleEngines>().FirstOrDefault();
}

public override void OnActive()
{
//base.OnActive();
staged = true;
}

public override void OnUpdate()
{
if (isDecoupled)
return;
if (engine == null)
return;
if (autoDecouple)
{
if (!wasRunning)
{
wasRunning = engine.GetCurrentThrust() > 0;
}
else
{
if (engine.GetCurrentThrust() <= 0)
Decouple();
}
}
}
}

class ModuleAnchoredDecoupleAfterBurn : ModuleAnchoredDecoupler
{
[KSPField(guiActive = true, isPersistant = true, guiActiveEditor = true, guiName = "Auto Jettison"), UI_Toggle()]
public bool autoDecouple = true;

private ModuleEngines engine;
private bool wasRunning = false;

public override void OnStart(StartState state)
{
base.OnStart(state);
engine = part.FindModulesImplementing<ModuleEngines>().FirstOrDefault();
}

public override void OnActive()
{
//base.OnActive();
staged = true;
}

public override void OnUpdate()
{
if (isDecoupled)
return;
if (engine == null)
return;
if (autoDecouple)
{
if (!wasRunning)
{
wasRunning = engine.GetCurrentThrust() > 0;
}
else
{
if (engine.GetCurrentThrust() <= 0)
Decouple();
}
}
}
}
}