From 6ad2922aca5897991ac164ff37ce5669d963b8ab Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 10 Mar 2023 02:34:05 -0800 Subject: [PATCH] filter displayed materials if building heat safety is set --- plugins/buildingplan/buildingplan.cpp | 18 ++++++++++++++++-- plugins/buildingplan/buildingplan.h | 1 + plugins/buildingplan/buildingplan_cycle.cpp | 17 +++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index 2b67c2353..abc3c6ebd 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -847,11 +847,25 @@ static int getMaterialFilter(lua_State *L) { const auto &mat_filter = filters[index].getMaterials(); map 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> 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 props; string count = "0"; diff --git a/plugins/buildingplan/buildingplan.h b/plugins/buildingplan/buildingplan.h index eef9808e6..0d0d5b45f 100644 --- a/plugins/buildingplan/buildingplan.h +++ b/plugins/buildingplan/buildingplan.h @@ -47,6 +47,7 @@ void set_config_bool(DFHack::PersistentDataItem &c, int index, bool value); std::vector 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 &jitems); void finalizeBuilding(DFHack::color_ostream &out, df::building *bld); diff --git a/plugins/buildingplan/buildingplan_cycle.cpp b/plugins/buildingplan/buildingplan_cycle.cpp index f401c90a8..c08324e8a 100644 --- a/plugins/buildingplan/buildingplan_cycle.cpp +++ b/plugins/buildingplan/buildingplan_cycle.cpp @@ -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())