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

Function grow_up

src/makemon.c:2050–2178  ·  view source on GitHub ↗

monster earned experience and will gain some hit points; it might also grow into a bigger monster (baby to adult, soldier to officer, etc) */

Source from the content-addressed store, hash-verified

2048/* monster earned experience and will gain some hit points; it might also
2049 grow into a bigger monster (baby to adult, soldier to officer, etc) */
2050struct permonst *
2051grow_up(struct monst *mtmp, struct monst *victim)
2052{
2053 int oldtype, newtype, max_increase, cur_increase, lev_limit, hp_threshold;
2054 unsigned fem;
2055 struct permonst *ptr = mtmp->data;
2056
2057 /* monster died after killing enemy but before calling this function */
2058 /* currently possible if killing a gas spore */
2059 if (DEADMONSTER(mtmp))
2060 return (struct permonst *) 0;
2061
2062 /* note: none of the monsters with special hit point calculations
2063 have both little and big forms (killer bee can't grow into queen
2064 bee by just killing things, so isn't in the little_to_big list) */
2065 oldtype = monsndx(ptr);
2066 newtype = (oldtype == PM_KILLER_BEE && !victim) ? PM_QUEEN_BEE
2067 : little_to_big(oldtype);
2068#if 0
2069 /* gender-neutral PM_CLERIC now */
2070 if (newtype == PM_PRIEST && mtmp->female)
2071 newtype = PM_PRIESTESS;
2072#endif
2073
2074 /* growth limits differ depending on method of advancement */
2075 if (victim) { /* killed a monster */
2076 /*
2077 * The HP threshold is the maximum number of hit points for the
2078 * current level; once exceeded, a level will be gained.
2079 * Possible bug: if somehow the hit points are already higher
2080 * than that, monster will gain a level without any increase in HP.
2081 */
2082 hp_threshold = mtmp->m_lev * 8; /* normal limit */
2083 if (!mtmp->m_lev)
2084 hp_threshold = 4;
2085 else if (is_golem(ptr)) /* strange creatures */
2086 hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1;
2087 else if (is_home_elemental(ptr))
2088 hp_threshold *= 3;
2089 lev_limit = 3 * (int) ptr->mlevel / 2; /* same as adj_lev() */
2090 /* If they can grow up, be sure the level is high enough for that */
2091 if (oldtype != newtype && mons[newtype].mlevel > lev_limit)
2092 lev_limit = (int) mons[newtype].mlevel;
2093 /* number of hit points to gain; unlike for the player, we put
2094 the limit at the bottom of the next level rather than the top */
2095 max_increase = rnd((int) victim->m_lev + 1);
2096 if (mtmp->mhpmax + max_increase > hp_threshold + 1)
2097 max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0);
2098 cur_increase = (max_increase > 1) ? rn2(max_increase) : 0;
2099 } else {
2100 /* a gain level potion or wraith corpse; always go up a level
2101 unless already at maximum (49 is hard upper limit except
2102 for demon lords, who start at 50 and can't go any higher) */
2103 max_increase = cur_increase = rnd(8);
2104 hp_threshold = 0; /* smaller than `mhpmax + max_increase' */
2105 lev_limit = 50; /* recalc below */
2106 }
2107

Callers 12

mhitm_ad_rustFunction · 0.85
mhitm_ad_dcayFunction · 0.85
mhitm_ad_fireFunction · 0.85
mhitm_ad_cursFunction · 0.85
do_stone_monFunction · 0.85
mhitm_ad_physFunction · 0.85
mhitm_ad_seduFunction · 0.85
engulfer_digests_foodFunction · 0.85
mdamagemFunction · 0.85
m_consume_objFunction · 0.85
bee_eat_jellyFunction · 0.85
use_miscFunction · 0.85

Calls 15

little_to_bigFunction · 0.85
is_home_elementalFunction · 0.85
rndFunction · 0.85
rn2Function · 0.85
mon_namFunction · 0.85
anFunction · 0.85
pmnameFunction · 0.85
MgenderFunction · 0.85
set_mon_dataFunction · 0.85
mondiedFunction · 0.85
pline_monFunction · 0.85
YMonnamFunction · 0.85

Tested by

no test coverage detected