* Mark object to be deallocated. _All_ objects should be run through here * for them to be deallocated. */
| 2742 | * for them to be deallocated. |
| 2743 | */ |
| 2744 | void |
| 2745 | dealloc_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 | } |
no test coverage detected