Skip to content

Commit

Permalink
Fixes for PP2, PAW grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 26, 2020
1 parent 791600c commit 7bae2c8
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 131 deletions.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ This mod will do nothing unless you install **all** of the dependencies!

[Module Manager forum thread]: http://forum.kerbalspaceprogram.com/index.php?/topic/50533-130-module-manager-280-may-26th-2017-better-late-than-never/

[Procedural Parts repository]: https://github.com/Starwaster/ProceduralParts
[Procedural Parts repository]: https://github.com/KSP-RO/ProceduralParts

[Procedural Parts forum thread]: http://forum.kerbalspaceprogram.com/index.php?/topic/162105-130-procedural-parts-starwaster-branch/

Kerbal Engineer Redux is **not** required. We use our own modified version of KER's vessel simulator, embedded in the main DLL.
[Procedural Parts forum thread]: https://forum.kerbalspaceprogram.com/index.php?/topic/169250-*

## Download

Expand All @@ -41,7 +39,7 @@ Unzip to your GameData folder.

Join us at the [forum thread].

[forum thread]: http://forum.kerbalspaceprogram.com/index.php?/topic/162743-130-smarttank/
[forum thread]: https://forum.kerbalspaceprogram.com/index.php?/topic/162743-*

## Localization

Expand All @@ -68,8 +66,3 @@ Special thanks to all those who have helped to translate SmartTank to other lang
| Spanish | [Fitiales](https://github.com/Fitiales) |

- Icon from http://fontawesome.io/icon/rocket/ http://fontawesome.io/icon/arrows-v/ http://fontawesome.io/icon/arrows-h/
- Includes vessel simulator from [Kerbal Engineer Redux][Kerbal Engineer repository] ([forum thread][Kerbal Engineer forum thread])

[Kerbal Engineer repository]: https://github.com/CYBUTEK/KerbalEngineer

[Kerbal Engineer forum thread]: http://forum.kerbalspaceprogram.com/index.php?/topic/17833-130-kerbal-engineer-redux-1130-2017-05-28/
6 changes: 3 additions & 3 deletions SmartTank.version
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
},
"VERSION": {
"MAJOR": 0,
"MINOR": 4,
"MINOR": 5,
"PATCH": 0,
"BUILD": 0
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
"MINOR": 8
"MINOR": 9
},
"KSP_VERSION_MAX": {
"MAJOR": 1,
"MINOR": 8
"MINOR": 10
}
}
16 changes: 16 additions & 0 deletions assets/SmartTank.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@
name = TextureDefaulter
}
}

@PART[proceduralHeatshield]:FOR[SmartTank]:NEEDS[ProceduralParts]
{
MODULE
{
name = DiameterMatcher
}
}

@PART[proceduralBattery]:FOR[SmartTank]:NEEDS[ProceduralParts]
{
MODULE
{
name = DiameterMatcher
}
}
47 changes: 37 additions & 10 deletions src/DiameterMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ private IEnumerator after(float seconds, Callback cb)
/// Field to toggle this module's functionality
/// </summary>
[KSPField(
guiName = "smartTank_DiameterMatchingPrompt",
isPersistant = true,
guiActive = false,
guiActiveEditor = true
guiName = "smartTank_DiameterMatchingPrompt",
isPersistant = true,
guiActive = false,
guiActiveEditor = true,
groupName = SmartTank.Name,
groupDisplayName = SmartTank.Name
), UI_Toggle(
scene = UI_Scene.Editor
scene = UI_Scene.Editor
)]
public bool DiameterMatching = Settings.Instance.DiameterMatching;

