Skip to content

Commit

Permalink
* fix up modular fuel tank surface-attach interaction
Browse files Browse the repository at this point in the history
* update modular fuel tank to offset surface-attached children when diameter is updated
* fix up modular fuel tank real-fuels interaction
* add more fully-fleshed out real-fuels stock patch
  • Loading branch information
shadowmage45 committed Dec 5, 2015
1 parent 915e2ac commit b9df463
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
27 changes: 26 additions & 1 deletion GameData/SSTU/Patches/RF.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
{
name = ModuleFuelTanks
volume = 2000
utilizationTweakable = true
type = Default
typeAvailable = Default
typeAvailable = Cryogenic
typeAvailable = ServiceModule
typeAvailable = Fuselage
typeAvailable = Balloon
typeAvailable = BalloonCryo
typeAvailable = Structural

}
}
@PART[SSTU_ShipCore_MUS-CB]:FOR[SSTU]:NEEDS[RealFuels]
Expand All @@ -21,19 +30,35 @@
{
name = ModuleFuelTanks
volume = 2000
utilizationTweakable = true
type = Default
typeAvailable = Default
typeAvailable = Cryogenic
typeAvailable = ServiceModule
typeAvailable = Fuselage
typeAvailable = Balloon
typeAvailable = BalloonCryo
typeAvailable = Structural
}
}
@PART[SSTU_ShipCore_MFT-A]:FOR[SSTU]:NEEDS[RealFuels]
{
@MODULE[SSTUCustomUpperStage]
@MODULE[SSTUModularFuelTank]
{
%useRF = true
}
MODULE
{
name = ModuleFuelTanks
volume = 2000
utilizationTweakable = true
type = Default
typeAvailable = Default
typeAvailable = Cryogenic
typeAvailable = ServiceModule
typeAvailable = Fuselage
typeAvailable = Balloon
typeAvailable = BalloonCryo
typeAvailable = Structural
}
}
Binary file modified GameData/SSTU/Plugins/SSTUTools.dll
Binary file not shown.
10 changes: 5 additions & 5 deletions Source/Module/SSTUModularFuelTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public override void OnStart(StartState state)
{
Events["nextFuelEvent"].active = false;
Fields["guiTankCost"].guiActiveEditor = false;
Fields["guiTankDryMass"].guiActiveEditor = false;
Fields["guiDryMass"].guiActiveEditor = false;
Fields["guiTankVolume"].guiActiveEditor = false;
}
if (textureSets.Length <= 1)
Expand Down Expand Up @@ -663,9 +663,9 @@ private void setTankDiameterFromEditor(float newDiameter, bool updateSymmetry)
restoreEditorFields();

updateEditorStats(true);
//SSTUUtils.updateSurfaceAttachedChildren(part, oldDiameter, newDiameter);

SSTUUtils.updateSurfaceAttachedChildren(part, oldDiameter, newDiameter);

if (updateSymmetry)
{
foreach (Part p in part.symmetryCounterparts)
Expand Down Expand Up @@ -767,7 +767,7 @@ private void updateAttachNodes(bool userInput)
{
currentNoseModule.updateAttachNodes(part, topNodeNames, userInput);
currentMountModule.updateAttachNodes(part, bottomNodeNames, userInput);
AttachNode surface = part.findAttachNode("srf");
AttachNode surface = part.srfAttachNode;
if (surface != null)
{
Vector3 pos = new Vector3(currentTankDiameter * 0.5f, 0, 0);
Expand Down
23 changes: 17 additions & 6 deletions Source/Util/SSTUUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,27 @@ public static void destroyAttachNode(Part part, AttachNode node)
public static void updateSurfaceAttachedChildren(Part part, float oldDiameter, float newDiameter)
{
float delta = newDiameter - oldDiameter;
float percentage = newDiameter / oldDiameter;

//TODO change this to use the parts current position to determine angle, create a new vector using the previous position + delta
//this current implementation will magnify any user-set offset by the percentage scale factor.
delta *= 0.5f;
Vector3 parentPosWorldSpace = part.transform.position;
Vector3 parentPosChildSpace;
Vector3 diff;
float originalLen;
float newLen;
float newX, newY, newZ;
foreach (Part child in part.children)
{
if (child.srfAttachNode!=null && child.srfAttachNode.attachedPart == part)//has surface attach node, and surface attach node is attached to the input part
{
child.transform.localPosition *= percentage;
child.attPos0 *= percentage;
parentPosChildSpace = child.transform.InverseTransformPoint(parentPosWorldSpace);
diff = child.transform.localPosition - parentPosChildSpace;
originalLen = new Vector2(parentPosChildSpace.x, parentPosChildSpace.z).magnitude;
newLen = originalLen + delta;
float dp = newLen / originalLen;
newX = child.transform.localPosition.x * dp;
newY = child.transform.localPosition.y;
newZ = child.transform.localPosition.z * dp;
child.transform.localPosition = new Vector3(newX, newY, newZ);
child.attPos0 = new Vector3(newX, newY, newZ);
}
}
}
Expand Down

0 comments on commit b9df463

Please sign in to comment.