From cbf63e532dc6175fce101edb5842893d61c0fa30 Mon Sep 17 00:00:00 2001
From: ezsh <ezsh.junk@gmail.com>
Date: Sun, 28 Apr 2019 14:39:12 +0200
Subject: [PATCH] Fix subordinate slave assignment from the slave list

The "Subordinate Targeting" operates with the activeSlave, so we have to
set it before going to the passage.

Closes #694.
---
 src/facilities/penthouse/penthouseFramework.js |  5 ++++-
 src/js/utilJS.js                               | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/facilities/penthouse/penthouseFramework.js b/src/facilities/penthouse/penthouseFramework.js
index 3b8102501b2..39e01630609 100644
--- a/src/facilities/penthouse/penthouseFramework.js
+++ b/src/facilities/penthouse/penthouseFramework.js
@@ -132,7 +132,10 @@ App.Entity.Facilities.PenthouseJobs = {
 		}
 
 		assignmentLink(i, passage, callback, linkText) {
-			return super.assignmentLink(i, "Subordinate Targeting", callback, linkText);
+			return super.assignmentLink(i, "Subordinate Targeting",
+				(assignment) => {
+					return `<<run App.Utils.setActiveSlaveByIndex(${i})>>` + (callback !== undefined ? callback(assignment) : '');
+				}, linkText);
 		}
 	},
 	Cow: class extends App.Entity.Facilities.PenthouseJob {
diff --git a/src/js/utilJS.js b/src/js/utilJS.js
index d3b1c291519..69e26e93bdc 100644
--- a/src/js/utilJS.js
+++ b/src/js/utilJS.js
@@ -2198,3 +2198,13 @@ App.Utils.slaveRefString = function(i) {
 App.Utils.slaveByIndex = function(i) {
 	return i === -1 ? State.variables.activeSlave : State.variables.slaves[i];
 };
+
+/**
+ * Sets active slave to the slave with the given index. Does nothing if index < 0
+ * @param {number} index
+ */
+App.Utils.setActiveSlaveByIndex = function(index) {
+	if (index >= 0) {
+		State.variables.activeSlave = State.variables.slaves[index];
+	}
+}
-- 
GitLab