monster earned experience and will gain some hit points; it might also grow into a bigger monster (baby to adult, soldier to officer, etc) */
| 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) */ |
| 2050 | struct permonst * |
| 2051 | grow_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 |
no test coverage detected