From 5c3edfa95f0b1e447ebf1aef1af8a8d47c95e745 Mon Sep 17 00:00:00 2001 From: Alex Tearse-Doyle Date: Sun, 28 Jun 2020 17:35:02 -0700 Subject: [PATCH] Fix for 1.1 job pooling - queued jobs would be null and break things. --- Source/JobDriver_GearUpAndGo.cs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/JobDriver_GearUpAndGo.cs b/Source/JobDriver_GearUpAndGo.cs index 73d4712..5b7a644 100644 --- a/Source/JobDriver_GearUpAndGo.cs +++ b/Source/JobDriver_GearUpAndGo.cs @@ -80,15 +80,25 @@ protected override IEnumerable MakeNewToils() job.exitMapOnArrival = true; // I guess } - //preserve the queue - List queue = pawn.Drafted ? new List() : new List(pawn.jobs.jobQueue); - - pawn.drafter.Drafted = true; - pawn.jobs.StartJob(job, JobCondition.Succeeded); - foreach (QueuedJob qj in queue) + if (!pawn.Drafted) { - pawn.jobs.jobQueue.EnqueueLast(qj.job, qj.tag); + //Drafting clears the job queue. We want to keep the queue. + //It'll also return jobs to the pool, and clear each job too. + //So extract each job and clear the queue manually, then re-queue them all. + + List queue = new List(); + while (pawn.jobs.jobQueue.Count > 0) + queue.Add(pawn.jobs.jobQueue.Dequeue()); + + pawn.drafter.Drafted = true; + + pawn.jobs.StartJob(job, JobCondition.Succeeded); + + foreach (QueuedJob qj in queue) + pawn.jobs.jobQueue.EnqueueLast(qj.job, qj.tag); } + else + pawn.jobs.StartJob(job, JobCondition.Succeeded); MoteMaker.MakeStaticMote(intVec, pawn.Map, ThingDefOf.Mote_FeedbackGoto, 1f); }