MCPcopy Create free account
hub / github.com/NetHack/NetHack / discard_migrations

Function discard_migrations

src/dog.c:937–990  ·  view source on GitHub ↗

when entering the endgame, levels from the dungeon and its branches are discarded because they can't be reached again; do the same for monsters and objects scheduled to migrate to those levels */

Source from the content-addressed store, hash-verified

935 discarded because they can't be reached again; do the same for monsters
936 and objects scheduled to migrate to those levels */
937void
938discard_migrations(void)
939{
940 struct monst *mtmp, **mprev;
941 struct obj *otmp, **oprev;
942 d_level dest;
943
944 for (mprev = &gm.migrating_mons; (mtmp = *mprev) != 0; ) {
945 dest.dnum = mtmp->mux;
946 dest.dlevel = mtmp->muy;
947 /* the Wizard is kept regardless of location so that he is
948 ready to be brought back; nothing should be scheduled to
949 migrate to the endgame but if we find such, we'll keep it */
950 if (mtmp->iswiz || In_endgame(&dest)) {
951 mprev = &mtmp->nmon; /* keep mtmp on migrating_mons */
952 } else {
953 *mprev = mtmp->nmon; /* remove mtmp from migrating_mons */
954 mtmp->nmon = 0;
955 discard_minvent(mtmp, FALSE);
956 /* bypass mongone() and its call to m_detach() plus dmonsfree() */
957 if (emits_light(mtmp->data))
958 del_light_source(LS_MONSTER, monst_to_any(mtmp));
959 dealloc_monst(mtmp);
960 }
961 }
962
963 /* objects get similar treatment */
964 for (oprev = &gm.migrating_objs; (otmp = *oprev) != 0; ) {
965 dest.dnum = otmp->ox;
966 dest.dlevel = otmp->oy;
967 /* there is no special case like the Wizard (certainly not the
968 Amulet; the hero has to be carrying it to enter the endgame
969 which triggers the call to this routine); again we don't
970 expect any objects to be migrating to the endgame but will
971 keep any we find so that they could be delivered */
972 if (In_endgame(&dest)) {
973 oprev = &otmp->nobj; /* keep otmp on migrating_objs */
974 } else {
975 /* bypass obj_extract_self() */
976 *oprev = otmp->nobj; /* remove otmp from migrating_objs */
977 otmp->nobj = 0;
978 otmp->where = OBJ_FREE;
979 otmp->owornmask = 0L; /* overloaded for destination usage;
980 * obfree() will complain if nonzero */
981 /*
982 * obfree(otmp,)
983 * -> dealloc_obj(otmp)
984 * -> obj_stop_timers(otmp)
985 * -> del_light_source(LS_OBJECT, obj_to_any(otmp))
986 */
987 obfree(otmp, (struct obj *) 0); /* releases any contents too */
988 }
989 }
990}
991
992/* returns the quality of an item of food; the lower the better;
993 fungi and ghouls will eat even tainted food */

Callers 1

goto_levelFunction · 0.85

Calls 5

discard_minventFunction · 0.85
del_light_sourceFunction · 0.85
monst_to_anyFunction · 0.85
obfreeFunction · 0.85
dealloc_monstFunction · 0.70

Tested by

no test coverage detected