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

Method getPosition

library/modules/Items.cpp:586–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586df::coord Items::getPosition(df::item *item) {
587 CHECK_NULL_POINTER(item);
588 // Function reverse-engineered from DF code.
589 if (item->flags.bits.removed)
590 return df::coord();
591
592 if (item->flags.bits.in_inventory) {
593 for (auto gref : item->general_refs)
594 {
595 switch (gref->getType())
596 {
597 case general_ref_type::CONTAINED_IN_ITEM:
598 if (auto item2 = gref->getItem())
599 return getPosition(item2);
600 break;
601 case general_ref_type::UNIT_HOLDER:
602 if (auto unit = gref->getUnit())
603 return Units::getPosition(unit);
604 break;
605 /*case general_ref_type::BUILDING_HOLDER: // Note: Not "in_inventory"
606 if (auto bld = ref->getBuilding())
607 return df::coord(bld->centerx, bld->centery, bld->z);
608 break;*/
609 default:
610 break;
611 }
612 }
613
614 if (auto sref = getSpecificRef(item, specific_ref_type::VERMIN_ESCAPED_PET))
615 return sref->data.vermin->pos;
616 return df::coord();
617 }
618 return item->pos;
619}
620
621static const char quality_table[] = {
622 '\0', // (base)

Callers

nothing calls this directly

Calls 1

getTypeMethod · 0.80

Tested by

no test coverage detected