From e0318008800b61076cdcabc270b21eb0a320ad9e Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 15 Sep 2018 17:57:57 +0300 Subject: [PATCH] Use is_hole macro to check for trapdoors and holes --- include/trap.h | 1 + src/ball.c | 5 ++--- src/do.c | 5 ++--- src/dokick.c | 4 ++-- src/dothrow.c | 3 +-- src/mklev.c | 8 +++----- src/mon.c | 3 +-- src/muse.c | 2 +- src/objnam.c | 2 +- src/pager.c | 3 +-- src/sp_lev.c | 5 ++--- src/teleport.c | 2 +- src/trap.c | 11 ++++------- src/zap.c | 3 +-- 14 files changed, 23 insertions(+), 34 deletions(-) diff --git a/include/trap.h b/include/trap.h index 3b8e036bf..8eacc6ccd 100644 --- a/include/trap.h +++ b/include/trap.h @@ -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 */ diff --git a/src/ball.c b/src/ball.c index cd631eee5..762de85f8 100644 --- a/src/ball.c +++ b/src/ball.c @@ -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 { diff --git a/src/do.c b/src/do.c index d8ba1a725..81bbb6235 100644 --- 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); diff --git a/src/dokick.c b/src/dokick.c index 09fb44c36..874db822a 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -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; diff --git a/src/dothrow.c b/src/dothrow.c index 38f8d9923..00978165f 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -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 */ diff --git a/src/mklev.c b/src/mklev.c index acbf5b76d..aecba88fa 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -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) diff --git a/src/mon.c b/src/mon.c index d199c2ae5..cbdde81ba 100644 --- 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)) diff --git a/src/muse.c b/src/muse.c index ac462cea2..600bdd903 100644 --- a/src/muse.c +++ b/src/muse.c @@ -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)) { diff --git a/src/objnam.c b/src/objnam.c index b44ddbf2e..0b68f73dc 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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; diff --git a/src/pager.c b/src/pager.c index a82431aa0..9c2d74946 100644 --- a/src/pager.c +++ b/src/pager.c @@ -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); diff --git a/src/sp_lev.c b/src/sp_lev.c index c1a0c70aa..4f8df6b9c 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -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; diff --git a/src/teleport.c b/src/teleport.c index a79429c46..5003ed82d 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -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)) { diff --git a/src/trap.c b/src/trap.c index c4a96c99c..bdf944b31 100644 --- a/src/trap.c +++ b/src/trap.c @@ -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))) { diff --git a/src/zap.c b/src/zap.c index 35ce7a9e3..14b47902a 100644 --- 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; } -- 2.40.0