Merge pull request #3086 from myk002/myk_buildingplan_no_filter_items

[buildingplan] allow player to choose any item when choosing items manually
develop
Myk 2023-03-25 12:55:37 -07:00 committed by GitHub
commit 8b7223d1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 47 deletions

@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `tailor`: now properly discriminates between dyed and undyed cloth, no longer defaults to using adamantine, and properly tracks material requirements for already queued orders - `tailor`: now properly discriminates between dyed and undyed cloth, no longer defaults to using adamantine, and properly tracks material requirements for already queued orders
## Misc Improvements ## Misc Improvements
- `buildingplan`: filters and global settings are now ignored when manually choosing items for a building
- `stockpiles`: support applying stockpile configurations with fully enabled categories to stockpiles in worlds other than the one where the configuration was exported from - `stockpiles`: support applying stockpile configurations with fully enabled categories to stockpiles in worlds other than the one where the configuration was exported from
- `stockpiles`: support partial application of a saved config based on dynamic filtering - `stockpiles`: support partial application of a saved config based on dynamic filtering
- `stockpiles`: additive and subtractive modes when applying a second stockpile configuration on top of a first - `stockpiles`: additive and subtractive modes when applying a second stockpile configuration on top of a first

@ -437,7 +437,7 @@ static string getBucket(const df::job_item & ji, const PlannedBuilding & pb, int
} }
// get a list of item vectors that we should search for matches // get a list of item vectors that we should search for matches
vector<df::job_item_vector_id> getVectorIds(color_ostream &out, const df::job_item *job_item) { vector<df::job_item_vector_id> getVectorIds(color_ostream &out, const df::job_item *job_item, bool ignore_filters) {
std::vector<df::job_item_vector_id> ret; std::vector<df::job_item_vector_id> ret;
// if the filter already has the vector_id set to something specific, use it // if the filter already has the vector_id set to something specific, use it
@ -453,13 +453,13 @@ vector<df::job_item_vector_id> getVectorIds(color_ostream &out, const df::job_it
// which vectors to search // which vectors to search
if (job_item->flags2.bits.building_material) if (job_item->flags2.bits.building_material)
{ {
if (get_config_bool(config, CONFIG_BLOCKS)) if (ignore_filters || get_config_bool(config, CONFIG_BLOCKS))
ret.push_back(df::job_item_vector_id::BLOCKS); ret.push_back(df::job_item_vector_id::BLOCKS);
if (get_config_bool(config, CONFIG_BOULDERS)) if (ignore_filters || get_config_bool(config, CONFIG_BOULDERS))
ret.push_back(df::job_item_vector_id::BOULDER); ret.push_back(df::job_item_vector_id::BOULDER);
if (get_config_bool(config, CONFIG_LOGS)) if (ignore_filters || get_config_bool(config, CONFIG_LOGS))
ret.push_back(df::job_item_vector_id::WOOD); ret.push_back(df::job_item_vector_id::WOOD);
if (get_config_bool(config, CONFIG_BARS)) if (ignore_filters || get_config_bool(config, CONFIG_BARS))
ret.push_back(df::job_item_vector_id::BAR); ret.push_back(df::job_item_vector_id::BAR);
} }
@ -641,7 +641,7 @@ static void scheduleCycle(color_ostream &out) {
} }
static int scanAvailableItems(color_ostream &out, df::building_type type, int16_t subtype, static int scanAvailableItems(color_ostream &out, df::building_type type, int16_t subtype,
int32_t custom, int index, vector<int> *item_ids = NULL, int32_t custom, int index, bool ignore_filters, vector<int> *item_ids = NULL,
map<MaterialInfo, int32_t> *counts = NULL) { map<MaterialInfo, int32_t> *counts = NULL) {
DEBUG(status,out).print( DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n", "entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
@ -656,7 +656,7 @@ static int scanAvailableItems(color_ostream &out, df::building_type type, int16_
auto &specials = item_filters.getSpecials(); auto &specials = item_filters.getSpecials();
auto &jitem = job_items[index]; auto &jitem = job_items[index];
auto vector_ids = getVectorIds(out, jitem); auto vector_ids = getVectorIds(out, jitem, ignore_filters);
int count = 0; int count = 0;
for (auto vector_id : vector_ids) { for (auto vector_id : vector_ids) {
@ -668,7 +668,8 @@ static int scanAvailableItems(color_ostream &out, df::building_type type, int16_
filter.setMaterialMask(0); filter.setMaterialMask(0);
filter.setMaterials(set<MaterialInfo>()); filter.setMaterials(set<MaterialInfo>());
} }
if (itemPassesScreen(item) && matchesFilters(item, jitem, heat, filter, specials)) { if (itemPassesScreen(item) &&
(ignore_filters || matchesFilters(item, jitem, heat, filter, specials))) {
if (item_ids) if (item_ids)
item_ids->emplace_back(item->id); item_ids->emplace_back(item->id);
if (counts) { if (counts) {
@ -697,7 +698,7 @@ static int getAvailableItems(lua_State *L) {
"entering getAvailableItems building_type=%d subtype=%d custom=%d index=%d\n", "entering getAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
type, subtype, custom, index); type, subtype, custom, index);
vector<int> item_ids; vector<int> item_ids;
scanAvailableItems(*out, type, subtype, custom, index, &item_ids); scanAvailableItems(*out, type, subtype, custom, index, true, &item_ids);
Lua::PushVector(L, item_ids); Lua::PushVector(L, item_ids);
return 1; return 1;
} }
@ -720,7 +721,7 @@ static int countAvailableItems(color_ostream &out, df::building_type type, int16
DEBUG(status,out).print( DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n", "entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
type, subtype, custom, index); type, subtype, custom, index);
return scanAvailableItems(out, type, subtype, custom, index); return scanAvailableItems(out, type, subtype, custom, index, false);
} }
static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) { static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
@ -888,7 +889,7 @@ static int getMaterialFilter(lua_State *L) {
return 0; return 0;
const auto &mat_filter = filters[index].getMaterials(); const auto &mat_filter = filters[index].getMaterials();
map<MaterialInfo, int32_t> counts; map<MaterialInfo, int32_t> counts;
scanAvailableItems(*out, type, subtype, custom, index, NULL, &counts); scanAvailableItems(*out, type, subtype, custom, index, false, NULL, &counts);
HeatSafety heat = get_heat_safety_filter(key); HeatSafety heat = get_heat_safety_filter(key);
df::job_item jitem_cur_heat = getJobItemWithHeatSafety( df::job_item jitem_cur_heat = getJobItemWithHeatSafety(
get_job_items(*out, key)[index], heat); get_job_items(*out, key)[index], heat);

@ -47,7 +47,7 @@ bool get_config_bool(DFHack::PersistentDataItem &c, int index);
void set_config_val(DFHack::PersistentDataItem &c, int index, int value); void set_config_val(DFHack::PersistentDataItem &c, int index, int value);
void set_config_bool(DFHack::PersistentDataItem &c, int index, bool value); 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); std::vector<df::job_item_vector_id> getVectorIds(DFHack::color_ostream &out, const df::job_item *job_item, bool ignore_filters);
bool itemPassesScreen(df::item * item); bool itemPassesScreen(df::item * item);
df::job_item getJobItemWithHeatSafety(const df::job_item *job_item, HeatSafety heat); 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, const std::set<std::string> &special); bool matchesFilters(df::item * item, const df::job_item * job_item, HeatSafety heat, const ItemFilter &item_filter, const std::set<std::string> &special);

@ -29,7 +29,7 @@ static vector<vector<df::job_item_vector_id>> get_vector_ids(color_ostream &out,
auto &jitems = bld->jobs[0]->job_items; auto &jitems = bld->jobs[0]->job_items;
int num_job_items = (int)jitems.size(); int num_job_items = (int)jitems.size();
for (int jitem_idx = num_job_items - 1; jitem_idx >= 0; --jitem_idx) { for (int jitem_idx = num_job_items - 1; jitem_idx >= 0; --jitem_idx) {
ret.emplace_back(getVectorIds(out, jitems[jitem_idx])); ret.emplace_back(getVectorIds(out, jitems[jitem_idx], false));
} }
return ret; return ret;
} }

@ -496,13 +496,6 @@ function PlannerOverlay:init()
options={{label='Yes', value=true}, options={{label='Yes', value=true},
{label='No', value=false}}, {label='No', value=false}},
initial_option=false, initial_option=false,
enabled=function()
for idx = 1,4 do
if (self.subviews['item'..idx].available or 0) > 0 then
return true
end
end
end,
on_change=function(choose) on_change=function(choose)
buildingplan.setChooseItems(uibs.building_type, uibs.building_subtype, uibs.custom_type, choose) buildingplan.setChooseItems(uibs.building_type, uibs.building_subtype, uibs.custom_type, choose)
end, end,
@ -678,7 +671,7 @@ function PlannerOverlay:onInput(keys)
local filters = get_cur_filters() local filters = get_cur_filters()
local num_filters = #filters local num_filters = #filters
local choose = self.subviews.choose local choose = self.subviews.choose
if choose.enabled() and choose:getOptionValue() then if choose:getOptionValue() then
local bounds = get_selected_bounds() local bounds = get_selected_bounds()
self:save_placement() self:save_placement()
local is_hollow = self.subviews.hollow:getOptionValue() local is_hollow = self.subviews.hollow:getOptionValue()
@ -687,33 +680,29 @@ function PlannerOverlay:onInput(keys)
df.global.game.main_interface.bottom_mode_selected = -1 df.global.game.main_interface.bottom_mode_selected = -1
for idx = num_filters,1,-1 do for idx = num_filters,1,-1 do
chosen_items[idx] = {} chosen_items[idx] = {}
if (self.subviews['item'..idx].available or 0) > 0 then local filter = filters[idx]
local filter = filters[idx] active_screens[idx] = itemselection.ItemSelectionScreen{
active_screens[idx] = itemselection.ItemSelectionScreen{ index=idx,
index=idx, desc=require('plugins.buildingplan').get_desc(filter),
desc=require('plugins.buildingplan').get_desc(filter), quantity=get_quantity(filter, is_hollow, bounds),
quantity=get_quantity(filter, is_hollow, bounds), on_submit=function(items)
on_submit=function(items) chosen_items[idx] = items
chosen_items[idx] = items active_screens[idx]:dismiss()
active_screens[idx]:dismiss() active_screens[idx] = nil
active_screens[idx] = nil pending = pending - 1
pending = pending - 1 if pending == 0 then
if pending == 0 then
df.global.game.main_interface.bottom_mode_selected = df.main_bottom_mode_type.BUILDING_PLACEMENT
self:place_building(self:restore_placement(), chosen_items)
end
end,
on_cancel=function()
for i,scr in pairs(active_screens) do
scr:dismiss()
end
df.global.game.main_interface.bottom_mode_selected = df.main_bottom_mode_type.BUILDING_PLACEMENT df.global.game.main_interface.bottom_mode_selected = df.main_bottom_mode_type.BUILDING_PLACEMENT
self:restore_placement() self:place_building(self:restore_placement(), chosen_items)
end, end
}:show() end,
else on_cancel=function()
pending = pending - 1 for i,scr in pairs(active_screens) do
end scr:dismiss()
end
df.global.game.main_interface.bottom_mode_selected = df.main_bottom_mode_type.BUILDING_PLACEMENT
self:restore_placement()
end,
}:show()
end end
else else
self:place_building(get_placement_data()) self:place_building(get_placement_data())