|
|
@ -42,8 +42,338 @@ using namespace std;
|
|
|
|
#include "ModuleFactory.h"
|
|
|
|
#include "ModuleFactory.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Virtual.h"
|
|
|
|
#include "Virtual.h"
|
|
|
|
|
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "df/world.h"
|
|
|
|
|
|
|
|
#include "df/item.h"
|
|
|
|
|
|
|
|
#include "df/tool_uses.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_weaponst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_trapcompst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_toyst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_toolst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_instrumentst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_armorst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_ammost.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_siegeammost.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_glovesst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_shoesst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_shieldst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_helmst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_pantsst.h"
|
|
|
|
|
|
|
|
#include "df/itemdef_foodst.h"
|
|
|
|
|
|
|
|
#include "df/trapcomp_flags.h"
|
|
|
|
|
|
|
|
#include "df/job_item.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ITEMDEF_VECTORS \
|
|
|
|
|
|
|
|
ITEM(WEAPON, weapons) \
|
|
|
|
|
|
|
|
ITEM(TRAPCOMP, trapcomps) \
|
|
|
|
|
|
|
|
ITEM(TOY, toys) \
|
|
|
|
|
|
|
|
ITEM(TOOL, tools) \
|
|
|
|
|
|
|
|
ITEM(INSTRUMENT, instruments) \
|
|
|
|
|
|
|
|
ITEM(ARMOR, armor) \
|
|
|
|
|
|
|
|
ITEM(AMMO, ammo) \
|
|
|
|
|
|
|
|
ITEM(SIEGEAMMO, siege_ammo) \
|
|
|
|
|
|
|
|
ITEM(GLOVES, gloves) \
|
|
|
|
|
|
|
|
ITEM(SHOES, shoes) \
|
|
|
|
|
|
|
|
ITEM(SHIELD, shields) \
|
|
|
|
|
|
|
|
ITEM(HELM, helms) \
|
|
|
|
|
|
|
|
ITEM(PANTS, pants) \
|
|
|
|
|
|
|
|
ITEM(FOOD, food)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemTypeInfo::decode(df::item_type type_, int16_t subtype_)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type = type_;
|
|
|
|
|
|
|
|
subtype = subtype_;
|
|
|
|
|
|
|
|
custom = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (type_) {
|
|
|
|
|
|
|
|
case NONE:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ITEM(type,vec) \
|
|
|
|
|
|
|
|
case type: \
|
|
|
|
|
|
|
|
custom = vector_get(defs.vec, subtype); \
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
ITEMDEF_VECTORS
|
|
|
|
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isValid();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemTypeInfo::decode(df::item *ptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
|
|
|
|
return decode(item_type::NONE);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return decode(ptr->getType(), ptr->getSubtype());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string ItemTypeInfo::toString()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string rv = ENUM_KEY_STR(item_type, type);
|
|
|
|
|
|
|
|
if (custom)
|
|
|
|
|
|
|
|
rv += ":" + custom->id;
|
|
|
|
|
|
|
|
else if (subtype != -1)
|
|
|
|
|
|
|
|
rv += stl_sprintf(":%d", subtype);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemTypeInfo::find(const std::string &token)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> items;
|
|
|
|
|
|
|
|
split_string(&items, token, ":");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type = NONE;
|
|
|
|
|
|
|
|
subtype = -1;
|
|
|
|
|
|
|
|
custom = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (items.size() < 1 || items.size() > 2)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (items[0] == "NONE")
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FOR_ENUM_ITEMS(item_type, i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const char *key = ENUM_ATTR(item_type, key, i);
|
|
|
|
|
|
|
|
if (key && key == items[0])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type == NONE)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (items.size() == 1)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
#define ITEM(type,vec) \
|
|
|
|
|
|
|
|
case type: \
|
|
|
|
|
|
|
|
for (int i = 0; i < defs.vec.size(); i++) { \
|
|
|
|
|
|
|
|
if (defs.vec[i]->id == items[1]) { \
|
|
|
|
|
|
|
|
subtype = i; custom = defs.vec[i]; return true; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
ITEMDEF_VECTORS
|
|
|
|
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (subtype >= 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemTypeInfo::matches(const df::job_item &item, MaterialInfo *mat)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isValid())
|
|
|
|
|
|
|
|
return mat ? mat->matches(item) : true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::job_item_flags1 ok1, mask1, item_ok1, item_mask1;
|
|
|
|
|
|
|
|
df::job_item_flags2 ok2, mask2, item_ok2, item_mask2;
|
|
|
|
|
|
|
|
df::job_item_flags3 ok3, mask3, item_ok3, item_mask3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ok1.whole = mask1.whole = item_ok1.whole = item_mask1.whole = 0;
|
|
|
|
|
|
|
|
ok2.whole = mask2.whole = item_ok2.whole = item_mask2.whole = 0;
|
|
|
|
|
|
|
|
ok3.whole = mask3.whole = item_ok3.whole = item_mask3.whole = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mat) {
|
|
|
|
|
|
|
|
mat->getMatchBits(ok1, mask1);
|
|
|
|
|
|
|
|
mat->getMatchBits(ok2, mask2);
|
|
|
|
|
|
|
|
mat->getMatchBits(ok3, mask3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define OK(id,name) item_ok##id.bits.name = true
|
|
|
|
|
|
|
|
#define RQ(id,name) item_mask##id.bits.name = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up the flag mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RQ(1,millable); RQ(1,sharpenable); RQ(1,distillable); RQ(1,processable); RQ(1,bag);
|
|
|
|
|
|
|
|
RQ(1,extract_bearing_plant); RQ(1,extract_bearing_fish); RQ(1,extract_bearing_vermin);
|
|
|
|
|
|
|
|
RQ(1,processable_to_vial); RQ(1,processable_to_bag); RQ(1,processable_to_barrel);
|
|
|
|
|
|
|
|
RQ(1,solid); RQ(1,tameable_vermin); RQ(1,sand_bearing); RQ(1,milk); RQ(1,milkable);
|
|
|
|
|
|
|
|
RQ(1,not_bin); RQ(1,lye_bearing);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RQ(2,dye); RQ(2,dyeable); RQ(2,dyed); RQ(2,glass_making); RQ(2,screw);
|
|
|
|
|
|
|
|
RQ(2,building_material); RQ(2,fire_safe); RQ(2,magma_safe); RQ(2,non_economic);
|
|
|
|
|
|
|
|
RQ(2,totemable); RQ(2,plaster_containing); RQ(2,body_part); RQ(2,lye_milk_free);
|
|
|
|
|
|
|
|
RQ(2,blunt); RQ(2,unengraved); RQ(2,hair_wool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RQ(3,any_raw_material); RQ(3,non_pressed); RQ(3,food_storage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compute the ok mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OK(1,solid);
|
|
|
|
|
|
|
|
OK(1,not_bin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: furniture, ammo, finished good, craft
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case PLANT:
|
|
|
|
|
|
|
|
OK(1,millable); OK(1,processable);
|
|
|
|
|
|
|
|
OK(1,distillable);
|
|
|
|
|
|
|
|
OK(1,extract_bearing_plant);
|
|
|
|
|
|
|
|
OK(1,processable_to_vial);
|
|
|
|
|
|
|
|
OK(1,processable_to_bag);
|
|
|
|
|
|
|
|
OK(1,processable_to_barrel);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BOULDER:
|
|
|
|
|
|
|
|
OK(1,sharpenable);
|
|
|
|
|
|
|
|
OK(2,non_economic);
|
|
|
|
|
|
|
|
case BAR:
|
|
|
|
|
|
|
|
OK(3,any_raw_material);
|
|
|
|
|
|
|
|
case BLOCKS:
|
|
|
|
|
|
|
|
case WOOD:
|
|
|
|
|
|
|
|
OK(2,building_material);
|
|
|
|
|
|
|
|
OK(2,fire_safe); OK(2,magma_safe);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case VERMIN:
|
|
|
|
|
|
|
|
OK(1,extract_bearing_fish);
|
|
|
|
|
|
|
|
OK(1,extract_bearing_vermin);
|
|
|
|
|
|
|
|
OK(1,tameable_vermin);
|
|
|
|
|
|
|
|
OK(1,milkable);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case DRINK:
|
|
|
|
|
|
|
|
item_ok1.bits.solid = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ROUGH:
|
|
|
|
|
|
|
|
OK(2,glass_making);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ANIMALTRAP:
|
|
|
|
|
|
|
|
case CAGE:
|
|
|
|
|
|
|
|
OK(1,milk);
|
|
|
|
|
|
|
|
OK(1,milkable);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BUCKET:
|
|
|
|
|
|
|
|
case FLASK:
|
|
|
|
|
|
|
|
OK(1,milk);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case TOOL:
|
|
|
|
|
|
|
|
OK(1,lye_bearing);
|
|
|
|
|
|
|
|
OK(1,milk);
|
|
|
|
|
|
|
|
OK(2,lye_milk_free);
|
|
|
|
|
|
|
|
OK(2,blunt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(def, df::itemdef_toolst, custom)) {
|
|
|
|
|
|
|
|
df::enum_field<df::tool_uses,int16_t> key(tool_uses::FOOD_STORAGE);
|
|
|
|
|
|
|
|
if (linear_index(def->tool_use, key) >= 0)
|
|
|
|
|
|
|
|
OK(3,food_storage);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
OK(3,food_storage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BARREL:
|
|
|
|
|
|
|
|
OK(1,lye_bearing);
|
|
|
|
|
|
|
|
OK(1,milk);
|
|
|
|
|
|
|
|
OK(2,lye_milk_free);
|
|
|
|
|
|
|
|
OK(3,food_storage);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BOX:
|
|
|
|
|
|
|
|
OK(1,bag); OK(1,sand_bearing); OK(1,milk);
|
|
|
|
|
|
|
|
OK(2,dye); OK(2,plaster_containing);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case BIN:
|
|
|
|
|
|
|
|
item_ok1.bits.not_bin = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case LIQUID_MISC:
|
|
|
|
|
|
|
|
item_ok1.bits.solid = false;
|
|
|
|
|
|
|
|
OK(1,milk);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case POWDER_MISC:
|
|
|
|
|
|
|
|
OK(2,dye);
|
|
|
|
|
|
|
|
case GLOB:
|
|
|
|
|
|
|
|
OK(3,any_raw_material);
|
|
|
|
|
|
|
|
OK(3,non_pressed);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case THREAD:
|
|
|
|
|
|
|
|
case CLOTH:
|
|
|
|
|
|
|
|
OK(2,dyeable); OK(2,dyed);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case WEAPON:
|
|
|
|
|
|
|
|
case AMMO:
|
|
|
|
|
|
|
|
case ROCK:
|
|
|
|
|
|
|
|
OK(2,blunt);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case TRAPCOMP:
|
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(def, df::itemdef_trapcompst, custom)) {
|
|
|
|
|
|
|
|
if (def->flags.is_set(trapcomp_flags::IS_SCREW))
|
|
|
|
|
|
|
|
OK(2,screw);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
OK(2,screw);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OK(2,blunt);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CORPSE:
|
|
|
|
|
|
|
|
case CORPSEPIECE:
|
|
|
|
|
|
|
|
OK(2,totemable);
|
|
|
|
|
|
|
|
OK(2,body_part);
|
|
|
|
|
|
|
|
OK(2,hair_wool);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case SLAB:
|
|
|
|
|
|
|
|
OK(2,unengraved);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ANVIL:
|
|
|
|
|
|
|
|
OK(2,fire_safe); OK(2,magma_safe);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((item_ok1.whole & ~item_mask1.whole) ||
|
|
|
|
|
|
|
|
(item_ok2.whole & ~item_mask2.whole) ||
|
|
|
|
|
|
|
|
(item_ok3.whole & ~item_mask3.whole))
|
|
|
|
|
|
|
|
Core::getInstance().con.printerr("ItemTypeInfo.matches inconsistent\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef OK
|
|
|
|
|
|
|
|
#undef RQ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bits_match(item.flags1.whole, ok1.whole, mask1.whole) &&
|
|
|
|
|
|
|
|
bits_match(item.flags2.whole, ok2.whole, mask2.whole) &&
|
|
|
|
|
|
|
|
bits_match(item.flags3.whole, ok3.whole, mask3.whole) &&
|
|
|
|
|
|
|
|
bits_match(item.flags1.whole, item_ok1.whole, item_mask1.whole) &&
|
|
|
|
|
|
|
|
bits_match(item.flags2.whole, item_ok2.whole, item_mask2.whole) &&
|
|
|
|
|
|
|
|
bits_match(item.flags3.whole, item_ok3.whole, item_mask3.whole);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module* DFHack::createItems()
|
|
|
|
Module* DFHack::createItems()
|
|
|
|
{
|
|
|
|
{
|
|
|
|