Skip to content

Commit fa67e4a

Browse files
committed
Enable untrapping jammed drawbridge
When a drawbridge becomes jammed, it can be unjammed with the #untrap command, on either the drawbridge itself or the portcullis.
1 parent 7b4482f commit fa67e4a

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

include/extern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ extern boolean is_open_air(int, int);
320320
extern schar db_under_typ(int);
321321
extern int is_drawbridge_wall(int, int);
322322
extern boolean is_db_wall(int, int);
323+
extern boolean is_jammed_db(int, int);
323324
extern boolean find_drawbridge(int *, int *);
324325
extern boolean create_drawbridge(int, int, int, boolean);
325326
extern void open_drawbridge(int, int);
326327
extern void close_drawbridge(int, int);
327328
extern void destroy_drawbridge(int, int);
329+
extern int unjam_drawbridge(int, int);
328330

329331
/* ### decl.c ### */
330332

src/dbridge.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ is_db_wall(int x, int y)
181181
return (boolean) (levl[x][y].typ == DBWALL);
182182
}
183183

184+
boolean
185+
is_jammed_db(int x, int y)
186+
{
187+
if (!find_drawbridge(&x, &y))
188+
return FALSE;
189+
else
190+
return ((levl[x][y].drawbridgemask & DB_JAM) != 0);
191+
}
192+
184193
/*
185194
* Return true with x,y pointing to the drawbridge if x,y initially indicate
186195
* a drawbridge or drawbridge wall.
@@ -974,4 +983,47 @@ destroy_drawbridge(int x, int y)
974983
nokiller();
975984
}
976985

986+
int
987+
unjam_drawbridge(int x, int y)
988+
{
989+
boolean under_u = (!u.dx && !u.dy);
990+
struct monst *mtmp = m_at(x, y);
991+
992+
if (!is_jammed_db(x, y)) {
993+
impossible("unjam_drawbridge: clearing nonexistant jam?");
994+
return 0;
995+
}
996+
997+
/* Test for monster first, monsters are displayed instead of trap. */
998+
if (mtmp) {
999+
pline("%s is in the way.", Monnam(mtmp));
1000+
return 0;
1001+
}
1002+
/* We might be forced to move onto the trap's location. */
1003+
if (sobj_at(BOULDER, x, y) && !Passes_walls && !under_u) {
1004+
There("is a boulder in your way.");
1005+
return 0;
1006+
}
1007+
/* duplicate tight-space checks from test_move */
1008+
if (u.dx && u.dy && bad_rock(g.youmonst.data, u.ux, y)
1009+
&& bad_rock(g.youmonst.data, x, u.uy)) {
1010+
if ((g.invent && (inv_weight() + weight_cap() > 600))
1011+
|| bigmonst(g.youmonst.data)) {
1012+
/* don't allow untrap if they can't get thru to it */
1013+
You("are unable to reach the mechanism!");
1014+
return 0;
1015+
}
1016+
}
1017+
if (rn2(3)) {
1018+
You("are having a difficult time clearing the jam.");
1019+
return 1;
1020+
}
1021+
1022+
/* ok, disarm it. */
1023+
You("unjam the mechanism.");
1024+
(void) find_drawbridge(&x, &y);
1025+
levl[x][y].drawbridgemask &= ~DB_JAM;
1026+
return 1;
1027+
}
1028+
9771029
/*dbridge.c*/

src/music.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ do_play_instrument(struct obj* instr)
757757
u.uevent.uheard_tune = 2;
758758
record_achievement(ACH_TUNE);
759759
if (levl[x][y].typ == DRAWBRIDGE_DOWN) {
760-
boolean jammed =
761-
(levl[x][y].drawbridgemask & DB_JAM) != 0;
760+
boolean jammed = is_jammed_db(x, y);
762761
if (!rn2(5) || jammed) {
763762
pline("The mechanism seems to %s jammed.",
764763
jammed ? "be" : "get");

src/trap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5449,7 +5449,10 @@ untrap(
54495449
return 0;
54505450
}
54515451
}
5452-
} /* end if */
5452+
}
5453+
else if (is_jammed_db(x, y)) {
5454+
return unjam_drawbridge(x, y);
5455+
}
54535456

54545457
if (boxcnt) {
54555458
/* 3.7: this used to allow searching for traps on multiple

0 commit comments

Comments
 (0)