|
|
|
@ -674,13 +674,14 @@ static void scheduleCycle(color_ostream &out) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int scanAvailableItems(color_ostream &out, df::building_type type, int16_t subtype,
|
|
|
|
|
int32_t custom, int index, bool ignore_filters, vector<int> *item_ids = NULL,
|
|
|
|
|
map<MaterialInfo, int32_t> *counts = NULL) {
|
|
|
|
|
int32_t custom, int index, bool ignore_filters, bool ignore_quality, HeatSafety *heat_override = NULL,
|
|
|
|
|
vector<int> *item_ids = NULL, map<MaterialInfo, int32_t> *counts = NULL)
|
|
|
|
|
{
|
|
|
|
|
DEBUG(status,out).print(
|
|
|
|
|
"entering scanAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
|
|
|
|
|
type, subtype, custom, index);
|
|
|
|
|
BuildingTypeKey key(type, subtype, custom);
|
|
|
|
|
HeatSafety heat = get_heat_safety_filter(key);
|
|
|
|
|
HeatSafety heat = heat_override ? *heat_override : get_heat_safety_filter(key);
|
|
|
|
|
auto &job_items = get_job_items(out, key);
|
|
|
|
|
if (index < 0 || job_items.size() <= (size_t)index)
|
|
|
|
|
return 0;
|
|
|
|
@ -703,6 +704,10 @@ static int scanAvailableItems(color_ostream &out, df::building_type type, int16_
|
|
|
|
|
filter.setMaterials(set<MaterialInfo>());
|
|
|
|
|
special.clear();
|
|
|
|
|
}
|
|
|
|
|
if (ignore_quality) {
|
|
|
|
|
filter.setMinQuality(df::item_quality::Ordinary);
|
|
|
|
|
filter.setMaxQuality(df::item_quality::Artifact);
|
|
|
|
|
}
|
|
|
|
|
if (itemPassesScreen(out, item) && matchesFilters(item, jitem, heat, filter, special)) {
|
|
|
|
|
if (item_ids)
|
|
|
|
|
item_ids->emplace_back(item->id);
|
|
|
|
@ -732,7 +737,25 @@ static int getAvailableItems(lua_State *L) {
|
|
|
|
|
"entering getAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
|
|
|
|
|
type, subtype, custom, index);
|
|
|
|
|
vector<int> item_ids;
|
|
|
|
|
scanAvailableItems(*out, type, subtype, custom, index, true, &item_ids);
|
|
|
|
|
scanAvailableItems(*out, type, subtype, custom, index, true, false, NULL, &item_ids);
|
|
|
|
|
Lua::PushVector(L, item_ids);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int getAvailableItemsByHeat(lua_State *L) {
|
|
|
|
|
color_ostream *out = Lua::GetOutput(L);
|
|
|
|
|
if (!out)
|
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
|
df::building_type type = (df::building_type)luaL_checkint(L, 1);
|
|
|
|
|
int16_t subtype = luaL_checkint(L, 2);
|
|
|
|
|
int32_t custom = luaL_checkint(L, 3);
|
|
|
|
|
int index = luaL_checkint(L, 4);
|
|
|
|
|
HeatSafety heat = (HeatSafety)luaL_checkint(L, 5);
|
|
|
|
|
DEBUG(status,*out).print(
|
|
|
|
|
"entering getAvailableItemsByHeat building_type=%d subtype=%d custom=%d index=%d\n",
|
|
|
|
|
type, subtype, custom, index);
|
|
|
|
|
vector<int> item_ids;
|
|
|
|
|
scanAvailableItems(*out, type, subtype, custom, index, true, true, &heat, &item_ids);
|
|
|
|
|
Lua::PushVector(L, item_ids);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
@ -755,7 +778,7 @@ static int countAvailableItems(color_ostream &out, df::building_type type, int16
|
|
|
|
|
DEBUG(status,out).print(
|
|
|
|
|
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
|
|
|
|
|
type, subtype, custom, index);
|
|
|
|
|
int count = scanAvailableItems(out, type, subtype, custom, index, false);
|
|
|
|
|
int count = scanAvailableItems(out, type, subtype, custom, index, false, false);
|
|
|
|
|
if (count)
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
|
@ -968,7 +991,7 @@ static int getMaterialFilter(lua_State *L) {
|
|
|
|
|
return 0;
|
|
|
|
|
const auto &mat_filter = filters[index].getMaterials();
|
|
|
|
|
map<MaterialInfo, int32_t> counts;
|
|
|
|
|
scanAvailableItems(*out, type, subtype, custom, index, false, NULL, &counts);
|
|
|
|
|
scanAvailableItems(*out, type, subtype, custom, index, false, false, NULL, NULL, &counts);
|
|
|
|
|
HeatSafety heat = get_heat_safety_filter(key);
|
|
|
|
|
const df::job_item *jitem = get_job_items(*out, key)[index];
|
|
|
|
|
// name -> {count=int, enabled=bool, category=string, heat=string}
|
|
|
|
@ -1232,6 +1255,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
|
DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
|
DFHACK_LUA_COMMAND(getGlobalSettings),
|
|
|
|
|
DFHACK_LUA_COMMAND(getAvailableItems),
|
|
|
|
|
DFHACK_LUA_COMMAND(getAvailableItemsByHeat),
|
|
|
|
|
DFHACK_LUA_COMMAND(setMaterialMaskFilter),
|
|
|
|
|
DFHACK_LUA_COMMAND(getMaterialMaskFilter),
|
|
|
|
|
DFHACK_LUA_COMMAND(setMaterialFilter),
|
|
|
|
|