Skip to content

Commit

Permalink
also work around crew mass mess for build part overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Mar 22, 2018
1 parent 2ddb764 commit 9330226
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
42 changes: 40 additions & 2 deletions KerbalEngineer/Extensions/PartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,47 @@ public static double GetCostWet(this Part part)
/// </summary>
public static double GetDryMass(this Part part)
{
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass : 0d;
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass + part.getCrewAdjustment() : 0d;
}

public static double getCrewAdjustment(this Part part)
{
if (HighLogic.LoadedSceneIsEditor && PhysicsGlobals.KerbalCrewMass != 0 && ShipConstruction.ShipManifest != null)
{ //fix weird stock behavior with this physics setting.

var crewlist = ShipConstruction.ShipManifest.GetAllCrew(false);

int crew = 0;

foreach (var crewmem in crewlist)
{
if (crewmem != null) crew++;
}

if (crew > 0)
{
var pcm = ShipConstruction.ShipManifest.GetPartCrewManifest(part.craftID);

int actualCrew = 0;

foreach (var crewmem in pcm.GetPartCrew())
{
if (crewmem != null)
actualCrew++;
}

if (actualCrew < crew)
{
return PhysicsGlobals.KerbalCrewMass * (crew - actualCrew);
}

}
}

return 0;
}


/// <summary>
/// Gets the maximum thrust of the part if it's an engine.
/// </summary>
Expand Down Expand Up @@ -374,7 +412,7 @@ public static double GetSpecificImpulse(this Part part, float atmosphere)
/// </summary>
public static double GetWetMass(this Part part)
{
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass + part.GetResourceMass() : part.GetResourceMass();
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass + part.GetResourceMass() + part.getCrewAdjustment() : part.GetResourceMass();
}

/// <summary>
Expand Down
42 changes: 2 additions & 40 deletions KerbalEngineer/VesselSimulator/PartSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,46 +151,8 @@ public static PartSim New(Part p, int id, double atmosphere, LogMsg log)
}
else
{
partSim.realMass = p.mass;

if (HighLogic.LoadedSceneIsEditor && PhysicsGlobals.KerbalCrewMass != 0 && ShipConstruction.ShipManifest != null)
{ //fix weird stock behavior with this physics setting.

var crewlist = ShipConstruction.ShipManifest.GetAllCrew(false);

int crew = 0;

foreach(var crewmem in crewlist)
{
if(crewmem !=null) crew++;
}

if (log != null) log.AppendLine("crew count " + crew);

if (crew > 0)
{
var pcm = ShipConstruction.ShipManifest.GetPartCrewManifest(p.craftID);

if (log != null && pcm == null) log.AppendLine("pcm is null!");

if (log != null && pcm != null) log.AppendLine("pcm: " + pcm.GetPartCrew().Length);

int actualCrew = 0;

foreach (var crewmem in pcm.GetPartCrew())
{
if (crewmem != null)
actualCrew++;
}

if (actualCrew < crew)
{
partSim.crewMassOffset = -PhysicsGlobals.KerbalCrewMass * (crew-actualCrew);
partSim.realMass += partSim.crewMassOffset;
if (log != null) log.AppendLine("Adjusting Weight of Crew");
}
}
}
partSim.crewMassOffset = p.getCrewAdjustment();
partSim.realMass = p.mass + partSim.crewMassOffset;

if (log != null) log.AppendLine("Using part.mass of " + partSim.realMass);
}
Expand Down

0 comments on commit 9330226

Please sign in to comment.