MCPcopy Index your code
hub / github.com/NetHack/NetHack / replace_object

Function replace_object

src/mkobj.c:640–679  ·  view source on GitHub ↗

* Insert otmp right after obj in whatever chain(s) it is on. Then extract * obj from the chain(s). This function does a literal swap. It is up to * the caller to provide a valid context for the swap. When done, obj will * still exist, but not on any chain. * * Note: Don't use obj_extract_self() -- we are doing an in-place swap, * not actually moving something. */

Source from the content-addressed store, hash-verified

638 * not actually moving something.
639 */
640void
641replace_object(struct obj *obj, struct obj *otmp)
642{
643 otmp->where = obj->where;
644 switch (obj->where) {
645 case OBJ_FREE:
646 /* do nothing */
647 break;
648 case OBJ_INVENT:
649 otmp->nobj = obj->nobj;
650 obj->nobj = otmp;
651 extract_nobj(obj, &gi.invent);
652 break;
653 case OBJ_CONTAINED:
654 otmp->nobj = obj->nobj;
655 otmp->ocontainer = obj->ocontainer;
656 obj->nobj = otmp;
657 extract_nobj(obj, &obj->ocontainer->cobj);
658 break;
659 case OBJ_MINVENT:
660 otmp->nobj = obj->nobj;
661 otmp->ocarry = obj->ocarry;
662 obj->nobj = otmp;
663 extract_nobj(obj, &obj->ocarry->minvent);
664 break;
665 case OBJ_FLOOR:
666 otmp->nobj = obj->nobj;
667 otmp->nexthere = obj->nexthere;
668 otmp->ox = obj->ox;
669 otmp->oy = obj->oy;
670 obj->nobj = otmp;
671 obj->nexthere = otmp;
672 extract_nobj(obj, &fobj);
673 extract_nexthere(obj, &svl.level.objects[obj->ox][obj->oy]);
674 break;
675 default:
676 panic("replace_object: obj position");
677 break;
678 }
679}
680
681/* is 'obj' inside a container whose contents aren't known?
682 if so, return the outermost container meeting that criterium */

Callers 1

poly_objFunction · 0.85

Calls 3

extract_nobjFunction · 0.85
extract_nexthereFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected