From 7d361d0d7a496492543b978e44bdac14e2524789 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Thu, 29 Oct 2020 03:51:41 -0400
Subject: [PATCH] slave index

---
 src/endWeek/economics/neighborsDevelopment.js | 36 +++++++++----------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/endWeek/economics/neighborsDevelopment.js b/src/endWeek/economics/neighborsDevelopment.js
index 9f46bc8a8d6..742766d65d2 100644
--- a/src/endWeek/economics/neighborsDevelopment.js
+++ b/src/endWeek/economics/neighborsDevelopment.js
@@ -5,7 +5,7 @@ App.EndWeek.neighborsDevelopment = function() {
 	const el = document.createElement("p");
 	let He, his;
 
-	V.averageProsperity = 0;
+	let averageProsperity = 0;
 	let _agentBonus = 0;
 	let _corpBonus;
 	let _error;
@@ -17,9 +17,9 @@ App.EndWeek.neighborsDevelopment = function() {
 		if (V.arcologies[i].prosperity < 10) {
 			V.arcologies[i].prosperity = 10;
 		}
-		V.averageProsperity += V.arcologies[i].prosperity;
+		averageProsperity += V.arcologies[i].prosperity;
 	}
-	V.averageProsperity = V.averageProsperity / V.arcologies.length;
+	averageProsperity = averageProsperity / V.arcologies.length;
 
 	if (V.corp.Incorporated === 1) {
 		_corpBonus = Math.trunc(1000 * Math.pow(App.Corporate.value, 0.1));
@@ -71,15 +71,13 @@ App.EndWeek.neighborsDevelopment = function() {
 		if (arc.honeymoon > 0) {
 			arc.honeymoon -= 1;
 		}
-		let _agentIndex;
+		const _agent = App.currentAgent(i);
 		if (arc.government === "your agent") {
-			const _Agent = App.currentAgent(i);
-			({his} = getPronouns(_Agent));
-			r.push(`is being run by your agent <span class="deeppink">${SlaveFullName(_Agent)}.</span>`);
-			_agentIndex = V.slaveIndices[_Agent.ID];
-			if (_agentIndex && V.slaves[_agentIndex].assignment !== "be your agent") {
-				r.push(`<span class="red">BUG: ${V.slaves[_agentIndex].slaveName} also was ${V.slaves[_agentIndex].assignment}!</span>`);
-				assignJob(V.slaves[_agentIndex], "be your agent");
+			({He} = getPronouns(_agent));
+			r.push(`is being run by your agent <span class="deeppink">${SlaveFullName(_agent)}.</span>`);
+			if (_agent && _agent.assignment !== "be your agent") {
+				r.push(`<span class="red">BUG: ${_agent} also was ${_agent.assignment}!</span>`);
+				assignJob(_agent, "be your agent");
 			}
 			if (_agentBonus > 0) {
 				r.push(`<span class="green">${He} does an excellent job this week.</span>`);
@@ -115,11 +113,11 @@ App.EndWeek.neighborsDevelopment = function() {
 				arc.PCminority = 0;
 			}
 			r.push(`<span class="yellow">After a brief power struggle, it undergoes a change of government.</span>`);
-			if (_agentIndex && _agentIndex !== -1) {
-				({his} = getPronouns(V.slaves[_agentIndex]));
-				r.push(`<span class="deeppink">${V.slaves[_agentIndex].slaveName}</span> manages to escape with the help of a few loyal citizens and returns to you <span class="gold">fearing your displeasure at ${his} failure.</span>`);
-				V.slaves[_agentIndex].trust -= 40;
-				assignJob(V.slaves[_agentIndex], "rest"); // this takes care of necessary cleanup for agent and agent companion (if any)
+			if (_agent) {
+				({his} = getPronouns(_agent));
+				r.push(`<span class="deeppink">${_agent.slaveName}</span> manages to escape with the help of a few loyal citizens and returns to you <span class="gold">fearing your displeasure at ${his} failure.</span>`);
+				_agent.trust -= 40;
+				assignJob(_agent, "rest"); // this takes care of necessary cleanup for agent and agent companion (if any)
 			}
 			r.push(`A controlling interest has been taken by a single individual, leaving the arcology ruled like yours is.`);
 			arc.government = "an individual";
@@ -238,10 +236,10 @@ App.EndWeek.neighborsDevelopment = function() {
 			}
 		} else if (arc.prosperity >= 300) {
 			r.push(`at the maximum possible prosperity.`);
-		} else if (arc.prosperity > V.averageProsperity + 10) {
+		} else if (arc.prosperity > averageProsperity + 10) {
 			r.push(`much more prosperous than the rest of the Free City, limiting its economic development.`);
 			arc.prosperity -= 1;
-		} else if (arc.prosperity >= V.averageProsperity - 10) {
+		} else if (arc.prosperity >= averageProsperity - 10) {
 			r.push(`about as prosperous as the rest of the Free City.`);
 		} else {
 			if (arc.honeymoon > 0) {
@@ -289,7 +287,7 @@ App.EndWeek.neighborsDevelopment = function() {
 			if (arc.government !== "your agent") {
 				if (arc.government !== "your trustees") {
 					if (arc.minority + arc.ownership + arc.PCminority < 100) {
-						_prosperityDiff = arc.prosperity - V.averageProsperity;
+						_prosperityDiff = arc.prosperity - averageProsperity;
 						if (_prosperityDiff > random(-10, 50)) {
 							r.push(`Its leadership acquires an increased share of its ownership.`);
 							arc.ownership += 1;
-- 
GitLab