Use is_hole macro to check for trapdoors and holes
authorPasi Kallinen <paxed@alt.org>
Sat, 15 Sep 2018 14:57:57 +0000 (17:57 +0300)
committerPasi Kallinen <paxed@alt.org>
Sat, 15 Sep 2018 14:57:57 +0000 (17:57 +0300)
14 files changed:
include/trap.h
src/ball.c
src/do.c
src/dokick.c
src/dothrow.c
src/mklev.c
src/mon.c
src/muse.c
src/objnam.c
src/pager.c
src/sp_lev.c
src/teleport.c
src/trap.c
src/zap.c

index 3b8e036bfbd147ad5c91de1ddf51e12e2f8a83b9..8eacc6ccd2406e6ae6d8b731c8745cb424019e2a 100644 (file)
@@ -84,5 +84,6 @@ enum trap_types {
 };
 
 #define is_pit(ttyp) ((ttyp) == PIT || (ttyp) == SPIKED_PIT)
+#define is_hole(ttyp)  ((ttyp) == HOLE || (ttyp) == TRAPDOOR)
 
 #endif /* TRAP_H */
index cd631eee57582c36bd4b6e9c08df1ed01fa27dca..762de85f8d5417fd3e7522d6745c1e21a7ca277b 100644 (file)
@@ -599,8 +599,7 @@ drag:
              || !is_pool(uball->ox, uball->oy)
              || levl[uball->ox][uball->oy].typ == POOL))
         || ((t = t_at(uchain->ox, uchain->oy))
-            && (is_pit(t->ttyp) || t->ttyp == HOLE
-                || t->ttyp == TRAPDOOR))) {
+            && (is_pit(t->ttyp) || is_hole(t->ttyp)))) {
         if (Levitation) {
             You_feel("a tug from the iron ball.");
             if (t)
@@ -746,7 +745,7 @@ xchar x, y;
             && (is_pool(x, y)
                 || ((t = t_at(x, y))
                     && (is_pit(t->ttyp)
-                        || t->ttyp == TRAPDOOR || t->ttyp == HOLE)))) {
+                        || is_hole(t->ttyp))))) {
             u.ux = x;
             u.uy = y;
         } else {
index d8ba1a725bbcd94f9c4ed20363b95413eff68646..81bbb623544da3c13d447f55a805bbc4d0aa6a7b 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -149,8 +149,7 @@ const char *verb;
     if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) {
         return TRUE;
     } else if (obj->otyp == BOULDER && (t = t_at(x, y)) != 0
-               && (is_pit(t->ttyp)
-                 || t->ttyp == TRAPDOOR || t->ttyp == HOLE)) {
+               && (is_pit(t->ttyp) || is_hole(t->ttyp))) {
         if (((mtmp = m_at(x, y)) && mtmp->mtrapped)
             || (u.utrap && u.ux == x && u.uy == y)) {
             if (*verb)
@@ -956,7 +955,7 @@ dodown()
         if (trap && uteetering_at_seen_pit(trap)) {
             dotrap(trap, TOOKPLUNGE);
             return 1;
-        } else if (!trap || (trap->ttyp != TRAPDOOR && trap->ttyp != HOLE)
+        } else if (!trap || !is_hole(trap->ttyp)
                    || !Can_fall_thru(&u.uz) || !trap->tseen) {
             if (flags.autodig && !context.nopick && uwep && is_pick(uwep)) {
                 return use_pick_axe2(uwep);
index 09fb44c364ef8f8db698a6c9dec047f4906157a3..874db822a47dee4f1b10c85f4b198fe13c90c864 100644 (file)
@@ -1515,7 +1515,7 @@ boolean shop_floor_obj;
     /* boulders never fall through trap doors, but they might knock
        other things down before plugging the hole */
     if (otmp->otyp == BOULDER && ((t = t_at(x, y)) != 0)
-        && (t->ttyp == TRAPDOOR || t->ttyp == HOLE)) {
+        && is_hole(t->ttyp)) {
         if (impact)
             impact_drop(otmp, x, y, 0);
         return FALSE; /* let caller finish the drop */
@@ -1717,7 +1717,7 @@ xchar x, y;
     }
 
     if (((ttmp = t_at(x, y)) != 0 && ttmp->tseen)
-        && (ttmp->ttyp == TRAPDOOR || ttmp->ttyp == HOLE)) {
+        && is_hole(ttmp->ttyp)) {
         gate_str = (ttmp->ttyp == TRAPDOOR) ? "through the trap door"
                                             : "through the hole";
         return MIGR_RANDOM;
index 38f8d99239d4e91a2aaefa90f1c7b3f7cdaeabf6..00978165f516a413c37f035fd387b87c2fdd9c16 100644 (file)
@@ -744,8 +744,7 @@ int x, y;
             dotrap(ttmp, 0); /* doesn't print messages */
         } else if (ttmp->ttyp == FIRE_TRAP) {
             dotrap(ttmp, 0);
-        } else if ((is_pit(ttmp->ttyp)
-                    || ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR)
+        } 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 */
index acbf5b76d3a7746775681b89fa9d7562deaf621d..aecba88faa8b2cb7776128d1c01d03d891c4734c 100644 (file)
@@ -503,8 +503,7 @@ int trap_type;
             if (trap_type || !rn2(4)) {
                 rm->typ = SCORR;
                 if (trap_type) {
-                    if ((trap_type == HOLE || trap_type == TRAPDOOR)
-                        && !Can_fall_thru(&u.uz))
+                    if (is_hole(trap_type) && !Can_fall_thru(&u.uz))
                         trap_type = ROCKTRAP;
                     ttmp = maketrap(xx, yy + dy, trap_type);
                     if (ttmp) {
@@ -1342,15 +1341,14 @@ coord *tm;
         } while (kind == NO_TRAP);
     }
 
-    if ((kind == TRAPDOOR || kind == HOLE) && !Can_fall_thru(&u.uz))
+    if (is_hole(kind) && !Can_fall_thru(&u.uz))
         kind = ROCKTRAP;
 
     if (tm) {
         m = *tm;
     } else {
         register int tryct = 0;
-        boolean avoid_boulder = (is_pit(kind)
-                                 || kind == TRAPDOOR || kind == HOLE);
+        boolean avoid_boulder = (is_pit(kind) || is_hole(kind));
 
         do {
             if (++tryct > 200)
index d199c2ae512380e2eaa155e9eface292240fb93d..cbdde81bad3c7a0a89d74f7b962ae7ed250e66e5 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1446,8 +1446,7 @@ nexttry: /* eels prefer the water, but if there is no water nearby,
                     if ((ttmp->ttyp != RUST_TRAP
                          || mdat == &mons[PM_IRON_GOLEM])
                         && ttmp->ttyp != STATUE_TRAP
-                        && ((!is_pit(ttmp->ttyp)
-                             && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
+                        && ((!is_pit(ttmp->ttyp) && !is_hole(ttmp->ttyp))
                             || (!is_flyer(mdat) && !is_floater(mdat)
                                 && !is_clinger(mdat)) || Sokoban)
                         && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
index ac462cea23e95d446fe658e74d26c5bbd007d067..600bdd90322cc930609c29f3e06fe4fe73cbb89e 100644 (file)
@@ -439,7 +439,7 @@ struct monst *mtmp;
                 || onscary(xx, yy, mtmp))
                 continue;
             /* use trap if it's the correct type */
-            if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
+            if (is_hole(t->ttyp)
                 && !is_floater(mtmp->data)
                 && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
                 && Can_fall_thru(&u.uz)) {
index b44ddbf2e43b58d4219ceb5b2c1608052d381b5d..0b68f73dc0be3abce22e28102e75811c52f6b322 100644 (file)
@@ -3508,7 +3508,7 @@ wiztrap:
             if (strncmpi(tname, bp, strlen(tname)))
                 continue;
             /* found it; avoid stupid mistakes */
-            if ((trap == TRAPDOOR || trap == HOLE) && !Can_fall_thru(&u.uz))
+            if (is_hole(trap) && !Can_fall_thru(&u.uz))
                 trap = ROCKTRAP;
             if ((t = maketrap(x, y, trap)) != 0) {
                 trap = t->ttyp;
index a82431aa0f6f5829254eed3666cbebe42a11cd2d..9c2d74946dc8916dea150023d3ccefe24cd77513 100644 (file)
@@ -1362,8 +1362,7 @@ doidtrap()
                 break;
             tt = trap->ttyp;
             if (u.dz) {
-                if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE)
-                             : tt == ROCKTRAP)
+                if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
                     break;
             }
             tt = what_trap(tt);
index c1a0c70aafe3315efb3a0776b6aab43811bedb78..4f8df6b9c4207bb75b5043d959e17969d18528b1 100644 (file)
@@ -2660,8 +2660,7 @@ fill_empty_maze()
             maze1xy(&mm, DRY);
             trytrap = rndtrap();
             if (sobj_at(BOULDER, mm.x, mm.y))
-                while (is_pit(trytrap)
-                       || trytrap == TRAPDOOR || trytrap == HOLE)
+                while (is_pit(trytrap) || is_hole(trytrap))
                     trytrap = rndtrap();
             (void) maketrap(mm.x, mm.y, trytrap);
         }
@@ -4495,7 +4494,7 @@ ensure_way_out()
 
     while (ttmp) {
         if ((ttmp->ttyp == MAGIC_PORTAL || ttmp->ttyp == VIBRATING_SQUARE
-             || ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR)
+             || is_hole(ttmp->ttyp))
             && !selection_getpoint(ttmp->tx, ttmp->ty, ov))
             selection_floodfill(ov, ttmp->tx, ttmp->ty, TRUE);
         ttmp = ttmp->ntrap;
index a79429c461b75a88e2f650eeb08593923bef24c6..5003ed82d856a2207a37258e49d08687fed53a2f 100644 (file)
@@ -1159,7 +1159,7 @@ int in_sight;
         d_level tolevel;
         int migrate_typ = MIGR_RANDOM;
 
-        if ((tt == HOLE || tt == TRAPDOOR)) {
+        if (is_hole(tt)) {
             if (Is_stronghold(&u.uz)) {
                 assign_level(&tolevel, &valley_level);
             } else if (Is_botlevel(&u.uz)) {
index c4a96c99c2d924649a938d707c8d64d8a46ab5f1..bdf944b318baeb377bc34442ba21af396750a952 100644 (file)
@@ -406,8 +406,7 @@ int x, y, typ;
     case HOLE:
     case TRAPDOOR:
         if (*in_rooms(x, y, SHOPBASE)
-            && (typ == HOLE || typ == TRAPDOOR
-                || IS_DOOR(lev->typ) || IS_WALL(lev->typ)))
+            && (is_hole(typ) || IS_DOOR(lev->typ) || IS_WALL(lev->typ)))
             add_damage(x, y, /* schedule repair */
                        ((IS_DOOR(lev->typ) || IS_WALL(lev->typ))
                         && !context.mon_moving)
@@ -861,8 +860,7 @@ unsigned trflags;
     nomul(0);
 
     /* KMH -- You can't escape the Sokoban level traps */
-    if (Sokoban && (is_pit(ttype)
-                    || ttype == HOLE || ttype == TRAPDOOR)) {
+    if (Sokoban && (is_pit(ttype) || is_hole(ttype))) {
         /* The "air currents" message is still appropriate -- even when
          * the hero isn't flying or levitating -- because it conveys the
          * reason why the player cannot escape the trap with a dexterity
@@ -2864,8 +2862,7 @@ long hmask, emask; /* might cancel timeout */
     if (Punished && !carried(uball)
         && (is_pool(uball->ox, uball->oy)
             || ((trap = t_at(uball->ox, uball->oy))
-                && (is_pit(trap->ttyp)
-                    || (trap->ttyp == TRAPDOOR) || (trap->ttyp == HOLE))))) {
+                && (is_pit(trap->ttyp) || is_hole(trap->ttyp))))) {
         u.ux0 = u.ux;
         u.uy0 = u.uy;
         u.ux = uball->ox;
@@ -4986,7 +4983,7 @@ register struct trap *ttmp;
     if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || (ttmp->ttyp == BEAR_TRAP)
                  || (ttmp->ttyp == LANDMINE) || (ttmp->ttyp == FIRE_TRAP)
                  || is_pit(ttmp->ttyp)
-                 || (ttmp->ttyp == HOLE) || (ttmp->ttyp == TRAPDOOR)
+                 || is_hole(ttmp->ttyp)
                  || (ttmp->ttyp == TELEP_TRAP) || (ttmp->ttyp == LEVEL_TELEP)
                  || (ttmp->ttyp == WEB) || (ttmp->ttyp == MAGIC_TRAP)
                  || (ttmp->ttyp == ANTI_MAGIC))) {
index 35ce7a9e3b9788f4e8d6290b13a7baeec0ae1d96..14b47902a3880f7d5eca7272cf3b6f39e26990dc 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -3373,8 +3373,7 @@ struct obj **pobj; /* object tossed/used, set to NULL
                               The(distant_name(obj, xname))); /* lame */
                     range = 0;
                 } else if (Sokoban && (t = t_at(x, y)) != 0
-                           && (is_pit(t->ttyp)
-                               || t->ttyp == HOLE || t->ttyp == TRAPDOOR)) {
+                           && (is_pit(t->ttyp) || is_hole(t->ttyp))) {
                     /* hero falls into the trap, so ball stops */
                     range = 0;
                 }