Skip to content

Commit

Permalink
add property filters for brewable, millable, and processable
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Feb 10, 2025
1 parent 57d850f commit 928f243
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Template for new versions:
## Misc Improvements
- `spectate`: player-set configuration is now stored globally instead of per-fort
- `autobutcher`: treat animals on restraints as unavailable for slaughter
- `stockpiles`: add property filters for brewable, millable, and processable organic materials

## Documentation
- `stonesense-art-guide`: new guide for making sprite art for Stonesense
Expand Down
6 changes: 6 additions & 0 deletions docs/plugins/stockpiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ Flags and subcategory prefixes::
paste/
pressed/

Properties::

brewable
millable
processable

Settings files::

preparedmeals
Expand Down
8 changes: 3 additions & 5 deletions plugins/stockpiles/OrganicMatLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ void OrganicMatLookup::food_mat_by_idx(color_ostream& out, organic_mat_category:
DEBUG(log, out).print("type(%d) index(%d) token(%s)\n", type, main_idx, food_mat.material.getToken().c_str());
}
}
std::string OrganicMatLookup::food_token_by_idx(color_ostream& out, organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx) {
FoodMat food_mat;
food_mat_by_idx(out, mat_category, idx, food_mat);
std::string OrganicMatLookup::food_token_by_idx(color_ostream& out, const FoodMat& food_mat) {
if (food_mat.material.isValid()) {
return food_mat.material.getToken();
}
Expand All @@ -62,11 +60,11 @@ void OrganicMatLookup::food_build_map() {
df::special_mat_table table = raws.mat_table;
using df::enums::organic_mat_category::organic_mat_category;
using traits = df::enum_traits<organic_mat_category>;
for (int32_t mat_category = traits::first_item_value; mat_category <= traits::last_item_value; ++mat_category) {
for (int32_t mat_category = 0; mat_category <= traits::last_item_value; ++mat_category) {
for (size_t i = 0; i < table.organic_indexes[mat_category].size(); ++i) {
int16_t type = table.organic_types[mat_category].at(i);
int32_t index = table.organic_indexes[mat_category].at(i);
food_index[mat_category].insert(std::make_pair(std::make_pair(type, index), i)); // wtf.. only in c++
food_index[mat_category].insert(std::make_pair(std::make_pair(type, index), i));
}
}
index_built = true;
Expand Down
2 changes: 1 addition & 1 deletion plugins/stockpiles/OrganicMatLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OrganicMatLookup {
};

static void food_mat_by_idx(DFHack::color_ostream& out, df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type food_idx, FoodMat& food_mat);
static std::string food_token_by_idx(DFHack::color_ostream& out, df::enums::organic_mat_category::organic_mat_category mat_category, std::vector<int16_t>::size_type idx);
static std::string food_token_by_idx(DFHack::color_ostream& out, const FoodMat& food_mat);

static size_t food_max_size(df::enums::organic_mat_category::organic_mat_category mat_category);
static void food_build_map();
Expand Down
31 changes: 27 additions & 4 deletions plugins/stockpiles/StockpileSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ static bool serialize_list_organic_mat(color_ostream& out, FuncWriteExport add_v
all = false;
continue;
}
string token = OrganicMatLookup::food_token_by_idx(out, cat, i);
OrganicMatLookup::FoodMat food_mat;
OrganicMatLookup::food_mat_by_idx(out, cat, i, food_mat);
string token = OrganicMatLookup::food_token_by_idx(out, food_mat);
if (token.empty()) {
DEBUG(log, out).print("food mat invalid :(\n");
continue;
Expand All @@ -460,15 +462,34 @@ static bool serialize_list_organic_mat(color_ostream& out, FuncWriteExport add_v
return all;
}

static string get_filter_string(color_ostream& out, const OrganicMatLookup::FoodMat& food_mat) {
auto str = OrganicMatLookup::food_token_by_idx(out, food_mat);
if (auto plant = food_mat.material.plant) {
if (plant->flags.is_set(df::plant_raw_flags::DRINK))
str += "/brewable";
if (plant->flags.is_set(df::plant_raw_flags::MILL))
str += "/millable";
if (auto mat = food_mat.material.material) {
if (mat->flags.is_set(df::material_flags::STRUCTURAL_PLANT_MAT) &&
(plant->flags.is_set(df::plant_raw_flags::THREAD) ||
plant->flags.is_set(df::plant_raw_flags::EXTRACT_VIAL) ||
plant->flags.is_set(df::plant_raw_flags::EXTRACT_BARREL)))
str += "/processable";
}
}
return str;
}

static void unserialize_list_organic_mat(color_ostream& out, const char* subcat, bool all, char val, const vector<string>& filters,
FuncReadImport read_value, size_t list_size, vector<char>& pile_list,
organic_mat_category::organic_mat_category cat) {
size_t num_elems = OrganicMatLookup::food_max_size(cat);
pile_list.resize(num_elems, '\0');
if (all) {
for (size_t idx = 0; idx < num_elems; ++idx) {
string token = OrganicMatLookup::food_token_by_idx(out, cat, idx);
set_filter_elem(out, subcat, filters, val, token, idx, pile_list.at(idx));
OrganicMatLookup::FoodMat food_mat;
OrganicMatLookup::food_mat_by_idx(out, cat, idx, food_mat);
set_filter_elem(out, subcat, filters, val, get_filter_string(out, food_mat), idx, pile_list.at(idx));
}
return;
}
Expand All @@ -480,7 +501,9 @@ static void unserialize_list_organic_mat(color_ostream& out, const char* subcat,
WARN(log, out).print("organic mat index too large! idx[%d] max_size[%zd]\n", idx, num_elems);
continue;
}
set_filter_elem(out, subcat, filters, val, token, idx, pile_list.at(idx));
OrganicMatLookup::FoodMat food_mat;
OrganicMatLookup::food_mat_by_idx(out, cat, idx, food_mat);
set_filter_elem(out, subcat, filters, val, get_filter_string(out, food_mat), idx, pile_list.at(idx));
}
}

Expand Down

0 comments on commit 928f243

Please sign in to comment.