identify bars as non_economic items

allows Job::isSuitableMaterial() to match metal bars as a building
material
develop
myk002 2020-11-12 19:10:06 -08:00
parent 7958c1f9e3
commit 02a86d761a
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 15 additions and 9 deletions

@ -102,7 +102,7 @@ namespace DFHack
int filter_idx = -1, int insert_idx = -1);
DFHACK_EXPORT bool isSuitableItem(df::job_item *item, df::item_type itype, int isubtype);
DFHACK_EXPORT bool isSuitableMaterial(df::job_item *item, int mat_type, int mat_index);
DFHACK_EXPORT bool isSuitableMaterial(df::job_item *item, int mat_type, int mat_index, df::item_type itype = df::item_type::NONE);
DFHACK_EXPORT std::string getName(df::job *job);
}

@ -78,6 +78,7 @@ namespace DFHack
int16_t type;
int32_t index;
df::item_type itype;
df::material *material;
@ -98,7 +99,7 @@ namespace DFHack
df::historical_figure *figure;
public:
MaterialInfo(int16_t type = -1, int32_t index = -1) { decode(type, index); }
MaterialInfo(int16_t type = -1, int32_t index = -1, df::item_type itype = df::item_type::NONE) { decode(type, index, itype); }
MaterialInfo(const t_matpair &mp) { decode(mp.mat_type, mp.mat_index); }
template<class T> MaterialInfo(T *ptr) { decode(ptr); }
@ -113,7 +114,7 @@ namespace DFHack
bool isAnyInorganic() const { return type == 0; }
bool isInorganicWildcard() const { return isAnyInorganic() && isBuiltin(); }
bool decode(int16_t type, int32_t index = -1);
bool decode(int16_t type, int32_t index = -1, df::item_type itype = df::item_type::NONE);
bool decode(df::item *item);
bool decode(const df::material_vec_ref &vr, int idx);
bool decode(const t_matpair &mp) { return decode(mp.mat_type, mp.mat_index); }

@ -608,7 +608,8 @@ bool Job::isSuitableItem(df::job_item *item, df::item_type itype, int isubtype)
return iinfo.isValid() && iinfo.matches(*item, &minfo);
}
bool Job::isSuitableMaterial(df::job_item *item, int mat_type, int mat_index)
bool Job::isSuitableMaterial(
df::job_item *item, int mat_type, int mat_index, df::item_type itype)
{
CHECK_NULL_POINTER(item);
@ -616,7 +617,7 @@ bool Job::isSuitableMaterial(df::job_item *item, int mat_type, int mat_index)
return true;
ItemTypeInfo iinfo(item);
MaterialInfo minfo(mat_type, mat_index);
MaterialInfo minfo(mat_type, mat_index, itype);
return minfo.isValid() && iinfo.matches(*item, &minfo);
}

@ -75,7 +75,9 @@ bool MaterialInfo::decode(df::item *item)
if (!item)
return decode(-1);
else
return decode(item->getActualMaterial(), item->getActualMaterialIndex());
return decode(item->getActualMaterial(),
item->getActualMaterialIndex(),
item->getType());
}
bool MaterialInfo::decode(const df::material_vec_ref &vr, int idx)
@ -86,10 +88,11 @@ bool MaterialInfo::decode(const df::material_vec_ref &vr, int idx)
return decode(vr.mat_type[idx], vr.mat_index[idx]);
}
bool MaterialInfo::decode(int16_t type, int32_t index)
bool MaterialInfo::decode(int16_t type, int32_t index, df::item_type itype)
{
this->type = type;
this->index = index;
this->itype = itype;
material = NULL;
mode = Builtin; subtype = 0;
@ -513,7 +516,7 @@ void MaterialInfo::getMatchBits(df::job_item_flags2 &ok, df::job_item_flags2 &ma
TEST(fire_safe, material->heat.melting_point > 11000);
TEST(magma_safe, material->heat.melting_point > 12000);
TEST(deep_material, FLAG(inorganic, inorganic_flags::SPECIAL));
TEST(non_economic, !inorganic || !(ui && vector_get(ui->economic_stone, index)));
TEST(non_economic, !inorganic || !(ui && vector_get(ui->economic_stone, index)) || itype == df::item_type::BAR);
TEST(plant, plant);
TEST(silk, MAT_FLAG(SILK));

@ -825,7 +825,8 @@ static bool matchesFilters(df::item * item,
return DFHack::Job::isSuitableItem(
job_item, item->getType(), item->getSubtype())
&& DFHack::Job::isSuitableMaterial(
job_item, item->getMaterial(), item->getMaterialIndex())
job_item, item->getMaterial(), item->getMaterialIndex(),
item->getType())
&& item_filter.matches(item);
}