| 486 | } |
| 487 | |
| 488 | bool 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 | |
| 523 | df::item *Items::getContainer(df::item *item) { |
| 524 | auto ref = getGeneralRef(item, general_ref_type::CONTAINED_IN_ITEM); |
nothing calls this directly
no test coverage detected