| 649 | } |
| 650 | |
| 651 | static ItemConstraint *get_constraint(color_ostream &out, const std::string &str, PersistentDataItem *cfg, bool create) |
| 652 | { |
| 653 | std::vector<std::string> tokens; |
| 654 | split_string(&tokens, str, "/"); |
| 655 | |
| 656 | if (tokens.size() > 4) |
| 657 | return NULL; |
| 658 | |
| 659 | int weight = 0; |
| 660 | |
| 661 | bool is_craft = false; |
| 662 | ItemTypeInfo item; |
| 663 | |
| 664 | if (tokens[0] == "ANY_CRAFT" || tokens[0] == "CRAFTS") { |
| 665 | is_craft = true; |
| 666 | } else if (!item.find(tokens[0]) || !item.isValid()) { |
| 667 | out.printerr("Cannot find item type: {}\n", tokens[0]); |
| 668 | return NULL; |
| 669 | } |
| 670 | |
| 671 | if (item.subtype >= 0) |
| 672 | weight += 10000; |
| 673 | |
| 674 | df::dfhack_material_category mat_mask; |
| 675 | std::string maskstr = vector_get(tokens,1); |
| 676 | if (!maskstr.empty() && !parseJobMaterialCategory(&mat_mask, maskstr)) { |
| 677 | out.printerr("Cannot decode material mask: {}\n", maskstr); |
| 678 | return NULL; |
| 679 | } |
| 680 | |
| 681 | if (mat_mask.whole != 0) |
| 682 | weight += 100; |
| 683 | |
| 684 | MaterialInfo material; |
| 685 | std::string matstr = vector_get(tokens,2); |
| 686 | if (!matstr.empty() && (!material.find(matstr) || !material.isValid())) { |
| 687 | out.printerr("Cannot find material: {}\n", matstr); |
| 688 | return NULL; |
| 689 | } |
| 690 | |
| 691 | if (material.type >= 0) |
| 692 | weight += (material.index >= 0 ? 5000 : 1000); |
| 693 | |
| 694 | if (mat_mask.whole && material.isValid() && !material.matches(mat_mask)) { |
| 695 | out.printerr("Material {} doesn't match mask {}\n", matstr, maskstr); |
| 696 | return NULL; |
| 697 | } |
| 698 | |
| 699 | item_quality::item_quality minqual = item_quality::Ordinary; |
| 700 | bool is_local = false; |
| 701 | std::string qualstr = vector_get(tokens, 3); |
| 702 | |
| 703 | if(!qualstr.empty()) |
| 704 | { |
| 705 | std::vector<std::string> qtokens; |
| 706 | split_string(&qtokens, qualstr, ","); |
| 707 | |
| 708 | for (size_t i = 0; i < qtokens.size(); i++) |
no test coverage detected