diff --git a/src/endWeek/slaveAssignmentReport.js b/src/endWeek/slaveAssignmentReport.js index ee8212872be6b032d346d3b2b83f4894b727e399..c9f614f9dc533bef60b1ea701aa5325ef881d6f2 100644 --- a/src/endWeek/slaveAssignmentReport.js +++ b/src/endWeek/slaveAssignmentReport.js @@ -747,6 +747,19 @@ App.EndWeek.slaveAssignmentReport = function() { slave.subTarget = 0; } } + break; + case Job.AGENT: + { + const arc = V.arcologies.find((a) => a.leaderID === slave.ID); + if (!arc) { + _printSlaveUnassignedNote(slave, "is not assigned to an arcology"); + removeJob(slave, Job.AGENT); + } else if (arc.government !== "your agent") { + _printSlaveUnassignedNote(slave, "is assigned to an arcology that is not lead by an agent"); + removeJob(slave, Job.AGENT); + } + break; + } } if (slave.ID === V.LurcherID) { diff --git a/src/js/assignJS.js b/src/js/assignJS.js index a79213523cab2231a372807a8bda25c85a24d73f..877f22a63ea4375592edd0af3a40e38f6a748ea7 100644 --- a/src/js/assignJS.js +++ b/src/js/assignJS.js @@ -388,8 +388,18 @@ globalThis.assignJob = function(slave, job) { WombCleanGenericReserve(slave, 'incubator', 9999); WombCleanGenericReserve(slave, 'nursery', 9999); if (job === Job.AGENT) { - App.activeArcology().leaderID = slave.ID; - App.activeArcology().government = "your agent"; + if (App.activeArcology().direction !== 0) { // never assign an agent to the player's arcology + if (App.activeArcology().leaderID !== 0) { + const oldAgent = getSlave(App.activeArcology().leaderID); + if (oldAgent && oldAgent.assignment === Job.AGENT) { + // this is an error...you should never be able to assign an agent over the top of another + // but in order to prevent game state corruption, we are going to remove the old agent + removeJob(oldAgent, oldAgent.assignment, false); + } + } + App.activeArcology().leaderID = slave.ID; + App.activeArcology().government = "your agent"; + } } break; @@ -436,6 +446,8 @@ globalThis.assignJobSafely = function(slave, assignmentStr) { if (V.assignmentRecords[slave.ID] === Job.CHOICE) { assignJob(slave, Job.REST); slave.choosesOwnAssignment = 1; + } else if ([Job.AGENT, Job.AGENTPARTNER].includes(V.assignmentRecords[slave.ID])) { // it is NEVER safe to auto-reassign agents (we don't know which arcology they came from) + assignJob(slave, Job.REST); } else if (!App.Utils.jobForAssignment(assignmentStr).canEmploy(slave).length) { // If nothing complains about job requirements not being met assignJob(slave, assignmentStr); } else { @@ -629,8 +641,10 @@ globalThis.removeJob = function(slave, assignment, saveRecord = false) { case Job.AGENTPARTNER: if (slave.assignment === Job.AGENT) { const arc = V.arcologies.find((a) => a.leaderID === slave.ID); - arc.leaderID = 0; - arc.government = "your trustees"; + if (arc) { + arc.leaderID = 0; + arc.government = "your trustees"; + } } slave.assignment = Job.REST; if (slave.relationshipTarget > 0) {