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

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. */
/* 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"

View 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 {

View File

@@ -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);

View 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);
}
}
}