Expand Down Expand Up @@ -259,9 +261,7 @@ private bool SetShape<T>() where T : ProceduralAbstractShape
ProceduralPart pp = part.Modules.GetModule<ProceduralPart>();
T shape = part.Modules.GetModule<T>();
if (pp.shapeName != shape.displayName) {
pp.shapeName = shape.displayName;
// Give the module a chance to update before we do anything else
pp.Update();
pp.SetShapeName(shape.displayName);
}
return true;
} else {
Expand All @@ -273,19 +273,29 @@ private void SetCylindricalDiameter(float diameter)
{
if (SetShape<ProceduralShapeCylinder>()) {
ProceduralShapeCylinder cyl = part.Modules.GetModule<ProceduralShapeCylinder>();
cyl.diameter = diameter;
float prevDiameter = cyl.diameter;
cyl.diameter = diameter;
Notify(() => cyl.OnShapeDimensionChanged(cyl.Fields["diameter"], prevDiameter));
} else if (SetShape<ProceduralShapePill>()) {
ProceduralShapePill pil = part.Modules.GetModule<ProceduralShapePill>();
pil.diameter = diameter;
float prevDiameter = pil.diameter;
pil.diameter = diameter;
Notify(() => pil.OnShapeDimensionChanged(pil.Fields["diameter"], prevDiameter));
}
}

private void SetConeDiameters(float topDiameter, float bottomDiameter)
{
if (SetShape<ProceduralShapeCone>()) {
ProceduralShapeCone con = part.Modules.GetModule<ProceduralShapeCone>();
float prevTopDiameter = con.topDiameter;
float prevBottomDiameter = con.bottomDiameter;
con.topDiameter = topDiameter;
con.bottomDiameter = bottomDiameter;
Notify(() => {
con.OnShapeDimensionChanged(con.Fields["topDiameter"], prevTopDiameter);
con.OnShapeDimensionChanged(con.Fields["bottomDiameter"], prevBottomDiameter);
});
} else {
SetCylindricalDiameter(Math.Max(topDiameter, bottomDiameter));
}
Expand All @@ -303,6 +313,23 @@ public void Update()
}
}

private bool needChangeNotif = false;

private void Notify(Action how)
{
var others = part.symmetryCounterparts
.Select(other => other.Modules.GetModule<DiameterMatcher>())
.ToList();
if (others.All(dm => dm.needChangeNotif)) {
how();
foreach (DiameterMatcher dm in others) {
dm.needChangeNotif = false;
}
} else {
needChangeNotif = true;
}
}

}

}
6 changes: 3 additions & 3 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HebaruSan")]
[assembly: AssemblyProduct("SmartTank")]
[assembly: AssemblyCopyright("Copyright © 2017-2019")]
[assembly: AssemblyCopyright("Copyright © 2017-2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("0.5.0.0")]
14 changes: 7 additions & 7 deletions src/SmartTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void Start()
{
if (ProceduralPartsInstalled) {
Settings.Instance.HideNonProceduralPartsChanged();
// SmartTank requires the "All Part Upgrades Applied In Sandbox" setting
HighLogic.CurrentGame.Parameters.CustomParams<GameParameters.AdvancedParams>().PartUpgradesInSandbox = true;
GameEvents.onDeltaVCalcsCompleted.Add(OnDeltaVCalcsCompleted);
}
}
Expand Down Expand Up @@ -177,13 +179,11 @@ private void OnSimUpdate(VesselDeltaV dvCalc)
totalMassChange += massChange;
}

// Distribute the mass in the same proportions as it is now
double perTankRatio = targetProcTankMass / currentProcTankMass;
if (Math.Abs(perTankRatio - 1) > 0.01) {
for (int t = 0; t < numTanks; ++t) {
drained[t].nodesError = nodesErr;
drained[t].IdealTotalMass = perTankRatio * partTotalMass(drained[t].part);
}
// Distribute the mass evenly
double massPerTank = targetProcTankMass / numTanks;
for (int t = 0; t < numTanks; ++t) {
drained[t].nodesError = nodesErr;
drained[t].IdealTotalMass = massPerTank;
}
}
}
Expand Down
Loading

0 comments on commit 7bae2c8

Please sign in to comment.