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

Method setOwner

library/modules/Items.cpp:488–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488bool Items::setOwner(df::item *item, df::unit *unit) {
489 CHECK_NULL_POINTER(item);
490
491 for (int i = item->general_refs.size()-1; i >= 0; i--)
492 {
493 auto ref = item->general_refs[i];
494 if (ref->getType() != general_ref_type::UNIT_ITEMOWNER)
495 continue;
496
497 if (auto cur = ref->getUnit()) {
498 if (cur == unit)
499 return true;
500 erase_from_vector(cur->owned_items, item->id);
501 }
502
503 vector_erase_at(item->general_refs, i);
504 delete ref;
505 }
506
507 item->flags.bits.owned = false;
508
509 if (unit) {
510 auto ref = df::allocate<df::general_ref_unit_itemownerst>();
511 if (!ref)
512 return false;
513
514 item->flags.bits.owned = true;
515 ref->unit_id = unit->id;
516
517 insert_into_vector(unit->owned_items, item->id);
518 item->general_refs.push_back(ref);
519 }
520 return true;
521}
522
523df::item *Items::getContainer(df::item *item) {
524 auto ref = getGeneralRef(item, general_ref_type::CONTAINED_IN_ITEM);

Callers

nothing calls this directly

Calls 5

erase_from_vectorFunction · 0.85
vector_erase_atFunction · 0.85
insert_into_vectorFunction · 0.85
getTypeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected