Skip to content
Snippets Groups Projects
Commit 010ce4d0 authored by svornost's avatar svornost
Browse files

Guard against health NaNs by throwing immediately.

parent d2b720e1
No related branches found
No related tags found
1 merge request!7291Guard against health NaNs
......@@ -28,6 +28,9 @@ globalThis.healthPenalty = function(slave) {
* @returns {void}
*/
globalThis.healthDamage = function(slave, damage) {
if (!_.isFinite(damage)) {
throw "Health damage must be a finite number.";
}
const H = slave.health;
damage = Math.max(Math.trunc(damage), 0);
H.shortDamage += damage;
......@@ -43,6 +46,9 @@ globalThis.healthDamage = function(slave, damage) {
* @returns {void}
*/
globalThis.healthCure = function(slave, cure) {
if (!_.isFinite(cure)) {
throw "Health cure must be a finite number.";
}
const H = slave.health;
cure = Math.max(Math.trunc(cure), 0);
if (cure > H.shortDamage) {
......@@ -71,6 +77,9 @@ globalThis.surgeryDamage = function(slave, damage) {
* @returns {void}
*/
globalThis.improveCondition = function(slave, condition) {
if (!_.isFinite(condition)) {
throw "Health condition change must be a finite number.";
}
const H = slave.health;
H.condition += Math.max(Math.trunc(condition), 0);
updateHealth(slave);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment