summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/LuaApi.cpp7
-rw-r--r--library/include/modules/Items.h3
-rw-r--r--library/modules/Items.cpp32
3 files changed, 42 insertions, 0 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index f69fa7a1..f8497569 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -886,6 +886,12 @@ static bool items_moveToInventory
return Items::moveToInventory(mc, item, unit, mode, body_part);
}
+static bool items_remove(df::item *item, bool no_uncat)
+{
+ MapExtras::MapCache mc;
+ return Items::remove(mc, item, no_uncat);
+}
+
static df::proj_itemst *items_makeProjectile(df::item *item)
{
MapExtras::MapCache mc;
@@ -904,6 +910,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPN(moveToBuilding, items_moveToBuilding),
WRAPN(moveToInventory, items_moveToInventory),
WRAPN(makeProjectile, items_makeProjectile),
+ WRAPN(remove, items_remove),
{ NULL, NULL }
};
diff --git a/library/include/modules/Items.h b/library/include/modules/Items.h
index 7493d22f..81c8e128 100644
--- a/library/include/modules/Items.h
+++ b/library/include/modules/Items.h
@@ -157,6 +157,9 @@ DFHACK_EXPORT bool moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::b
DFHACK_EXPORT bool moveToInventory(MapExtras::MapCache &mc, df::item *item, df::unit *unit,
df::unit_inventory_item::T_mode mode = df::unit_inventory_item::Carried, int body_part = -1);
+/// Makes the item removed and marked for garbage collection
+DFHACK_EXPORT bool remove(MapExtras::MapCache &mc, df::item *item, bool no_uncat = false);
+
/// 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);
}
diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp
index 751797f0..b8c697a4 100644
--- a/library/modules/Items.cpp
+++ b/library/modules/Items.cpp
@@ -730,6 +730,18 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
item->flags.bits.in_inventory = false;
return true;
}
+ else if (item->flags.bits.removed)
+ {
+ item->flags.bits.removed = false;
+
+ if (item->flags.bits.garbage_collect)
+ {
+ item->flags.bits.garbage_collect = false;
+ item->categorize(true);
+ }
+
+ return true;
+ }
else
return false;
}
@@ -871,6 +883,26 @@ bool DFHack::Items::moveToInventory(
return true;
}
+bool Items::remove(MapExtras::MapCache &mc, df::item *item, bool no_uncat)
+{
+ CHECK_NULL_POINTER(item);
+
+ auto pos = getPosition(item);
+
+ if (!detachItem(mc, item))
+ return false;
+
+ if (pos.isValid())
+ item->pos = pos;
+
+ if (!no_uncat)
+ item->uncategorize();
+
+ item->flags.bits.removed = true;
+ item->flags.bits.garbage_collect = !no_uncat;
+ return true;
+}
+
df::proj_itemst *Items::makeProjectile(MapExtras::MapCache &mc, df::item *item)
{
CHECK_NULL_POINTER(item);