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

Function migrate_to_level

src/dog.c:886–932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886void
887migrate_to_level(
888 struct monst *mtmp,
889 xint16 tolev, /* destination level */
890 xint16 xyloc, /* MIGR_xxx destination xy location: */
891 coord *cc) /* optional destination coordinates */
892{
893 d_level new_lev;
894 coordxy xyflags;
895 coordxy mx = mtmp->mx, my = mtmp->my; /* <mx,my> needed below */
896 int num_segs; /* count of worm segments */
897
898 if (mtmp->mleashed) {
899 mtmp->mtame--;
900 m_unleash(mtmp, TRUE);
901 }
902
903 /* prepare to take mtmp off the map */
904 num_segs = mon_leave(mtmp);
905 /* take off map and move mtmp from fmon list to migrating_mons */
906 relmon(mtmp, &gm.migrating_mons); /* mtmp->mx,my retain their value */
907 mtmp->mstate |= MON_MIGRATING;
908
909 new_lev.dnum = ledger_to_dnum((xint16) tolev);
910 new_lev.dlevel = ledger_to_dlev((xint16) tolev);
911 /* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as
912 destination codes */
913 xyflags = (depth(&new_lev) < depth(&u.uz)); /* 1 => up */
914 if (In_W_tower(mx, my, &u.uz))
915 xyflags |= 2;
916 mtmp->wormno = num_segs;
917 mtmp->mlstmv = svm.moves;
918 mtmp->mtrack[2].x = u.uz.dnum; /* migrating from this dungeon */
919 mtmp->mtrack[2].y = u.uz.dlevel; /* migrating from this dungeon level */
920 mtmp->mtrack[1].x = cc ? cc->x : mx;
921 mtmp->mtrack[1].y = cc ? cc->y : my;
922 mtmp->mtrack[0].x = xyloc;
923 mtmp->mtrack[0].y = xyflags;
924 mtmp->mux = new_lev.dnum;
925 mtmp->muy = new_lev.dlevel;
926 mtmp->mx = mtmp->my = 0; /* mx==0 implies migrating */
927
928 /* don't extinguish a mobile light; it still exists but has changed
929 from local (monst->mx > 0) to global (mx==0, not on this level) */
930 if (emits_light(mtmp->data))
931 vision_recalc(0);
932}
933
934/* when entering the endgame, levels from the dungeon and its branches are
935 discarded because they can't be reached again; do the same for monsters

Callers 9

mlevel_tele_trapFunction · 0.85
digactualholeFunction · 0.85
wiz_migrate_monsFunction · 0.85
keepdogsFunction · 0.85
migrate_monFunction · 0.85
use_defensiveFunction · 0.85
use_miscFunction · 0.85
migrate_orcFunction · 0.85
make_happy_shkFunction · 0.85

Calls 8

m_unleashFunction · 0.85
mon_leaveFunction · 0.85
relmonFunction · 0.85
ledger_to_dnumFunction · 0.85
ledger_to_dlevFunction · 0.85
depthFunction · 0.85
In_W_towerFunction · 0.85
vision_recalcFunction · 0.85

Tested by

no test coverage detected