df_item -> df::item, t_itemflags -> df::item_flags

develop
Quietust 2012-01-16 20:16:16 -06:00
parent 97bae19c13
commit 64b55acf37
8 changed files with 87 additions and 548 deletions

@ -34,6 +34,7 @@ distribution.
#include "MemAccess.h" #include "MemAccess.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/item.h"
#include "df/item_type.h" #include "df/item_type.h"
namespace df namespace df
@ -90,58 +91,6 @@ class Context;
class DFContextShared; class DFContextShared;
class Units; class Units;
/**
* Item flags. A bit fuzzy.
* Mostly from http://dwarffortresswiki.net/index.php/User:Rick/Memory_research
* \ingroup grp_items
*/
union t_itemflags
{
uint32_t whole; ///< the whole struct. all 32 bits of it, as an integer
struct
{
unsigned int on_ground : 1; ///< 0000 0001 Item on ground
unsigned int in_job : 1; ///< 0000 0002 Item currently being used in a job
unsigned int hostile : 1; ///< 0000 0004 Item owned by hostile
unsigned int in_inventory : 1; ///< 0000 0008 Item in a creature or workshop inventory
unsigned int unk1 : 1; ///< 0000 0010 unknown, lost (artifact)?, unusable, unseen
unsigned int in_building : 1; ///< 0000 0020 Part of a building (including mechanisms, bodies in coffins)
unsigned int unk2 : 1; ///< 0000 0040 unknown, unseen
unsigned int dead_dwarf : 1; ///< 0000 0080 Dwarf's dead body or body part
unsigned int rotten : 1; ///< 0000 0100 Rotten food
unsigned int spider_web : 1; ///< 0000 0200 Thread in spider web
unsigned int construction : 1; ///< 0000 0400 Material used in construction
unsigned int unk3 : 1; ///< 0000 0800 unknown, unseen, unusable
unsigned int unk4 : 1; ///< 0000 1000 unknown, unseen
unsigned int murder : 1; ///< 0000 2000 Implies murder - used in fell moods
unsigned int foreign : 1; ///< 0000 4000 Item is imported
unsigned int trader : 1; ///< 0000 8000 Item ownwed by trader
unsigned int owned : 1; ///< 0001 0000 Item is owned by a dwarf
unsigned int garbage_colect : 1; ///< 0002 0000 Marked for deallocation by DF it seems
unsigned int artifact1 : 1; ///< 0004 0000 Artifact ?
unsigned int forbid : 1; ///< 0008 0000 Forbidden item
unsigned int unk6 : 1; ///< 0010 0000 unknown, unseen
unsigned int dump : 1; ///< 0020 0000 Designated for dumping
unsigned int on_fire: 1; ///< 0040 0000 Indicates if item is on fire, Will Set Item On Fire if Set!
unsigned int melt : 1; ///< 0080 0000 Designated for melting, if applicable
unsigned int hidden : 1; ///< 0100 0000 Hidden item
unsigned int in_chest : 1; ///< 0200 0000 Stored in chest/part of well?
unsigned int unk7 : 1; ///< 0400 0000 unknown, unseen
unsigned int artifact2 : 1; ///< 0800 0000 Artifact ?
unsigned int unk8 : 1; ///< 1000 0000 unknown, unseen, common
unsigned int unk9 : 1; ///< 2000 0000 unknown, set when viewing details
unsigned int unk10 : 1; ///< 4000 0000 unknown, unseen
unsigned int unk11 : 1; ///< 8000 0000 unknown, unseen
};
};
/** /**
* Describes relationship of an item with other objects * Describes relationship of an item with other objects
* \ingroup grp_items * \ingroup grp_items
@ -161,337 +110,17 @@ struct df_contaminant
int32_t size; ///< 1-24=spatter, 25-49=smear, 50-* = coating int32_t size; ///< 1-24=spatter, 25-49=smear, 50-* = coating
}; };
/**
* A partial mirror of a DF base type for items
* \ingroup grp_items
*/
class df_item
{
public:
// 4
int16_t x;
int16_t y;
// 8
int16_t z;
// C
t_itemflags flags;
// 10
uint32_t age;
// 14
uint32_t id;
// 18
std::vector<void *> unk1;
// 24 L, 28 W
std::vector<t_itemref *> itemrefs;
// 30 L, 38 W - these were mostly unset (0xCC with malloc patch)
int16_t mystery_meat[12];
// 48 L, 50 W
int32_t mystery1;
// 4C L, 54 W
int32_t mystery2;
// 50 L, 58 W
int32_t mystery3;
// 54 L, 5C W
int32_t mystery4;
// 58 L, 60 W
int32_t mystery5;
// 5C L, 64 W - pointer to vector of contaminants
std::vector <df_contaminant *> * contaminants;
// 60 L, 6C W - temperature in Urists
int16_t temperature;
// 62 L, 6E W - temperature fraction (maybe, just a guess)
int16_t temperature_fraction;
public:
// 0x0
virtual t_itemType getType();
virtual t_itemSubtype getSubtype();
virtual t_materialType getMaterial();
virtual t_materialIndex getMaterialIndex();
// 0x10
virtual void setSubType(t_itemSubtype);
virtual void setMaterial(t_materialType mat);
virtual void setMaterialIndex (t_materialIndex submat);
virtual t_materialType getMaterial2(); // weird
// 0x20
virtual t_materialIndex getMaterialIndex2(); // weird
virtual void fn9(void);
virtual void fn10(void);
virtual void fn11(void);
// 0x30
virtual void fn12(void);
virtual void fn13(void);
virtual void fn14(void);
virtual void fn15(void);
// 0x40
virtual void fn16(void);
virtual void fn17(void);
virtual void fn18(void);
virtual void fn19(void);
// 0x50
virtual void fn20(void);
virtual void fn21(void);
virtual void fn22(void);
virtual void fn23(void);
// 0x60
virtual void fn24(void);
virtual void fn25(void);
virtual void fn26(void);
virtual void fn27(void);
// 0x70
virtual void fn28(void);
virtual void fn29(void);
virtual void fn30(void);
virtual void fn31(void);
// 0x80
virtual void fn32(void);
virtual void fn33(void);
virtual void fn34(void);
virtual void fn35(void);
// 0x90
virtual void fn36(void);
virtual void fn37(void);
virtual void fn38(void);
virtual void fn39(void);
// 0xA0
virtual void fn40(void);
virtual void fn41(void);
virtual void fn42(void);
virtual void fn43(void);
// 0xB0
virtual void fn44(void);
virtual void fn45(void);
virtual void fn46(void);
virtual void fn47(void);
// 0xC0
virtual void fn48(void);
virtual void fn49(void);
virtual void fn50(void);
virtual int16_t getWear(void); // 0 = normal, 1 = x, 2 = X, 3 = XX
// 0xD0
virtual void setWear(int16_t wear); // also zeroes wear timer?
virtual void fn53(void);
virtual void fn54(void);
virtual void fn55(void);
// 0xE0
virtual void fn56(void);
virtual void fn57(void);
virtual void fn58(void);
virtual void fn59(void);
// 0xF0
virtual void fn60(void);
virtual void fn61(void);
virtual void fn62(void);
virtual void fn63(void);
// 0x100
virtual void fn64(void);
virtual void fn65(void);
virtual void fn66(void);
virtual void fn67(void);
// 0x110
virtual void fn68(void);
virtual void fn69(void);
virtual void fn70(void);
virtual void fn71(void);
// 0x120
virtual void fn72(void);
virtual void fn73(void);
virtual void fn74(void);
virtual void fn75(void);
// 0x130
virtual void fn76(void);
virtual void fn77(void);
virtual void fn78(void);
virtual void fn79(void);
// 0x140
virtual void fn80(void);
virtual void fn81(void);
virtual void fn82(void);
virtual void fn83(void);
// 0x150
virtual void fn84(void);
virtual void fn85(void);
virtual void fn86(void);
virtual void fn87(void);
// 0x160
virtual void fn88(void);
virtual void fn89(void);
virtual void fn90(void);
virtual void fn91(void);
// 0x170
virtual void fn92(void);
virtual void fn93(void);
virtual void fn94(void);
virtual void fn95(void);
// 0x180
virtual void fn96(void);
virtual void fn97(void);
virtual void fn98(void);
virtual void fn99(void);
// 0x190
virtual void fn100(void);
virtual void fn101(void);
virtual void fn102(void);
virtual void fn103(void);
// 0x1A0
virtual void fn104(void);
virtual void fn105(void);
virtual void fn106(void);
virtual void fn107(void);
// 0x1B0
virtual void fn108(void);
virtual void fn109(void);
virtual void fn110(void);
virtual void fn111(void);
// 0x1C0
virtual void fn112(void);
virtual void fn113(void);
virtual void fn114(void);
virtual void fn115(void);
// 0x1D0
virtual void fn116(void);
virtual void fn117(void);
virtual void fn118(void);
virtual void fn119(void);
// 0x1E0
virtual void fn120(void);
virtual void fn121(void);
virtual void fn122(void);
virtual void fn123(void);
// 0x1F0
virtual void fn124(void);
virtual void fn125(void);
virtual void fn126(void);
virtual void fn127(void);
// 0x200
virtual void fn128(void);
virtual void fn129(void);
virtual void fn130(void);
virtual void fn131(void);
// 0x210
virtual void fn132(void);
virtual int32_t getStackSize( void );
virtual void fn134(void);
virtual void fn135(void);
// 0x220
virtual void fn136(void);
virtual void fn137(void);
virtual void fn138(void);
virtual void fn139(void);
// 0x230
virtual void fn140(void);
virtual void fn141(void);
virtual void fn142(void);
virtual void fn143(void);
// 0x240
virtual void fn144(void);
virtual void fn145(void);
virtual void fn146(void);
virtual void fn147(void);
// 0x250
virtual void fn148(void);
virtual void fn149(void);
virtual void fn150(void);
virtual int16_t getQuality( void );
// 0x260
virtual void fn152(void);
virtual void fn153(void);
virtual void fn154(void);
virtual void fn155(void);
// 0x270
virtual void fn156(void);
virtual void fn157(void);
virtual void fn158(void);
virtual void fn159(void);
// 0x280
virtual void fn160(void);
virtual void fn161(void);
virtual void fn162(void);
virtual void fn163(void);
// 0x290
virtual void fn164(void);
virtual void fn165(void);
virtual void fn166(void);
virtual void fn167(void);
// 0x2A0
virtual void fn168(void); // value returned (int) = first param to descriprion construction function
virtual void fn169(void);
virtual void fn170(void);
virtual void fn171(void);
// 0x2B0
virtual void fn172(void);
virtual void fn173(void);
virtual void fn174(void);
virtual void fn175(void);
// 0x2C0
virtual void fn176(void);
virtual void fn177(void);
//virtual std::string *getItemDescription ( std::string * str, int sizes = 0); // 0 = stacked, 1 = singular, 2 = plural
virtual std::string *getItemDescription ( std::string * str, int sizes = 0); // 0 = stacked, 1 = singular, 2 = plural
virtual void fn179(void);
// 0x2D0
virtual void fn180(void);
virtual void fn181(void);
virtual void fn182(void);
virtual void fn183(void);
// 0x2E0
virtual void fn184(void);
virtual void fn185(void);
virtual void fn186(void);
virtual void fn187(void);
// 0x2F0
virtual void fn188(void);
virtual void fn189(void);
virtual void fn190(void);
virtual void fn191(void);
// 0x300
virtual void fn192(void);
virtual void fn193(void);
virtual void fn194(void);
virtual void fn195(void);
// 0x310
virtual void fn196(void);
virtual void fn197(void);
virtual void fn198(void);
virtual void fn199(void);
// 0x320
virtual void fn200(void);
virtual void fn201(void);
virtual void fn202(void);
virtual void fn203(void);
// 0x330
virtual void fn204(void);
virtual void fn205(void);
virtual void fn206(void);
virtual void fn207(void);
// 0x340
virtual void fn208(void);
virtual void fn209(void);
virtual void fn210(void);
virtual void fn211(void);
// 0x350
virtual void fn212(void);
virtual void fn213(void);
virtual void fn214(void);
virtual void fn215(void);
// 0x360
virtual void fn216(void);
virtual void fn217(void);
// and this should be all 218 of them
// fn numbers start with 0
};
/** /**
* Type for holding an item read from DF * Type for holding an item read from DF
* \ingroup grp_items * \ingroup grp_items
*/ */
struct dfh_item struct dfh_item
{ {
df_item *origin; // where this was read from df::item *origin; // where this was read from
int16_t x; int16_t x;
int16_t y; int16_t y;
int16_t z; int16_t z;
t_itemflags flags; df::item_flags flags;
uint32_t age; uint32_t age;
uint32_t id; uint32_t id;
t_material matdesc; t_material matdesc;
@ -523,98 +152,6 @@ public:
* All the known item types as an enum * All the known item types as an enum
* From http://df.magmawiki.com/index.php/DF2010:Item_token * From http://df.magmawiki.com/index.php/DF2010:Item_token
*/ */
enum item_types
{
BAR, ///< Bars, such as metal, fuel, or soap.
SMALLGEM, ///< Cut gemstones usable in jeweler's workshop
BLOCKS, ///< Blocks of any kind.
ROUGH, ///< Rough gemstones.
BOULDER, ///< or IT_STONE - raw mined stone.
STONE = BOULDER,
WOOD, ///< Wooden logs.
DOOR, ///< Doors.
FLOODGATE, ///< Floodgates.
BED, ///< Beds.
CHAIR, ///< Chairs and thrones.
CHAIN, ///< Restraints.
FLASK, ///< Flasks.
GOBLET, ///< Goblets.
INSTRUMENT, ///< Musical instruments. Subtypes come from item_instrument.txt
TOY, ///< Toys. Subtypes come from item_toy.txt
WINDOW, ///< Glass windows.
CAGE, ///< Cages.
BARREL, ///< Barrels.
BUCKET, ///< Buckets.
ANIMALTRAP, ///< Animal traps.
TABLE, ///< Tables.
COFFIN, ///< Coffins.
STATUE, ///< Statues.
CORPSE, ///< Corpses.
WEAPON, ///< Weapons. Subtypes come from item_weapon.txt
ARMOR, ///< Armor and clothing worn on the upper body. Subtypes come from item_armor.txt
SHOES, ///< Armor and clothing worn on the feet. Subtypes come from item_shoes.txt
SHIELD, ///< Shields and bucklers. Subtypes come from item_shield.txt
HELM, ///< Armor and clothing worn on the head. Subtypes come from item_helm.txt
GLOVES, ///< Armor and clothing worn on the hands. Subtypes come from item_gloves.txt
BOX, ///< Chests (wood), coffers (stone), boxes (glass), and bags (cloth or leather).
BIN, ///< Bins.
ARMORSTAND, ///< Armor stands.
WEAPONRACK, ///< Weapon racks.
CABINET, ///< Cabinets.
FIGURINE, ///< Figurines.
AMULET, ///< Amulets.
SCEPTER, ///< Scepters.
AMMO, ///< Ammunition for hand-held weapons. Subtypes come from item_ammo.txt
CROWN, ///< Crowns.
RING, ///< Rings.
EARRING, ///< Earrings.
BRACELET, ///< Bracelets.
GEM, ///< Large gems.
ANVIL, ///< Anvils.
CORPSEPIECE,///< Body parts.
REMAINS, ///< Dead vermin bodies.
MEAT, ///< Butchered meat.
FISH, ///< Prepared fish.
FISH_RAW, ///< Unprepared fish.
VERMIN, ///< Live vermin.
PET, ///< Tame vermin.
SEEDS, ///< Seeds from plants.
PLANT, ///< Plants.
SKIN_TANNED,///< Tanned skins.
LEAVES, ///< Leaves, usually from quarry bushes.
THREAD, ///< Thread gathered from webs or made at the farmer's workshop.
CLOTH, ///< Cloth made at the loom.
TOTEM, ///< Skull totems.
PANTS, ///< Armor and clothing worn on the legs. Subtypes come from item_pants.txt
BACKPACK, ///< Backpacks.
QUIVER, ///< Quivers.
CATAPULTPARTS, ///< Catapult parts.
BALLISTAPARTS, ///< Ballista parts.
SIEGEAMMO, ///< Siege engine ammunition. Subtypes come from item_siegeammo.txt
BALLISTAARROWHEAD, ///< Ballista arrow heads.
TRAPPARTS, ///< Mechanisms.
TRAPCOMP, ///< Trap components. Subtypes come from item_trapcomp.txt
DRINK, ///< Alcoholic drinks.
POWDER_MISC,///< Powders such as flour, gypsum plaster, dye, or sand.
CHEESE, ///< Pieces of cheese.
FOOD, ///< Prepared meals. Subtypes come from item_food.txt
LIQUID_MISC,///< Liquids such as water, lye, and extracts.
COIN, ///< Coins.
GLOB, ///< Fat, tallow, pastes/pressed objects, and small bits of molten rock/metal.
ROCK, ///< Small rocks (usually sharpened and/or thrown in adventurer mode)
PIPE_SECTION, ///< Pipe sections.
HATCH_COVER, ///< Hatch covers.
GRATE, ///< Grates.
QUERN, ///< Querns.
MILLSTONE, ///< Millstones.
SPLINT, ///< Splints.
CRUTCH, ///< Crutches.
TRACTION_BENCH, ///< Traction benches.
ORTHOPEDIC_CAST, ///< Casts.
TOOL, ///< Tools. Subtypes come from item_tool.txt
SLAB, ///< Slabs.
EGG, ///< Eggs.
};
public: public:
Items(); Items();
@ -622,30 +159,30 @@ public:
bool Start(); bool Start();
bool Finish(); bool Finish();
/// Read the item vector from DF into a supplied vector /// Read the item vector from DF into a supplied vector
bool readItemVector(std::vector<df_item *> &items); bool readItemVector(std::vector<df::item *> &items);
/// Look for a particular item by ID /// Look for a particular item by ID
df_item * findItemByID(int32_t id); df::item * findItemByID(int32_t id);
/// Make a partial copy of a DF item /// Make a partial copy of a DF item
bool copyItem(df_item * source, dfh_item & target); bool copyItem(df::item * source, dfh_item & target);
/// write copied item back to its origin /// write copied item back to its origin
bool writeItem(const dfh_item & item); bool writeItem(const dfh_item & item);
/// get the class name of an item /// get the class name of an item
std::string getItemClass(const df_item * item); std::string getItemClass(const df::item * item);
/// who owns this item we already read? /// who owns this item we already read?
int32_t getItemOwnerID(const df_item * item); int32_t getItemOwnerID(const df::item * item);
/// which item is it contained in? /// which item is it contained in?
int32_t getItemContainerID(const df_item * item); int32_t getItemContainerID(const df::item * item);
/// which items does it contain? /// which items does it contain?
bool getContainedItems(const df_item * item, /*output*/ std::vector<int32_t> &items); bool getContainedItems(const df::item * item, /*output*/ std::vector<int32_t> &items);
/// wipe out the owner records /// wipe out the owner records
bool removeItemOwner(df_item * item, Units *creatures); bool removeItemOwner(df::item * item, Units *creatures);
/// read item references, filtered by class /// read item references, filtered by class
bool readItemRefs(const df_item * item, const ClassNameCheck &classname, bool readItemRefs(const df::item * item, const ClassNameCheck &classname,
/*output*/ std::vector<int32_t> &values); /*output*/ std::vector<int32_t> &values);
/// get list of item references that are unknown along with their values /// get list of item references that are unknown along with their values
bool unknownRefs(const df_item * item, /*output*/ std::vector<std::pair<std::string, int32_t> >& refs); bool unknownRefs(const df::item * item, /*output*/ std::vector<std::pair<std::string, int32_t> >& refs);
private: private:
class Private; class Private;
Private* d; Private* d;

@ -557,7 +557,7 @@ namespace DFHack
int16_t unk_280; int16_t unk_280;
int32_t unk_284; int32_t unk_284;
std::vector<df_item *> inventory; // 288 - vector of item pointers std::vector<df::item *> inventory; // 288 - vector of item pointers
std::vector<int32_t> owned_items; // 298 - vector of item IDs std::vector<int32_t> owned_items; // 298 - vector of item IDs
std::vector<uint32_t> unk_2a8; std::vector<uint32_t> unk_2a8;
std::vector<uint32_t> unk_2b8; std::vector<uint32_t> unk_2b8;
@ -777,8 +777,8 @@ namespace DFHack
bool ReadJob(const df_unit * unit, std::vector<t_material> & mat); bool ReadJob(const df_unit * unit, std::vector<t_material> & mat);
bool ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item); bool ReadInventoryByIdx(const uint32_t index, std::vector<df::item *> & item);
bool ReadInventoryByPtr(const df_unit * unit, std::vector<df_item *> & item); bool ReadInventoryByPtr(const df_unit * unit, std::vector<df::item *> & item);
bool ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item); bool ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item);
bool ReadOwnedItemsByPtr(const df_unit * unit, std::vector<int32_t> & item); bool ReadOwnedItemsByPtr(const df_unit * unit, std::vector<int32_t> & item);

