* Add obj to container, make sure obj is "free". Returns (merged) obj. * The input obj may be deleted in the process. * * Caveat: this does not update the container's weight [possibly to * prevent that from being recalculated repeatedly when adding multiple * items]. */
| 2673 | * items]. |
| 2674 | */ |
| 2675 | struct obj * |
| 2676 | add_to_container(struct obj *container, struct obj *obj) |
| 2677 | { |
| 2678 | struct obj *otmp; |
| 2679 | |
| 2680 | if (obj->where != OBJ_FREE) |
| 2681 | panic("add_to_container: obj where=%d, not free", obj->where); |
| 2682 | if (container->where != OBJ_INVENT && container->where != OBJ_MINVENT) |
| 2683 | obj_no_longer_held(obj); |
| 2684 | |
| 2685 | /* merge if possible */ |
| 2686 | for (otmp = container->cobj; otmp; otmp = otmp->nobj) |
| 2687 | if (merged(&otmp, &obj)) |
| 2688 | return otmp; |
| 2689 | |
| 2690 | obj->where = OBJ_CONTAINED; |
| 2691 | obj->ocontainer = container; |
| 2692 | obj->nobj = container->cobj; |
| 2693 | container->cobj = obj; |
| 2694 | return obj; |
| 2695 | } |
| 2696 | |
| 2697 | void |
| 2698 | add_to_migration(struct obj *obj) |
no test coverage detected