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

Function setMaterialMaskFilter

plugins/buildingplan/buildingplan.cpp:810–867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808}
809
810static int setMaterialMaskFilter(lua_State *L) {
811 color_ostream *out = Lua::GetOutput(L);
812 if (!out)
813 out = &Core::getInstance().getConsole();
814 df::building_type type = (df::building_type)luaL_checkint(L, 1);
815 int16_t subtype = luaL_checkint(L, 2);
816 int32_t custom = luaL_checkint(L, 3);
817 int index = luaL_checkint(L, 4);
818 DEBUG(control,*out).print(
819 "entering setMaterialMaskFilter building_type={} subtype={} custom={} index={}\n",
820 ENUM_AS_STR(type), subtype, custom, index);
821 BuildingTypeKey key(type, subtype, custom);
822 auto &filters = get_item_filters(*out, key).getItemFilters();
823 if (index < 0 || filters.size() <= (size_t)index)
824 return 0;
825 uint32_t mask = 0;
826 vector<string> cats;
827 Lua::GetVector(L, cats, 5);
828 for (auto &cat : cats) {
829 if (cat == "stone")
830 mask |= stone_cat.whole;
831 else if (cat == "wood")
832 mask |= wood_cat.whole;
833 else if (cat == "metal")
834 mask |= metal_cat.whole;
835 else if (cat == "glass")
836 mask |= glass_cat.whole;
837 else if (cat == "gem")
838 mask |= gem_cat.whole;
839 else if (cat == "clay")
840 mask |= clay_cat.whole;
841 else if (cat == "cloth")
842 mask |= cloth_cat.whole;
843 else if (cat == "silk")
844 mask |= silk_cat.whole;
845 else if (cat == "yarn")
846 mask |= yarn_cat.whole;
847 }
848 DEBUG(control,*out).print(
849 "setting material mask filter for building_type={} subtype={} custom={} index={} to {:x}\n",
850 ENUM_AS_STR(type), subtype, custom, index, mask);
851 ItemFilter filter = filters[index];
852 filter.setMaterialMask(mask);
853 set<MaterialInfo> new_mats;
854 if (mask) {
855 // remove materials from the list that don't match the mask
856 const auto &mats = filter.getMaterials();
857 const df::dfhack_material_category mat_mask(mask);
858 for (auto & mat : mats) {
859 if (mat.matches(mat_mask))
860 new_mats.emplace(mat);
861 }
862 }
863 filter.setMaterials(new_mats);
864 get_item_filters(*out, key).setItemFilter(*out, filter, index);
865 Lua::CallLuaModuleFunction(*out, "plugins.buildingplan", "signal_reset");
866 return 0;
867}

Callers

nothing calls this directly

Calls 10

get_item_filtersFunction · 0.85
GetVectorFunction · 0.85
CallLuaModuleFunctionFunction · 0.85
setMaterialMaskMethod · 0.80
getMaterialsMethod · 0.80
setMaterialsMethod · 0.80
setItemFilterMethod · 0.80
printMethod · 0.45
sizeMethod · 0.45
matchesMethod · 0.45

Tested by

no test coverage detected