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

Function autobutcher_cycle

plugins/autobutcher.cpp:679–747  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

677}
678
679static void autobutcher_cycle(color_ostream &out) {
680 // mark that we have recently run
681 cycle_timestamp = world->frame_counter;
682
683 DEBUG(cycle,out).print("running {} cycle\n", plugin_name);
684
685 // check if there is anything to watch before walking through units vector
686 if (!config.get_bool(CONFIG_AUTOWATCH)) {
687 bool watching = false;
688 for (auto w : watched_races) {
689 if (w.second->isWatched) {
690 watching = true;
691 break;
692 }
693 }
694 if (!watching)
695 return;
696 }
697
698 for (auto unit : world->units.active) {
699 // this check is now divided into two steps, squeezed autowatch into the middle
700 // first one ignores completely inappropriate units (dead, undead, not belonging to the fort, ...)
701 // then let autowatch add units to the watchlist which will probably start breeding (owned pets, war animals, ...)
702 // then process units counting those which can't be butchered (war animals, named pets, ...)
703 // so that they are treated as "own stock" as well and count towards the target quota
704 if (isInappropriateUnit(unit)
705 || Units::isMarkedForSlaughter(unit)
706 || !Units::isTame(unit))
707 continue;
708
709 WatchedRace *w;
710 if (watched_races.count(unit->race)) {
711 w = watched_races[unit->race];
712 }
713 else if (!config.get_bool(CONFIG_AUTOWATCH)) {
714 continue;
715 }
716 else {
717 w = new WatchedRace(out, unit->race, true, config.get_int(CONFIG_DEFAULT_FK),
718 config.get_int(CONFIG_DEFAULT_MK), config.get_int(CONFIG_DEFAULT_FA),
719 config.get_int(CONFIG_DEFAULT_MA));
720 w->UpdateConfig(out);
721 watched_races.emplace(unit->race, w);
722
723 INFO(cycle,out).print("New race added to autobutcher watchlist: {}\n",
724 Units::getRaceNamePluralById(unit->race));
725 }
726
727 if (w->isWatched) {
728 // don't butcher protected units, but count them as stock as well
729 // this way they count towards target quota, so if you order that you want 1 female adult cat
730 // and have 2 cats, one of them being a pet, the other gets butchered
731 if(isProtectedUnit(unit))
732 w->PushProtectedUnit(unit);
733 else
734 w->PushButcherableUnit(unit);
735 }
736 }

Callers 4

df_autobutcherFunction · 0.85
autowatch_setEnabledFunction · 0.85

Calls 9

isInappropriateUnitFunction · 0.85
isProtectedUnitFunction · 0.85
UpdateConfigMethod · 0.80
PushProtectedUnitMethod · 0.80
PushButcherableUnitMethod · 0.80
ProcessUnitsMethod · 0.80
printMethod · 0.45
countMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected