From 010ce4d04d28b22dc4cd7f946009a25e0f598668 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Wed, 29 Jul 2020 14:33:32 -0700
Subject: [PATCH] Guard against health NaNs by throwing immediately.

---
 src/js/health.js | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/js/health.js b/src/js/health.js
index 824a1a3376a..5bdaef11421 100644
--- a/src/js/health.js
+++ b/src/js/health.js
@@ -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);
-- 
GitLab