Skip to content

Commit

Permalink
feat(village): Fill farmer job first
Browse files Browse the repository at this point in the history
When no farmers are assigned yet, but they could be, then assign a farmer first, regardless of other possibilities to fill jobs.
This might prevent some cases of death loops after resetting with suboptimal settings.

Relates to #15
  • Loading branch information
oliversalzburg committed Jan 7, 2023
1 parent 2f60841 commit b1c8e9f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/userscript/source/VillageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,16 @@ export class VillageManager implements Automation {
return;
}

// Check if we _could_ assign farmers _and_ currently don't have any assigned.
// The idea here is, don't assign any kittens into jobs without having filled
// that single open farmer position first. This might prevent kitten death in
// certain scenarios.
const noFarmersAssigned =
jobsNotCapped.find(job => job.job.name === "farmer" && job.count === 0) !== null;

// Find the job with the least kittens assigned and assign a kitten to that job.
jobsNotCapped.sort((a, b) => a.count - b.count);
const jobName = jobsNotCapped[0].job.name;
const jobName = noFarmersAssigned ? "farmer" : jobsNotCapped[0].job.name;

this._host.gamePage.village.assignJob(this._host.gamePage.village.getJob(jobName), 1);
this.manager.render();
Expand Down

0 comments on commit b1c8e9f

Please sign in to comment.