| 532 | } |
| 533 | |
| 534 | static 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 | |
| 571 | static void remove_available_clothing() { |
| 572 | MaterialInfo matInfo; |
no test coverage detected