2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2010-05-02 03:27:16 -06:00
|
|
|
/*
|
2011-04-11 14:13:06 -06:00
|
|
|
* Items!
|
2010-05-02 03:27:16 -06:00
|
|
|
*/
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "MemAccess.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
#include "DataDefs.h"
|
2012-01-16 19:16:16 -07:00
|
|
|
#include "df/item.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
#include "df/item_type.h"
|
2012-01-16 19:40:29 -07:00
|
|
|
#include "df/general_ref.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct itemdef;
|
|
|
|
}
|
|
|
|
|
2011-05-25 18:10:23 -06:00
|
|
|
/**
|
|
|
|
* \defgroup grp_items Items module and its types
|
|
|
|
* @ingroup grp_modules
|
|
|
|
*/
|
|
|
|
|
2010-05-02 03:27:16 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-01-09 05:20:17 -07:00
|
|
|
struct DFHACK_EXPORT ItemTypeInfo {
|
|
|
|
df::item_type type;
|
|
|
|
int16_t subtype;
|
|
|
|
|
|
|
|
df::itemdef *custom;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ItemTypeInfo(df::item_type type_ = df::enums::item_type::NONE, int16_t subtype_ = -1) {
|
|
|
|
decode(type_, subtype_);
|
|
|
|
}
|
|
|
|
template<class T> ItemTypeInfo(T *ptr) { decode(ptr); }
|
|
|
|
|
|
|
|
bool isValid() const {
|
|
|
|
return (type != df::enums::item_type::NONE) && (subtype == -1 || custom);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool decode(df::item_type type_, int16_t subtype_ = -1);
|
|
|
|
bool decode(df::item *ptr);
|
|
|
|
|
|
|
|
template<class T> bool decode(T *ptr) {
|
|
|
|
return ptr ? decode(ptr->item_type, ptr->item_subtype) : decode(df::enums::item_type::NONE);
|
|
|
|
}
|
|
|
|
|
2012-01-15 04:39:20 -07:00
|
|
|
std::string getToken();
|
2012-01-09 05:20:17 -07:00
|
|
|
std::string toString();
|
|
|
|
|
|
|
|
bool find(const std::string &token);
|
|
|
|
|
|
|
|
bool matches(const df::job_item &item, MaterialInfo *mat = NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator== (const ItemTypeInfo &a, const ItemTypeInfo &b) {
|
|
|
|
return a.type == b.type && a.subtype == b.subtype;
|
|
|
|
}
|
|
|
|
inline bool operator!= (const ItemTypeInfo &a, const ItemTypeInfo &b) {
|
|
|
|
return a.type != b.type || a.subtype != b.subtype;
|
|
|
|
}
|
2010-05-02 03:27:16 -06:00
|
|
|
|
2011-05-25 18:10:23 -06:00
|
|
|
/**
|
|
|
|
* Type for holding an item read from DF
|
|
|
|
* \ingroup grp_items
|
|
|
|
*/
|
2011-04-11 14:13:06 -06:00
|
|
|
struct dfh_item
|
2010-05-02 03:27:16 -06:00
|
|
|
{
|
2012-01-16 19:16:16 -07:00
|
|
|
df::item *origin; // where this was read from
|
2011-10-26 14:18:13 -06:00
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
int16_t z;
|
2012-01-16 19:16:16 -07:00
|
|
|
df::item_flags flags;
|
2011-10-26 14:18:13 -06:00
|
|
|
uint32_t age;
|
|
|
|
uint32_t id;
|
2010-06-24 23:11:26 -06:00
|
|
|
t_material matdesc;
|
|
|
|
int32_t quantity;
|
|
|
|
int32_t quality;
|
2011-04-10 12:42:25 -06:00
|
|
|
int16_t wear_level;
|
2011-04-11 14:13:06 -06:00
|
|
|
};
|
|
|
|
|
2011-05-25 18:10:23 -06:00
|
|
|
/**
|
|
|
|
* The Items module
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_items
|
|
|
|
*/
|
2012-01-16 21:12:58 -07:00
|
|
|
namespace Items
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Look for a particular item by ID
|
|
|
|
DFHACK_EXPORT df::item * findItemByID(int32_t id);
|
|
|
|
|
|
|
|
/// Make a partial copy of a DF item
|
|
|
|
DFHACK_EXPORT bool copyItem(df::item * source, dfh_item & target);
|
|
|
|
/// write copied item back to its origin
|
|
|
|
DFHACK_EXPORT bool writeItem(const dfh_item & item);
|
|
|
|
|
|
|
|
/// who owns this item we already read?
|
|
|
|
DFHACK_EXPORT int32_t getItemOwnerID(const df::item * item);
|
2012-01-24 10:32:34 -07:00
|
|
|
DFHACK_EXPORT df::unit *getItemOwner(const df::item * item);
|
2012-01-16 21:12:58 -07:00
|
|
|
/// which item is it contained in?
|
|
|
|
DFHACK_EXPORT int32_t getItemContainerID(const df::item * item);
|
2012-01-24 10:32:34 -07:00
|
|
|
DFHACK_EXPORT df::item *getItemContainer(const df::item * item);
|
2012-01-16 21:12:58 -07:00
|
|
|
/// which items does it contain?
|
|
|
|
DFHACK_EXPORT bool getContainedItems(const df::item * item, /*output*/ std::vector<int32_t> &items);
|
|
|
|
/// wipe out the owner records
|
2012-01-24 10:32:34 -07:00
|
|
|
DFHACK_EXPORT bool removeItemOwner(df::item * item);
|
2012-01-16 21:12:58 -07:00
|
|
|
/// read item references, filtered by class
|
|
|
|
DFHACK_EXPORT bool readItemRefs(const df::item * item, const df::general_ref_type type,
|
|
|
|
/*output*/ std::vector<int32_t> &values);
|
|
|
|
}
|
|
|
|
}
|