Fix for faulty temperature calculation for multiple systems (also fixes temperature overflows).

It could probably use some optimization and I'm not sure about exact correctness of math used, but it should be immeasurably better than what we had before.

__EDIT:__ (by @impaktor)
Closes #3023 
Fixes #2963