moveToBuilding improvements

- Don't set in_building by default when use_mode is 0 (consistent with most vanilla DF items)
- make use_mode optional and default to 0 (including in Lua API)

Resolves #885
develop
lethosor 2016-04-05 11:43:02 -04:00
parent d9e368cab4
commit b97d33ca28
4 changed files with 25 additions and 11 deletions

@ -1205,10 +1205,15 @@ Items module
Move the item to the container. Returns *false* if impossible. Move the item to the container. Returns *false* if impossible.
* ``dfhack.items.moveToBuilding(item,building,use_mode)`` * ``dfhack.items.moveToBuilding(item,building[,use_mode[,force_in_building])``
Move the item to the building. Returns *false* if impossible. Move the item to the building. Returns *false* if impossible.
``use_mode`` defaults to 0. If set to 2, the item will be treated as part of the building.
If ``force_in_building`` is true, the item will be considered to be stored by the building
(used for items temporarily used in traps in vanilla DF)
* ``dfhack.items.moveToInventory(item,unit,use_mode,body_part)`` * ``dfhack.items.moveToInventory(item,unit,use_mode,body_part)``
Move the item to the unit inventory. Returns *false* if impossible. Move the item to the unit inventory. Returns *false* if impossible.

@ -1597,12 +1597,6 @@ 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 bool items_moveToInventory static bool items_moveToInventory
(df::item *item, df::unit *unit, df::unit_inventory_item::T_mode mode, int body_part) (df::item *item, df::unit *unit, df::unit_inventory_item::T_mode mode, int body_part)
{ {
@ -1653,7 +1647,6 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, createItem), WRAPM(Items, createItem),
WRAPN(moveToGround, items_moveToGround), WRAPN(moveToGround, items_moveToGround),
WRAPN(moveToContainer, items_moveToContainer), WRAPN(moveToContainer, items_moveToContainer),
WRAPN(moveToBuilding, items_moveToBuilding),
WRAPN(moveToInventory, items_moveToInventory), WRAPN(moveToInventory, items_moveToInventory),
WRAPN(makeProjectile, items_makeProjectile), WRAPN(makeProjectile, items_makeProjectile),
WRAPN(remove, items_remove), WRAPN(remove, items_remove),
@ -1675,9 +1668,22 @@ static int items_getContainedItems(lua_State *state)
return 1; return 1;
} }
static int items_moveToBuilding(lua_State *state)
{
MapExtras::MapCache mc;
auto item = Lua::CheckDFObject<df::item>(state, 1);
auto building = Lua::CheckDFObject<df::building_actual>(state, 2);
int use_mode = luaL_optint(state, 3, 0);
bool force_in_building = lua_toboolean(state, 4);
lua_pushboolean(state, Items::moveToBuilding(mc, item, building, use_mode, force_in_building));
return 1;
}
static const luaL_Reg dfhack_items_funcs[] = { static const luaL_Reg dfhack_items_funcs[] = {
{ "getPosition", items_getPosition }, { "getPosition", items_getPosition },
{ "getContainedItems", items_getContainedItems }, { "getContainedItems", items_getContainedItems },
{ "moveToBuilding", items_moveToBuilding },
{ NULL, NULL } { NULL, NULL }
}; };

@ -164,7 +164,8 @@ DFHACK_EXPORT std::string getDescription(df::item *item, int type = 0, bool deco
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); DFHACK_EXPORT bool moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,
int16_t use_mode = 0, bool force_in_building = false);
DFHACK_EXPORT bool moveToInventory(MapExtras::MapCache &mc, df::item *item, df::unit *unit, DFHACK_EXPORT bool moveToInventory(MapExtras::MapCache &mc, df::item *item, df::unit *unit,
df::unit_inventory_item::T_mode mode = df::unit_inventory_item::Hauled, int body_part = -1); df::unit_inventory_item::T_mode mode = df::unit_inventory_item::Hauled, int body_part = -1);

@ -892,7 +892,8 @@ bool DFHack::Items::moveToContainer(MapExtras::MapCache &mc, df::item *item, df:
return true; return true;
} }
bool DFHack::Items::moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,int16_t use_mode) bool DFHack::Items::moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,
int16_t use_mode, bool force_in_building)
{ {
CHECK_NULL_POINTER(item); CHECK_NULL_POINTER(item);
CHECK_NULL_POINTER(building); CHECK_NULL_POINTER(building);
@ -915,7 +916,8 @@ bool DFHack::Items::moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::
item->pos.x=building->centerx; item->pos.x=building->centerx;
item->pos.y=building->centery; item->pos.y=building->centery;
item->pos.z=building->z; item->pos.z=building->z;
item->flags.bits.in_building=true; if (use_mode == 2 || force_in_building)
item->flags.bits.in_building=true;
ref->building_id=building->id; ref->building_id=building->id;
item->general_refs.push_back(ref); item->general_refs.push_back(ref);