Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,22 @@ private static string GetSubDescription()

private static LocalizedString GetTotalHullVolume()
{
return $"{TextManager.Get("TotalHullVolume")}:\n{Hull.HullList.Sum(h => h.Volume)}";
float totalVolume = 0.0f;
float ballastVolume = 0.0f;
Hull.HullList.ForEach(h =>
{
totalVolume += h.Volume;

if (h.IsBallast())
{
ballastVolume += h.Volume;
}
});

string retVal = $"{TextManager.Get("TotalHullVolume")}:\n{totalVolume}";
retVal += $" ({(ballastVolume / totalVolume * 100).ToString("0.00")} % {TextManager.Get("roomname.Ballast")})";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that if totalVolume is 0.0f, the division here could result in Infinity, which might cause unexpected behavior when formatting the string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thought when writing this, though GetTotalHullVolume is only called when at least one hull is selected so this should never happen.
That being said, I have no problem adding a defensive guard just in case.


return retVal;
}

private static LocalizedString GetSelectedHullVolume()
Expand Down
5 changes: 5 additions & 0 deletions Barotrauma/BarotraumaShared/SharedSource/Map/Hull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,11 @@ private void DetermineIsAirlock()
IsAirlock = false;
}

public bool IsBallast()
{
return roomName != null && roomName.Contains("ballast", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Does this hull have any doors leading outside?
/// </summary>
Expand Down