use new default_item_filters structure

so vector references aren't to items on the stack
also don't let query mode swallow all input
develop
Myk Taylor 2020-10-04 23:53:42 -07:00
parent 4d7f4d80ad
commit 5087b6d2ae
3 changed files with 10 additions and 9 deletions

@ -439,7 +439,7 @@ void Planner::initialize()
void Planner::reset() void Planner::reset()
{ {
debug("resetting Planner state"); debug("resetting Planner state");
item_filters.clear(); default_item_filters.clear();
planned_buildings.clear(); planned_buildings.clear();
std::vector<PersistentDataItem> items; std::vector<PersistentDataItem> items;
@ -549,9 +549,9 @@ Planner::ItemFiltersWrapper Planner::getItemFilters(BuildingTypeKey key)
int nfilters = getNumFilters(key); int nfilters = getNumFilters(key);
if (nfilters < 1) if (nfilters < 1)
return empty_ret; return empty_ret;
std::vector<ItemFilter> ret; while (default_item_filters[key].size() < nfilters)
ret.push_back(item_filters[std::get<0>(key)]); default_item_filters[key].push_back(ItemFilter());
return ItemFiltersWrapper(ret); return ItemFiltersWrapper(default_item_filters[key]);
} }
void Planner::doCycle() void Planner::doCycle()

@ -119,7 +119,9 @@ public:
private: private:
std::map<df::building_type, df::item_type> item_for_building_type; std::map<df::building_type, df::item_type> item_for_building_type;
std::map<df::building_type, ItemFilter> item_filters; std::unordered_map<BuildingTypeKey,
std::vector<ItemFilter>,
BuildingTypeKeyHash> default_item_filters;
std::map<df::item_type, std::vector<df::item *>> available_item_vectors; std::map<df::item_type, std::vector<df::item *>> available_item_vectors;
std::map<df::item_type, bool> is_relevant_item_type; //Needed for fast check when looping over all items std::map<df::item_type, bool> is_relevant_item_type; //Needed for fast check when looping over all items
std::vector<PlannedBuilding> planned_buildings; std::vector<PlannedBuilding> planned_buildings;

@ -309,13 +309,12 @@ struct buildingplan_query_hook : public df::viewscreen_dwarfmodest
return true; // Don't unsuspend planned buildings return true; // Don't unsuspend planned buildings
if (input->count(interface_key::DESTROYBUILDING)) if (input->count(interface_key::DESTROYBUILDING))
{ {
// remove persistent data // remove persistent data and allow the parent to handle the key
// so the building is removed
planner.getPlannedBuilding(world->selected_building)->remove(); planner.getPlannedBuilding(world->selected_building)->remove();
// still allow the building to be removed
return false;
} }
return true; return false;
} }
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input)) DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))