Skip to content

Commit

Permalink
Decoupler workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
e-dog committed Jul 25, 2014
1 parent 21743b2 commit 2b75348
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
Binary file modified GameData/ProceduralFairings/ProceduralFairings.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Misc/makezip.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
set name=C:\games\KSPtest\ProcFairings_3.06.zip
set name=C:\games\KSPtest\ProcFairings_3.07.zip
del %name%
7z a %name% readme.txt
cd ..
Expand Down
6 changes: 6 additions & 0 deletions Misc/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Right-click parts and use tweakables.
Maximum (and minimum) part size is limited by tech. See GameData/ProceduralFairings/common.cfg for details.

--- Version history ---
3.07
-Added procedural costs for PF parts, KSP 0.24.1 is required.
-Added workaround for Win64 decoupler bug.
-Made "removed" node markers much less visible (they are still somewhere 10km from the VAB).
-Updated KAE DLL.

3.06
-Updated for KSP 0.24.

Expand Down
89 changes: 68 additions & 21 deletions Source/FairingDecoupler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class ProceduralFairingDecoupler : PartModule
[KSPField] public Vector3 forceVector=Vector3.right;
[KSPField] public Vector3 torqueVector=-Vector3.forward;

[KSPField(isPersistant=true)] bool decoupled=false;
bool didForce=false;


public override void OnStart(StartState state)
{
Expand All @@ -55,36 +58,80 @@ public override void OnStart(StartState state)
}


[KSPEvent(name = "Jettison", active=true, guiActive=true, guiActiveUnfocused=false, guiName="Jettison")]
public void Jettison()
public override void OnLoad(ConfigNode cfg)
{
if (part.parent)
{
foreach (var p in part.parent.children)
foreach (var joint in p.GetComponents<ConfigurableJoint>())
if (joint!=null && (joint.rigidbody==part.Rigidbody || joint.connectedBody==part.Rigidbody))
Destroy(joint);
base.OnLoad(cfg);
didForce=decoupled;
}

part.decouple(0);

var tr=part.FindModelTransform(transformName);
if (tr)
public void FixedUpdate()
{
if (decoupled)
{
if (part.parent)
{
part.Rigidbody.AddForce(tr.TransformDirection(forceVector)
*Mathf.Lerp(ejectionLowDv, ejectionDv, ejectionPower),
ForceMode.VelocityChange);
part.Rigidbody.AddTorque(tr.TransformDirection(torqueVector)
*Mathf.Lerp(ejectionLowTorque, ejectionTorque, torqueAmount),
ForceMode.VelocityChange);
}
else
Debug.LogError("[ProceduralFairingDecoupler] no '"+transformName+"' transform in part", part);
foreach (var p in part.parent.children)
foreach (var joint in p.GetComponents<ConfigurableJoint>())
if (joint!=null && (joint.rigidbody==part.Rigidbody || joint.connectedBody==part.Rigidbody))
Destroy(joint);

ejectFx.audio.Play();
part.decouple(0);
ejectFx.audio.Play();
}
else if (!didForce)
{
var tr=part.FindModelTransform(transformName);
if (tr)
{
part.Rigidbody.AddForce(tr.TransformDirection(forceVector)
*Mathf.Lerp(ejectionLowDv, ejectionDv, ejectionPower),
ForceMode.VelocityChange);
part.Rigidbody.AddTorque(tr.TransformDirection(torqueVector)
*Mathf.Lerp(ejectionLowTorque, ejectionTorque, torqueAmount),
ForceMode.VelocityChange);
}
else
Debug.LogError("[ProceduralFairingDecoupler] no '"+transformName+"' transform in part", part);

didForce=true;
}
}
}


[KSPEvent(name = "Jettison", active=true, guiActive=true, guiActiveUnfocused=false, guiName="Jettison")]
public void Jettison()
{
decoupled=true;

// if (part.parent)
// {
// foreach (var p in part.parent.children)
// foreach (var joint in p.GetComponents<ConfigurableJoint>())
// if (joint!=null && (joint.rigidbody==part.Rigidbody || joint.connectedBody==part.Rigidbody))
// Destroy(joint);

// part.decouple(0);

// var tr=part.FindModelTransform(transformName);
// if (tr)
// {
// part.Rigidbody.AddForce(tr.TransformDirection(forceVector)
// *Mathf.Lerp(ejectionLowDv, ejectionDv, ejectionPower),
// ForceMode.VelocityChange);
// part.Rigidbody.AddTorque(tr.TransformDirection(torqueVector)
// *Mathf.Lerp(ejectionLowTorque, ejectionTorque, torqueAmount),
// ForceMode.VelocityChange);
// }
// else
// Debug.LogError("[ProceduralFairingDecoupler] no '"+transformName+"' transform in part", part);

// ejectFx.audio.Play();
// }
}


public override void OnActive()
{
Jettison();
Expand Down

0 comments on commit 2b75348

Please sign in to comment.