|
|
@ -143,27 +143,48 @@ bool MaterialInfo::decode(int16_t type, int32_t index)
|
|
|
|
return (material != NULL);
|
|
|
|
return (material != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::find(const std::string &token, const std::string &subtoken)
|
|
|
|
bool MaterialInfo::find(const std::string &token)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (findBuiltin(token))
|
|
|
|
std::vector<std::string> items;
|
|
|
|
return true;
|
|
|
|
split_string(&items, token, ":");
|
|
|
|
if (subtoken.empty())
|
|
|
|
|
|
|
|
|
|
|
|
if (items[0] == "INORGANIC")
|
|
|
|
|
|
|
|
return findInorganic(vector_get(items,1));
|
|
|
|
|
|
|
|
if (items[0] == "CREATURE_MAT" || items[0] == "CREATURE")
|
|
|
|
|
|
|
|
return findCreature(vector_get(items,1), vector_get(items,2));
|
|
|
|
|
|
|
|
if (items[0] == "PLANT_MAT" || items[0] == "PLANT")
|
|
|
|
|
|
|
|
return findPlant(vector_get(items,1), vector_get(items,2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (items.size() == 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (findInorganic(token))
|
|
|
|
if (findBuiltin(items[0]))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (findInorganic(items[0]))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (findPlant(items[0], ""))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else if (items.size() == 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (findPlant(token, subtoken))
|
|
|
|
if (findPlant(items[0], items[1]))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
if (findCreature(token, subtoken))
|
|
|
|
if (findCreature(items[0], items[1]))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::findBuiltin(const std::string &token)
|
|
|
|
bool MaterialInfo::findBuiltin(const std::string &token)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
|
|
|
return decode(-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (token == "NONE") {
|
|
|
|
|
|
|
|
decode(-1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
for (int i = 1; i < NUM_BUILTIN; i++)
|
|
|
|
for (int i = 1; i < NUM_BUILTIN; i++)
|
|
|
|
if (raws.mat_table.builtin[i]->id == token)
|
|
|
|
if (raws.mat_table.builtin[i]->id == token)
|
|
|
@ -173,6 +194,14 @@ bool MaterialInfo::findBuiltin(const std::string &token)
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::findInorganic(const std::string &token)
|
|
|
|
bool MaterialInfo::findInorganic(const std::string &token)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
|
|
|
return decode(-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (token == "NONE") {
|
|
|
|
|
|
|
|
decode(0, -1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
for (unsigned i = 0; i < raws.inorganics.size(); i++)
|
|
|
|
for (unsigned i = 0; i < raws.inorganics.size(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -185,6 +214,8 @@ bool MaterialInfo::findInorganic(const std::string &token)
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::findPlant(const std::string &token, const std::string &subtoken)
|
|
|
|
bool MaterialInfo::findPlant(const std::string &token, const std::string &subtoken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
|
|
|
return decode(-1);
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
for (unsigned i = 0; i < raws.plants.all.size(); i++)
|
|
|
|
for (unsigned i = 0; i < raws.plants.all.size(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -192,6 +223,10 @@ bool MaterialInfo::findPlant(const std::string &token, const std::string &subtok
|
|
|
|
if (p->id != token)
|
|
|
|
if (p->id != token)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// As a special exception, return the structural material with empty subtoken
|
|
|
|
|
|
|
|
if (subtoken.empty())
|
|
|
|
|
|
|
|
return decode(p->material_defs.type_basic_mat, p->material_defs.idx_basic_mat);
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < p->material.size(); j++)
|
|
|
|
for (unsigned j = 0; j < p->material.size(); j++)
|
|
|
|
if (p->material[j]->id == subtoken)
|
|
|
|
if (p->material[j]->id == subtoken)
|
|
|
|
return decode(PLANT_BASE+j, i);
|
|
|
|
return decode(PLANT_BASE+j, i);
|
|
|
@ -203,6 +238,8 @@ bool MaterialInfo::findPlant(const std::string &token, const std::string &subtok
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::findCreature(const std::string &token, const std::string &subtoken)
|
|
|
|
bool MaterialInfo::findCreature(const std::string &token, const std::string &subtoken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (token.empty() || subtoken.empty())
|
|
|
|
|
|
|
|
return decode(-1);
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
df::world_raws &raws = df::global::world->raws;
|
|
|
|
for (unsigned i = 0; i < raws.creatures.all.size(); i++)
|
|
|
|
for (unsigned i = 0; i < raws.creatures.all.size(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -298,7 +335,7 @@ bool MaterialInfo::matches(const df::job_material_category &cat)
|
|
|
|
|
|
|
|
|
|
|
|
bool MaterialInfo::matches(const df::job_item &item)
|
|
|
|
bool MaterialInfo::matches(const df::job_item &item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isValid()) return false;
|
|
|
|
if (!isValid()) return true;
|
|
|
|
|
|
|
|
|
|
|
|
df::job_item_flags1 ok1, mask1;
|
|
|
|
df::job_item_flags1 ok1, mask1;
|
|
|
|
getMatchBits(ok1, mask1);
|
|
|
|
getMatchBits(ok1, mask1);
|
|
|
@ -309,9 +346,9 @@ bool MaterialInfo::matches(const df::job_item &item)
|
|
|
|
df::job_item_flags3 ok3, mask3;
|
|
|
|
df::job_item_flags3 ok3, mask3;
|
|
|
|
getMatchBits(ok3, mask3);
|
|
|
|
getMatchBits(ok3, mask3);
|
|
|
|
|
|
|
|
|
|
|
|
return ((item.flags1.whole & mask1.whole) == (item.flags1.whole & ok1.whole)) &&
|
|
|
|
return bits_match(item.flags1.whole, ok1.whole, mask1.whole) &&
|
|
|
|
((item.flags2.whole & mask2.whole) == (item.flags2.whole & ok2.whole)) &&
|
|
|
|
bits_match(item.flags2.whole, ok2.whole, mask2.whole) &&
|
|
|
|
((item.flags3.whole & mask3.whole) == (item.flags3.whole & ok3.whole));
|
|
|
|
bits_match(item.flags3.whole, ok3.whole, mask3.whole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &mask)
|
|
|
|
void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &mask)
|
|
|
@ -330,7 +367,7 @@ void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &ma
|
|
|
|
TEST(sharpenable, MAT_FLAG(IS_STONE));
|
|
|
|
TEST(sharpenable, MAT_FLAG(IS_STONE));
|
|
|
|
TEST(distillable, structural && FLAG(plant, plant_raw_flags::DRINK));
|
|
|
|
TEST(distillable, structural && FLAG(plant, plant_raw_flags::DRINK));
|
|
|
|
TEST(processable, structural && FLAG(plant, plant_raw_flags::THREAD));
|
|
|
|
TEST(processable, structural && FLAG(plant, plant_raw_flags::THREAD));
|
|
|
|
TEST(bag, isAnyCloth());
|
|
|
|
TEST(bag, isAnyCloth() || MAT_FLAG(LEATHER));
|
|
|
|
TEST(cookable, MAT_FLAG(EDIBLE_COOKED));
|
|
|
|
TEST(cookable, MAT_FLAG(EDIBLE_COOKED));
|
|
|
|
TEST(extract_bearing_plant, structural && FLAG(plant, plant_raw_flags::EXTRACT_STILL_VIAL));
|
|
|
|
TEST(extract_bearing_plant, structural && FLAG(plant, plant_raw_flags::EXTRACT_STILL_VIAL));
|
|
|
|
TEST(extract_bearing_fish, false);
|
|
|
|
TEST(extract_bearing_fish, false);
|
|
|
@ -344,7 +381,7 @@ void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &ma
|
|
|
|
MAT_FLAG(LIQUID_MISC_CREATURE) ||
|
|
|
|
MAT_FLAG(LIQUID_MISC_CREATURE) ||
|
|
|
|
MAT_FLAG(LIQUID_MISC_OTHER)));
|
|
|
|
MAT_FLAG(LIQUID_MISC_OTHER)));
|
|
|
|
TEST(tameable_vermin, false);
|
|
|
|
TEST(tameable_vermin, false);
|
|
|
|
TEST(sharpenable, MAT_FLAG(IS_GLASS));
|
|
|
|
TEST(sharpenable, MAT_FLAG(IS_STONE));
|
|
|
|
TEST(milk, linear_index(material->reaction_product.id, std::string("CHEESE_MAT")) >= 0);
|
|
|
|
TEST(milk, linear_index(material->reaction_product.id, std::string("CHEESE_MAT")) >= 0);
|
|
|
|
//04000000 - "milkable" - vtable[107],1,1
|
|
|
|
//04000000 - "milkable" - vtable[107],1,1
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -393,6 +430,25 @@ void MaterialInfo::getMatchBits(df::job_item_flags3 &ok, df::job_item_flags3 &ma
|
|
|
|
#undef FLAG
|
|
|
|
#undef FLAG
|
|
|
|
#undef TEST
|
|
|
|
#undef TEST
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DFHack::parseJobMaterialCategory(df::job_material_category *cat, const std::string &token)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cat->whole = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> items;
|
|
|
|
|
|
|
|
split_string(&items, toLower(token), ",", true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < items.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int id = findBitfieldField(*cat, items[i]);
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cat->whole |= (1 << id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Module* DFHack::createMaterials()
|
|
|
|
Module* DFHack::createMaterials()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new Materials();
|
|
|
|
return new Materials();
|
|
|
|