From 2d264843467da66eaa708a1a98824b8c669d1c45 Mon Sep 17 00:00:00 2001
From: Alaco <12716-Alaco@users.noreply.gitgud.io>
Date: Sat, 15 Mar 2025 19:41:42 +0000
Subject: [PATCH] Allow RA to return slaves to previous assignment

---
 src/js/DefaultRules.js          | 16 ++++++++++++++++
 src/js/rulesAssistantOptions.js |  1 +
 2 files changed, 17 insertions(+)

diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js
index 3dce8a687ba..c7b8fcecd6c 100644
--- a/src/js/DefaultRules.js
+++ b/src/js/DefaultRules.js
@@ -133,6 +133,22 @@ globalThis.DefaultRules = function(slave, options) {
 			delete rule.setAssignment;
 			return rule;
 		}
+
+		// RA uses "@prevAssignment" to indicate that the player wants the slave to return to their previous Assignment
+		// @ts-ignore - this comparison is intentional
+		if (rule.setAssignment === "@prevAssignment"){
+			// In these cases we can't auto re-assign the slave, either because we don't know which arcology the slave came from(AGENT jobs)
+			// or because the slave doesn't have a job to return to.
+			// We set the slaves assignment to REST since that is probably closer to what the player wanted
+			// rather than leaving the slave in their current assignment
+			if ([Job.AGENT, Job.AGENTPARTNER].includes(V.assignmentRecords[slave.ID]) || V.assignmentRecords[slave.ID] === undefined){
+				rule.setAssignment = Job.REST;
+			} else {
+				rule.setAssignment = V.assignmentRecords[slave.ID];
+			}
+		}
+
+
 		const job = App.Utils.jobForAssignment(rule.setAssignment);
 		if (job === undefined) {
 			r += `<span class="red">No job for assignment '${rule.setAssignment}'.</span>`;
diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js
index e15c6a715ac..f8be8f23157 100644
--- a/src/js/rulesAssistantOptions.js
+++ b/src/js/rulesAssistantOptions.js
@@ -4286,6 +4286,7 @@ App.RA.options = (function() {
 					items.push([f.manager.desc.position, f.manager.desc.assignment]);
 				}
 			}
+			items.push(["Previous Assignment", "@prevAssignment"]);
 
 			super("Automatically set assignment", items);
 			this.setValue(current_rule.set.setAssignment);
-- 
GitLab