From: PatR Date: Thu, 24 Feb 2022 20:17:21 +0000 (-0800) Subject: trap followup X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab2bcf4dac2df4be8f1da66239e898f1e2a3737d;p=nethack trap followup Make the flags argument to dotrap() and mintrap() and the constants passed to them all have consistent type: unsigned int. --- diff --git a/include/extern.h b/include/extern.h index a552f6f30..bfae9f194 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2692,7 +2692,7 @@ extern void reset_utrap(boolean); extern void dotrap(struct trap *, unsigned); extern void seetrap(struct trap *); extern void feeltrap(struct trap *); -extern int mintrap(struct monst *, long); +extern int mintrap(struct monst *, unsigned); extern void instapetrify(const char *); extern void minstapetrify(struct monst *, boolean); extern void selftouch(const char *); diff --git a/include/hack.h b/include/hack.h index 4b2a094cf..a0277508b 100644 --- a/include/hack.h +++ b/include/hack.h @@ -382,15 +382,15 @@ typedef struct sortloot_item Loot; #define PICK_RIGID 1 /* Flags to control dotrap() and mintrap() in trap.c */ -#define NO_TRAP_FLAGS 0 -#define FORCETRAP 0x01 /* triggering not left to chance */ -#define NOWEBMSG 0x02 /* suppress stumble into web message */ -#define FORCEBUNGLE 0x04 /* adjustments appropriate for bungling */ -#define RECURSIVETRAP 0x08 /* trap changed into another type this same turn */ -#define TOOKPLUNGE 0x10 /* used '>' to enter pit below you */ -#define VIASITTING 0x20 /* #sit while at trap location (affects message) */ -#define FAILEDUNTRAP 0x40 /* trap activated by failed untrap attempt */ -#define HURTLING 0x80 /* monster is hurtling through air */ +#define NO_TRAP_FLAGS 0x00U +#define FORCETRAP 0x01U /* triggering not left to chance */ +#define NOWEBMSG 0x02U /* suppress stumble into web message */ +#define FORCEBUNGLE 0x04U /* adjustments appropriate for bungling */ +#define RECURSIVETRAP 0x08U /* trap changed into another type this same turn */ +#define TOOKPLUNGE 0x10U /* used '>' to enter pit below you */ +#define VIASITTING 0x20U /* #sit while at trap location (affects message) */ +#define FAILEDUNTRAP 0x40U /* trap activated by failed untrap attempt */ +#define HURTLING 0x80U /* monster is hurtling through air */ /* Flags to control test_move in hack.c */ #define DO_MOVE 0 /* really doing the move */ diff --git a/src/dothrow.c b/src/dothrow.c index 003830fe4..3eb5374ac 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -766,7 +766,8 @@ hurtle_step(genericptr_t arg, int x, int y) } if ((u.ux - x) && (u.uy - y) && bad_rock(g.youmonst.data, u.ux, y) && bad_rock(g.youmonst.data, x, u.uy)) { - boolean too_much = (g.invent && (inv_weight() + weight_cap() > 600)); + boolean too_much = (g.invent + && (inv_weight() + weight_cap() > 600)); /* Move at a diagonal. */ if (bigmonst(g.youmonst.data) || too_much) { @@ -791,17 +792,18 @@ hurtle_step(genericptr_t arg, int x, int y) && (Flying || Levitation || Wwalking)) #endif ) { - const char *mnam, *pronoun; + const char *mnam; int glyph = glyph_at(x, y); mon->mundetected = 0; /* wakeup() will handle mimic */ - mnam = a_monnam(mon); /* after unhiding */ - pronoun = noit_mhim(mon); - if (!strcmp(mnam, "it")) { - mnam = !strcmp(pronoun, "it") ? "something" : "someone"; - } + /* after unhiding; combination of a_monnam() and some_mon_nam(); + yields "someone" or "something" instead of "it" for unseen mon */ + mnam = x_monnam(mon, ARTICLE_A, (char *) 0, + ((has_mgivenname(mon) ? SUPPRESS_SADDLE : 0) + | AUGMENT_IT), + FALSE); if (!glyph_is_monster(glyph) && !glyph_is_invisible(glyph)) - You("find %s by bumping into %s.", mnam, pronoun); + You("find %s by bumping into %s.", mnam, noit_mhim(mon)); else You("bump into %s.", mnam); wakeup(mon, FALSE); @@ -849,12 +851,14 @@ hurtle_step(genericptr_t arg, int x, int y) if (is_pool(x, y) && !u.uinwater) { if ((Is_waterlevel(&u.uz) && is_waterwall(x,y)) || !(Levitation || Flying || Wwalking)) { - g.multi = 0; /* can move, so drown() allows crawling out of water */ + /* couldn't move while hurtling; allow movement now so that + drown() will give a chance to crawl out of pool and survive */ + g.multi = 0; (void) drown(); return FALSE; } else if (!Is_waterlevel(&u.uz) && !stopping_short) { Norep("You move over %s.", an(is_moat(x, y) ? "moat" : "pool")); - } + } } else if (is_lava(x, y) && !stopping_short) { Norep("You move over some lava."); } @@ -870,19 +874,19 @@ hurtle_step(genericptr_t arg, int x, int y) if (stopping_short) { ; /* see the comment above hurtle_jump() */ } else if (ttmp->ttyp == MAGIC_PORTAL) { - dotrap(ttmp, 0); + dotrap(ttmp, NO_TRAP_FLAGS); return FALSE; } else if (ttmp->ttyp == VIBRATING_SQUARE) { pline("The ground vibrates as you pass it."); - dotrap(ttmp, 0); /* doesn't print messages */ + dotrap(ttmp, NO_TRAP_FLAGS); /* doesn't print messages */ } else if (ttmp->ttyp == FIRE_TRAP) { - dotrap(ttmp, 0); + dotrap(ttmp, NO_TRAP_FLAGS); } else if ((is_pit(ttmp->ttyp) || is_hole(ttmp->ttyp)) && Sokoban) { /* air currents overcome the recoil in Sokoban; when jumping, caller performs last step and enters trap */ if (!via_jumping) - dotrap(ttmp, 0); + dotrap(ttmp, NO_TRAP_FLAGS); *range = 0; return TRUE; } else { diff --git a/src/polyself.c b/src/polyself.c index fb7e38996..4d10f4e1c 100644 --- a/src/polyself.c +++ b/src/polyself.c @@ -1392,7 +1392,7 @@ dospinweb(void) case ANTI_MAGIC: case POLY_TRAP: You("have triggered a trap!"); - dotrap(ttmp, 0); + dotrap(ttmp, NO_TRAP_FLAGS); return ECMD_TIME; default: impossible("Webbing over trap type %d?", ttmp->ttyp); diff --git a/src/trap.c b/src/trap.c index 3f365bddd..ab00c0738 100644 --- a/src/trap.c +++ b/src/trap.c @@ -2287,7 +2287,7 @@ trapeffect_landmine( trapkilled = TRUE; } else { /* monsters recursively fall into new pit */ - if (mintrap(mtmp, trflags|FORCETRAP) == Trap_Killed_Mon) + if (mintrap(mtmp, trflags | FORCETRAP) == Trap_Killed_Mon) trapkilled = TRUE; } /* a boulder may fill the new pit, crushing monster */ @@ -2472,9 +2472,9 @@ trapeffect_selector( } void -dotrap(register struct trap* trap, unsigned int trflags) +dotrap(struct trap *trap, unsigned trflags) { - register int ttype = trap->ttyp; + int ttype = trap->ttyp; boolean already_seen = trap->tseen, forcetrap = ((trflags & FORCETRAP) != 0 || (trflags & FAILEDUNTRAP) != 0), @@ -3115,9 +3115,9 @@ isclearpath( } int -mintrap(register struct monst *mtmp, long mintrapflags) +mintrap(struct monst *mtmp, unsigned mintrapflags) { - register struct trap *trap = t_at(mtmp->mx, mtmp->my); + struct trap *trap = t_at(mtmp->mx, mtmp->my); struct permonst *mptr = mtmp->data; int trap_result = Trap_Effect_Finished; @@ -3526,7 +3526,7 @@ float_down( /*FALLTHRU*/ default: if (!u.utrap) /* not already in the trap */ - dotrap(trap, 0); + dotrap(trap, NO_TRAP_FLAGS); } } if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow @@ -5272,7 +5272,7 @@ closeholdingtrap( /* dotrap calls mintrap when mounted hero encounters a web */ if (u.usteed) dotrapflags |= NOWEBMSG; - dotrap(t, dotrapflags|FORCETRAP); + dotrap(t, dotrapflags | FORCETRAP); result = (u.utrap != 0); } else { if (mon->mtrapped) diff --git a/src/zap.c b/src/zap.c index e052e894f..ee3278818 100644 --- a/src/zap.c +++ b/src/zap.c @@ -3058,7 +3058,7 @@ zap_updown(struct obj *obj) /* wand or spell */ ttmp->tseen = 1; newsym(x, y); /* might fall down hole */ - dotrap(ttmp, 0); + dotrap(ttmp, NO_TRAP_FLAGS); } else if (!striking && ttmp->ttyp == HOLE) { /* locking transforms hole into trapdoor */ ttmp->ttyp = TRAPDOOR;