| 526 | } |
| 527 | |
| 528 | void 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 | |
| 563 | void Items::getContainedItems(df::item *item, vector<df::item *> *items) { |
| 564 | CHECK_NULL_POINTER(item); |