]> granicus.if.org Git - nethack/commitdiff
digging conjoined pits follow-up (trunk only)
authornethack.allison <nethack.allison>
Sat, 25 Mar 2006 18:59:53 +0000 (18:59 +0000)
committernethack.allison <nethack.allison>
Sat, 25 Mar 2006 18:59:53 +0000 (18:59 +0000)
Pat Rankin wrote:
>      Isn't an array of booleans overkill?  A single byte bitmap
> could achieve the same result.

include/patchlevel.h
include/trap.h
src/dig.c
src/trap.c

index 0ecea015a68a6a1e1faa69f7d546332919d05abd..768e655e40de808ded465b3f28620df2a10e257c 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)patchlevel.h       3.5     2006/01/07      */
+/*     SCCS Id: @(#)patchlevel.h       3.5     2006/03/25      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -13,7 +13,7 @@
  * Incrementing EDITLEVEL can be used to force invalidation of old bones
  * and save files.
  */
-#define EDITLEVEL      27
+#define EDITLEVEL      28
 
 #define COPYRIGHT_BANNER_A \
 "NetHack, Copyright 1985-2006"
index 2e2cb5c4731b9ec8560268ead57983ed5d320e62..e672d43d3137bae269e90cc74e0fab3efa576b60 100644 (file)
@@ -10,7 +10,7 @@
 union vlaunchinfo {
        short v_launch_otyp;    /* type of object to be triggered */
        coord v_launch2;        /* secondary launch point (for boulders) */
-       boolean v_conjoined[8]; /* conjoined pit locations */
+       uchar v_conjoined;      /* conjoined pit locations */
 };
 
 struct trap {
index 2b3dc3a2b9cf3e1e18737ccd2d53e69a28497451..022918d3958edb41e2fa1aa6fd72e9bfbe4e86f9 100644 (file)
--- a/src/dig.c
+++ b/src/dig.c
@@ -999,8 +999,8 @@ struct obj *obj;
                                /* idx is valid if < 8 */
                                if (idx < 8) {
                                        int adjidx = (idx + 4) % 8;
-                                       trap_with_u->conjoined[idx] = TRUE;
-                                       trap->conjoined[adjidx] = TRUE;
+                                       trap_with_u->conjoined |= (1 << idx);
+                                       trap->conjoined |= (1 << adjidx);
                                        pline(
                                  "You clear some debris from between the pits.");
                                }
@@ -1319,8 +1319,8 @@ zap_dig()
                    if (adjpit && (adjpit->ttyp == PIT ||
                                   adjpit->ttyp == SPIKED_PIT)) {
                                int adjidx = (diridx + 4) % 8;
-                               trap_with_u->conjoined[diridx] = TRUE;
-                               adjpit->conjoined[adjidx] = TRUE;
+                               trap_with_u->conjoined |= (1 << diridx);
+                               adjpit->conjoined |= (1 << adjidx);
                                flow_x = zx;
                                flow_y = zy;
                                pitflow = TRUE;
@@ -1524,7 +1524,7 @@ schar filltyp;
                            "Suddenly %s flows in from the adjacent pit!":
                            (char *)0);
                for(idx = 0; idx < 8; ++idx) {
-                       if (t.conjoined[idx]) {
+                       if (t.conjoined & (1 << idx)) {
                                int x, y;
                                struct trap *t2;
                                x = t.tx + xdir[idx];
@@ -1535,7 +1535,8 @@ schar filltyp;
                                 * called deltrap() which cleaned up the
                                 * conjoined fields on both pits.
                                 */
-                               if (t2 && t2->conjoined[(idx + 4) % 8])
+                                
+                               if (t2 && (t2->conjoined & (1 << ((idx + 4) % 8))))
 #endif
                                /* recursion */
                                pit_flow(t2, filltyp);
index 718ea9a599f6b01adbc36f07b7823a3b4553e22c..29fddcd9d31000624199b2145e97682c575b5058 100644 (file)
@@ -227,7 +227,6 @@ register int x, y, typ;
        register struct trap *ttmp;
        register struct rm *lev;
        register boolean oldplace;
-       int idx;
 
        if ((ttmp = t_at(x,y)) != 0) {
            if (ttmp->ttyp == MAGIC_PORTAL) return (struct trap *)0;
@@ -268,12 +267,12 @@ register int x, y, typ;
            case ROLLING_BOULDER_TRAP:  /* boulder will roll towards trigger */
                (void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
                break;
-           case HOLE:
            case PIT:
            case SPIKED_PIT:
+               ttmp->conjoined = 0;
+               /* fall through */
+           case HOLE:
            case TRAPDOOR:
-               for (idx = 0; idx < 8; ++idx)
-                   ttmp->conjoined[idx] = FALSE;
                lev = &levl[x][y];
                if (*in_rooms(x, y, SHOPBASE) &&
                        ((typ == HOLE || typ == TRAPDOOR) ||
@@ -4004,7 +4003,8 @@ boolean u_entering_trap2;
        /* diridx is valid if < 8 */
        if (diridx < 8) {
                adjidx = (diridx + 4) % 8;
-               if (trap1->conjoined[diridx] && trap2->conjoined[adjidx])
+               if ((trap1->conjoined & (1 << diridx)) &&
+                   (trap2->conjoined & (1 << adjidx)))
                        return TRUE;
        }
        return FALSE;
@@ -4014,20 +4014,20 @@ void
 clear_conjoined_pits(trap)
 struct trap *trap;
 {
-       int tmp, adj, x, y;
+       int diridx, adjidx, x, y;
        struct trap *t;
        if (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) {
-               for(tmp = 0; tmp < 8; ++tmp) {
-                   if (trap->conjoined[tmp]) {
-                       x = trap->tx + xdir[tmp];
-                       y = trap->ty + ydir[tmp];
+               for(diridx = 0; diridx < 8; ++diridx) {
+                   if (trap->conjoined & (1 << diridx)) {
+                       x = trap->tx + xdir[diridx];
+                       y = trap->ty + ydir[diridx];
                        t = t_at(x,y);
                        if (isok(x,y) && t &&
                            (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
-                               adj = (tmp + 4) % 8;
-                               t->conjoined[adj] = FALSE;
+                               adjidx = (diridx + 4) % 8;
+                               t->conjoined &= ~(1 << adjidx);
                        }
-                       trap->conjoined[tmp] = FALSE;
+                       trap->conjoined &= ~(1 << diridx);
                    }
                }
        }       
@@ -4043,17 +4043,17 @@ join_adjacent_pits(trap)
 struct trap *trap;
 {
        struct trap *t;
-       int tmp, x, y;
+       int diridx, x, y;
        if (!trap) return;
-       for(tmp = 0; tmp < 8; ++tmp) {
-               x = trap->tx + xdir[tmp];
-               y = trap->ty + ydir[tmp];
+       for(diridx = 0; diridx < 8; ++diridx) {
+               x = trap->tx + xdir[diridx];
+               y = trap->ty + ydir[diridx];
                if (isok(x,y)) {
                    if (((t = t_at(x,y)) != 0) &&
                          (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
-                       trap->conjoined[tmp] = TRUE;
+                       trap->conjoined |= (1 << diridx);
                        join_adjacent_pits(t);
-                   } else trap->conjoined[tmp] = FALSE;
+                   } else trap->conjoined &= ~(1 << diridx);
                }
        }
 }