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

Function replmon

src/mon.c:2514–2556  ·  view source on GitHub ↗

called when monster is moved to larger structure */

Source from the content-addressed store, hash-verified

2512
2513/* called when monster is moved to larger structure */
2514void
2515replmon(struct monst *mtmp, struct monst *mtmp2)
2516{
2517 struct obj *otmp;
2518
2519 /* transfer the monster's inventory */
2520 for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
2521 if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
2522 impossible("replmon: minvent inconsistency");
2523 otmp->ocarry = mtmp2;
2524 }
2525 mtmp->minvent = 0;
2526 /* before relmon(mtmp), because it could clear polearm.hitmon */
2527 if (svc.context.polearm.hitmon == mtmp)
2528 svc.context.polearm.hitmon = mtmp2;
2529
2530 /* remove the old monster from the map and from `fmon' list */
2531 relmon(mtmp, (struct monst **) 0);
2532
2533 /* finish adding its replacement */
2534 if (mtmp != u.usteed) /* don't place steed onto the map */
2535 place_monster(mtmp2, mtmp2->mx, mtmp2->my);
2536 if (mtmp2->wormno) /* update level.monsters[wseg->wx][wseg->wy] */
2537 place_wsegs(mtmp2, mtmp); /* locations to mtmp2 not mtmp. */
2538 if (emits_light(mtmp2->data)) {
2539 /* since this is so rare, we don't have any `mon_move_light_source' */
2540 new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
2541 LS_MONSTER, monst_to_any(mtmp2));
2542 /* here we rely on fact that `mtmp' hasn't actually been deleted */
2543 del_light_source(LS_MONSTER, monst_to_any(mtmp));
2544 }
2545 mtmp2->nmon = fmon;
2546 fmon = mtmp2;
2547 if (u.ustuck == mtmp)
2548 set_ustuck(mtmp2);
2549 if (u.usteed == mtmp)
2550 u.usteed = mtmp2;
2551 if (mtmp2->isshk)
2552 replshk(mtmp, mtmp2);
2553
2554 /* discard the old monster */
2555 dealloc_monst(mtmp);
2556}
2557
2558/* release mon from the display and the map's monster list,
2559 maybe transfer it to one of the other monster lists */

Callers 1

montraitsFunction · 0.85

Calls 10

relmonFunction · 0.85
place_monsterFunction · 0.85
place_wsegsFunction · 0.85
new_light_sourceFunction · 0.85
monst_to_anyFunction · 0.85
del_light_sourceFunction · 0.85
set_ustuckFunction · 0.85
replshkFunction · 0.85
impossibleFunction · 0.70
dealloc_monstFunction · 0.70

Tested by

no test coverage detected