Petr Mrázek 2012-05-18 17:41:09 +02:00
commit ed6da7618a
3 changed files with 43 additions and 1 deletions

@ -755,6 +755,12 @@ static bool items_moveToContainer(df::item *item, df::item *container)
return Items::moveToContainer(mc, 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[] = { static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, getGeneralRef), WRAPM(Items, getGeneralRef),
WRAPM(Items, getSpecificRef), WRAPM(Items, getSpecificRef),
@ -763,6 +769,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, getContainer), WRAPM(Items, getContainer),
WRAPN(moveToGround, items_moveToGround), WRAPN(moveToGround, items_moveToGround),
WRAPN(moveToContainer, items_moveToContainer), WRAPN(moveToContainer, items_moveToContainer),
WRAPN(moveToBuilding, items_moveToBuilding),
{ NULL, NULL } { NULL, NULL }
}; };

@ -37,6 +37,7 @@ distribution.
#include "df/item_type.h" #include "df/item_type.h"
#include "df/general_ref.h" #include "df/general_ref.h"
#include "df/specific_ref.h" #include "df/specific_ref.h"
#include "df/building_actual.h"
namespace df 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 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 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);
} }
} }

@ -48,6 +48,7 @@ using namespace std;
#include "df/world.h" #include "df/world.h"
#include "df/item.h" #include "df/item.h"
#include "df/building.h" #include "df/building.h"
#include "df/building_actual.h"
#include "df/tool_uses.h" #include "df/tool_uses.h"
#include "df/itemdef_weaponst.h" #include "df/itemdef_weaponst.h"
#include "df/itemdef_trapcompst.h" #include "df/itemdef_trapcompst.h"
@ -69,6 +70,7 @@ using namespace std;
#include "df/general_ref_unit_itemownerst.h" #include "df/general_ref_unit_itemownerst.h"
#include "df/general_ref_contains_itemst.h" #include "df/general_ref_contains_itemst.h"
#include "df/general_ref_contained_in_itemst.h" #include "df/general_ref_contained_in_itemst.h"
#include "df/general_ref_building_holderst.h"
#include "df/vermin.h" #include "df/vermin.h"
using namespace DFHack; using namespace DFHack;
@ -676,3 +678,34 @@ bool DFHack::Items::moveToContainer(MapExtras::MapCache &mc, df::item *item, df:
return true; 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<df::general_ref_building_holderst>();
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;
}