Skip to content

Commit

Permalink
Fix for 1.1 job pooling - queued jobs would be null and break things.
Browse files Browse the repository at this point in the history
  • Loading branch information
alextd committed Jun 29, 2020
1 parent bcb3290 commit 5c3edfa
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Source/JobDriver_GearUpAndGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,25 @@ protected override IEnumerable<Toil> MakeNewToils()
job.exitMapOnArrival = true; // I guess
}

//preserve the queue
List<QueuedJob> queue = pawn.Drafted ? new List<QueuedJob>() : new List<QueuedJob>(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<QueuedJob> queue = new List<QueuedJob>();
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);
}
Expand Down

0 comments on commit 5c3edfa

Please sign in to comment.