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

Function generate_control

plugins/autoclothing.cpp:688–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

686}
687
688static void generate_control(color_ostream &out) {
689 map<int, int> fullUnitList;
690 map<int, int> missingArmor;
691 map<int, int> missingShoes;
692 map<int, int> missingHelms;
693 map<int, int> missingGloves;
694 map<int, int> missingPants;
695
696 Units::forCitizens([&](auto unit) {
697 fullUnitList[unit->race]++;
698 int numArmor = 0, numShoes = 0, numHelms = 0, numGloves = 0, numPants = 0;
699 for (auto itemId : unit->owned_items)
700 {
701 auto item = Items::findItemByID(itemId);
702 if (!item) {
703 DEBUG(cycle, out).print("autoclothing: Invalid inventory item ID: {}\n", itemId);
704 continue;
705 }
706 else if (item->getWear() >= 1)
707 continue;
708 switch (item->getType())
709 {
710 case df::item_type::ARMOR:
711 numArmor++;
712 break;
713 case df::item_type::SHOES:
714 numShoes++;
715 break;
716 case df::item_type::HELM:
717 numHelms++;
718 break;
719 case df::item_type::GLOVES:
720 numGloves++;
721 break;
722 case df::item_type::PANTS:
723 numPants++;
724 break;
725 default:
726 break;
727 }
728 }
729 if (numArmor == 0)
730 missingArmor[unit->race]++;
731 if (numShoes < 2)
732 missingShoes[unit->race]++;
733 if (numHelms == 0)
734 missingHelms[unit->race]++;
735 if (numGloves < 2)
736 missingGloves[unit->race]++;
737 if (numPants == 0)
738 missingPants[unit->race]++;
739 DEBUG(control, out) << DF2CONSOLE(Units::getReadableName(unit)) <<
740 " has " << numArmor << " armor, " << numShoes << " shoes, " << numHelms <<
741 " helms, " << numGloves << " gloves, " << numPants << " pants" << endl;
742 });
743
744 if (missingArmor.empty() && missingShoes.empty() && missingHelms.empty() &&
745 missingGloves.empty() && missingPants.empty())

Callers 1

autoclothingFunction · 0.85

Calls 5

list_unit_countsFunction · 0.85
isAvailableItemFunction · 0.85
getTypeMethod · 0.80
printMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected