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

Function find_needed_clothing_items

plugins/autoclothing.cpp:534–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534static void find_needed_clothing_items() {
535 MaterialInfo matInfo;
536 Units::forCitizens([&](auto unit) {
537 // Now check each clothing order to see what the unit might be missing.
538 for (auto &clothingOrder : clothingOrders)
539 {
540 int alreadyOwnedAmount = 0;
541 // Looping through the items first, then clothing order might be a little faster, but this way is cleaner.
542 for (auto ownedItem : unit->owned_items)
543 {
544 auto item = Items::findItemByID(ownedItem);
545 if (!item) {
546 DEBUG(cycle).print("autoclothing: Invalid inventory item ID: {}\n", ownedItem);
547 continue;
548 }
549
550 if (item->getType() != clothingOrder.itemType ||
551 item->getSubtype() != clothingOrder.item_subtype ||
552 item->getWear() >= 1
553 )
554 continue;
555
556 matInfo.decode(item);
557 if (!matInfo.matches(clothingOrder.material_category))
558 continue;
559
560 alreadyOwnedAmount++;
561 }
562 int neededAmount = clothingOrder.needed_per_citizen - alreadyOwnedAmount;
563 if (neededAmount <= 0)
564 continue;
565 // Technically, there's some leeway in sizes, but only caring about exact sizes is simpler.
566 clothingOrder.total_needed_per_race[unit->race] += neededAmount;
567 }
568 });
569}
570
571static void remove_available_clothing() {
572 MaterialInfo matInfo;

Callers 1

do_autoclothingFunction · 0.85

Calls 4

getTypeMethod · 0.80
printMethod · 0.45
decodeMethod · 0.45
matchesMethod · 0.45

Tested by

no test coverage detected