KeenSoftwareHouse / SpaceEngineers

2.93k stars 896 forks source link

JumpDrive range miscalculation on weld grids. With fix. #516

Closed plaYer2k closed 8 years ago

plaYer2k commented 8 years ago

The current code (version 01.131) still contains the miscalculation of masses for weld together grids when calculating the jump range for jump drives.

I have tried to bring that to attention in the forum at the according bug report with the included fix, though there was either no time, attention or interest to take that over. Thus i am trying it here as well.

The bug report with included fix. http://forum.keenswh.com/threads/1-121-10-jump-distance-is-improperly-divided-between-number-of-attached-ships-with-landing-gears.7379608/#post-1286964860

The current code in the source https://github.com/KeenSoftwareHouse/SpaceEngineers/blob/950174085c1cd098a82b6ff17a274bdf89523e82/Sources/Sandbox.Game/Game/GameSystems/MyGridJumpDriveSystem.cs#L324

The isolated fix

private double GetMass()
{
    double mass = 0f;
    Sandbox.Engine.Physics.MyPhysicsBody weldParent;
    foreach (var grid in m_connectedGrids)
    {
        // Get the weld parent for each grid and only add the mass if the grid has no parent or it is the root (it is its own parent).
        weldParent = grid.Physics.WeldInfo.Parent;
        if(weldParent == null || weldParent == grid.Physics)
            mass += grid.Physics.Mass;
    }
    return mass;
}