filter displayed materials if building heat safety is set

develop
Myk Taylor 2023-03-10 02:34:05 -08:00
parent 3d1ccd7df6
commit 6ad2922aca
No known key found for this signature in database
3 changed files with 28 additions and 8 deletions

@ -847,11 +847,25 @@ static int getMaterialFilter(lua_State *L) {
const auto &mat_filter = filters[index].getMaterials();
map<MaterialInfo, int32_t> counts;
scanAvailableItems(*out, type, subtype, custom, index, NULL, &counts);
// name -> {count=int, enabled=bool, category=string}
HeatSafety heat = get_heat_safety_filter(key);
df::job_item jitem_cur_heat = getJobItemWithHeatSafety(
get_job_items(*out, key)[index], heat);
df::job_item jitem_fire = getJobItemWithHeatSafety(
get_job_items(*out, key)[index], HEAT_SAFETY_FIRE);
df::job_item jitem_magma = getJobItemWithHeatSafety(
get_job_items(*out, key)[index], HEAT_SAFETY_MAGMA);
// name -> {count=int, enabled=bool, category=string, heat=string}
map<string, map<string, string>> ret;
for (auto & entry : mat_cache) {
auto &name = entry.first;
auto &mat = entry.second.first;
if (!mat.matches(jitem_cur_heat))
continue;
string heat_safety = "";
if (mat.matches(jitem_magma))
heat_safety = "magma-safe";
else if (mat.matches(jitem_fire))
heat_safety = "fire-safe";
auto &name = entry.first;
auto &cat = entry.second.second;
map<string, string> props;
string count = "0";

@ -47,6 +47,7 @@ void set_config_bool(DFHack::PersistentDataItem &c, int index, bool value);
std::vector<df::job_item_vector_id> getVectorIds(DFHack::color_ostream &out, const df::job_item *job_item);
bool itemPassesScreen(df::item * item);
df::job_item getJobItemWithHeatSafety(const df::job_item *job_item, HeatSafety heat);
bool matchesFilters(df::item * item, const df::job_item * job_item, HeatSafety heat, const ItemFilter &item_filter);
bool isJobReady(DFHack::color_ostream &out, const std::vector<df::job_item *> &jitems);
void finalizeBuilding(DFHack::color_ostream &out, df::building *bld);

@ -48,6 +48,16 @@ bool itemPassesScreen(df::item * item) {
&& !item->isAssignedToStockpile();
}
df::job_item getJobItemWithHeatSafety(const df::job_item *job_item, HeatSafety heat) {
df::job_item jitem = *job_item;
if (heat >= HEAT_SAFETY_MAGMA) {
jitem.flags2.bits.magma_safe = true;
jitem.flags2.bits.fire_safe = false;
} else if (heat == HEAT_SAFETY_FIRE && !jitem.flags2.bits.magma_safe)
jitem.flags2.bits.fire_safe = true;
return jitem;
}
bool matchesFilters(df::item * item, const df::job_item * job_item, HeatSafety heat, const ItemFilter &item_filter) {
// check the properties that are not checked by Job::isSuitableItem()
if (job_item->item_type > -1 && job_item->item_type != item->getType())
@ -67,12 +77,7 @@ bool matchesFilters(df::item * item, const df::job_item * job_item, HeatSafety h
&& !item->hasToolUse(job_item->has_tool_use))
return false;
df::job_item jitem = *job_item;
if (heat == HEAT_SAFETY_MAGMA) {
jitem.flags2.bits.magma_safe = true;
jitem.flags2.bits.fire_safe = false;
} else if (heat == HEAT_SAFETY_FIRE && !jitem.flags2.bits.magma_safe)
jitem.flags2.bits.fire_safe = true;
df::job_item jitem = getJobItemWithHeatSafety(job_item, heat);
return Job::isSuitableItem(
&jitem, item->getType(), item->getSubtype())