Bug #25964
Vessel.GetTotalMass() does not return the correct mass of unloaded vessels
Status:
New
Severity:
Low
Assignee:
-
Category:
Physics
Target version:
-
Start date:
08/15/2020
% Done:
0%
Language:
English (US)
Mod Related:
No
Votes:
Description
I have no idea what it's actually returning, but it's wrong, based on comparing the values for a vessel when it is loaded and then when it is unloaded
This has been an error for a long time
The following code does return the correct values, feel free to use it or just to compare to what you have:
private double GetUnloadedVesselMass(string name, ProtoVessel protoVessel)
{
double num = 0.0;
for (int i = 0; i < protoVessel.protoPartSnapshots.Count; i++)
{
ProtoPartSnapshot protoPartSnapshot = protoVessel.protoPartSnapshots[i];
num = (double)protoPartSnapshot.mass;
for (int j = 0; j < protoPartSnapshot.resources.Count; j+)
{
ProtoPartResourceSnapshot protoPartResourceSnapshot = protoPartSnapshot.resources[j];
if (protoPartResourceSnapshot != null)
{
if (protoPartResourceSnapshot.definition != null)
{
num += protoPartResourceSnapshot.amount * (double)protoPartResourceSnapshot.definition.density;
}
else
Debug.Log("Vessel: " + name + ", resource: " + protoPartResourceSnapshot.resourceName + ", no definition");
}
}
}
return num;
}
History
#1 Updated by linuxgurugamer over 4 years ago
Please note that the seventh line is being displayed badly.
The plus equals seemed to turn into an underline.
This is what it should be:
num = num + (double)protoPartSnapshot.mass;