Skip to content

Commit

Permalink
Separately staged fairing mass jettisons are now calculated in the ed…
Browse files Browse the repository at this point in the history
…itor.
  • Loading branch information
CYBUTEK committed May 2, 2015
1 parent 80cf264 commit 5567732
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
44 changes: 26 additions & 18 deletions KerbalEngineer/VesselSimulator/PartSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//

#region Using Directives

#endregion

namespace KerbalEngineer.VesselSimulator
Expand Down Expand Up @@ -53,7 +52,10 @@ public class PartSim : Pool<PartSim>
public bool isLanded;
public bool isNoPhysics;
public bool isSepratron;
public bool isFairing;
public bool localCorrectThrust;
public float moduleMass;
public int stageIndex;
public String name;
public String noCrossFeedNodeKey;
public PartSim parent;
Expand Down Expand Up @@ -287,7 +289,7 @@ public bool EmptyOf(HashSet<int> types)
return true;
}

public double GetMass()
public double GetMass(int currentStage)
{
double mass = baseMass;

Expand All @@ -296,6 +298,11 @@ public double GetMass()
mass += resources.GetResourceMass(resources.Types[i]);
}

if (hasVessel == false && isFairing && inverseStage < currentStage)
{
mass = mass + moduleMass;
}

return mass;
}

Expand Down Expand Up @@ -478,6 +485,7 @@ public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)
Reset(this);

part = thePart;
hasVessel = (part.vessel != null);
centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset);
partId = id;
name = part.partInfo.name;
Expand All @@ -495,30 +503,23 @@ public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)
isFuelLine = part.HasModule<CModuleFuelLine>();
isFuelTank = part is FuelTank;
isSepratron = IsSepratron();
isFairing = IsFairing(part);
inverseStage = part.inverseStage;
stageIndex = part.inStageIndex;
//MonoBehaviour.print("inverseStage = " + inverseStage);

cost = part.GetCostWet();

// Work out if the part should have no physical significance
isNoPhysics = part.HasModule<LaunchClamp>();

if (isNoPhysics == false)
{
if (part.vessel != null)
{
baseMass = part.mass;
}
else
baseMass = part.mass;
if (hasVessel == false)
{
baseMass = part.mass + part.GetModuleMass(part.mass);
moduleMass = part.GetModuleMass(part.mass);
}
}

if (SimManager.logOutput)
{
MonoBehaviour.print((isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + part.mass);
}
cost = part.GetCostWet();

for (int i = 0; i < part.Resources.Count; ++i)
{
Expand All @@ -542,9 +543,6 @@ public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)
}
}

startMass = GetMass();

hasVessel = (part.vessel != null);
isLanded = hasVessel && part.vessel.Landed;
if (hasVessel)
{
Expand All @@ -559,6 +557,8 @@ public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)

isEngine = hasMultiModeEngine || hasModuleEnginesFX || hasModuleEngines;

startMass = GetMass(-1);

if (SimManager.logOutput)
{
MonoBehaviour.print("Created " + name + ". Decoupled in stage " + decoupledInStage);
Expand Down Expand Up @@ -723,6 +723,7 @@ private static void Reset(PartSim partSim)
partSim.isLanded = false;
partSim.isNoPhysics = false;
partSim.isSepratron = false;
partSim.isFairing = false;
partSim.localCorrectThrust = false;
partSim.name = null;
partSim.noCrossFeedNodeKey = null;
Expand All @@ -732,6 +733,8 @@ private static void Reset(PartSim partSim)
partSim.partId = 0;
partSim.vesselName = null;
partSim.vesselType = VesselType.Base;
partSim.moduleMass = 0.0f;
partSim.stageIndex = 0;
}

private Vector3 CalculateThrustVector(List<Transform> thrustTransforms, LogMsg log)
Expand Down Expand Up @@ -799,6 +802,11 @@ private bool IsDecoupler(Part thePart)
thePart.HasModule<ModuleAnchoredDecoupler>();
}

private bool IsFairing(Part thePart)
{
return thePart.HasModule<ModuleProceduralFairing>();
}

private bool IsSepratron()
{
if (!part.ActivatesEvenIfDisconnected)
Expand Down
11 changes: 8 additions & 3 deletions KerbalEngineer/VesselSimulator/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class Simulation
public String vesselName;
public VesselType vesselType;
private WeightedVectorAverager vectorAverager = new WeightedVectorAverager();
private static ModuleProceduralFairing moduleProceduralFairing;

public Simulation()
{
Expand All @@ -91,7 +92,7 @@ private double ShipMass
double mass = 0d;

for (int i = 0; i < allParts.Count; ++i) {
mass += allParts[i].GetMass();
mass += allParts[i].GetMass(currentStage);
}

return mass;
Expand All @@ -107,7 +108,7 @@ private Vector3d ShipCom
for (int i = 0; i < allParts.Count; ++i)
{
PartSim partSim = allParts[i];
vectorAverager.Add(partSim.centerOfMass, partSim.GetMass());
vectorAverager.Add(partSim.centerOfMass, partSim.GetMass(currentStage));
}

return vectorAverager.Get();
Expand Down Expand Up @@ -373,7 +374,6 @@ public Stage[] RunSimulation()
// Create the array of stages that will be returned
Stage[] stages = new Stage[this.currentStage + 1];


// Loop through the stages
while (this.currentStage >= 0)
{
Expand Down Expand Up @@ -445,6 +445,11 @@ public Stage[] RunSimulation()
stage.cost += partSim.cost;
stage.mass += partSim.GetStartMass();
}

if (partSim.hasVessel == false && partSim.isFairing && partSim.inverseStage == currentStage)
{
stage.mass += partSim.moduleMass;
}
}

this.dontStageParts = dontStagePartsLists[this.currentStage];
Expand Down
Binary file modified Output/KerbalEngineer/KerbalEngineer.dll
Binary file not shown.

0 comments on commit 5567732

Please sign in to comment.