2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2011-06-16 15:53:39 -06:00
|
|
|
|
|
|
|
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-05-03 01:47:04 -06:00
|
|
|
#include "df/specific_ref.h"
|
2012-05-18 07:05:29 -06:00
|
|
|
#include "df/building_actual.h"
|
2012-05-15 04:01:59 -06:00
|
|
|
#include "df/body_part_raw.h"
|
2012-05-20 11:57:45 -06:00
|
|
|
#include "df/unit_inventory_item.h"
|
2012-10-20 11:01:22 -06:00
|
|
|
#include "df/job_item_vector_id.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct itemdef;
|
2012-09-12 08:17:42 -06:00
|
|
|
struct proj_itemst;
|
2012-01-09 05:20:17 -07:00
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
namespace MapExtras {
|
|
|
|
class MapCache;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2012-10-20 11:01:22 -06:00
|
|
|
bool matches(df::job_item_vector_id vec_id);
|
2020-11-12 23:44:38 -07:00
|
|
|
bool matches(const df::job_item &item, MaterialInfo *mat = NULL,
|
|
|
|
bool skip_vector = false,
|
|
|
|
df::item_type itype = df::item_type::NONE);
|
2012-01-09 05:20:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
DFHACK_EXPORT bool isCasteMaterial(df::item_type itype);
|
|
|
|
DFHACK_EXPORT int getSubtypeCount(df::item_type itype);
|
|
|
|
DFHACK_EXPORT df::itemdef *getSubtypeDef(df::item_type itype, int subtype);
|
|
|
|
|
2012-01-16 21:12:58 -07:00
|
|
|
/// 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);
|
|
|
|
|
2012-05-03 01:47:04 -06:00
|
|
|
/// Retrieve refs
|
|
|
|
DFHACK_EXPORT df::general_ref *getGeneralRef(df::item *item, df::general_ref_type type);
|
|
|
|
DFHACK_EXPORT df::specific_ref *getSpecificRef(df::item *item, df::specific_ref_type type);
|
|
|
|
|
2012-04-11 10:10:31 -06:00
|
|
|
/// Retrieve the owner of the item.
|
|
|
|
DFHACK_EXPORT df::unit *getOwner(df::item *item);
|
|
|
|
/// Set the owner of the item. Pass NULL as unit to remove the owner.
|
|
|
|
DFHACK_EXPORT bool setOwner(df::item *item, df::unit *unit);
|
|
|
|
|
2012-01-16 21:12:58 -07:00
|
|
|
/// which item is it contained in?
|
2012-04-12 08:37:27 -06:00
|
|
|
DFHACK_EXPORT df::item *getContainer(df::item *item);
|
2022-03-13 18:19:35 -06:00
|
|
|
/// what is the outermost object it is contained in? Possible ref types: UNIT, ITEM_GENERAL, VERMIN_EVENT
|
|
|
|
DFHACK_EXPORT void getOuterContainerRef(df::specific_ref &spec_ref, df::item *item, bool init_ref = true);
|
|
|
|
DFHACK_EXPORT inline df::specific_ref getOuterContainerRef(df::item *item) { df::specific_ref s; getOuterContainerRef(s, item); return s; }
|
2012-01-16 21:12:58 -07:00
|
|
|
/// which items does it contain?
|
2012-04-12 08:37:27 -06:00
|
|
|
DFHACK_EXPORT void getContainedItems(df::item *item, /*output*/ std::vector<df::item*> *items);
|
|
|
|
|
2012-10-30 02:40:26 -06:00
|
|
|
/// which building holds it?
|
|
|
|
DFHACK_EXPORT df::building *getHolderBuilding(df::item *item);
|
|
|
|
/// which unit holds it?
|
|
|
|
DFHACK_EXPORT df::unit *getHolderUnit(df::item *item);
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
/// Returns the true position of the item.
|
|
|
|
DFHACK_EXPORT df::coord getPosition(df::item *item);
|
2020-01-25 04:43:02 -07:00
|
|
|
|
|
|
|
/// Returns the title of a codex or "tool", either as the codex title or as the title of the
|
|
|
|
/// first page or writing it has that has a non blank title. An empty string is returned if
|
2020-01-26 03:47:47 -07:00
|
|
|
/// no title is found (which is the case for everything that isn't a "book").
|
2020-01-25 13:46:10 -07:00
|
|
|
DFHACK_EXPORT std::string getBookTitle(df::item *item);
|
2012-04-12 08:37:27 -06:00
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
/// Returns the description string of the item.
|
|
|
|
DFHACK_EXPORT std::string getDescription(df::item *item, int type = 0, bool decorate = false);
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
DFHACK_EXPORT bool moveToGround(MapExtras::MapCache &mc, df::item *item, df::coord pos);
|
|
|
|
DFHACK_EXPORT bool moveToContainer(MapExtras::MapCache &mc, df::item *item, df::item *container);
|
2016-04-05 09:43:02 -06:00
|
|
|
DFHACK_EXPORT bool moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,
|
|
|
|
int16_t use_mode = 0, bool force_in_building = false);
|
2012-05-20 11:57:45 -06:00
|
|
|
DFHACK_EXPORT bool moveToInventory(MapExtras::MapCache &mc, df::item *item, df::unit *unit,
|
2012-10-22 11:37:12 -06:00
|
|
|
df::unit_inventory_item::T_mode mode = df::unit_inventory_item::Hauled, int body_part = -1);
|
2012-09-12 08:17:42 -06:00
|
|
|
|
2012-09-14 08:49:02 -06:00
|
|
|
/// Makes the item removed and marked for garbage collection
|
|
|
|
DFHACK_EXPORT bool remove(MapExtras::MapCache &mc, df::item *item, bool no_uncat = false);
|
|
|
|
|
2012-09-12 08:17:42 -06:00
|
|
|
/// Detaches the items from its current location and turns it into a projectile
|
|
|
|
DFHACK_EXPORT df::proj_itemst *makeProjectile(MapExtras::MapCache &mc, df::item *item);
|
2014-04-25 10:04:21 -06:00
|
|
|
|
|
|
|
/// Gets value of base-quality item with specified type and material
|
|
|
|
DFHACK_EXPORT int getItemBaseValue(int16_t item_type, int16_t item_subtype, int16_t mat_type, int32_t mat_subtype);
|
|
|
|
|
|
|
|
/// Gets the value of a specific item, ignoring civ values and trade agreements
|
|
|
|
DFHACK_EXPORT int getValue(df::item *item);
|
2014-07-03 08:36:55 -06:00
|
|
|
|
|
|
|
DFHACK_EXPORT int32_t createItem(df::item_type type, int16_t item_subtype, int16_t mat_type, int32_t mat_index, df::unit* creator);
|
2018-05-12 09:51:36 -06:00
|
|
|
|
|
|
|
/// Returns true if the item is free from mandates, or false if mandates prevent trading the item
|
|
|
|
DFHACK_EXPORT bool checkMandates(df::item *item);
|
|
|
|
/// Checks whether the item can be traded
|
|
|
|
DFHACK_EXPORT bool canTrade(df::item *item);
|
|
|
|
/// Checks whether the item and all items it contains, if any, can be traded
|
|
|
|
DFHACK_EXPORT bool canTradeWithContents(df::item *item);
|
|
|
|
|
2018-05-12 12:49:30 -06:00
|
|
|
/// Checks whether the item is an assigned hauling vehicle
|
|
|
|
DFHACK_EXPORT bool isRouteVehicle(df::item *item);
|
|
|
|
/// Checks whether the item is assigned to a squad
|
|
|
|
DFHACK_EXPORT bool isSquadEquipment(df::item *item);
|
|
|
|
|
2012-05-18 07:05:29 -06:00
|
|
|
}
|
2012-01-16 21:12:58 -07:00
|
|
|
}
|