diff --git a/code/modules/power/port_gen.dm b/code/modules/power/port_gen.dm index a858a5fd43..61cf05477a 100644 --- a/code/modules/power/port_gen.dm +++ b/code/modules/power/port_gen.dm @@ -214,7 +214,11 @@ else if (temperature > upper_limit) bias = max(round((temperature - average)/TEMPERATURE_DIVISOR, 1), -TEMPERATURE_CHANGE_MAX) - temperature += rand(-7 + bias, 7 + bias) + //limit temperature increase so that it cannot raise temperature above upper_limit, + //or if it is already above upper_limit, limit the increase to 0. + var/inc_limit = max(upper_limit - temperature, 0) + var/dec_limit = min(temperature - lower_limit, 0) + temperature += between(dec_limit, rand(-7 + bias, 7 + bias), inc_limit) if (temperature > max_temperature) overheat()