From 48185568e9a9370f843fb28f1ff53335639b92d6 Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 18 May 2012 16:05:29 +0300 Subject: [PATCH] Added df::Items::moveToBuilding. Moved item from ground to building, usefull for museum forts (placing items on tables) --- library/LuaApi.cpp | 7 +++++++ library/include/modules/Items.h | 4 +++- library/modules/Items.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 529bdd077..d4c3b157d 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -755,6 +755,12 @@ static bool items_moveToContainer(df::item *item, df::item *container) return Items::moveToContainer(mc, item, container); } +static bool items_moveToBuilding(df::item *item, df::building_actual *building, int use_mode) +{ + MapExtras::MapCache mc; + return Items::moveToBuilding(mc, item, building,use_mode); +} + static const LuaWrapper::FunctionReg dfhack_items_module[] = { WRAPM(Items, getGeneralRef), WRAPM(Items, getSpecificRef), @@ -763,6 +769,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = { WRAPM(Items, getContainer), WRAPN(moveToGround, items_moveToGround), WRAPN(moveToContainer, items_moveToContainer), + WRAPN(moveToBuilding, items_moveToBuilding), { NULL, NULL } }; diff --git a/library/include/modules/Items.h b/library/include/modules/Items.h index 8353d24c3..54db8e6ca 100644 --- a/library/include/modules/Items.h +++ b/library/include/modules/Items.h @@ -37,6 +37,7 @@ distribution. #include "df/item_type.h" #include "df/general_ref.h" #include "df/specific_ref.h" +#include "df/building_actual.h" namespace df { @@ -147,5 +148,6 @@ DFHACK_EXPORT df::coord getPosition(df::item *item); 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); +DFHACK_EXPORT bool moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,int16_t use_mode); +} } -} \ No newline at end of file diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 335d7d8fc..a18ba60cb 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -48,6 +48,7 @@ using namespace std; #include "df/world.h" #include "df/item.h" #include "df/building.h" +#include "df/building_actual.h" #include "df/tool_uses.h" #include "df/itemdef_weaponst.h" #include "df/itemdef_trapcompst.h" @@ -69,6 +70,7 @@ using namespace std; #include "df/general_ref_unit_itemownerst.h" #include "df/general_ref_contains_itemst.h" #include "df/general_ref_contained_in_itemst.h" +#include "df/general_ref_building_holderst.h" #include "df/vermin.h" using namespace DFHack; @@ -676,3 +678,34 @@ bool DFHack::Items::moveToContainer(MapExtras::MapCache &mc, df::item *item, df: return true; } +DFHACK_EXPORT bool DFHack::Items::moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,int16_t use_mode) +{ + CHECK_NULL_POINTER(item); + CHECK_NULL_POINTER(building); + + auto ref = df::allocate(); + if(!ref) + { + delete ref; + Core::printerr("Could not allocate building holder refs.\n"); + return false; + } + if (!detachItem(mc, item)) + { + delete ref; + return false; + } + item->pos.x=building->centerx; + item->pos.y=building->centery; + item->pos.z=building->z; + item->flags.bits.in_building=true; + + ref->building_id=building->id; + item->itemrefs.push_back(ref); + + auto con=new df::building_actual::T_contained_items; + con->item=item; + con->use_mode=use_mode; + building->contained_items.push_back(con); + return true; +}