Skip to content

Commit 6bbc217

Browse files
committed
Add ModuleAutoCutDrogue
- Added ModuleAutoCutDrogue, Adapted with permission from Bluedog Design Bureau.
1 parent 31ba0f6 commit 6bbc217

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Localization
2+
{
3+
en-us
4+
{
5+
// ModuleAutoCutDrogue
6+
#KSPCPM_CutDrogues = Auto-Cut Drogue Chute(s)
7+
}
8+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ Compatible with **KSP 1.12.3** and up - Available on [CKAN]
2121

2222
- **ModuleCoPFollowTransform**<br/>This module adjusts the Centre of Pressure (CoP) to follow a specified transform on the same part, improving functionality for animated drag-based systems like parachutes.
2323

24+
- **ModuleAutoCutDrogue**<br/>Automatically cuts deployed drogue chutes when main parachutes deploy, allowing for more realistic landings without requiring users to set up complicated action groups.
25+
2426

2527
[CKAN]: https://forum.kerbalspaceprogram.com/topic/197082-ckan-the-comprehensive-kerbal-archive-network-v1332-laplace-ksp-2-support/

Source/KSPCommunityPartModules.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<PackageReference Include="KSPBuildTools" Version="0.0.2-alpha.5" />
3535
</ItemGroup>
3636
<ItemGroup>
37+
<Compile Include="Modules\ModuleAutoCutDrogue.cs" />
3738
<Compile Include="Modules\ModuleCoPFollowTransform.cs" />
3839
<Compile Include="Properties\AssemblyInfo.cs" />
3940
</ItemGroup>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Usecase: Automatically cutting parachute modules that are specified as drogue chutes
3+
Example: Bluedog Design Bureau Apollo command pod parachutes.
4+
Originally By: Jsolson
5+
Originally For: Bluedog Design Bureau
6+
*/
7+
using System.Linq;
8+
using UnityEngine;
9+
10+
namespace KSPCommunityPartModules.Modules
11+
{
12+
class ModuleAutoCutDrogue : PartModule
13+
{
14+
[KSPField]
15+
public bool isDrogueChute = false;
16+
17+
[UI_Toggle(scene = UI_Scene.All, disabledText = "No", enabledText = "Yes")]
18+
[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "#KSPCPM_CutDrogues")]
19+
public bool autoCutDrogue = true;
20+
21+
[KSPField(isPersistant = true)]
22+
public bool triggered = false;
23+
24+
private ModuleParachute chute = null;
25+
private bool IsChuteDeployed(ModuleParachute pParachute) => pParachute.deploymentState == ModuleParachute.deploymentStates.DEPLOYED
26+
|| pParachute.deploymentState == ModuleParachute.deploymentStates.SEMIDEPLOYED;
27+
public override void OnStart(StartState state)
28+
{
29+
chute = part.FindModulesImplementing<ModuleParachute>().FirstOrDefault();
30+
if (chute == null)
31+
Debug.LogError($"[{nameof(ModuleAutoCutDrogue)}] ModuleParachute not found on part {part.partInfo.title}");
32+
33+
Fields[nameof(autoCutDrogue)].guiActive = !isDrogueChute;
34+
Fields[nameof(autoCutDrogue)].guiActiveEditor = !isDrogueChute;
35+
}
36+
37+
public void FixedUpdate()
38+
{
39+
if (isDrogueChute || chute == null)
40+
{
41+
this.isEnabled = false;
42+
this.enabled = false;
43+
return;
44+
}
45+
46+
if (IsChuteDeployed(chute))
47+
{
48+
if (!triggered)
49+
{
50+
var drogues = vessel.FindPartModulesImplementing<ModuleAutoCutDrogue>().Where(d => d.isDrogueChute && d.chute != null);
51+
foreach (ModuleAutoCutDrogue d in drogues)
52+
{
53+
if (IsChuteDeployed(d.chute)) d.chute.CutParachute();
54+
}
55+
triggered = true;
56+
}
57+
}
58+
else if (chute.deploymentState == ModuleParachute.deploymentStates.STOWED)
59+
{
60+
triggered = false;
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)