Rest "Until Healed" broken for characters with stunted magicka.

To reproduce:

Start a new game. Choose a class that has at least one starting spell. Choose “The Atronach” as birth-sign. (AFAIK the only source of a “Stunted Magicka” magic effect in vanilla Morrowind) Complete the tutorial. Cast a spell. Go back to the bedroll in the Census & Excise office. Sleep “Until Healed”. Observe: “Game is autosaved (if enabled)”. Character does not rest. Screen does not darken, no rest bar appears, neither health nor fatigue replenish.

To compare: Start a new game. Choose a class that has at least one starting spell. Choose any birth-sign, except “The Atronach”. Complete the tutorial. Cast a spell. Go back to the bedroll in the Census & Excise office. Sleep “Until Healed”. Observe: “Game is autosaved (if enabled)”. Character rests until health, magicka and fatigue are restored.

Current OpenMW behaviour: The character does not rest.

In original Morrowind: The character with stunted magicka would rest until health and fatigue had been restored.

To resolve: The calculation of time to rest until healed should ignore any of health, magicka and fatigue, that does not regenerate while sleeping.

Caused by inclusive edge case in code:

        float healthHours  = healthPerHour >= 0
                             ? (stats.getHealth().getModified() - stats.getHealth().getCurrent()) / healthPerHour
                             : 1.0f;
        float magickaHours = magickaPerHour >= 0
                              ? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour
                              : 1.0f;

Using greater-than or equal, allows the calculation to divide by zero. Apparently this does not throw an error, but likely the result is NaN and this throws things out of whack. I have fixed it in my local fork and will make a pull request.

(RM-1409 from redmine: created on 2014-06-06 by Gijsbert ter Horst, , closed on 2014-06-06 by Gijsbert ter Horst)

Edited by redmine