digging conjoined pits follow-up (trunk only)

Pat Rankin wrote:
>      Isn't an array of booleans overkill?  A single byte bitmap
> could achieve the same result.
This commit is contained in:
nethack.allison
2006-03-25 18:59:53 +00:00
parent a0156b9278
commit e063031f00
4 changed files with 29 additions and 28 deletions
+2 -2
View 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. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -13,7 +13,7 @@
* Incrementing EDITLEVEL can be used to force invalidation of old bones * Incrementing EDITLEVEL can be used to force invalidation of old bones
* and save files. * and save files.
*/ */
#define EDITLEVEL 27 #define EDITLEVEL 28
#define COPYRIGHT_BANNER_A \ #define COPYRIGHT_BANNER_A \
"NetHack, Copyright 1985-2006" "NetHack, Copyright 1985-2006"
+1 -1
View File
@@ -10,7 +10,7 @@
union vlaunchinfo { union vlaunchinfo {
short v_launch_otyp; /* type of object to be triggered */ short v_launch_otyp; /* type of object to be triggered */
coord v_launch2; /* secondary launch point (for boulders) */ coord v_launch2; /* secondary launch point (for boulders) */
boolean v_conjoined[8]; /* conjoined pit locations */ uchar v_conjoined; /* conjoined pit locations */
}; };
struct trap { struct trap {
+7 -6
View File
@@ -999,8 +999,8 @@ struct obj *obj;
/* idx is valid if < 8 */ /* idx is valid if < 8 */
if (idx < 8) { if (idx < 8) {
int adjidx = (idx + 4) % 8; int adjidx = (idx + 4) % 8;
trap_with_u->conjoined[idx] = TRUE; trap_with_u->conjoined |= (1 << idx);
trap->conjoined[adjidx] = TRUE; trap->conjoined |= (1 << adjidx);
pline( pline(
"You clear some debris from between the pits."); "You clear some debris from between the pits.");
} }
@@ -1319,8 +1319,8 @@ zap_dig()
if (adjpit && (adjpit->ttyp == PIT || if (adjpit && (adjpit->ttyp == PIT ||
adjpit->ttyp == SPIKED_PIT)) { adjpit->ttyp == SPIKED_PIT)) {
int adjidx = (diridx + 4) % 8; int adjidx = (diridx + 4) % 8;
trap_with_u->conjoined[diridx] = TRUE; trap_with_u->conjoined |= (1 << diridx);
adjpit->conjoined[adjidx] = TRUE; adjpit->conjoined |= (1 << adjidx);
flow_x = zx; flow_x = zx;
flow_y = zy; flow_y = zy;
pitflow = TRUE; pitflow = TRUE;
@@ -1524,7 +1524,7 @@ schar filltyp;
"Suddenly %s flows in from the adjacent pit!": "Suddenly %s flows in from the adjacent pit!":
(char *)0); (char *)0);
for(idx = 0; idx < 8; ++idx) { for(idx = 0; idx < 8; ++idx) {
if (t.conjoined[idx]) { if (t.conjoined & (1 << idx)) {
int x, y; int x, y;
struct trap *t2; struct trap *t2;
x = t.tx + xdir[idx]; x = t.tx + xdir[idx];
@@ -1535,7 +1535,8 @@ schar filltyp;
* called deltrap() which cleaned up the * called deltrap() which cleaned up the
* conjoined fields on both pits. * conjoined fields on both pits.
*/ */
if (t2 && t2->conjoined[(idx + 4) % 8])
if (t2 && (t2->conjoined & (1 << ((idx + 4) % 8))))
#endif #endif
/* recursion */ /* recursion */
pit_flow(t2, filltyp); pit_flow(t2, filltyp);
+19 -19
View File
@@ -227,7 +227,6 @@ register int x, y, typ;
register struct trap *ttmp; register struct trap *ttmp;
register struct rm *lev; register struct rm *lev;
register boolean oldplace; register boolean oldplace;
int idx;
if ((ttmp = t_at(x,y)) != 0) { if ((ttmp = t_at(x,y)) != 0) {
if (ttmp->ttyp == MAGIC_PORTAL) return (struct trap *)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 */ case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */
(void) mkroll_launch(ttmp, x, y, BOULDER, 1L); (void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
break; break;
case HOLE:
case PIT: case PIT:
case SPIKED_PIT: case SPIKED_PIT:
ttmp->conjoined = 0;
/* fall through */
case HOLE:
case TRAPDOOR: case TRAPDOOR:
for (idx = 0; idx < 8; ++idx)
ttmp->conjoined[idx] = FALSE;
lev = &levl[x][y]; lev = &levl[x][y];
if (*in_rooms(x, y, SHOPBASE) && if (*in_rooms(x, y, SHOPBASE) &&
((typ == HOLE || typ == TRAPDOOR) || ((typ == HOLE || typ == TRAPDOOR) ||
@@ -4004,7 +4003,8 @@ boolean u_entering_trap2;
/* diridx is valid if < 8 */ /* diridx is valid if < 8 */
if (diridx < 8) { if (diridx < 8) {
adjidx = (diridx + 4) % 8; adjidx = (diridx + 4) % 8;
if (trap1->conjoined[diridx] && trap2->conjoined[adjidx]) if ((trap1->conjoined & (1 << diridx)) &&
(trap2->conjoined & (1 << adjidx)))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@@ -4014,20 +4014,20 @@ void
clear_conjoined_pits(trap) clear_conjoined_pits(trap)
struct trap *trap; struct trap *trap;
{ {
int tmp, adj, x, y; int diridx, adjidx, x, y;
struct trap *t; struct trap *t;
if (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) { if (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) {
for(tmp = 0; tmp < 8; ++tmp) { for(diridx = 0; diridx < 8; ++diridx) {
if (trap->conjoined[tmp]) { if (trap->conjoined & (1 << diridx)) {
x = trap->tx + xdir[tmp]; x = trap->tx + xdir[diridx];
y = trap->ty + ydir[tmp]; y = trap->ty + ydir[diridx];
t = t_at(x,y); t = t_at(x,y);
if (isok(x,y) && t && if (isok(x,y) && t &&
(t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
adj = (tmp + 4) % 8; adjidx = (diridx + 4) % 8;
t->conjoined[adj] = FALSE; 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 *trap;
{ {
struct trap *t; struct trap *t;
int tmp, x, y; int diridx, x, y;
if (!trap) return; if (!trap) return;
for(tmp = 0; tmp < 8; ++tmp) { for(diridx = 0; diridx < 8; ++diridx) {
x = trap->tx + xdir[tmp]; x = trap->tx + xdir[diridx];
y = trap->ty + ydir[tmp]; y = trap->ty + ydir[diridx];
if (isok(x,y)) { if (isok(x,y)) {
if (((t = t_at(x,y)) != 0) && if (((t = t_at(x,y)) != 0) &&
(t->ttyp == PIT || t->ttyp == SPIKED_PIT)) { (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
trap->conjoined[tmp] = TRUE; trap->conjoined |= (1 << diridx);
join_adjacent_pits(t); join_adjacent_pits(t);
} else trap->conjoined[tmp] = FALSE; } else trap->conjoined &= ~(1 << diridx);
} }
} }
} }