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

Function montraits

src/zap.c:712–827  ·  view source on GitHub ↗

used by revive() and animate_statue() */

Source from the content-addressed store, hash-verified

710
711/* used by revive() and animate_statue() */
712struct monst *
713montraits(
714 struct obj *obj,
715 coord *cc,
716 boolean adjacentok) /* False: at obj's spot only,
717 * True: nearby is allowed */
718{
719 struct monst *mtmp = (struct monst *) 0,
720 *mtmp2 = has_omonst(obj) ? get_mtraits(obj, TRUE) : 0;
721
722 if (mtmp2) {
723 /* save_mtraits() validated mtmp2->mnum */
724 mtmp2->data = &mons[mtmp2->mnum];
725
726 if (mtmp2->mhpmax > 0 || is_rider(mtmp2->data)) {
727 mtmp = makemon(mtmp2->data, cc->x, cc->y,
728 (NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH
729 /* in case mtmp2 is a long worm; saved traits for
730 long worm don't include tail segments so don't
731 give mtmp any; it will be given a new 'wormno'
732 though (unless those are exhausted) so be able
733 to grow new tail segments */
734 | MM_NOTAIL | MM_NOMSG
735 | (adjacentok ? MM_ADJACENTOK : 0)));
736 }
737 if (!mtmp) {
738 /* mtmp2 is a copy of obj's object->oextra->omonst extension
739 and is not on the map or on any monst lists */
740 dealloc_monst(mtmp2);
741 return (struct monst *) 0;
742 }
743
744 /* heal the monster; lower than normal level might come from
745 adj_lev() but we assume it has come from 'mtmp' being level
746 drained before finally killed; give a chance to restore
747 some levels so that trolls and Riders can't be drained to
748 level 0 and then trivially killed repeatedly */
749 if ((int) mtmp->m_lev < mtmp->data->mlevel) {
750 int ltmp = rnd(mtmp->data->mlevel + 1);
751
752 if (ltmp > (int) mtmp->m_lev) {
753 while ((int) mtmp->m_lev < ltmp) {
754 mtmp->m_lev++;
755 mtmp->mhpmax += monhp_per_lvl(mtmp);
756 }
757 mtmp2->m_lev = mtmp->m_lev;
758 }
759 }
760 if (mtmp->mhpmax > mtmp2->mhpmax) /* &&is_rider(mtmp2->data)*/
761 mtmp2->mhpmax = mtmp->mhpmax;
762 mtmp2->mhp = mtmp2->mhpmax;
763 /* Get these ones from mtmp */
764 mtmp2->minvent = mtmp->minvent; /*redundant*/
765 /* monster ID is available if the monster died in the current
766 game, but will be zero if the corpse was in a bones level
767 (we cleared it when loading bones) */
768 if (mtmp->m_id) {
769 mtmp2->m_id = mtmp->m_id;

Callers 2

animate_statueFunction · 0.85
reviveFunction · 0.85

Calls 10

get_mtraitsFunction · 0.85
makemonFunction · 0.85
rndFunction · 0.85
monhp_per_lvlFunction · 0.85
dmgtypeFunction · 0.85
replmonFunction · 0.85
newsymFunction · 0.85
restore_chamFunction · 0.85
dealloc_monstFunction · 0.70
neweshkFunction · 0.70

Tested by

no test coverage detected