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

Function scanAvailableItems

plugins/buildingplan/buildingplan.cpp:652–705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650}
651
652static int scanAvailableItems(color_ostream &out, df::building_type type, int16_t subtype,
653 int32_t custom, int index, bool ignore_filters, bool ignore_quality, HeatSafety *heat_override = NULL,
654 vector<int> *item_ids = NULL, map<MaterialInfo, int32_t> *counts = NULL)
655{
656 DEBUG(control,out).print(
657 "entering scanAvailableItems building_type={} subtype={} custom={} index={}\n",
658 ENUM_AS_STR(type), subtype, custom, index);
659 BuildingTypeKey key(type, subtype, custom);
660 HeatSafety heat = heat_override ? *heat_override : get_heat_safety_filter(key);
661 auto &job_items = get_job_items(out, key);
662 if (index < 0 || job_items.size() <= (size_t)index)
663 return 0;
664 auto &item_filters = get_item_filters(out, key);
665 auto &filters = item_filters.getItemFilters();
666 auto &specials = item_filters.getSpecials();
667
668 auto &jitem = job_items[index];
669 auto vector_ids = getVectorIds(out, jitem, ignore_filters);
670
671 ItemFilter filter = filters[index];
672 set<string> special = specials;
673 if (ignore_filters || counts) {
674 // don't filter by material; we want counts for all materials
675 filter.setMaterialMask(0);
676 filter.setMaterials(set<MaterialInfo>());
677 special.clear();
678 }
679 if (ignore_quality) {
680 filter.setMinQuality(df::item_quality::Ordinary);
681 filter.setMaxQuality(df::item_quality::Artifact);
682 }
683
684 update_walkability_groups(); // ensure that itemPassesScreen is accurate
685
686 int count = 0;
687 for (auto vector_id : vector_ids) {
688 auto other_id = ENUM_ATTR(job_item_vector_id, other, vector_id);
689 for (auto &item : df::global::world->items.other[other_id]) {
690 if (itemPassesScreen(out, item) && matchesFilters(item, jitem, heat, filter, special)) {
691 if (item_ids)
692 item_ids->emplace_back(item->id);
693 if (counts) {
694 MaterialInfo mi;
695 mi.decode(item);
696 (*counts)[mi]++;
697 }
698 ++count;
699 }
700 }
701 }
702
703 DEBUG(control,out).print("found matches {}\n", count);
704 return count;
705}
706
707static int getAvailableItems(lua_State *L) {
708 color_ostream *out = Lua::GetOutput(L);

Callers 4

getAvailableItemsFunction · 0.85
getAvailableItemsByHeatFunction · 0.85
countAvailableItemsFunction · 0.85
getMaterialFilterFunction · 0.85

Calls 14

get_heat_safety_filterFunction · 0.85
get_item_filtersFunction · 0.85
getVectorIdsFunction · 0.85
itemPassesScreenFunction · 0.85
matchesFiltersFunction · 0.85
setMaterialMaskMethod · 0.80
setMaterialsMethod · 0.80
setMinQualityMethod · 0.80
setMaxQualityMethod · 0.80
printMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected