From d90d43aaef4ca7a866252a62a5ad63b24b42acf1 Mon Sep 17 00:00:00 2001
From: Blank <blank@national.shitposting.agency>
Date: Fri, 31 May 2019 07:18:36 -0700
Subject: [PATCH] neighborArchology fixes

---
 src/js/SlaveState.js                        |  2 +-
 src/js/assignJS.js                          | 19 ++++++
 src/npc/agent/agentRetrieve.tw              |  4 +-
 src/npc/agent/agentWorkaround.tw            |  4 +-
 src/uncategorized/BackwardsCompatibility.tw |  4 ++
 src/uncategorized/neighborInteract.tw       | 70 +++++++++++----------
 6 files changed, 63 insertions(+), 40 deletions(-)

diff --git a/src/js/SlaveState.js b/src/js/SlaveState.js
index 6495168e52c..75d6d6f5337 100644
--- a/src/js/SlaveState.js
+++ b/src/js/SlaveState.js
@@ -2402,4 +2402,4 @@ App.Entity.SlaveState = class SlaveState {
  * @callback slaveTestCallback
  * @param {App.Entity.SlaveState} slave
  * @returns {boolean}
- */
+ */
\ No newline at end of file
diff --git a/src/js/assignJS.js b/src/js/assignJS.js
index 9fbd943c18f..94f7c847c9c 100644
--- a/src/js/assignJS.js
+++ b/src/js/assignJS.js
@@ -289,6 +289,8 @@ window.assignJob = function assignJob(slave, job) {
 			WombCleanGenericReserve(slave, 'nursery', 9999);
 			if (job === "be your agent") {
 				V.leaders.push(slave);
+				App.activeArcology().leaderID = slave.ID;
+				App.activeArcology().government = "your agent";
 			}
 			break;
 
@@ -487,6 +489,10 @@ window.removeJob = function removeJob(slave, assignment) {
 
 			case "be your agent":
 			case "live with your agent":
+				if (slave.assignment === "be your agent") {
+					App.activeArcology().leaderID = 0;
+					App.activeArcology().government = "your trustees";
+				}
 				slave.assignment = "rest";
 				V.leaders.deleteWith(s => s.ID === slave.ID);
 				if (slave.relationshipTarget > 0) {
@@ -654,3 +660,16 @@ App.UI.SlaveInteract = {
 		return res;
 	}
 };
+
+App.activeArcology = function() {
+	const V = State.variables;
+	return V.arcologies[V.activeArcologyIdx];
+}
+App.currentAgent = function() {
+	const V = State.variables, T = State.temporary;
+	for (let j = 0; j < V.leaders.length; j++) {
+		if (V.arcologies[T.currentNeighbor].leaderID == V.leaders[j].ID) {
+			T.Agent = V.leaders[j];
+		}
+	}
+}
\ No newline at end of file
diff --git a/src/npc/agent/agentRetrieve.tw b/src/npc/agent/agentRetrieve.tw
index f0ce24aaef9..80b38107192 100644
--- a/src/npc/agent/agentRetrieve.tw
+++ b/src/npc/agent/agentRetrieve.tw
@@ -1,12 +1,10 @@
 :: Agent Retrieve [silently]
 
-<<set _ID = $activeArcology.leaderID>>
+<<set _ID = App.activeArcology().leaderID>>
 
 <<set _i = $slaveIndices[_ID]>>
 <<if def _i>>
 	<<= removeJob($slaves[_i], "be your agent")>>
 <</if>>
 
-<<set $activeArcology.leaderID = 0, $activeArcology.government = "your trustees">>
-
 <<goto "Neighbor Interact">>
diff --git a/src/npc/agent/agentWorkaround.tw b/src/npc/agent/agentWorkaround.tw
index 91a2df7a4c3..464ce48be91 100644
--- a/src/npc/agent/agentWorkaround.tw
+++ b/src/npc/agent/agentWorkaround.tw
@@ -1,6 +1,6 @@
 :: Agent Workaround [nobr]
 
-<<set $nextButton = "Continue", $nextLink = "Neighbor Interact", _ID = $slaves[$i].ID>>
+<<set $nextButton = "Continue", $nextLink = "Neighbor Interact">>
 
 <<= assignJob($slaves[$i], "be your agent")>>
 
@@ -27,8 +27,6 @@
 	<<set $slaves[$i].relationship = 0, $slaves[$i].relationshipTarget = 0>>
 <</if>>
 
-<<set $activeArcology.leaderID = _ID, $activeArcology.government = "your agent">>
-
 <<set $desc = SlaveTitle($slaves[$i])>>
 <<setLocalPronouns $slaves[$i]>>
 
diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw
index 19ec895146c..b13dd6261b1 100644
--- a/src/uncategorized/BackwardsCompatibility.tw
+++ b/src/uncategorized/BackwardsCompatibility.tw
@@ -3859,6 +3859,10 @@ Done<br>
 	<<set $releaseID = App.Version.release>>
 <</if>>
 
+<<if def $activeArcology>>
+	<<unset $activeArcology>>
+<</if>>
+
 <<set $HackingSkillMultiplier = HackingSkillMultiplier()>>
 <<set $upgradeMultiplierArcology = upgradeMultiplierArcology()>>
 <<set $upgradeMultiplierMedicine = upgradeMultiplierMedicine()>>
diff --git a/src/uncategorized/neighborInteract.tw b/src/uncategorized/neighborInteract.tw
index fde9c6363dd..431c8edf09c 100644
--- a/src/uncategorized/neighborInteract.tw
+++ b/src/uncategorized/neighborInteract.tw
@@ -176,6 +176,7 @@ You have <<print $arcologies.length-1>> neighbors. <br><br>
 <span id="Security">
 <<for _currentNeighbor = 1; _currentNeighbor < $arcologies.length; _currentNeighbor++>>
 <<capture _currentNeighbor>>
+	<<= App.currentAgent()>>
 	<<set $arcologies[_currentNeighbor].prosperity = Math.clamp($arcologies[_currentNeighbor].prosperity, 1, 300)>>
 	<br>You own $arcologies[_currentNeighbor].PCminority% of 
 	<<link "$arcologies[_currentNeighbor].name">>
@@ -250,41 +251,38 @@ You have <<print $arcologies.length-1>> neighbors. <br><br>
 			<</if>>
 		<</if>>
 
-	<<if ($arcologies[_currentNeighbor].government == "your trustees") || ($arcologies[_currentNeighbor].government == "your agent")>> <br>
+	<<if $arcologies[_currentNeighbor].government == "your trustees" || $arcologies[_currentNeighbor].government == "your agent">>
+		<br><br>
 		<<if $arcologies[_currentNeighbor].government == "your trustees">>
-			<br>
-			[[Appoint an agent|Agent Select]]
-			<span id="rename"> | <<link "Instruct them to rename the arcology">><<replace #rename>> | <<textbox "$arcologies[_currentNeighbor].name" $arcologies[_currentNeighbor].name>> [[Confirm name|Neighbor Interact]]<</replace>><</link>></span>
+			 <<set $activeArcologyIdx = _currentNeighbor>>
+			[[Appoint an agent|Agent Select]] <<set $him = "them">>
 		<<else>>
-			<br>
-			<<for _j = 0; _j < $leaders.length; _j++>>
-				<<if $arcologies[_currentNeighbor].leaderID == $leaders[_j].ID>>
-					<<setLocalPronouns $leaders[_j]>>
-					Your agent @@.deeppink;<<= SlaveFullName($leaders[_j])>>@@ is running this arcology. [["Recall and reenslave " + $him|Agent Retrieve]]
-					<span id="rename"> | <<link "Instruct $him to rename the arcology">><<replace #rename>> | <<textbox "$arcologies[_currentNeighbor].name" $arcologies[_currentNeighbor].name>> [[Confirm name|Neighbor Interact]]<</replace>><</link>></span>
-					<br>$His <<if $leaders[_j].intelligence > 95>>brilliance<<else>>intelligence<</if>> and education are the most important qualities for $him.
-					<<if $leaders[_j].actualAge > 35>>
-						As with the Head Girl position, $his age and experience lend $him leadership weight.
-					<</if>>
-					<<if $leaders[_j].career == "an arcology owner">>
-						$His career as an arcology owner $himself is, obviously, useful to $him.
-					<<elseif setup.HGCareers.includes($leaders[_j].career)>>
-						$His career in leadership helps $him.
-					<</if>>
-					<<if $leaders[_j].fetishStrength > 95>>
-						<<if ($leaders[_j].fetish == "dom") || ($leaders[_j].fetish == "sadist")>>
-							$His sexually dominant fetish helps $him fill a leadership role.
-						<<elseif ($leaders[_j].fetish == "submissive") || ($leaders[_j].fetish == "masochist")>>
-							Unfortunately, $he has an inappropriate fetish for a leader.
-						<<else>>
-							$His sexual fetishes will influence how $he leads the arcology.
-						<</if>>
-					<</if>>
-					<<if $leaders[_j].energy > 95>>
-						Finally, $his sexual depravity lets $him fit into arcology society naturally.
-					<</if>>
+			<<setLocalPronouns _Agent>>
+			Your agent @@.deeppink;<<= SlaveFullName(_Agent)>>@@ is running this arcology. [["Recall and reenslave " + $him|Agent Retrieve]]
+		<</if>>
+		<span id="rename"> | <<link "Instruct $him to rename the arcology">><<replace #rename>> | <<textbox "$arcologies[$activeArcologyIdx].name" $arcologies[$activeArcologyIdx].name>> [[Confirm name|Neighbor Interact]]<</replace>><</link>></span>
+		<<if $arcologies[_currentNeighbor].government === "your agent">>
+			<br>$His <<if _Agent.intelligence > 95>>brilliance<<else>>intelligence<</if>> and education are the most important qualities for $him.
+			<<if _Agent.actualAge > 35>>
+				As with the Head Girl position, $his age and experience lend $him leadership weight.
+			<</if>>
+			<<if _Agent.career == "an arcology owner">>
+				$His career as an arcology owner $himself is, obviously, useful to $him.
+			<<elseif setup.HGCareers.includes(_Agent.career)>>
+				$His career in leadership helps $him.
+			<</if>>
+			<<if _Agent.fetishStrength > 95>>
+				<<if (_Agent.fetish == "dom") || (_Agent.fetish == "sadist")>>
+					$His sexually dominant fetish helps $him fill a leadership role.
+				<<elseif (_Agent.fetish == "submissive") || (_Agent.fetish == "masochist")>>
+					Unfortunately, $he has an inappropriate fetish for a leader.
+				<<else>>
+					$His sexual fetishes will influence how $he leads the arcology.
 				<</if>>
-			<</for>>
+			<</if>>
+			<<if _Agent.energy > 95>>
+				Finally, $his sexual depravity lets $him fit into arcology society naturally.
+			<</if>>
 		<</if>>
 		<<if $arcologies[_currentNeighbor].FSSubjugationist != "unset">>
 			<br><<link "Force Abandonment of Racial Subjugation">><<set $arcologies[_currentNeighbor].FSSubjugationist = "unset">><<goto "Neighbor Interact">><</link>>
@@ -710,7 +708,13 @@ You have <<print $arcologies.length-1>> neighbors. <br><br>
 	<</if>>
 
 	<</replace>>
-	<</link>> with an estimated GSP of @@.yellowgreen;<<print cashFormat(Math.trunc((0.1*$arcologies[_currentNeighbor].prosperity*random(100-$economicUncertainty,100+$economicUncertainty))/100))>>m@@ and is ran by $arcologies[_currentNeighbor].government who own $arcologies[_currentNeighbor].ownership%.
+	<</link>>
+	with an estimated GSP of @@.yellowgreen;<<print cashFormat(Math.trunc((0.1*$arcologies[_currentNeighbor].prosperity*random(100-$economicUncertainty,100+$economicUncertainty))/100))>>m@@ and is ran by
+	<<if $arcologies[_currentNeighbor].government !== "your agent">>
+		$arcologies[_currentNeighbor].government who own $arcologies[_currentNeighbor].ownership%.
+	<<else>>
+	 your agent @@.deeppink;<<= SlaveFullName(_Agent)>>@@.
+	<</if>>
 <</capture>>
 <</for>>
 </span>
\ No newline at end of file
-- 
GitLab