MCPcopy Index your code
hub / github.com/NetHack/NetHack / newcham

Function newcham

src/mon.c:5277–5535  ·  view source on GitHub ↗

make a chameleon take on another shape, or a polymorph target (possibly self-inflicted) become a different monster; returns 1 if it actually changes form */

Source from the content-addressed store, hash-verified

5275 (possibly self-inflicted) become a different monster;
5276 returns 1 if it actually changes form */
5277int
5278newcham(
5279 struct monst *mtmp,
5280 struct permonst *mdat,
5281 unsigned ncflags)
5282{
5283 boolean polyspot = ((ncflags & NC_VIA_WAND_OR_SPELL) !=0),
5284 /* "The oldmon turns into a newmon!" */
5285 msg = ((ncflags & NC_SHOW_MSG) != 0),
5286 seenorsensed = canspotmon(mtmp);
5287 int hpn, hpd, mndx, tryct;
5288 struct permonst *olddata = mtmp->data;
5289 char *p, oldname[BUFSZ], l_oldname[BUFSZ];
5290
5291 /* Riders are immune to polymorph and green slime
5292 (but apparent Rider might actually be a doppelganger) */
5293 if (mtmp->cham == NON_PM) { /* not a shapechanger */
5294 if (is_rider(olddata))
5295 return 0;
5296 /* make Nazgul and erinyes immune too, to reduce chance of
5297 anomalous extinction feedback during final disclosure */
5298 if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
5299 return 0;
5300 /* cancelled shapechangers become uncancelled prior
5301 to being given a new shape */
5302 if (mtmp->mcan && !Protection_from_shape_changers) {
5303 mtmp->cham = pm_to_cham(monsndx(mtmp->data));
5304 if (mtmp->cham != NON_PM)
5305 mtmp->mcan = 0;
5306 }
5307 }
5308
5309 if (msg) {
5310 Strcpy(oldname,
5311 /* like YMonnam() but never mention saddle */
5312 x_monnam(mtmp, mtmp->mtame ? ARTICLE_YOUR : ARTICLE_THE,
5313 (char *) 0, SUPPRESS_SADDLE, FALSE));
5314 oldname[0] = highc(oldname[0]);
5315 }
5316 /* we need this one whether msg is true or not */
5317 Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
5318 has_mgivenname(mtmp) ? SUPPRESS_SADDLE : 0,
5319 FALSE));
5320
5321 /* mdat = 0 -> caller wants a random monster shape */
5322 if (mdat == 0) {
5323 /* select_newcham_form() loops when resorting to random but
5324 it doesn't always pick that so we still retry here too */
5325 tryct = 20;
5326 do {
5327 mndx = select_newcham_form(mtmp);
5328 mdat = accept_newcham_form(mtmp, mndx);
5329 /* for the first several tries we require upper-case on
5330 the rogue level (after that, we take whatever we get) */
5331 if (tryct > 15 && Is_rogue_level(&u.uz)
5332 && mdat && !isupper(monsym(mdat)))
5333 mdat = 0;
5334 if (mdat)

Callers 15

mhitm_ad_slimFunction · 0.85
gulpumFunction · 0.85
engulfer_digests_foodFunction · 0.85
gulpmmFunction · 0.85
mdamagemFunction · 0.85
mon_polyFunction · 0.85
m_consume_objFunction · 0.85
vamprisesFunction · 0.85
mon_to_stoneFunction · 0.85
vamp_stoneFunction · 0.85
normal_shapeFunction · 0.85
decide_to_shapeshiftFunction · 0.85

Calls 15

mbirth_limitFunction · 0.85
pm_to_chamFunction · 0.85
highcFunction · 0.85
select_newcham_formFunction · 0.85
accept_newcham_formFunction · 0.85
isupperFunction · 0.85
mgender_from_permonstFunction · 0.85
wormgoneFunction · 0.85
place_monsterFunction · 0.85
seemimicFunction · 0.85
newmonhpFunction · 0.85
set_mon_dataFunction · 0.85

Tested by

no test coverage detected