New KerbalMassTracker Module that makes parts weigh more when Kerbals are inside.
New KerbalMassTracker Module that makes parts weigh more when Kerbals are inside.

--- /dev/null
+++ b/MM/MassTrackers.cfg
@@ -1,1 +1,16 @@
+
+@PART[*]:HAS[#CrewCapacity[*]&!#CrewCapacity[0]]:NEEDS[!RealismOverhaul]:FOR[NidaSampi]
+{
+	MODULE
+	{
+		name = ModuleKerbalMassTracker
+	}
+}
 
+@PART[*]:HAS[#CrewCapacity[*]&!#CrewCapacity[0]]:NEEDS[RealismOverhaul]:AFTER[RealismOverhaul]
+{
+	MODULE
+	{
+		name = ModuleKerbalMassTracker
+	}
+}

--- /dev/null
+++ b/ModuleKerbalMassTracker.cs
@@ -1,1 +1,165 @@
+// NSScientific
+// by toadicus, dudecon
+//
+// KerbalMassTracker.cs
+//
+// This work is released into the Public Domain.
+//
 
+using KSP;
+using System;
+using System.Collections.Generic;
+using ToadicusTools;
+using UnityEngine;
+
+namespace NSScientific
+{
+	public class ModuleKerbalMassTracker : PartModule
+	{
+		private const string KERBAL_RESOURCE_NAME = "KerbalMass";
+
+		private PartResourceDefinition kerbalMassInfo;
+
+		private PartResource partKerbalMass;
+
+		private bool firstRun;
+
+		public override void OnAwake()
+		{
+			Tools.PostDebugMessage(this, "Waking up...");
+
+			this.firstRun = true;
+
+			base.OnAwake();
+
+			if (PartResourceLibrary.Instance != null)
+			{
+				this.kerbalMassInfo = PartResourceLibrary.Instance.GetDefinition(KERBAL_RESOURCE_NAME);
+			}
+
+			Tools.PostDebugMessage(
+				this,
+				"Fetched resource definition for {0}: {1}",
+				KERBAL_RESOURCE_NAME,
+				this.kerbalMassInfo == null ? "null" : this.kerbalMassInfo.ToString());
+
+			if (base.part.CrewCapacity == 0)
+			{
+				Tools.PostDebugMessage(
+					this,
+					"Aborting, part has 0 CrewCapacity.  Checking if {0} in Resources",
+					KERBAL_RESOURCE_NAME);
+
+				return;
+			}
+
+			bool hasResource = (base.part.Resources != null && base.part.Resources.Contains(KERBAL_RESOURCE_NAME));
+
+			Tools.PostDebugMessage(this, "hasResource: {0}", hasResource);
+
+			if (!hasResource)
+			{
+				Tools.PostDebugMessage(this, "resource not found, checking components manually just to be sure.");
+
+				foreach (PartResource resourceComponent in base.part.GetComponents<PartResource>())
+				{
+					Tools.PostDebugMessage(this, "Checking {0}", resourceComponent.resourceName);
+
+					if (resourceComponent.resourceName == KERBAL_RESOURCE_NAME)
+					{
+						hasResource = true;
+						break;
+					}
+				}
+			}
+
+			Tools.PostDebugMessage(this, "hasResource: {0}", hasResource);
+
+			if (!hasResource)
+			{
+				Tools.PostDebugMessage(this, "Adding resource to part");
+
+				PartResource resource = base.part.gameObject.AddComponent<PartResource>();
+				resource.SetInfo(this.kerbalMassInfo);
+				resource.amount = 0;
+				resource.maxAmount = base.part.CrewCapacity;
+			}
+
+			foreach (PartResource resource in base.part.GetComponents<PartResource>())
+			{
+				if (resource.resourceName == KERBAL_RESOURCE_NAME)
+				{
+					hasResource = true;
+					this.partKerbalMass = resource;
+					break;
+				}
+			}
+
+			#if DEBUG
+
+			Tools.PostDebugMessage(this, "Resource {0}added.", hasResource ? "" : "not ");
+			#endif
+
+			GameEvents.onCrewOnEva.Add(this.handleCrewOnEva);
+			GameEvents.onCrewBoardVessel.Add(this.handleCrewBoardVessel);
+			GameEvents.onCrewTransferred.Add(this.handleCrewTransferred);
+
+			Tools.PostDebugMessage(this, "Awake.");
+		}
+
+		public void FixedUpdate()
+		{
+			if (this.firstRun)
+			{
+				Tools.PostDebugMessage(this, "First FixedUpdate.");
+
+				this.resetKerbalMass();
+
+				this.firstRun = false;
+			}
+		}
+
+		public void OnDestroy()
+		{
+			GameEvents.onCrewOnEva.Remove(this.handleCrewOnEva);
+			GameEvents.onCrewBoardVessel.Remove(this.handleCrewBoardVessel);
+			GameEvents.onCrewTransferred.Remove(this.handleCrewTransferred);
+
+			Tools.PostDebugMessage(this, "Destroyed.");
+		}
+
+		private void resetKerbalMass()
+		{
+			int crewCount = 0;
+			if (base.part.protoModuleCrew != null)
+			{
+				crewCount = base.part.protoModuleCrew.Count;
+			}
+
+			this.partKerbalMass.amount = crewCount;
+		}
+
+		private void handleCrewOnEva(GameEvents.FromToAction<Part, Part> data)
+		{
+			Tools.PostDebugMessage(this, "Handling onCrewOnEva");
+
+			this.resetKerbalMass();
+		}
+
+		private void handleCrewBoardVessel(GameEvents.FromToAction<Part, Part> data)
+		{
+			Tools.PostDebugMessage(this, "Handling onCrewOnEva");
+
+			this.resetKerbalMass();
+		}
+
+		private void handleCrewTransferred(GameEvents.HostedFromToAction<ProtoCrewMember, Part> data)
+		{
+			Tools.PostDebugMessage(this, "Handling onCrewOnEva");
+
+			this.resetKerbalMass();
+		}
+	}
+}
+
+

--- a/NSScientific.csproj
+++ b/NSScientific.csproj
@@ -93,6 +93,7 @@
     <Compile Include="..\ToadicusTools\Tools.cs">

       <Link>Tools.cs</Link>

     </Compile>

+    <Compile Include="ModuleKerbalMassTracker.cs" />

   </ItemGroup>

   <ItemGroup>

     <None Include="MM\ModuleRedefs.cfg">

@@ -102,6 +103,12 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

     </None>

     <None Include="MM\ScienceRedefs.cfg">

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="Resources.cfg">

+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+    </None>

+    <None Include="MM\MassTrackers.cfg">

       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

     </None>

   </ItemGroup>


file:b/Resources.cfg (new)
--- /dev/null
+++ b/Resources.cfg
@@ -1,1 +1,22 @@
+//
+// NidaSampi Scientific
+// by toadicus, dudecon
+//
+// Resources.cfg
+//
+// This work is released into the Public Domain
+//
+// This software uses ModuleManager © 2014 sarbian, ialdabaoth, et al
+// used under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
+//
 
+
+RESOURCE_DEFINITION
+{
+	name = KerbalMass
+	density = 0.094
+	unitCost = 0
+	flowMode = NO_FLOW
+	transfer = NONE
+	isTweakable = false
+}