@ -403,7 +403,7 @@ class Items::Private
{ {
public: public:
Process * owner; Process * owner;
std::map<int32_t, df_item *> idLookupTable; std::map<int32_t, df::item *> idLookupTable;
uint32_t refVectorOffset; uint32_t refVectorOffset;
uint32_t idFieldOffset; uint32_t idFieldOffset;
void * itemVectorAddress; void * itemVectorAddress;
@ -498,16 +498,16 @@ bool Items::Finish()
return true; return true;
} }
bool Items::readItemVector(std::vector<df_item *> &items) bool Items::readItemVector(std::vector<df::item *> &items)
{ {
std::vector <df_item *> *p_items = (std::vector <df_item *> *) d->itemVectorAddress; std::vector <df::item *> *p_items = (std::vector <df::item *> *) d->itemVectorAddress;
d->idLookupTable.clear(); d->idLookupTable.clear();
items.resize(p_items->size()); items.resize(p_items->size());
for (unsigned i = 0; i < p_items->size(); i++) for (unsigned i = 0; i < p_items->size(); i++)
{ {
df_item * ptr = p_items->at(i); df::item * ptr = p_items->at(i);
items[i] = ptr; items[i] = ptr;
d->idLookupTable[ptr->id] = ptr; d->idLookupTable[ptr->id] = ptr;
} }
@ -515,14 +515,14 @@ bool Items::readItemVector(std::vector<df_item *> &items)
return true; return true;
} }
df_item * Items::findItemByID(int32_t id) df::item * Items::findItemByID(int32_t id)
{ {
if (id < 0) if (id < 0)
return 0; return 0;
if (d->idLookupTable.empty()) if (d->idLookupTable.empty())
{ {
std::vector<df_item *> tmp; std::vector<df::item *> tmp;
readItemVector(tmp); readItemVector(tmp);
} }
@ -535,11 +535,11 @@ Items::~Items()
delete d; delete d;
} }
bool Items::copyItem(df_item * itembase, DFHack::dfh_item &item) bool Items::copyItem(df::item * itembase, DFHack::dfh_item &item)
{ {
if(!itembase) if(!itembase)
return false; return false;
df_item * itreal = (df_item *) itembase; df::item * itreal = (df::item *) itembase;
item.origin = itembase; item.origin = itembase;
item.x = itreal->x; item.x = itreal->x;
item.y = itreal->y; item.y = itreal->y;
@ -557,7 +557,7 @@ bool Items::copyItem(df_item * itembase, DFHack::dfh_item &item)
return true; return true;
} }
int32_t Items::getItemOwnerID(const DFHack::df_item * item) int32_t Items::getItemOwnerID(const df::item * item)
{ {
std::vector<int32_t> vals; std::vector<int32_t> vals;
if (readItemRefs(item, d->isOwnerRefClass, vals)) if (readItemRefs(item, d->isOwnerRefClass, vals))
@ -566,7 +566,7 @@ int32_t Items::getItemOwnerID(const DFHack::df_item * item)
return -1; return -1;
} }
int32_t Items::getItemContainerID(const DFHack::df_item * item) int32_t Items::getItemContainerID(const df::item * item)
{ {
std::vector<int32_t> vals; std::vector<int32_t> vals;
if (readItemRefs(item, d->isContainerRefClass, vals)) if (readItemRefs(item, d->isContainerRefClass, vals))
@ -575,14 +575,14 @@ int32_t Items::getItemContainerID(const DFHack::df_item * item)
return -1; return -1;
} }
bool Items::getContainedItems(const DFHack::df_item * item, std::vector<int32_t> &items) bool Items::getContainedItems(const df::item * item, std::vector<int32_t> &items)
{ {
return readItemRefs(item, d->isContainsRefClass, items); return readItemRefs(item, d->isContainsRefClass, items);
} }
bool Items::readItemRefs(const df_item * item, const ClassNameCheck &classname, std::vector<int32_t> &values) bool Items::readItemRefs(const df::item * item, const ClassNameCheck &classname, std::vector<int32_t> &values)
{ {
const std::vector <t_itemref *> &p_refs = item->itemrefs; const std::vector <t_itemref *> &p_refs = (const std::vector<t_itemref *> &)item->itemrefs;
values.clear(); values.clear();
for (uint32_t i=0; i<p_refs.size(); i++) for (uint32_t i=0; i<p_refs.size(); i++)
@ -594,11 +594,11 @@ bool Items::readItemRefs(const df_item * item, const ClassNameCheck &classname,
return !values.empty(); return !values.empty();
} }
bool Items::unknownRefs(const df_item * item, std::vector<std::pair<std::string, int32_t> >& refs) bool Items::unknownRefs(const df::item * item, std::vector<std::pair<std::string, int32_t> >& refs)
{ {
refs.clear(); refs.clear();
const std::vector <t_itemref *> &p_refs = item->itemrefs; const std::vector <t_itemref *> &p_refs = (const std::vector<t_itemref *> &)item->itemrefs;
for (uint32_t i=0; i<p_refs.size(); i++) for (uint32_t i=0; i<p_refs.size(); i++)
{ {
@ -613,9 +613,9 @@ bool Items::unknownRefs(const df_item * item, std::vector<std::pair<std::string,
return (refs.size() > 0); return (refs.size() > 0);
} }
bool Items::removeItemOwner(df_item * item, Units *creatures) bool Items::removeItemOwner(df::item * item, Units *creatures)
{ {
std::vector <t_itemref *> &p_refs = item->itemrefs; std::vector <t_itemref *> &p_refs = (std::vector<t_itemref *> &)item->itemrefs;
for (uint32_t i=0; i<p_refs.size(); i++) for (uint32_t i=0; i<p_refs.size(); i++)
{ {
if (!d->isOwnerRefClass(d->owner, p_refs[i]->vptr)) if (!d->isOwnerRefClass(d->owner, p_refs[i]->vptr))
@ -632,12 +632,12 @@ bool Items::removeItemOwner(df_item * item, Units *creatures)
p_refs.erase(p_refs.begin() + i--); p_refs.erase(p_refs.begin() + i--);
} }
item->flags.owned = 0; item->flags.bits.owned = 0;
return true; return true;
} }
std::string Items::getItemClass(const df_item * item) std::string Items::getItemClass(const df::item * item)
{ {
const t_virtual * virt = (t_virtual *) item; const t_virtual * virt = (t_virtual *) item;
return virt->getClassName(); return virt->getClassName();

@ -549,7 +549,7 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
return true; return true;
} }
*/ */
bool Units::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item) bool Units::ReadInventoryByIdx(const uint32_t index, std::vector<df::item *> & item)
{ {
if(!d->Started) return false; if(!d->Started) return false;
if(index >= creatures->size()) return false; if(index >= creatures->size()) return false;
@ -557,7 +557,7 @@ bool Units::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & it
return this->ReadInventoryByPtr(temp, item); return this->ReadInventoryByPtr(temp, item);
} }
bool Units::ReadInventoryByPtr(const df_unit * temp, std::vector<df_item *> & items) bool Units::ReadInventoryByPtr(const df_unit * temp, std::vector<df::item *> & items)
{ {
if(!d->Started) return false; if(!d->Started) return false;
items = temp->inventory; items = temp->inventory;

@ -19,6 +19,7 @@ using namespace std;
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
#include "Virtual.h" #include "Virtual.h"
#include "df/item_type.h"
namespace DFHack namespace DFHack
{ {
@ -89,7 +90,7 @@ namespace Kitchen
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->materialIndices[i] == materialIndex if(d->materialIndices[i] == materialIndex
&& (d->itemTypes[i] == DFHack::Items::SEEDS || d->itemTypes[i] == DFHack::Items::PLANT) && (d->itemTypes[i] == df::item_type::SEEDS || d->itemTypes[i] == df::item_type::PLANT)
&& d->exclusionTypes[i] == cookingExclusion && d->exclusionTypes[i] == cookingExclusion
) )
{ {
@ -119,15 +120,15 @@ namespace Kitchen
if(d->materialIndices[i] == materialIndex if(d->materialIndices[i] == materialIndex
&& d->exclusionTypes[i] == cookingExclusion) && d->exclusionTypes[i] == cookingExclusion)
{ {
if(d->itemTypes[i] == DFHack::Items::SEEDS) if(d->itemTypes[i] == df::item_type::SEEDS)
SeedAlreadyIn = true; SeedAlreadyIn = true;
else if (d->itemTypes[i] == DFHack::Items::PLANT) else if (d->itemTypes[i] == df::item_type::PLANT)
PlantAlreadyIn = true; PlantAlreadyIn = true;
} }
} }
if(!SeedAlreadyIn) if(!SeedAlreadyIn)
{ {
d->itemTypes.push_back(DFHack::Items::SEEDS); d->itemTypes.push_back(df::item_type::SEEDS);
d->itemSubtypes.push_back(organicSubtype); d->itemSubtypes.push_back(organicSubtype);
d->materialTypes.push_back(type->material_type_seed); d->materialTypes.push_back(type->material_type_seed);
d->materialIndices.push_back(materialIndex); d->materialIndices.push_back(materialIndex);
@ -135,7 +136,7 @@ namespace Kitchen
} }
if(!PlantAlreadyIn) if(!PlantAlreadyIn)
{ {
d->itemTypes.push_back(DFHack::Items::PLANT); d->itemTypes.push_back(df::item_type::PLANT);
d->itemSubtypes.push_back(organicSubtype); d->itemSubtypes.push_back(organicSubtype);
d->materialTypes.push_back(type->material_type_basic_mat); d->materialTypes.push_back(type->material_type_basic_mat);
d->materialIndices.push_back(materialIndex); d->materialIndices.push_back(materialIndex);

@ -98,7 +98,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
DFHack::Items * Items = c->getItems(); DFHack::Items * Items = c->getItems();
DFHack::Maps *Maps = c->getMaps(); DFHack::Maps *Maps = c->getMaps();
vector <df_item*> p_items; vector <df::item*> p_items;
if(!Items->readItemVector(p_items)) if(!Items->readItemVector(p_items))
{ {
c->con.printerr("Can't access the item vector.\n"); c->con.printerr("Can't access the item vector.\n");
@ -148,7 +148,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
// proceed with the dumpification operation // proceed with the dumpification operation
for(std::size_t i=0; i< numItems; i++) for(std::size_t i=0; i< numItems; i++)
{ {
df_item * itm = p_items[i]; df::item * itm = p_items[i];
DFCoord pos_item(itm->x, itm->y, itm->z); DFCoord pos_item(itm->x, itm->y, itm->z);
// keep track how many items are at places. all items. // keep track how many items are at places. all items.
@ -165,22 +165,22 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
// iterator is valid here, we use it later to decrement the pile counter if the item is moved // iterator is valid here, we use it later to decrement the pile counter if the item is moved
// only dump the stuff marked for dumping and laying on the ground // only dump the stuff marked for dumping and laying on the ground
if ( !itm->flags.dump if ( !itm->flags.bits.dump
|| !itm->flags.on_ground || !itm->flags.bits.on_ground
|| itm->flags.construction || itm->flags.bits.construction
|| itm->flags.hidden || itm->flags.bits.hidden
|| itm->flags.in_building || itm->flags.bits.in_building
|| itm->flags.in_chest || itm->flags.bits.in_chest
|| itm->flags.in_inventory || itm->flags.bits.in_inventory
|| itm->flags.artifact1 || itm->flags.bits.artifact1
) )
continue; continue;
if(!destroy) // move to cursor if(!destroy) // move to cursor
{ {
// Change flags to indicate the dump was completed, as if by super-dwarfs // Change flags to indicate the dump was completed, as if by super-dwarfs
itm->flags.dump = false; itm->flags.bits.dump = false;
itm->flags.forbid = true; itm->flags.bits.forbid = true;
// Don't move items if they're already at the cursor // Don't move items if they're already at the cursor
if (pos_cursor == pos_item) if (pos_cursor == pos_item)
@ -221,11 +221,11 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
if (here && pos_item != pos_cursor) if (here && pos_item != pos_cursor)
continue; continue;
itm->flags.garbage_colect = true; itm->flags.bits.garbage_colect = true;
// Cosmetic changes: make them disappear from view instantly // Cosmetic changes: make them disappear from view instantly
itm->flags.forbid = true; itm->flags.bits.forbid = true;
itm->flags.hidden = true; itm->flags.bits.hidden = true;
} }
// keeping track of item pile sizes ;) // keeping track of item pile sizes ;)
it->second --; it->second --;

@ -99,7 +99,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
ok &= Creatures->Start(num_creatures); ok &= Creatures->Start(num_creatures);
ok &= Tran->Start(); ok &= Tran->Start();
vector<df_item *> p_items; vector<df::item *> p_items;
ok &= Items->readItemVector(p_items); ok &= Items->readItemVector(p_items);
if(!ok) if(!ok)
{ {
@ -111,11 +111,11 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
for (std::size_t i=0; i < p_items.size(); i++) for (std::size_t i=0; i < p_items.size(); i++)
{ {
df_item * item = p_items[i]; df::item * item = p_items[i];
bool confiscate = false; bool confiscate = false;
bool dump = false; bool dump = false;
if (!item->flags.owned) if (!item->flags.bits.owned)
{ {
int32_t owner = Items->getItemOwnerID(item); int32_t owner = Items->getItemOwnerID(item);
if (owner >= 0) if (owner >= 0)
@ -131,21 +131,21 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
std::string name = Items->getItemClass(item); std::string name = Items->getItemClass(item);
if (item->flags.rotten) if (item->flags.bits.rotten)
{ {
c->con.print("Confiscating a rotten item: \t"); c->con.print("Confiscating a rotten item: \t");
confiscate = true; confiscate = true;
} }
else if (item->flags.on_ground) else if (item->flags.bits.on_ground)
{ {
int32_t type = item->getType(); int32_t type = item->getType();
if(type == Items::MEAT || if(type == df::item_type::MEAT ||
type == Items::FISH || type == df::item_type::FISH ||
type == Items::VERMIN || type == df::item_type::VERMIN ||
type == Items::PET || type == df::item_type::PET ||
type == Items::PLANT || type == df::item_type::PLANT ||
type == Items::CHEESE || type == df::item_type::CHEESE ||
type == Items::FOOD type == df::item_type::FOOD
) )
{ {
confiscate = true; confiscate = true;
@ -209,7 +209,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
if (!Items->removeItemOwner(item, Creatures)) if (!Items->removeItemOwner(item, Creatures))
c->con.print("(unsuccessfully) "); c->con.print("(unsuccessfully) ");
if (dump) if (dump)
item->flags.dump = 1; item->flags.bits.dump = 1;
} }
c->con.print("\n"); c->con.print("\n");
} }

@ -13,6 +13,7 @@
#include "modules/World.h" #include "modules/World.h"
#include "modules/kitchen.h" #include "modules/kitchen.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "df/item_flags.h"
using DFHack::t_materialType; using DFHack::t_materialType;
using DFHack::t_materialIndex; using DFHack::t_materialIndex;
@ -23,19 +24,19 @@ bool running = false; // whether seedwatch is counting the seeds or not
// abbreviations for the standard plants // abbreviations for the standard plants
std::map<std::string, std::string> abbreviations; std::map<std::string, std::string> abbreviations;
bool ignoreSeeds(DFHack::t_itemflags& f) // seeds with the following flags should not be counted bool ignoreSeeds(df::item_flags& f) // seeds with the following flags should not be counted
{ {
return return
f.dump || f.bits.dump ||
f.forbid || f.bits.forbid ||
f.garbage_colect || f.bits.garbage_colect ||
f.hidden || f.bits.hidden ||
f.hostile || f.bits.hostile ||
f.on_fire || f.bits.on_fire ||
f.rotten || f.bits.rotten ||
f.trader || f.bits.trader ||
f.in_building || f.bits.in_building ||
f.in_job; f.bits.in_job;
}; };
void printHelp(DFHack::Core& core) // prints help void printHelp(DFHack::Core& core) // prints help
@ -329,9 +330,9 @@ DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore)
std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds
DFHack::Items& itemsModule = *core.getItems(); DFHack::Items& itemsModule = *core.getItems();
itemsModule.Start(); itemsModule.Start();
std::vector<DFHack::df_item*> items; std::vector<df::item*> items;
itemsModule.readItemVector(items); itemsModule.readItemVector(items);
DFHack::df_item * item; df::item * item;
// count all seeds and plants by RAW material // count all seeds and plants by RAW material
for(std::size_t i = 0; i < items.size(); ++i) for(std::size_t i = 0; i < items.size(); ++i)
{ {
@ -339,10 +340,10 @@ DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore)
t_materialIndex materialIndex = item->getMaterialIndex(); t_materialIndex materialIndex = item->getMaterialIndex();
switch(item->getType()) switch(item->getType())
{ {
case DFHack::Items::SEEDS: case df::item_type::SEEDS:
if(!ignoreSeeds(item->flags)) ++seedCount[materialIndex]; if(!ignoreSeeds(item->flags)) ++seedCount[materialIndex];
break; break;
case DFHack::Items::PLANT: case df::item_type::PLANT:
break; break;
} }
} }