MCPcopy Create free account
hub / github.com/DFHack/dfhack / command_result plugin_onupdate

Function command_result plugin_onupdate

plugins/autolabor/autolabor.cpp:736–1055  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

734}
735
736DFhackCExport command_result plugin_onupdate ( color_ostream &out )
737{
738 if(!world || !world->map.block_index || !enable_autolabor)
739 {
740 return CR_OK;
741 }
742
743 if (world->frame_counter - cycle_timestamp <= CYCLE_TICKS)
744 return CR_OK;
745
746 cycle_timestamp = world->frame_counter;
747
748 std::vector<df::unit *> dwarfs;
749
750 bool has_butchers = false;
751 bool has_fishery = false;
752 bool trader_requested = false;
753
754 for (auto& build : world->buildings.all)
755 {
756 auto type = build->getType();
757 if (building_type::Workshop == type)
758 {
759 df::workshop_type subType = (df::workshop_type)build->getSubtype();
760 if (workshop_type::Butchers == subType)
761 has_butchers = true;
762 if (workshop_type::Fishery == subType)
763 has_fishery = true;
764 }
765 else if (building_type::TradeDepot == type)
766 {
767 df::building_tradedepotst* depot = (df::building_tradedepotst*) build;
768 trader_requested = trader_requested || depot->trade_flags.bits.trader_requested;
769 TRACE(cycle,out).print("{}", trader_requested
770 ? "Trade depot found and trader requested, trader will be excluded from all labors.\n"
771 : "Trade depot found but trader is not requested.\n"
772 );
773 }
774 }
775
776 for (auto& cre : world->units.active)
777 {
778 if (Units::isCitizen(cre))
779 {
780 if (cre->burrows.size() > 0)
781 continue; // dwarfs assigned to active burrows are skipped entirely
782 dwarfs.push_back(cre);
783 }
784 }
785
786 int n_dwarfs = dwarfs.size();
787
788 if (n_dwarfs == 0)
789 return CR_OK;
790
791 std::vector<dwarf_info_t> dwarf_info(n_dwarfs);
792
793 // Find total skill and highest skill for each dwarf. More skilled dwarves shouldn't be used for minor tasks.

Callers

nothing calls this directly

Calls 12

binsearch_in_vectorFunction · 0.85
sortFunction · 0.85
assign_laborFunction · 0.85
getTypeMethod · 0.80
modeMethod · 0.80
findFunction · 0.50
printMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected