More fixes to per-stage mass and cost values
[VesselSimulator.git] / KerbalEngineer / VesselSimulator / PartSim.cs
blob:a/KerbalEngineer/VesselSimulator/PartSim.cs -> blob:b/KerbalEngineer/VesselSimulator/PartSim.cs
--- a/KerbalEngineer/VesselSimulator/PartSim.cs
+++ b/KerbalEngineer/VesselSimulator/PartSim.cs
@@ -38,7 +38,7 @@
         public double baseMass;
         public double baseMassForCoM;
         public Vector3d centerOfMass;
-        public double cost;
+        public double baseCost;
         public int decoupledInStage;
         public bool fuelCrossFeed;
         public List<PartSim> fuelTargets = new List<PartSim>();
@@ -90,6 +90,7 @@
             partSim.resourceDrains.Reset();
             partSim.resourceFlowStates.Reset();
             partSim.resources.Reset();
+            partSim.baseCost = 0d;
             partSim.baseMass = 0d;
             partSim.baseMassForCoM = 0d;
             partSim.startMass = 0d;
@@ -122,7 +123,7 @@
             partSim.inverseStage = partSim.part.inverseStage;
             //MonoBehaviour.print("inverseStage = " + inverseStage);
 
-            partSim.cost = partSim.part.GetCostWet();
+            partSim.baseCost = partSim.part.GetCostDry();
 
             if (log != null)
             {
@@ -146,6 +147,8 @@
                 partSim.realMass = partSim.part.mass;
                 if (log != null) log.buf.AppendLine("Using part.mass of " + partSim.part.mass);
             }
+
+            partSim.moduleMass = partSim.part.GetModuleMass((float)partSim.realMass);
 
             for (int i = 0; i < partSim.part.Resources.Count; i++)
             {
@@ -408,6 +411,9 @@
 
         public double GetMass(int currentStage, bool forCoM = false)
         {
+            if (decoupledInStage >= currentStage)
+                return 0d;
+
             double mass = forCoM ? baseMassForCoM : baseMass;
 
             for (int i = 0; i < resources.Types.Count; ++i)
@@ -422,7 +428,22 @@
 
             return mass;
         }
-                
+
+        public double GetCost(int currentStage)
+        {
+            if (decoupledInStage >= currentStage)
+                return 0d;
+
+            double cost = baseCost;
+
+            for (int i = 0; i < resources.Types.Count; ++i)
+            {
+                cost += resources.GetResourceCost(resources.Types[i]);
+            }
+
+            return cost;
+        }
+
         public void ReleasePart()
         {
             this.part = null;