MCPcopy Create free account
hub / github.com/DFHack/dfhack / moveToInventory

Method moveToInventory

library/modules/Items.cpp:1009–1042  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1007}
1008
1009bool DFHack::Items::moveToInventory(df::item *item, df::unit *unit,
1010 df::inv_item_role_type mode, int body_part)
1011{
1012 CHECK_NULL_POINTER(item);
1013 CHECK_NULL_POINTER(unit);
1014 CHECK_NULL_POINTER(unit->body.body_plan);
1015 CHECK_INVALID_ARGUMENT(is_valid_enum_item(mode));
1016 int body_plan_size = unit->body.body_plan->body_parts.size();
1017 CHECK_INVALID_ARGUMENT(body_part < 0 || body_part <= body_plan_size);
1018
1019 auto holderReference = df::allocate<df::general_ref_unit_holderst>();
1020 if (!holderReference) {
1021 Core::printerr("Could not allocate UNIT_HOLDER reference.\n");
1022 return false;
1023 }
1024 else if (!detachItem(item)) {
1025 delete holderReference;
1026 return false;
1027 }
1028
1029 item->flags.bits.in_inventory = true;
1030
1031 auto newInventoryItem = new df::unit_inventory_item();
1032 newInventoryItem->item = item;
1033 newInventoryItem->mode = mode;
1034 newInventoryItem->body_part_id = body_part;
1035 unit->inventory.push_back(newInventoryItem);
1036
1037 holderReference->unit_id = unit->id;
1038 item->general_refs.push_back(holderReference);
1039
1040 resetUnitInvFlags(unit, newInventoryItem);
1041 return true;
1042}
1043
1044bool Items::remove(df::item *item, bool no_uncat) {
1045 CHECK_NULL_POINTER(item);

Callers

nothing calls this directly

Calls 5

is_valid_enum_itemFunction · 0.85
detachItemFunction · 0.85
resetUnitInvFlagsFunction · 0.85
printerrFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected