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

Method getOuterContainerRef

library/modules/Items.cpp:528–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528void Items::getOuterContainerRef(df::specific_ref &spec_ref, df::item *item, bool init_ref)
529{ // Reverse-engineered from ambushing unit code.
530 CHECK_NULL_POINTER(item);
531 if (init_ref) {
532 spec_ref.type = specific_ref_type::ITEM_GENERAL;
533 spec_ref.data.object = item;
534 }
535
536 if (item->flags.bits.removed || !item->flags.bits.in_inventory)
537 return;
538
539 for (auto gref : item->general_refs)
540 {
541 switch (gref->getType())
542 {
543 case general_ref_type::CONTAINED_IN_ITEM:
544 if (auto item2 = gref->getItem())
545 return Items::getOuterContainerRef(spec_ref, item2);
546 break;
547 case general_ref_type::UNIT_HOLDER:
548 if (auto unit = gref->getUnit())
549 return Units::getOuterContainerRef(spec_ref, unit);
550 break;
551 default:
552 break;
553 }
554 }
555
556 if (auto sref = getSpecificRef(item, specific_ref_type::VERMIN_ESCAPED_PET)) {
557 spec_ref.type = specific_ref_type::VERMIN_EVENT;
558 spec_ref.data.vermin = sref->data.vermin;
559 }
560 return;
561}
562
563void Items::getContainedItems(df::item *item, vector<df::item *> *items) {
564 CHECK_NULL_POINTER(item);

Callers

nothing calls this directly

Calls 1

getTypeMethod · 0.80

Tested by

no test coverage detected