]> granicus.if.org Git - nethack/commitdiff
Get rid of force_mintrap, allow passing flags to mintrap
authorPasi Kallinen <paxed@alt.org>
Thu, 24 Feb 2022 15:13:20 +0000 (17:13 +0200)
committerPasi Kallinen <paxed@alt.org>
Thu, 24 Feb 2022 15:13:23 +0000 (17:13 +0200)
It uses the same flags as dotrap, so simulate force_mintrap
by passing FORCETRAP flag.

19 files changed:
include/decl.h
include/extern.h
include/hack.h
src/apply.c
src/decl.c
src/dig.c
src/dog.c
src/dokick.c
src/dothrow.c
src/fountain.c
src/hack.c
src/mhitm.c
src/mklev.c
src/monmove.c
src/muse.c
src/steed.c
src/teleport.c
src/trap.c
src/uhitm.c

index a71493535fcc8e1298f6021c18a3d51b186e034e..3735dadfe32bee83b7893a19c55141b2870c4c40 100644 (file)
@@ -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 */
index 2e9152715c92935a8c41c4ad17cd84f6e983c8d3..a552f6f30174182663859e036d35abb3f0dcbe77 100644 (file)
@@ -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 *);
index e940c50b878283c091c7c8ae3658f724314cf768..037751b8eb2cfe66e490b9c360812695ed3fcd03 100644 (file)
@@ -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 */
index 86b39e0ae8a6447a744e763755ac612087bdc97c..6ef88e89f590e92cd00dc80f2d6b2c891b33de04 100644 (file)
@@ -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);
                 }
             }
index e2a5f77d7b282b98dec40f18e5b6df8f64aba4e6..c35085c6223fe90b699344e402b8e2c00fcfe255 100644 (file)
@@ -654,7 +654,6 @@ const struct instance_globals g_init = {
     WIN_ERR, /* toptenwin */
 
     /* trap.c */
-    0, /* force_mintrap */
     { 0, 0, FALSE },
     UNDEFINED_VALUES,
 
index 55d9949be675f8caf9152a4df492ba092b08128b..97f4b1f9b674765a511bcfcbde618ab42fdb5eb9 100644 (file)
--- 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*/
 
index a3bed238d7e80b93f6e587747ff85aa8b67c2a4c..0a68bd45e6b3276b2df696d3f5679575174c2208 100644 (file)
--- 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 */
index 32bbad0e8d0c1c5a3a6cfca34a2f78a85418f9df..28c6fef04ce29b45215ad90521a429b2a566135c 100644 (file)
@@ -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;
             }
         }
index 939a69673de6c646ca5be73f2384249c15b6e1f8..874e3b20b91bc424505663ff634be25470260449 100644 (file)
@@ -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)
index b6d389560f098adec324a9df9e90f496c611fbd8..ea81dd7db7f546dca2f6689d0814da75156244bc 100644 (file)
@@ -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
index 3397233ae473ac2eebeae6b914eb2977c0fe57ad..56e7480ad909c18abc66c41622aef68894b9a10d 100644 (file)
@@ -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 */
index 5a0a10aca95e2614761f9c7adad9b546b467a5ab..f6c0bcbf676dc66396c35032a74bb346b534ceba 100644 (file)
@@ -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 <dx,dy> 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);
index be78a4504e0b2fd104a196990ab333300ee93901..1471013ffb754e81b14a9dcca6af68b9d5fe5a04 100644 (file)
@@ -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);
     }
index 7e901d45f8535a5b90ed28116d3489c28b70a2cb..9e9f9bd245e2c041fa90a9b8dec80aa4cd2d2d01 100644 (file)
@@ -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 */
index 9ed9b2ed2837e742285664d4e311b6a7d3fbac71..98764a69b40bbb2d754690e717f630a2c995e4d1 100644 (file)
@@ -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)
index d87ed719742305ca7db7ad9a8df5b9aa1b2bea9d..834840fa22336277d27d21dc1b83501680737846 100644 (file)
@@ -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. */
index c39421dfa0aee3fe747d50f3c96425323821d3d9..60034361c305c3e0bea8f9b7420b6aaca067801f 100644 (file)
@@ -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
index e42f363ea9d4b7b14587e9dbc7fcd6e1d8224e3b..9db2e3cc2001f093b3dfec0fb2a94bafdc94f46b 100644 (file)
@@ -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;
index 738d26f8920e152a6e16b0334eac2c03ee9287d2..11c04b89f886df65b6eabcf239b68516b4be8793 100644 (file)
@@ -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);
         }
     }