create_door() warning hackery

Redo the warning suppression in create_door().  The unreachable 'goto'
was unnecessary and without it there's no need to toggle unreachable
code warnings off and back on.  Taking a step back, the whole 'default'
case is unnecessary since rn2(4) will always hit one of the 0..3 cases.
So instead of just getting rid of the unreachable 'goto', get rid of
the panic() too.
This commit is contained in:
PatR
2021-12-19 04:54:34 -08:00
parent 9f41ab7bfe
commit 5f98102e73

View File

@@ -1570,17 +1570,15 @@ create_subroom(
return TRUE;
}
DISABLE_WARNING_UNREACHABLE_CODE
/*
* Create a new door in a room.
* It's placed on a wall (north, south, east or west).
*/
static void
create_door(room_door* dd, struct mkroom* broom)
create_door(room_door *dd, struct mkroom *broom)
{
int x = 0, y = 0;
int trycnt = 0, wtry = 0;
int trycnt;
if (dd->secret == -1)
dd->secret = rn2(2);
@@ -1610,8 +1608,8 @@ create_door(room_door* dd, struct mkroom* broom)
}
}
do {
register int dwall, dpos;
for (trycnt = 0; trycnt < 100; ++trycnt) {
int dwall, dpos;
dwall = dd->wall;
if (dwall == -1) /* The wall is RANDOM */
@@ -1620,57 +1618,52 @@ create_door(room_door* dd, struct mkroom* broom)
dpos = dd->pos;
/* Convert wall and pos into an absolute coordinate! */
wtry = rn2(4);
switch (wtry) {
switch (rn2(4)) {
case 0:
if (!(dwall & W_NORTH))
goto redoloop;
continue;
y = broom->ly - 1;
x = broom->lx
+ ((dpos == -1) ? rn2(1 + (broom->hx - broom->lx)) : dpos);
x = broom->lx + ((dpos == -1) ? rn2(1 + broom->hx - broom->lx)
: dpos);
if (!isok(x, y - 1) || IS_ROCK(levl[x][y - 1].typ))
goto redoloop;
goto outdirloop;
continue;
break;
case 1:
if (!(dwall & W_SOUTH))
goto redoloop;
continue;
y = broom->hy + 1;
x = broom->lx
+ ((dpos == -1) ? rn2(1 + (broom->hx - broom->lx)) : dpos);
x = broom->lx + ((dpos == -1) ? rn2(1 + broom->hx - broom->lx)
: dpos);
if (!isok(x, y + 1) || IS_ROCK(levl[x][y + 1].typ))
goto redoloop;
goto outdirloop;
continue;
break;
case 2:
if (!(dwall & W_WEST))
goto redoloop;
continue;
x = broom->lx - 1;
y = broom->ly
+ ((dpos == -1) ? rn2(1 + (broom->hy - broom->ly)) : dpos);
y = broom->ly + ((dpos == -1) ? rn2(1 + broom->hy - broom->ly)
: dpos);
if (!isok(x - 1, y) || IS_ROCK(levl[x - 1][y].typ))
goto redoloop;
goto outdirloop;
continue;
break;
case 3:
if (!(dwall & W_EAST))
goto redoloop;
continue;
x = broom->hx + 1;
y = broom->ly
+ ((dpos == -1) ? rn2(1 + (broom->hy - broom->ly)) : dpos);
y = broom->ly + ((dpos == -1) ? rn2(1 + broom->hy - broom->ly)
: dpos);
if (!isok(x + 1, y) || IS_ROCK(levl[x + 1][y].typ))
goto redoloop;
goto outdirloop;
continue;
break;
default:
x = y = 0;
panic("create_door: No wall for door!");
/*UNREACHABLE_CODE*/
goto outdirloop;
/*NOTREACHED*/
break;
}
outdirloop:
if (okdoor(x, y))
break;
redoloop:
;
} while (++trycnt <= 100);
if (trycnt > 100) {
}
if (trycnt >= 100) {
impossible("create_door: Can't find a proper place!");
return;
}
@@ -1678,8 +1671,6 @@ create_door(room_door* dd, struct mkroom* broom)
levl[x][y].doormask = dd->mask;
}
RESTORE_WARNING_UNREACHABLE_CODE
/*
* Create a secret door in croom on any one of the specified walls.
*/