From a71176ccc6ec8e86462bdcb59deebc7afcaaa717 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Thu, 17 Sep 2020 18:03:47 -0700
Subject: [PATCH] Birth.js fixes and cleanup

---
 js/birth.js | 92 ++++++++++++++++++++++++++---------------------------
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/js/birth.js b/js/birth.js
index c4238256bb5..41304ba4ab5 100644
--- a/js/birth.js
+++ b/js/birth.js
@@ -12,7 +12,6 @@ globalThis.birth = function(slave) {
 	} = getPronouns(slave);
 	let He2, he2, his2;
 	const r = [];
-	let bw;
 	let animals = [];
 	let roll;
 	const HGL = App.Entity.facilities.headGirlSuite.hostedSlaves;
@@ -102,44 +101,45 @@ globalThis.birth = function(slave) {
 				}
 				break;
 
-			case "be a subordinate slave":
-				bw = V.slaveIndices[slave.subTarget];
-				if (bw) {
-					({he2} = getPronouns(getSlave(slave.subTarget)).appendSuffix("2"));
+			case "be a subordinate slave": {
+				const domSlave = getSlave(slave.subTarget);
+				if (domSlave) {
+					({he2} = getPronouns(domSlave).appendSuffix("2"));
 				}
 				if (slave.fetish === "mindbroken") {
 					if (slave.subTarget === 0) {
 						r.push(`${He} returns to ${his} bed and strips before slipping into it. Instinctively, ${he} begins to push out ${his} ${babies}. ${His} ${childrenAre} promptly taken and ${he} rests for a short while before returning to your waiting slaves.`);
 					} else {
-						r.push(`${He} is lead by ${V.slaves[bw].slaveName} to a private room so that ${he2} may`);
-						if (canSee(V.slaves[bw])) {
+						r.push(`${He} is lead by ${domSlave.slaveName} to a private room so that ${he2} may`);
+						if (canSee(domSlave)) {
 							r.push(`watch.`);
 						} else {
 							r.push(`be present.`);
 						}
-						r.push(`Instinctively ${he} begins to push out ${his} ${babies}, indifferent to ${his} watching audience. ${His} ${childrenAre} promptly taken and ${V.slaves[bw].slaveName} eagerly descends upon ${his} defenseless body.`);
+						r.push(`Instinctively ${he} begins to push out ${his} ${babies}, indifferent to ${his} watching audience. ${His} ${childrenAre} promptly taken and ${domSlave.slaveName} eagerly descends upon ${his} defenseless body.`);
 					}
 				} else {
 					if (slave.subTarget === 0) {
 						r.push(`${He} returns to ${his} bed and strips before slipping into it. ${He} makes ${himself} comfortable and begins working on birthing ${his} ${babies}${UH}. ${His} ${childrenAre} promptly taken and ${he} rests for a short while before returning to your waiting slaves.`);
 					} else {
-						r.push(`${He} is taken by ${V.slaves[bw].slaveName} to a private room so that ${he2} may`);
-						if (canSee(V.slaves[bw])) {
+						r.push(`${He} is taken by ${domSlave.slaveName} to a private room so that ${he2} may`);
+						if (canSee(domSlave)) {
 							r.push(`watch.`);
 						} else {
 							r.push(`be present.`);
 						}
-						r.push(`Reluctantly, ${he} begins to push out ${his} ${babies}${UH}, fully aware of ${V.slaves[bw].slaveName}'s`);
-						if (V.slaves[bw].fetish === "pregnancy") {
+						r.push(`Reluctantly, ${he} begins to push out ${his} ${babies}${UH}, fully aware of ${domSlave.slaveName}'s`);
+						if (domSlave.fetish === "pregnancy") {
 							r.push(`hungry gaze.`);
 						} else {
 							r.push(`amused gaze.`);
 						}
-						r.push(`${His} ${childrenAre} promptly taken and ${V.slaves[bw].slaveName} eagerly descends upon ${his} exhausted body.`);
+						r.push(`${His} ${childrenAre} promptly taken and ${domSlave.slaveName} eagerly descends upon ${his} exhausted body.`);
 						V.humiliation = 1;
 					}
 				}
 				break;
+			}
 
 			case "whore":
 				if (!canWalk(slave)) {
@@ -775,22 +775,22 @@ globalThis.ampBirth = function(slave) { // "AmpBirth"
 				}
 				break;
 
-			case "be a subordinate slave":
-				bw = V.slaveIndices[slave.subTarget];
+			case "be a subordinate slave": {
+				const domSlave = getSlave(slave.subTarget);
 				if (bw) {
-					({he2} = getPronouns(getSlave(slave.subTarget)).appendSuffix("2"));
+					({he2} = getPronouns(domSlave).appendSuffix("2"));
 				}
 				if (slave.fetish === "mindbroken") {
 					if (slave.subTarget === 0) {
 						r.push(`${He} is placed on ${his} bed and stripped. Instinctively, ${he} begins to push out ${his} ${babies}, indifferent to ${his} watching helper. ${His} ${childrenAre} promptly taken and ${he} is returned to your waiting slaves.`);
 					} else {
-						r.push(`${He} is placed with ${V.slaves[bw].slaveName} so that ${he2} may`);
-						if (canSee(V.slaves[bw])) {
+						r.push(`${He} is placed with ${domSlave.slaveName} so that ${he2} may`);
+						if (canSee(domSlave)) {
 							r.push(`enjoy the show.`);
 						} else {
 							r.push(`be present.`);
 						}
-						r.push(`Instinctively, ${he} begins to push out ${his} ${babies}, indifferent to ${his} watching audience. ${His} ${childrenAre} promptly taken and ${he} is tipped into ${V.slaves[bw].slaveName}'s eager lap.`);
+						r.push(`Instinctively, ${he} begins to push out ${his} ${babies}, indifferent to ${his} watching audience. ${His} ${childrenAre} promptly taken and ${he} is tipped into ${domSlave.slaveName}'s eager lap.`);
 					}
 				} else {
 					if (slave.subTarget === 0) {
@@ -801,8 +801,8 @@ globalThis.ampBirth = function(slave) { // "AmpBirth"
 						r.push(`fully aware of ${his} watching helper. ${His} ${childrenAre} promptly taken and ${he} is returned to your waiting slaves.`);
 						V.humiliation = 1;
 					} else {
-						r.push(`${He} is placed with ${V.slaves[bw].slaveName} so that ${he2} may`);
-						if (canSee(V.slaves[bw])) {
+						r.push(`${He} is placed with ${domSlave.slaveName} so that ${he2} may`);
+						if (canSee(domSlave)) {
 							r.push(`watch.`);
 						} else {
 							r.push(`be present.`);
@@ -811,17 +811,18 @@ globalThis.ampBirth = function(slave) { // "AmpBirth"
 						if (slave.geneticQuirks.uterineHypersensitivity === 2) {
 							r.push(`convulsing with orgasms in the process and`);
 						}
-						r.push(`fully aware of ${V.slaves[bw].slaveName}'s`);
-						if (V.slaves[bw].fetish === "pregnancy") {
+						r.push(`fully aware of ${domSlave.slaveName}'s`);
+						if (domSlave.fetish === "pregnancy") {
 							r.push(`hungry gaze.`);
 						} else {
 							r.push(`amused gaze.`);
 						}
-						r.push(`${His} ${childrenAre} promptly taken and ${he} is tipped into ${V.slaves[bw].slaveName}'s eager lap.`);
+						r.push(`${His} ${childrenAre} promptly taken and ${he} is tipped into ${domSlave.slaveName}'s eager lap.`);
 						V.humiliation = 1;
 					}
 				}
 				break;
+			}
 
 			case "whore":
 				if (slave.fetish === "mindbroken") {
@@ -1169,7 +1170,6 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 		heU, himU, himselfU, girlU
 	} = getNonlocalPronouns(V.seeDicks).appendSuffix('U');
 	let r = [];
-	let bw;
 	const birthScene = random(1, 100);
 	const babies = slave.pregType > 1 ? `babies` : `baby`;
 	const children = slave.pregType > 1 ? `children` : `child`;
@@ -1181,11 +1181,9 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 	if (random(1, 2) === 1 && canWalk(slave)) {
 		// at assignment else in halls/etc, only if able to move
 
-		if (slave.rivalry > 0) {
-			bw = V.slaveIndices[slave.rivalryTarget];
-			if (bw) {
-				({he2} = getPronouns(getSlave(slave.rivalryTarget)).appendSuffix("2"));
-			}
+		const rival = slave.rivalry > 0 ? getSlave(slave.rivalryTarget) : null;
+		if (rival) {
+			({he2} = getPronouns(rival).appendSuffix("2"));
 		}
 
 		if (slave.fetish === "mindbroken") {
@@ -1208,17 +1206,17 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 				r.push(`through the penthouse on the way to ${his} next assignment, ${slave.slaveName}'s water breaks. Unable to reach the prepared birthing room in time, ${he} finds a secluded nook to give birth in.`);
 				r.push(clothingBirth(slave));
 				r.push(`${He} gathers ${his} ${newborns} and recovers ${his} strength before finding a servant to give ${his} ${children} to before hurrying to ${his} assignment.`);
-			} else if (birthScene > 66 && slave.rivalry === 3 && isSlaveAvailable(V.slaves[bw]) && canWalk(V.slaves[bw])) {
-				if (slave.pregSource === V.slaves[bw].ID) {
-					r.push(`While hustling through the penthouse on ${his} way to give birth, ${slave.slaveName} finds ${his} path blocked by ${V.slaves[bw].slaveName} — and a hospital gurney, of all things. ${He2} appears genuinely concerned for the (soon-to-be) mother of ${his2} ${children}, and helps ${him} onto the bed, then pushes the surprised ${girl} onwards. ${slave.slaveName}, focusing on ${his} labor, begins to rethink the animosity ${he} feels for ${him2} — until ${he} realizes ${V.slaves[bw].slaveName} has brought them to the cafeteria. With a smug pride in ${his2} potency, ${he2} introduces the shocked pregnant ${girl} to ${his} new audience. ${His} contractions becoming too frequent to move, ${he} begins giving birth in front of ${his} audience.`);
+			} else if (birthScene > 66 && slave.rivalry === 3 && isSlaveAvailable(rival) && canWalk(rival)) {
+				if (slave.pregSource === rival.ID) {
+					r.push(`While hustling through the penthouse on ${his} way to give birth, ${slave.slaveName} finds ${his} path blocked by ${rival.slaveName} — and a hospital gurney, of all things. ${He2} appears genuinely concerned for the (soon-to-be) mother of ${his2} ${children}, and helps ${him} onto the bed, then pushes the surprised ${girl} onwards. ${slave.slaveName}, focusing on ${his} labor, begins to rethink the animosity ${he} feels for ${him2} — until ${he} realizes ${rival.slaveName} has brought them to the cafeteria. With a smug pride in ${his2} potency, ${he2} introduces the shocked pregnant ${girl} to ${his} new audience. ${His} contractions becoming too frequent to move, ${he} begins giving birth in front of ${his} audience.`);
 					V.humiliation = 1;
 					r.push(clothingBirth(slave));
-					r.push(`${V.slaves[bw].slaveName} gathers ${his2} ${babies} from ${his2} exhausted rival, roughly pushes ${him} off the gurney, then hands the ${children} to a servant that had been called in by the commotion. ${slave.slaveName}, humiliated by the spectacle and ${his} own naïveté, pushes through the jeering crowd and hastily heads back to ${his} bed to hide ${himself} from the mockery.`);
+					r.push(`${rival.slaveName} gathers ${his2} ${babies} from ${his2} exhausted rival, roughly pushes ${him} off the gurney, then hands the ${children} to a servant that had been called in by the commotion. ${slave.slaveName}, humiliated by the spectacle and ${his} own naïveté, pushes through the jeering crowd and hastily heads back to ${his} bed to hide ${himself} from the mockery.`);
 				} else {
-					r.push(`While hustling through the penthouse on ${his} way to give birth, ${slave.slaveName} finds ${his} path blocked by ${V.slaves[bw].slaveName}. Seeing ${his} distress brings a grin to ${his2} face. ${He2} quickly rushes the laboring slave.slaveName, circling around behind ${him} and hooking ${him} under the arms. ${He2} forces the poor ${girl} into the cafeteria and holds ${him} in place, leaving ${him} with no other option than to begin giving birth in front of ${his} audience.`);
+					r.push(`While hustling through the penthouse on ${his} way to give birth, ${slave.slaveName} finds ${his} path blocked by ${rival.slaveName}. Seeing ${his} distress brings a grin to ${his2} face. ${He2} quickly rushes the laboring ${slave.slaveName}, circling around behind ${him} and hooking ${him} under the arms. ${He2} forces the poor ${girl} into the cafeteria and holds ${him} in place, leaving ${him} with no other option than to begin giving birth in front of ${his} audience.`);
 					V.humiliation = 1;
 					r.push(clothingBirth(slave));
-					r.push(`${V.slaves[bw].slaveName} releases ${him} and ${he} moves to gather ${his} ${newborns}. With a shove from ${his} rival, ${he} rushes out of the jeering crowd's sight. Finding a servant to give ${his} ${children} to, ${he} hastily heads back to ${his} bed to hide ${himself} from the mockery.`);
+					r.push(`${rival.slaveName} releases ${him} and ${he} moves to gather ${his} ${newborns}. With a shove from ${his} rival, ${he} rushes out of the jeering crowd's sight. Finding a servant to give ${his} ${children} to, ${he} hastily heads back to ${his} bed to hide ${himself} from the mockery.`);
 				}
 			} else {
 				r.push(`While waddling through the penthouse on ${his} way to the cafeteria, ${slave.slaveName}'s water breaks. Unable to reach the prepared birthing room in time, ${he} finds ${himself} stranded in the middle of all the dining slaves.`);
@@ -1253,10 +1251,10 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 				}
 				break;
 
-			case "be a subordinate slave":
-				bw = V.slaveIndices[slave.subTarget];
-				if (bw) {
-					({he2} = getPronouns(getSlave(slave.subTarget)).appendSuffix("2"));
+			case "be a subordinate slave": {
+				const domSlave = getSlave(slave.subTarget);
+				if (domSlave) {
+					({he2} = getPronouns(domSlave).appendSuffix("2"));
 				}
 				if (slave.fetish === "mindbroken") {
 					if (slave.subTarget === 0) {
@@ -1276,7 +1274,7 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 						}
 						r.push(`as ${he} draws ${his} ${children} to ${his} ${breasts}.`);
 					} else {
-						r.push(`While servicing ${V.slaves[bw].slaveName}, ${slave.slaveName}'s water breaks, though it does nothing to deter ${him} from ${his} task.`);
+						r.push(`While servicing ${domSlave.slaveName}, ${slave.slaveName}'s water breaks, though it does nothing to deter ${him} from ${his} task.`);
 						r.push(clothingBirth(slave));
 						r.push(`No sooner than ${his} ${babies}`);
 						if (slave.pregType > 1) {
@@ -1294,13 +1292,14 @@ globalThis.suddenBirth = function(slave) { // "SuddenBirth"
 						r.push(`${He} is allowed a moment to prepare ${his} ${children}`);
 						r.push(`to be sent off before returning to pleasuring your other slaves.`);
 					} else {
-						r.push(`While servicing ${V.slaves[bw].slaveName}, ${slave.slaveName}'s water breaks, causing ${him} to immediately try to break off. ${His} dom eagerly watches ${his2} pregnant sub's ordeal.`);
+						r.push(`While servicing ${domSlave.slaveName}, ${slave.slaveName}'s water breaks, causing ${him} to immediately try to break off. ${His} dom eagerly watches ${his2} pregnant sub's ordeal.`);
 						V.humiliation = 1;
 						r.push(clothingBirth(slave));
-						r.push(`${V.slaves[bw].slaveName} collects the newborn ${childrenAre} to be sent off before returning and planting ${his2} crotch directly onto ${his2} exhausted sub's face.`);
+						r.push(`${domSlave.slaveName} collects the newborn ${childrenAre} to be sent off before returning and planting ${his2} crotch directly onto ${his2} exhausted sub's face.`);
 					}
 				}
 				break;
+			}
 
 			case "whore":
 				if (!canWalk(slave)) {
@@ -5019,6 +5018,7 @@ globalThis.broodmotherBirth = function(slave) {
 							} else if (V.HeadGirlID !== 0) {
 								r.push(S.HeadGirl.slaveName);
 							} else {
+								r.push(`anyone`);
 							}
 							r.push(`shouts at ${him} for dragging ${his} pregnant ass.`);
 						} else {
@@ -5749,7 +5749,7 @@ globalThis.broodmotherBirth = function(slave) {
 				({he2} = getPronouns(S.HeadGirl).appendSuffix("2"));
 				if (slave.pregSource === V.HeadGirlID) {
 					if (random(1, 20) > V.suddenBirth) {
-						r.push(`${S.HeadGirl.slaveName} makes sure that the mother of ${his2} child is happy and comfortable for the upcoming birth, even if they won't be spending much time with their offspring. ${he2} carefully undresses slave.slaveName, all the while whispering sweet nothings in ${his} ear. ${He} begins to push out ${firstText} baby${UH}, and ${his} child is carefully collected by their father. Once they are out of the way, ${S.HeadGirl.slaveName} moves in to fondle ${slave.slaveName}'s tired, still very gravid body.`);
+						r.push(`${S.HeadGirl.slaveName} makes sure that the mother of ${his2} child is happy and comfortable for the upcoming birth, even if they won't be spending much time with their offspring. ${he2} carefully undresses ${slave.slaveName}, all the while whispering sweet nothings in ${his} ear. ${He} begins to push out ${firstText} baby${UH}, and ${his} child is carefully collected by their father. Once they are out of the way, ${S.HeadGirl.slaveName} moves in to fondle ${slave.slaveName}'s tired, still very gravid body.`);
 					} else {
 					}
 				} else {
@@ -6790,7 +6790,7 @@ globalThis.hyperBroodmotherBirth = function(slave) {
 						r.push(clothingBirth(slave));
 						r.push(`As ${his} child is removed from the dance floor, ${he} is helped into one of the back rooms by several of ${his} aroused onlookers.`);
 					} else {
-						r.push(`${slave.slaveName} is showing off ${his} grotesque body and trying to attract citizens by dancing as well as ${he} can. During one of ${his} dances, slave.slaveName's body begins to birth another of ${his} brood. ${He} frantically struggles to move drawing even more attention to ${his} helpless state. ${He} is roughly pulled into one of the side rooms by a group of men looking forward to the show ${he}'s about to perform for them.`);
+						r.push(`${slave.slaveName} is showing off ${his} grotesque body and trying to attract citizens by dancing as well as ${he} can. During one of ${his} dances, ${slave.slaveName}'s body begins to birth another of ${his} brood. ${He} frantically struggles to move drawing even more attention to ${his} helpless state. ${He} is roughly pulled into one of the side rooms by a group of men looking forward to the show ${he}'s about to perform for them.`);
 						V.humiliation = 1;
 						r.push(clothingBirth(slave));
 						r.push(`Only once the last of ${his} clients cums over ${his} bloated body is ${he} handed ${his} child and allowed to rest. ${He} enjoys a moment with ${his} newborn before the servant comes to collect them.`);
@@ -6806,7 +6806,7 @@ globalThis.hyperBroodmotherBirth = function(slave) {
 						r.push(clothingBirth(slave));
 						r.push(`As ${his} child is removed from the dance floor, ${he} is helped into one of the back rooms by several of ${his} aroused onlookers.`);
 					} else {
-						r.push(`${slave.slaveName} is showing off ${his} grotesque body and trying to attract citizens by dancing as well as ${he} can. During one of ${his} dances, slave.slaveName's body begins to birth another of ${his} brood. ${He} clumsily tries to leave the dance floor only to find hands groping ${his} titanic belly. ${He} is roughly pulled into one of the side rooms by a group of men looking forward to the show ${he}'s about to perform for them.`);
+						r.push(`${slave.slaveName} is showing off ${his} grotesque body and trying to attract citizens by dancing as well as ${he} can. During one of ${his} dances, ${slave.slaveName}'s body begins to birth another of ${his} brood. ${He} clumsily tries to leave the dance floor only to find hands groping ${his} titanic belly. ${He} is roughly pulled into one of the side rooms by a group of men looking forward to the show ${he}'s about to perform for them.`);
 						V.humiliation = 1;
 						r.push(clothingBirth(slave));
 						r.push(`Only once the last of ${his} clients cums over ${his} bloated body is ${he} handed ${his} child and allowed to rest. ${He} enjoys a moment with ${his} newborn before the servant comes to collect them.`);
-- 
GitLab