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

Function done_object_cleanup

src/end.c:850–903  ·  view source on GitHub ↗

deal with some objects which may be in an abnormal state at end of game */

Source from the content-addressed store, hash-verified

848
849/* deal with some objects which may be in an abnormal state at end of game */
850void
851done_object_cleanup(void)
852{
853 int ox, oy;
854
855 /* might have been killed while using a disposable item, so make sure
856 it's gone prior to inventory disclosure and creation of bones */
857 inven_inuse(TRUE);
858 /*
859 * Hero can die when throwing an object (by hitting an adjacent
860 * gas spore, for instance, or being hit by mis-returning Mjollnir),
861 * or while in transit (from falling down stairs). If that happens,
862 * some object(s) might be in limbo rather than on the map or in
863 * any inventory. Saving bones with an active light source in limbo
864 * would trigger an 'object not local' panic.
865 *
866 * We used to use dealloc_obj() on gt.thrownobj and gk.kickedobj but
867 * that keeps them out of bones and could leave uball in a confused
868 * state (gone but still attached). Place them on the map but
869 * bypass flooreffects(). That could lead to minor anomalies in
870 * bones, like undamaged paper at water or lava locations or piles
871 * not being knocked down holes, but it seems better to get this
872 * game over with than risk being tangled up in more and more details.
873 */
874 ox = u.ux + u.dx, oy = u.uy + u.dy;
875 if (!isok(ox, oy) || !accessible(ox, oy))
876 ox = u.ux, oy = u.uy;
877 /* put thrown or kicked object on map (for bones); location might
878 be incorrect (perhaps killed by divine lightning when throwing at
879 a temple priest?) but this should be better than just vanishing
880 (fragile stuff should be taken care of before getting here) */
881 if (gt.thrownobj && gt.thrownobj->where == OBJ_FREE) {
882 place_object(gt.thrownobj, ox, oy);
883 stackobj(gt.thrownobj), gt.thrownobj = 0;
884 }
885 if (gk.kickedobj && gk.kickedobj->where == OBJ_FREE) {
886 place_object(gk.kickedobj, ox, oy);
887 stackobj(gk.kickedobj), gk.kickedobj = 0;
888 }
889 /* if Punished hero dies during level change or dies or quits while
890 swallowed, uball and uchain will be in limbo; put them on floor
891 so bones will have them and object list cleanup finds them */
892 if (uchain && uchain->where == OBJ_FREE) {
893 /* placebc(); */
894 lift_covet_and_placebc(override_restriction);
895 }
896 /* persistent inventory window now obsolete since disclosure uses
897 a normal popup one; avoids "Bad fruit #n" when saving bones */
898 if (iflags.perm_invent) {
899 iflags.perm_invent = FALSE;
900 perm_invent_toggled(TRUE); /* make interface notice the change */
901 }
902 return;
903}
904
905/* called twice; first to calculate total, then to list relevant items */
906staticfn void

Callers 3

really_doneFunction · 0.85
dosave0Function · 0.85
freedynamicdataFunction · 0.85

Calls 7

inven_inuseFunction · 0.85
isokFunction · 0.85
accessibleFunction · 0.85
place_objectFunction · 0.85
stackobjFunction · 0.85
lift_covet_and_placebcFunction · 0.85
perm_invent_toggledFunction · 0.85

Tested by

no test coverage detected