| 955 | } |
| 956 | |
| 957 | static int getMaterialFilter(lua_State *L) { |
| 958 | color_ostream *out = Lua::GetOutput(L); |
| 959 | if (!out) |
| 960 | out = &Core::getInstance().getConsole(); |
| 961 | df::building_type type = (df::building_type)luaL_checkint(L, 1); |
| 962 | int16_t subtype = luaL_checkint(L, 2); |
| 963 | int32_t custom = luaL_checkint(L, 3); |
| 964 | int index = luaL_checkint(L, 4); |
| 965 | DEBUG(control,*out).print( |
| 966 | "entering getMaterialFilter building_type={} subtype={} custom={} index={}\n", |
| 967 | ENUM_AS_STR(type), subtype, custom, index); |
| 968 | BuildingTypeKey key(type, subtype, custom); |
| 969 | auto &filters = get_item_filters(*out, key).getItemFilters(); |
| 970 | if (index < 0 || filters.size() <= (size_t)index) |
| 971 | return 0; |
| 972 | const auto &mat_filter = filters[index].getMaterials(); |
| 973 | map<MaterialInfo, int32_t> counts; |
| 974 | scanAvailableItems(*out, type, subtype, custom, index, false, false, NULL, NULL, &counts); |
| 975 | HeatSafety heat = get_heat_safety_filter(key); |
| 976 | const df::job_item *jitem = get_job_items(*out, key)[index]; |
| 977 | // name -> {count=int, enabled=bool, category=string, heat=string} |
| 978 | map<string, map<string, string>> ret; |
| 979 | for (auto & entry : mat_cache) { |
| 980 | auto &mat = entry.second.first; |
| 981 | if (!mat.matches(jitem)) |
| 982 | continue; |
| 983 | if (!matchesHeatSafety(mat.type, mat.index, heat)) |
| 984 | continue; |
| 985 | string heat_safety = ""; |
| 986 | if (matchesHeatSafety(mat.type, mat.index, HEAT_SAFETY_MAGMA)) |
| 987 | heat_safety = "magma-safe"; |
| 988 | else if (matchesHeatSafety(mat.type, mat.index, HEAT_SAFETY_FIRE)) |
| 989 | heat_safety = "fire-safe"; |
| 990 | auto &name = entry.first; |
| 991 | auto &cat = entry.second.second; |
| 992 | map<string, string> props; |
| 993 | string count = "0"; |
| 994 | if (counts.count(mat)) |
| 995 | count = int_to_string(counts.at(mat)); |
| 996 | props.emplace("count", count); |
| 997 | props.emplace("enabled", (!mat_filter.size() || mat_filter.count(mat)) ? "true" : "false"); |
| 998 | props.emplace("category", cat); |
| 999 | ret.emplace(name, props); |
| 1000 | } |
| 1001 | Lua::Push(L, ret); |
| 1002 | return 1; |
| 1003 | } |
| 1004 | |
| 1005 | static void setChooseItems(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int choose) { |
| 1006 | DEBUG(control,out).print( |
nothing calls this directly
no test coverage detected