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

Function dealloc_obj

src/mkobj.c:2744–2811  ·  view source on GitHub ↗

* Mark object to be deallocated. _All_ objects should be run through here * for them to be deallocated. */

Source from the content-addressed store, hash-verified

2742 * for them to be deallocated.
2743 */
2744void
2745dealloc_obj(struct obj *obj)
2746{
2747 if (obj->otyp == BOULDER)
2748 obj->next_boulder = 0;
2749 if (obj->where == OBJ_DELETED) {
2750 impossible("dealloc_obj: obj already deleted (type=%d)", obj->otyp);
2751 return;
2752 } else if (obj->where != OBJ_FREE && obj->where != OBJ_LUAFREE) {
2753 panic("dealloc_obj: obj not free (type=%d, where=%d)",
2754 obj->otyp, obj->where);
2755 }
2756 if (obj->nobj)
2757 panic("dealloc_obj with nobj");
2758 if (obj->cobj)
2759 panic("dealloc_obj with cobj");
2760 if (obj == &hands_obj) {
2761 impossible("dealloc_obj with hands_obj");
2762 return;
2763 }
2764
2765 /* free up any timers attached to the object */
2766 if (obj->timed)
2767 obj_stop_timers(obj);
2768
2769 /*
2770 * Free up any light sources attached to the object.
2771 *
2772 * We may want to just call del_light_source() without any
2773 * checks (requires a code change there). Otherwise this
2774 * list must track all objects that can have a light source
2775 * attached to it (and also requires lamplit to be set).
2776 */
2777 if (obj_sheds_light(obj)) {
2778 del_light_source(LS_OBJECT, obj_to_any(obj));
2779 obj->lamplit = 0;
2780 }
2781
2782 if (obj == gt.thrownobj)
2783 gt.thrownobj = 0;
2784 if (obj == gk.kickedobj)
2785 gk.kickedobj = 0;
2786 if (obj == svc.context.tin.tin) {
2787 svc.context.tin.tin = (struct obj *) 0;
2788 svc.context.tin.o_id = 0;
2789 }
2790
2791 /* if obj came from the most recent splitobj(), it's no longer eligible
2792 for unsplitobj(); perform inline clear_splitobjs() */
2793 if (obj->o_id == svc.context.objsplit.parent_oid
2794 || obj->o_id == svc.context.objsplit.child_oid)
2795 svc.context.objsplit.parent_oid = svc.context.objsplit.child_oid = 0;
2796
2797 if (obj->lua_ref_cnt) {
2798 /* obj is referenced from a lua script, let lua gc free it */
2799 obj->where = OBJ_LUAFREE;
2800 return;
2801 }

Callers 15

resetobjsFunction · 0.85
namefloorobjFunction · 0.85
impact_arti_lightFunction · 0.85
l_obj_gcFunction · 0.85
mhitm_ad_dgstFunction · 0.85
that_is_a_mimicFunction · 0.85
obj_absorbFunction · 0.85
thitmFunction · 0.85
ini_inv_mkobj_filterFunction · 0.85
ini_invFunction · 0.85
kick_nondoorFunction · 0.85
fill_ordinary_roomFunction · 0.85

Calls 7

obj_stop_timersFunction · 0.85
obj_sheds_lightFunction · 0.85
del_light_sourceFunction · 0.85
obj_to_anyFunction · 0.85
dealloc_obj_realFunction · 0.85
impossibleFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected