From: Pasi Kallinen Date: Thu, 24 Feb 2022 15:13:20 +0000 (+0200) Subject: Get rid of force_mintrap, allow passing flags to mintrap X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2777f45bd5039036539e616f5fae1ae7df907e48;p=nethack Get rid of force_mintrap, allow passing flags to mintrap It uses the same flags as dotrap, so simulate force_mintrap by passing FORCETRAP flag. --- diff --git a/include/decl.h b/include/decl.h index a71493535..3735dadfe 100644 --- a/include/decl.h +++ b/include/decl.h @@ -1203,8 +1203,6 @@ struct instance_globals { winid toptenwin; /* trap.c */ - int force_mintrap; /* mintrap() should take a flags argument, but for time - being we use this */ /* context for water_damage(), managed by water_damage_chain(); when more than one stack of potions of acid explode while processing a chain of objects, use alternate phrasing after the first message */ diff --git a/include/extern.h b/include/extern.h index 2e9152715..a552f6f30 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 *); +extern int mintrap(struct monst *, long); 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 e940c50b8..037751b8e 100644 --- a/include/hack.h +++ b/include/hack.h @@ -381,14 +381,15 @@ typedef struct sortloot_item Loot; #define PICK_RANDOM 0 #define PICK_RIGID 1 -/* Flags to control dotrap() in trap.c */ -#define FORCETRAP 0x01 /* triggering not left to chance */ -#define NOWEBMSG 0x02 /* suppress stumble into web message */ -#define FORCEBUNGLE 0x04 /* adjustments appropriate for bungling */ +/* 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 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 */ /* Flags to control test_move in hack.c */ #define DO_MOVE 0 /* really doing the move */ diff --git a/src/apply.c b/src/apply.c index 86b39e0ae..6ef88e89f 100644 --- a/src/apply.c +++ b/src/apply.c @@ -509,7 +509,7 @@ use_magic_whistle(struct obj *obj) mtmp->mundetected = 0; /* reveal non-mimic hider */ if (canspotmon(mtmp)) ++pet_cnt; - if (mintrap(mtmp) == Trap_Killed_Mon) + if (mintrap(mtmp, NO_TRAP_FLAGS) == Trap_Killed_Mon) change_luck(-1); } } diff --git a/src/decl.c b/src/decl.c index e2a5f77d7..c35085c62 100644 --- a/src/decl.c +++ b/src/decl.c @@ -654,7 +654,6 @@ const struct instance_globals g_init = { WIN_ERR, /* toptenwin */ /* trap.c */ - 0, /* force_mintrap */ { 0, 0, FALSE }, UNDEFINED_VALUES, diff --git a/src/dig.c b/src/dig.c index 55d9949be..97f4b1f9b 100644 --- a/src/dig.c +++ b/src/dig.c @@ -634,7 +634,7 @@ digactualhole(int x, int y, struct monst *madeby, int ttyp) pline("%s %s over the pit.", Monnam(mtmp), (is_flyer(mtmp->data)) ? "flies" : "floats"); } else if (mtmp != madeby) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } } else { /* was TRAPDOOR now a HOLE*/ diff --git a/src/dog.c b/src/dog.c index a3bed238d..0a68bd45e 100644 --- a/src/dog.c +++ b/src/dog.c @@ -616,7 +616,7 @@ keepdogs(boolean pets_only) /* true for ascension or final escape */ && !(mtmp->mstrategy & STRAT_WAITFORU)) { stay_behind = FALSE; if (mtmp->mtrapped) - (void) mintrap(mtmp); /* try to escape */ + (void) mintrap(mtmp, NO_TRAP_FLAGS); /* try to escape */ if (mtmp == u.usteed) { /* make sure steed is eligible to accompany hero */ mtmp->mtrapped = 0; /* escape trap */ diff --git a/src/dokick.c b/src/dokick.c index 32bbad0e8..28c6fef04 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -91,6 +91,7 @@ kickdmg(struct monst *mon, boolean clumsy) /* see if the monster has a place to move into */ mdx = mon->mx + u.dx; mdy = mon->my + u.dy; + /* TODO: replace with mhurtle? */ if (goodpos(mdx, mdy, mon, 0)) { pline("%s reels from the blow.", Monnam(mon)); if (m_in_out_region(mon, mdx, mdy)) { @@ -99,7 +100,7 @@ kickdmg(struct monst *mon, boolean clumsy) place_monster(mon, mdx, mdy); newsym(mon->mx, mon->my); set_apparxy(mon); - if (mintrap(mon) == Trap_Killed_Mon) + if (mintrap(mon, NO_TRAP_FLAGS) == Trap_Killed_Mon) trapkilled = TRUE; } } diff --git a/src/dothrow.c b/src/dothrow.c index 939a69673..874e3b20b 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -921,7 +921,7 @@ mhurtle_step(genericptr_t arg, int x, int y) set_apparxy(mon); if (is_waterwall(x, y)) return FALSE; - res = mintrap(mon); + res = mintrap(mon, NO_TRAP_FLAGS); /* TODO: TEMPFLIGHT? */ if (res == Trap_Killed_Mon || res == Trap_Caught_Mon || res == Trap_Moved_Mon) diff --git a/src/fountain.c b/src/fountain.c index b6d389560..ea81dd7db 100644 --- a/src/fountain.c +++ b/src/fountain.c @@ -49,7 +49,7 @@ dowatersnakes(void) if ((mtmp = makemon(&mons[PM_WATER_MOCCASIN], u.ux, u.uy, MM_NOMSG)) != 0 && t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } else pline_The("fountain bubbles furiously for a moment, then calms."); } @@ -76,7 +76,7 @@ dowaterdemon(void) /* give a wish and discard the monster (mtmp set to null) */ mongrantswish(&mtmp); } else if (t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } } else pline_The("fountain bubbles furiously for a moment, then calms."); @@ -97,7 +97,7 @@ dowaternymph(void) You_hear("a seductive voice."); mtmp->msleeping = 0; if (t_at(mtmp->mx, mtmp->my)) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } else if (!Blind) pline("A large bubble rises to the surface and pops."); else diff --git a/src/hack.c b/src/hack.c index 3397233ae..56e7480ad 100644 --- a/src/hack.c +++ b/src/hack.c @@ -2058,7 +2058,7 @@ domove_core(void) or blame if something bad happens to it */ g.context.mon_moving = 1; if (!minliquid(mtmp)) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); g.context.mon_moving = 0; /* @@ -2138,7 +2138,8 @@ domove_core(void) has_mgivenname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE)); /* check for displacing it into pools and traps */ - switch (minliquid(mtmp) ? Trap_Killed_Mon : mintrap(mtmp)) { + switch (minliquid(mtmp) ? Trap_Killed_Mon + : mintrap(mtmp, NO_TRAP_FLAGS)) { case Trap_Effect_Finished: break; case Trap_Caught_Mon: /* trapped */ diff --git a/src/mhitm.c b/src/mhitm.c index 5a0a10aca..f6c0bcbf6 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -438,7 +438,7 @@ mattackm(register struct monst *magr, register struct monst *mdef) pline("%s divides as %s hits it!", buf, mon_nam(magr)); } - (void) mintrap(mclone); + (void) mintrap(mclone, NO_TRAP_FLAGS); } } } else @@ -810,7 +810,9 @@ gulpmm(register struct monst *magr, register struct monst *mdef, place_monster(magr, dx, dy); newsym(dx, dy); /* aggressor moves to and might encounter trouble there */ - if (minliquid(magr) || (t_at(dx, dy) && mintrap(magr) == Trap_Killed_Mon)) + if (minliquid(magr) + || (t_at(dx, dy) + && mintrap(magr, NO_TRAP_FLAGS) == Trap_Killed_Mon)) status |= MM_AGR_DIED; } else if (status & MM_AGR_DIED) { /* aggressor died */ place_monster(mdef, dx, dy); diff --git a/src/mklev.c b/src/mklev.c index be78a4504..1471013ff 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -1981,7 +1981,7 @@ mkinvpos(xchar x, xchar y, int dist) seemimic(mon); if ((ttmp = t_at(x, y)) != 0) - (void) mintrap(mon); + (void) mintrap(mon, NO_TRAP_FLAGS); else (void) minliquid(mon); } diff --git a/src/monmove.c b/src/monmove.c index 7e901d45f..9e9f9bd24 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1021,7 +1021,7 @@ m_move(register struct monst* mtmp, register int after) int omx = mtmp->mx, omy = mtmp->my; if (mtmp->mtrapped) { - int i = mintrap(mtmp); + int i = mintrap(mtmp, NO_TRAP_FLAGS); if (i == Trap_Killed_Mon) { newsym(mtmp->mx, mtmp->my); @@ -1491,7 +1491,7 @@ m_move(register struct monst* mtmp, register int after) } newsym(omx, omy); /* update the old position */ - if (mintrap(mtmp) == Trap_Killed_Mon) { + if (mintrap(mtmp, NO_TRAP_FLAGS) == Trap_Killed_Mon) { if (mtmp->mx) newsym(mtmp->mx, mtmp->my); return 2; /* it died */ diff --git a/src/muse.c b/src/muse.c index 9ed9b2ed2..98764a69b 100644 --- a/src/muse.c +++ b/src/muse.c @@ -2775,9 +2775,7 @@ muse_unslime( is_floater(mon->data) ? "over" : "onto", trap->tseen ? "the" : "a"); } - /* hack to avoid mintrap()'s chance of avoiding known trap */ - mon->mtrapseen &= ~(1 << (FIRE_TRAP - 1)); - (void) mintrap(mon); + (void) mintrap(mon, FORCETRAP); } else if (otyp == STRANGE_OBJECT) { /* monster is using fire breath on self */ if (vis) diff --git a/src/steed.c b/src/steed.c index d87ed7197..834840fa2 100644 --- a/src/steed.c +++ b/src/steed.c @@ -662,7 +662,7 @@ dismount_steed( /* Put your steed in your trap */ if (save_utrap) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } /* Couldn't move hero... try moving the steed. */ diff --git a/src/teleport.c b/src/teleport.c index c39421dfa..60034361c 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -1288,7 +1288,7 @@ rloc_to_core(struct monst* mtmp, /* trapped monster teleported away */ if (mtmp->mtrapped && !mtmp->wormno) - (void) mintrap(mtmp); + (void) mintrap(mtmp, NO_TRAP_FLAGS); } void diff --git a/src/trap.c b/src/trap.c index e42f363ea..9db2e3cc2 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1248,7 +1248,7 @@ trapeffect_bear_trap( || mptr == &mons[PM_BUGBEAR]) You_hear("the roaring of an angry bear!"); } - } else if (g.force_mintrap) { + } else if (forcetrap) { if (in_sight) { pline("%s evades %s bear trap!", Monnam(mtmp), a_your[trap->madeby_u]); @@ -1640,7 +1640,8 @@ trapeffect_pit( int tt = trap->ttyp; boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); boolean trapkilled = FALSE; - boolean inescapable = (g.force_mintrap + boolean forcetrap = ((trflags & FORCETRAP) != 0); + boolean inescapable = (forcetrap || ((tt == HOLE || tt == PIT) && Sokoban && !trap->madeby_u)); struct permonst *mptr = mtmp->data; @@ -1648,7 +1649,7 @@ trapeffect_pit( fallverb = "falls"; if (!grounded(mptr) || (mtmp->wormno && count_wsegs(mtmp) > 5)) { - if (g.force_mintrap && !Sokoban) { + if (forcetrap && !Sokoban) { /* openfallingtrap; not inescapable here */ if (in_sight) { seetrap(trap); @@ -1699,7 +1700,8 @@ trapeffect_hole( int tt = trap->ttyp; struct permonst *mptr = mtmp->data; boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); - boolean inescapable = (g.force_mintrap + boolean forcetrap = ((trflags & FORCETRAP) != 0); + boolean inescapable = (forcetrap || ((tt == HOLE || tt == PIT) && Sokoban && !trap->madeby_u)); @@ -1710,7 +1712,7 @@ trapeffect_hole( } if (!grounded(mptr) || (mtmp->wormno && count_wsegs(mtmp) > 5) || mptr->msize >= MZ_HUGE) { - if (g.force_mintrap && !Sokoban) { + if (forcetrap && !Sokoban) { /* openfallingtrap; not inescapable here */ if (in_sight) { seetrap(trap); @@ -1769,7 +1771,8 @@ trapeffect_level_telep( } else { int tt = trap->ttyp; boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); - boolean inescapable = (g.force_mintrap + boolean forcetrap = ((trflags & FORCETRAP) != 0); + boolean inescapable = (forcetrap || ((tt == HOLE || tt == PIT) && Sokoban && !trap->madeby_u)); @@ -1845,7 +1848,7 @@ trapeffect_web( /* mintrap currently does not return Trap_Killed_Mon (mon died) for webs */ - if (mintrap(u.usteed)) { + if (mintrap(u.usteed, trflags) != Trap_Effect_Finished) { u.usteed->mtrapped = 0; if (strongmonst(u.usteed->data)) str = 17; @@ -1883,6 +1886,7 @@ trapeffect_web( /* Monster in a web. */ boolean tear_web; boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); + boolean forcetrap = ((trflags & FORCETRAP) != 0); struct permonst *mptr = mtmp->data; if (webmaker(mptr)) @@ -1935,7 +1939,7 @@ trapeffect_web( a_your[trap->madeby_u]); deltrap(trap); newsym(mtmp->mx, mtmp->my); - } else if (g.force_mintrap && !mtmp->mtrapped) { + } else if (forcetrap && !mtmp->mtrapped) { if (in_sight) { pline("%s avoids %s spider web!", Monnam(mtmp), a_your[trap->madeby_u]); @@ -2243,7 +2247,7 @@ trapeffect_landmine( trapkilled = TRUE; } else { /* monsters recursively fall into new pit */ - if (mintrap(mtmp) == Trap_Killed_Mon) + if (mintrap(mtmp, trflags|FORCETRAP) == Trap_Killed_Mon) trapkilled = TRUE; } /* a boulder may fill the new pit, crushing monster */ @@ -3069,7 +3073,7 @@ isclearpath( } int -mintrap(register struct monst *mtmp) +mintrap(register struct monst *mtmp, long mintrapflags) { register struct trap *trap = t_at(mtmp->mx, mtmp->my); struct permonst *mptr = mtmp->data; @@ -3125,7 +3129,8 @@ mintrap(register struct monst *mtmp) trap_result = mtmp->mtrapped ? Trap_Caught_Mon : Trap_Effect_Finished; } else { register int tt = trap->ttyp; - boolean inescapable = (g.force_mintrap + boolean forcetrap = ((mintrapflags & FORCETRAP) != 0); + boolean inescapable = (forcetrap || ((tt == HOLE || tt == PIT) && Sokoban && !trap->madeby_u)); @@ -3146,7 +3151,7 @@ mintrap(register struct monst *mtmp) if (trap->madeby_u && rnl(5)) setmangry(mtmp, FALSE); - trap_result = trapeffect_selector(mtmp, trap, 0); + trap_result = trapeffect_selector(mtmp, trap, mintrapflags); } return trap_result; } @@ -5221,9 +5226,7 @@ closeholdingtrap( /* dotrap calls mintrap when mounted hero encounters a web */ if (u.usteed) dotrapflags |= NOWEBMSG; - ++g.force_mintrap; - dotrap(t, dotrapflags); - --g.force_mintrap; + dotrap(t, dotrapflags|FORCETRAP); result = (u.utrap != 0); } else { if (mon->mtrapped) @@ -5231,9 +5234,7 @@ closeholdingtrap( /* you notice it if you see the trap close/tremble/whatever or if you sense the monster who becomes trapped */ *noticed = cansee(t->tx, t->ty) || canspotmon(mon); - ++g.force_mintrap; - result = (mintrap(mon) != Trap_Effect_Finished); - --g.force_mintrap; + result = (mintrap(mon, FORCETRAP) != Trap_Effect_Finished); } return result; } @@ -5274,9 +5275,7 @@ openfallingtrap( *noticed = cansee(t->tx, t->ty) || canspotmon(mon); /* monster will be angered; mintrap doesn't handle that */ wakeup(mon, TRUE); - ++g.force_mintrap; - result = (mintrap(mon) != 0); - --g.force_mintrap; + result = (mintrap(mon, FORCETRAP) != Trap_Effect_Finished); /* mon might now be on the migrating monsters list */ } return result; diff --git a/src/uhitm.c b/src/uhitm.c index 738d26f89..11c04b89f 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -1365,7 +1365,7 @@ hmon_hitmon( Sprintf(withwhat, " with %s", yname(obj)); pline("%s divides as you hit it%s!", Monnam(mon), withwhat); hittxt = TRUE; - (void) mintrap(mclone); + (void) mintrap(mclone, NO_TRAP_FLAGS); } }