From: nhmall Date: Sat, 28 May 2022 23:35:48 +0000 (-0400) Subject: switch to using a flag parameter on newcham() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e6ac144b4c75a1befe28bc6d599ff0b778f9204;p=nethack switch to using a flag parameter on newcham() --- diff --git a/include/extern.h b/include/extern.h index c164eca53..e8db45a92 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1568,7 +1568,7 @@ extern boolean valid_vampshiftform(int, int); extern boolean validvamp(struct monst *, int *, int); extern int select_newcham_form(struct monst *); extern void mgender_from_permonst(struct monst *, struct permonst *); -extern int newcham(struct monst *, struct permonst *, boolean, boolean); +extern int newcham(struct monst *, struct permonst *, unsigned); extern int can_be_hatched(int); extern int egg_type_from_parent(int, boolean); extern boolean dead_species(int, boolean); diff --git a/include/hack.h b/include/hack.h index a3aa8ae6c..1f0ce728e 100644 --- a/include/hack.h +++ b/include/hack.h @@ -585,6 +585,11 @@ enum bodypart_types { #define ECMD_CANCEL 0x02 /* cmd canceled by user */ #define ECMD_FAIL 0x04 /* cmd failed to finish, maybe with a yafm */ +/* flags for newcham() */ +#define NO_NC_FLAGS 0U +#define NC_SHOW_MSG 0x01U +#define NC_VIA_WAND_OR_SPELL 0x02U + /* values returned from getobj() callback functions */ enum getobj_callback_returns { /* generally invalid - can't be used for this purpose. will give a "silly diff --git a/src/do.c b/src/do.c index 2cadbca35..34599c464 100644 --- a/src/do.c +++ b/src/do.c @@ -766,7 +766,7 @@ engulfer_digests_food(struct obj *obj) if (could_poly || could_slime) { (void) newcham(u.ustuck, could_slime ? &mons[PM_GREEN_SLIME] : 0, - FALSE, could_slime); + could_slime ? NC_SHOW_MSG : NO_NC_FLAGS); } else if (could_petrify) { minstapetrify(u.ustuck, TRUE); } else if (could_grow) { diff --git a/src/dogmove.c b/src/dogmove.c index 5a5f5f68a..b0d43a9c3 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -356,7 +356,8 @@ dog_eat(struct monst *mtmp, if (poly || slimer) { struct permonst *ptr = slimer ? &mons[PM_GREEN_SLIME] : 0; - (void) newcham(mtmp, ptr, FALSE, cansee(mtmp->mx, mtmp->my)); + (void) newcham(mtmp, ptr, + cansee(mtmp->mx, mtmp->my) ? NC_SHOW_MSG : 0); } /* limit "instant" growth to prevent potential abuse */ diff --git a/src/makemon.c b/src/makemon.c index b1bb5d90b..426eb9399 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1326,7 +1326,7 @@ makemon( to the level's difficulty but ignoring the changer's usual type selection, so was inappropriate for vampshifters. Let newcham() pick the shape. */ - && newcham(mtmp, (struct permonst *) 0, FALSE, FALSE)) + && newcham(mtmp, (struct permonst *) 0, NO_NC_FLAGS)) allow_minvent = FALSE; } else if (mndx == PM_WIZARD_OF_YENDOR) { mtmp->iswiz = TRUE; diff --git a/src/mhitm.c b/src/mhitm.c index c20e1e7f1..dced0d5b0 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -772,7 +772,7 @@ gulpmm(register struct monst *magr, register struct monst *mdef, } if (is_vampshifter(mdef) - && newcham(mdef, &mons[mdef->cham], FALSE, FALSE)) { + && newcham(mdef, &mons[mdef->cham], NO_NC_FLAGS)) { if (g.vis) { /* 'it' -- previous form is no longer available and using that would be excessively verbose */ @@ -959,9 +959,9 @@ mdamagem(struct monst *magr, struct monst *mdef, /* various checks similar to dog_eat and meatobj. * after monkilled() to provide better message ordering */ if (mdef->cham >= LOW_PM) { - (void) newcham(magr, (struct permonst *) 0, FALSE, TRUE); + (void) newcham(magr, (struct permonst *) 0, NC_SHOW_MSG); } else if (pd == &mons[PM_GREEN_SLIME] && !slimeproof(pa)) { - (void) newcham(magr, &mons[PM_GREEN_SLIME], FALSE, TRUE); + (void) newcham(magr, &mons[PM_GREEN_SLIME], NC_SHOW_MSG); } else if (pd == &mons[PM_WRAITH]) { (void) grow_up(magr, (struct monst *) 0); /* don't grow up twice */ @@ -1029,7 +1029,7 @@ mon_poly(struct monst *magr, struct monst *mdef, int dmg) else monkilled(mdef, "", AD_RBRE); } - } else if (newcham(mdef, (struct permonst *) 0, FALSE, FALSE)) { + } else if (newcham(mdef, (struct permonst *) 0, NO_NC_FLAGS)) { if (g.vis) { /* either seen or adjacent */ boolean was_seen = !!strcmpi("It", Before), verbosely = flags.verbose || !was_seen; diff --git a/src/mon.c b/src/mon.c index 4f53b0c50..cc0d6bab8 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1172,7 +1172,8 @@ meatmetal(struct monst *mtmp) delobj(otmp); ptr = mtmp->data; if (poly) { - if (newcham(mtmp, (struct permonst *) 0, FALSE, vis)) + if (newcham(mtmp, (struct permonst *) 0, + vis ? NC_SHOW_MSG : NO_NC_FLAGS)) ptr = mtmp->data; } else if (grow) { ptr = grow_up(mtmp, (struct monst *) 0); @@ -1334,7 +1335,8 @@ meatobj(struct monst* mtmp) /* for gelatinous cubes */ delobj(otmp); /* munch */ ptr = mtmp->data; if (poly) { - if (newcham(mtmp, (struct permonst *) 0, FALSE, vis)) + if (newcham(mtmp, (struct permonst *) 0, + vis ? NC_SHOW_MSG : NO_NC_FLAGS)) ptr = mtmp->data; } else if (grow) { ptr = grow_up(mtmp, (struct monst *) 0); @@ -1428,7 +1430,8 @@ meatcorpse(struct monst* mtmp) /* for purple worms and other voracious monsters ptr = original_ptr; delobj(otmp); if (poly) { - if (newcham(mtmp, (struct permonst *) 0, FALSE, vis)) + if (newcham(mtmp, (struct permonst *) 0, + vis ? NC_SHOW_MSG : NO_NC_FLAGS)) ptr = mtmp->data; } else if (grow) { ptr = grow_up(mtmp, (struct monst *) 0); @@ -2543,7 +2546,7 @@ mondead(register struct monst* mtmp) if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) rloc_to(mtmp, new_xy.x, new_xy.y); } - (void) newcham(mtmp, &mons[mndx], FALSE, FALSE); + (void) newcham(mtmp, &mons[mndx], NO_NC_FLAGS); if (mtmp->data == &mons[mndx]) mtmp->cham = NON_PM; else @@ -3201,7 +3204,7 @@ mon_to_stone(struct monst* mtmp) /* it's a golem, and not a stone golem */ if (canseemon(mtmp)) pline("%s solidifies...", Monnam(mtmp)); - if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) { + if (newcham(mtmp, &mons[PM_STONE_GOLEM], NO_NC_FLAGS)) { if (canseemon(mtmp)) pline("Now it's %s.", an(pmname(mtmp->data, Mgender(mtmp)))); } else { @@ -3253,7 +3256,7 @@ vamp_stone(struct monst* mtmp) pline("%s!", buf); display_nhwindow(WIN_MESSAGE, FALSE); } - (void) newcham(mtmp, &mons[mndx], FALSE, FALSE); + (void) newcham(mtmp, &mons[mndx], NO_NC_FLAGS); if (mtmp->data == &mons[mndx]) mtmp->cham = NON_PM; else @@ -3273,7 +3276,7 @@ vamp_stone(struct monst* mtmp) mtmp->mfrozen = 0; set_mon_min_mhpmax(mtmp, 10); /* mtmp->mhpmax=max(mtmp->m_lev+1,10) */ mtmp->mhp = mtmp->mhpmax; - (void) newcham(mtmp, &mons[mtmp->cham], FALSE, TRUE); + (void) newcham(mtmp, &mons[mtmp->cham], NC_SHOW_MSG); newsym(mtmp->mx, mtmp->my); return FALSE; /* didn't petrify */ } @@ -3808,7 +3811,7 @@ normal_shape(struct monst *mon) if (mcham >= LOW_PM) { unsigned mcan = mon->mcan; - (void) newcham(mon, &mons[mcham], FALSE, FALSE); + (void) newcham(mon, &mons[mcham], NO_NC_FLAGS); mon->cham = NON_PM; /* newcham() may uncancel a polymorphing monster; override that */ if (mcan) @@ -4124,7 +4127,7 @@ decide_to_shapeshift(struct monst* mon, int shiftflags) } } if (dochng) { - if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) { + if (newcham(mon, ptr, msg ? NC_SHOW_MSG : 0) && is_vampshifter(mon)) { /* for vampshift, override the 10% chance for sex change */ ptr = mon->data; if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr)) @@ -4440,12 +4443,12 @@ mgender_from_permonst(struct monst* mtmp, struct permonst* mdat) int newcham( struct monst *mtmp, - struct permonst *mdat, - boolean polyspot, /* change is the result of wand or spell of polymorph */ - boolean msg) /* "The oldmon turns into a newmon!" */ + struct permonst *mdat, unsigned ncflags) { - int hpn, hpd; - int mndx, tryct; + boolean polyspot = ((ncflags & NC_VIA_WAND_OR_SPELL) !=0), + /* "The oldmon turns into a newmon!" */ + msg = ((ncflags & NC_SHOW_MSG) != 0); + int hpn, hpd, mndx, tryct; struct permonst *olddata = mtmp->data; char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ]; @@ -4792,7 +4795,7 @@ kill_genocided_monsters(void) && (g.mvitals[mtmp->cham].mvflags & G_GENOD)); if ((g.mvitals[mndx].mvflags & G_GENOD) || kill_cham) { if (mtmp->cham >= LOW_PM && !kill_cham) - (void) newcham(mtmp, (struct permonst *) 0, FALSE, TRUE); + (void) newcham(mtmp, (struct permonst *) 0, NC_SHOW_MSG); else mondead(mtmp); } diff --git a/src/monmove.c b/src/monmove.c index aed2ab265..98e910fb1 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1967,7 +1967,7 @@ vamp_shift( reslt = 1; domsg = FALSE; } else if (is_vampshifter(mon)) { - reslt = newcham(mon, ptr, FALSE, FALSE); + reslt = newcham(mon, ptr, NO_NC_FLAGS); } if (reslt && domsg) { diff --git a/src/muse.c b/src/muse.c index ba70c5bac..10e453a1f 100644 --- a/src/muse.c +++ b/src/muse.c @@ -2143,7 +2143,7 @@ use_misc(struct monst* mtmp) return 2; case MUSE_WAN_POLYMORPH: mzapwand(mtmp, otmp, TRUE); - (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE); + (void) newcham(mtmp, muse_newcham_mon(mtmp), NC_VIA_WAND_OR_SPELL); if (oseen) makeknown(WAN_POLYMORPH); return 2; @@ -2152,7 +2152,7 @@ use_misc(struct monst* mtmp) m_useup(mtmp, otmp); if (vismon) pline("%s suddenly mutates!", Monnam(mtmp)); - (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE); + (void) newcham(mtmp, muse_newcham_mon(mtmp), NO_NC_FLAGS); if (oseen) makeknown(POT_POLYMORPH); return 2; @@ -2179,7 +2179,7 @@ use_misc(struct monst* mtmp) worm_move(mtmp); newsym(g.trapx, g.trapy); - (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); + (void) newcham(mtmp, (struct permonst *) 0, NO_NC_FLAGS); return 2; case MUSE_BAG: return mloot_container(mtmp, otmp, vismon); diff --git a/src/read.c b/src/read.c index 6d474103d..897785068 100644 --- a/src/read.c +++ b/src/read.c @@ -3117,7 +3117,7 @@ create_particular_creation(struct _create_particular_data* d) for, make it start out looking like what was asked for */ if (mtmp->cham != NON_PM && firstchoice != NON_PM && mtmp->cham != firstchoice) - (void) newcham(mtmp, &mons[firstchoice], FALSE, FALSE); + (void) newcham(mtmp, &mons[firstchoice], NO_NC_FLAGS); } return madeany; } diff --git a/src/trap.c b/src/trap.c index d1a4c1fb9..66ae64e03 100644 --- a/src/trap.c +++ b/src/trap.c @@ -656,7 +656,7 @@ animate_statue( /* if hero has protection from shape changers, cham field will be NON_PM; otherwise, set form to match the statue */ if (mon && mon->cham >= LOW_PM) - (void) newcham(mon, mptr, FALSE, FALSE); + (void) newcham(mon, mptr, NO_NC_FLAGS); } else { if (cause == ANIMATE_SPELL) mmflags |= MM_ADJACENTOK; @@ -2166,7 +2166,8 @@ trapeffect_poly_trap( if (resists_magm(mtmp)) { shieldeff(mtmp->mx, mtmp->my); } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) { - (void) newcham(mtmp, (struct permonst *) 0, FALSE, in_sight); + (void) newcham(mtmp, (struct permonst *) 0, + in_sight ? NC_SHOW_MSG : NO_NC_FLAGS); if (in_sight) seetrap(trap); } @@ -2617,7 +2618,7 @@ steedintrap(struct trap* trap, struct obj* otmp) if (!resists_magm(steed) && !resist(steed, WAND_CLASS, 0, NOTELL)) { struct permonst *mdat = steed->data; - (void) newcham(steed, (struct permonst *) 0, FALSE, FALSE); + (void) newcham(steed, (struct permonst *) 0, NO_NC_FLAGS); if (!can_saddle(steed) || !can_ride(steed)) { dismount_steed(DISMOUNT_POLY); } else { diff --git a/src/uhitm.c b/src/uhitm.c index 4fa32dd0e..b50b3d744 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -3001,7 +3001,7 @@ mhitm_ad_slim(struct monst *magr, struct attack *mattk, struct monst *mdef, /* this assumes newcham() won't fail; since hero has a slime attack, green slimes haven't been geno'd */ You("turn %s into slime.", mon_nam(mdef)); - if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE)) + if (newcham(mdef, &mons[PM_GREEN_SLIME], NO_NC_FLAGS)) pd = mdef->data; } /* munslime attempt could have been fatal */ @@ -3037,8 +3037,11 @@ mhitm_ad_slim(struct monst *magr, struct attack *mattk, struct monst *mdef, return; /* physical damage only */ if (!rn2(4) && !slimeproof(pd)) { if (!munslime(mdef, FALSE) && !DEADMONSTER(mdef)) { - if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, - (boolean) (g.vis && canseemon(mdef)))) + unsigned ncflags = NO_NC_FLAGS; + + if (g.vis && canseemon(mdef)) + ncflags |= NC_SHOW_MSG; + if (newcham(mdef, &mons[PM_GREEN_SLIME], ncflags)) pd = mdef->data; mdef->mstrategy &= ~STRAT_WAITFORU; mhm->hitflags = MM_HIT; @@ -4321,7 +4324,7 @@ gulpum(struct monst *mdef, struct attack *mattk) /* force vampire in bat, cloud, or wolf form to revert back to vampire form now instead of dealing with that when it dies */ if (is_vampshifter(mdef) - && newcham(mdef, &mons[mdef->cham], FALSE, FALSE)) { + && newcham(mdef, &mons[mdef->cham], NO_NC_FLAGS)) { You("engulf it, then expel it."); if (canspotmon(mdef)) pline("It turns into %s.", a_monnam(mdef)); diff --git a/src/zap.c b/src/zap.c index 6c139cf35..7a6b3a9fe 100644 --- a/src/zap.c +++ b/src/zap.c @@ -251,17 +251,24 @@ bhitm(struct monst *mtmp, struct obj *otmp) /* g.context.bypasses = TRUE; ## for make_corpse() */ /* no corpse after system shock */ xkilled(mtmp, XKILL_GIVEMSG | XKILL_NOCORPSE); - } else if (newcham(mtmp, (struct permonst *) 0, - polyspot, give_msg) != 0 - /* if shapechange failed because there aren't - enough eligible candidates (most likely for - vampshifter), try reverting to original form */ - || (mtmp->cham >= LOW_PM - && newcham(mtmp, &mons[mtmp->cham], - polyspot, give_msg) != 0)) { - if (give_msg && (canspotmon(mtmp) - || engulfing_u(mtmp))) - learn_it = TRUE; + } else { + unsigned ncflags = NO_NC_FLAGS; + + if (polyspot) + ncflags |= NC_VIA_WAND_OR_SPELL; + if (give_msg) + ncflags |= NC_SHOW_MSG; + if (newcham(mtmp, (struct permonst *) 0, ncflags) != 0 + /* if shapechange failed because there aren't + enough eligible candidates (most likely for + vampshifter), try reverting to original form */ + || (mtmp->cham >= LOW_PM + && newcham(mtmp, &mons[mtmp->cham], + ncflags) != 0)) { + if (give_msg && (canspotmon(mtmp) + || engulfing_u(mtmp))) + learn_it = TRUE; + } } /* do this even if polymorphed failed (otherwise using @@ -407,7 +414,7 @@ bhitm(struct monst *mtmp, struct obj *otmp) char *name = Monnam(mtmp); /* turn into flesh golem */ - if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) { + if (newcham(mtmp, &mons[PM_FLESH_GOLEM], NO_NC_FLAGS)) { if (canseemon(mtmp)) pline("%s turns to flesh!", name); } else { @@ -877,7 +884,7 @@ revive(struct obj *corpse, boolean by_hero) free_omonst(corpse); if (mtmp->cham == PM_DOPPELGANGER) { /* change shape to match the corpse */ - (void) newcham(mtmp, mptr, FALSE, FALSE); + (void) newcham(mtmp, mptr, NO_NC_FLAGS); } else if (mtmp->data->mlet == S_ZOMBIE) { mtmp->mhp = mtmp->mhpmax = 100; mon_adjust_speed(mtmp, 2, (struct obj *) 0); /* MFAST */ @@ -1901,7 +1908,8 @@ stone_to_flesh_obj(struct obj *obj) ptr = mon->data; /* this golem handling is redundant... */ if (is_golem(ptr) && ptr != &mons[PM_FLESH_GOLEM]) - (void) newcham(mon, &mons[PM_FLESH_GOLEM], TRUE, FALSE); + (void) newcham(mon, &mons[PM_FLESH_GOLEM], + NC_VIA_WAND_OR_SPELL); } else if ((ptr->geno & (G_NOCORPSE | G_UNIQ)) != 0) { /* didn't revive but can't leave corpse either */ res = 0;