From 682e9d3a86a058d3f768be2aaa201fb3654ef14e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 15 Oct 2023 14:03:31 -0700 Subject: [PATCH] filter cages by whether they are occupied --- docs/changelog.txt | 1 + plugins/buildingplan/buildingplan_cycle.cpp | 5 +++++ plugins/lua/buildingplan/planneroverlay.lua | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ee61d6dd6..2bb24e361 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -74,6 +74,7 @@ Template for new versions: - `orders`: ``recheck`` command now only resets orders that have conditions that can be rechecked - `sort`: added help button for squad assignment search/filter/sort - `zone`: animals trained for war or hunting are now labeled as such in animal assignment screens +- `buildingplan`: support filtering cages by whether they are occupied ## Documentation - unavailable tools are no longer listed in the tag indices in the online docs diff --git a/plugins/buildingplan/buildingplan_cycle.cpp b/plugins/buildingplan/buildingplan_cycle.cpp index c6e0fbc9a..6dd69e095 100644 --- a/plugins/buildingplan/buildingplan_cycle.cpp +++ b/plugins/buildingplan/buildingplan_cycle.cpp @@ -119,6 +119,11 @@ bool matchesFilters(df::item * item, const df::job_item * jitem, HeatSafety heat && static_cast(item)->engraving_type != df::slab_engraving_type::Memorial) return false; + if (item->getType() == df::item_type::CAGE && specials.count("empty") + && (Items::getGeneralRef(item, df::general_ref_type::CONTAINS_UNIT) + || Items::getGeneralRef(item, df::general_ref_type::CONTAINS_ITEM))) + return false; + if (!matchesHeatSafety(item->getMaterial(), item->getMaterialIndex(), heat)) return false; diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index 2cc15dfde..bca1c7e0b 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -162,6 +162,10 @@ local function is_slab() return uibs.building_type == df.building_type.Slab end +local function is_cage() + return uibs.building_type == df.building_type.Cage +end + local function is_stairs() return is_construction() and uibs.building_subtype == df.construction_type.UpDownStair @@ -477,6 +481,16 @@ function PlannerOverlay:init() buildingplan.setSpecial(uibs.building_type, uibs.building_subtype, uibs.custom_type, 'engraved', val) end, }, + widgets.ToggleHotkeyLabel { + view_id='empty', + frame={b=4, l=1, w=22}, + key='CUSTOM_T', + label='Empty only:', + visible=is_cage, + on_change=function(val) + buildingplan.setSpecial(uibs.building_type, uibs.building_subtype, uibs.custom_type, 'empty', val) + end, + }, widgets.Label{ frame={b=4, l=23}, text_pen=COLOR_DARKGREY, @@ -847,6 +861,8 @@ function PlannerOverlay:onRenderFrame(dc, rect) local buildingplan = require('plugins.buildingplan') self.subviews.engraved:setOption(buildingplan.getSpecials( uibs.building_type, uibs.building_subtype, uibs.custom_type).engraved or false) + self.subviews.empty:setOption(buildingplan.getSpecials( + uibs.building_type, uibs.building_subtype, uibs.custom_type).empty or false) self.subviews.choose:setOption(buildingplan.getChooseItems( uibs.building_type, uibs.building_subtype, uibs.custom_type)) self.subviews.safety:setOption(buildingplan.getHeatSafetyFilter(