MCPcopy Create free account
hub / github.com/DFHack/dfhack / assign_labor

Function assign_labor

plugins/autolabor/autolabor.cpp:488–711  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486
487
488static void assign_labor(unit_labor::unit_labor labor,
489 int n_dwarfs,
490 std::vector<dwarf_info_t>& dwarf_info,
491 bool trader_requested,
492 std::vector<df::unit *>& dwarfs,
493 bool has_butchers,
494 bool has_fishery,
495 color_ostream& out)
496{
497 df::job_skill skill = labor_to_skill[labor];
498
499 if (labor_infos[labor].mode() != AUTOMATIC)
500 return;
501
502 int best_skill = 0;
503
504 std::vector<int> values(n_dwarfs);
505 std::vector<int> candidates;
506 std::map<int, int> dwarf_skill;
507 std::map<int, int> dwarf_skillxp;
508 std::vector<bool> previously_enabled(n_dwarfs);
509
510 // Find candidate dwarfs, and calculate a preference value for each dwarf
511 for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
512 {
513 if (dwarf_info[dwarf].state == CHILD)
514 continue;
515 if (dwarf_info[dwarf].state == MILITARY)
516 continue;
517 if (dwarf_info[dwarf].trader && trader_requested)
518 continue;
519 if (dwarf_info[dwarf].diplomacy)
520 continue;
521
522 if (labor_infos[labor].is_exclusive && dwarf_info[dwarf].has_exclusive_labor)
523 continue;
524
525 int value = dwarf_info[dwarf].mastery_penalty;
526
527 if (skill != job_skill::NONE)
528 {
529 int skill_level = 0;
530 int skill_experience = 0;
531
532 for (auto s : dwarfs[dwarf]->status.souls[0]->skills)
533 {
534 if (s->id == skill)
535 {
536 skill_level = s->rating;
537 skill_experience = s->experience;
538 break;
539 }
540 }
541
542 dwarf_skill[dwarf] = skill_level;
543 dwarf_skillxp[dwarf] = skill_experience;
544
545 if (best_skill < skill_level)

Callers 1

Calls 10

sortFunction · 0.85
modeMethod · 0.80
talent_poolMethod · 0.80
minimum_dwarfsMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
resizeMethod · 0.45
maximum_dwarfsMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected