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

Method moveToContainer

library/modules/Items.cpp:936–972  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

934}
935
936bool DFHack::Items::moveToContainer(df::item *item, df::item *container) {
937 CHECK_NULL_POINTER(item);
938 CHECK_NULL_POINTER(container);
939
940 auto cpos = getPosition(container);
941 if (!cpos.isValid())
942 return false;
943
944 auto ref1 = df::allocate<df::general_ref_contains_itemst>();
945 auto ref2 = df::allocate<df::general_ref_contained_in_itemst>();
946
947 if (!ref1 || !ref2) {
948 delete ref1;
949 delete ref2;
950 Core::printerr("Could not allocate container refs.\n");
951 return false;
952 }
953 else if (!detachItem(item)) {
954 delete ref1;
955 delete ref2;
956 return false;
957 }
958
959 item->pos = container->pos;
960 item->flags.bits.in_inventory = true;
961
962 container->flags.bits.container = true;
963 container->flags.bits.weight_computed = false;
964
965 ref1->item_id = item->id;
966 container->general_refs.push_back(ref1);
967
968 ref2->item_id = container->id;
969 item->general_refs.push_back(ref2);
970
971 return true;
972}
973
974bool DFHack::Items::moveToBuilding(df::item *item, df::building_actual *building,
975 df::building_item_role_type use_mode, bool force_in_building)

Callers

nothing calls this directly

Calls 3

detachItemFunction · 0.85
printerrFunction · 0.50
isValidMethod · 0.45

Tested by

no test coverage detected