Skip to content

Commit

Permalink
CS115: Huge monsters stop drawbridges from closing
Browse files Browse the repository at this point in the history
Only real change with this commit is the slightly more informative
message when the drawbridge is blocked.

I wanted m in close_drawbridge to be const, but mhis doesn't like it,
even though it doesn't modify its input. The code still needs more
const, at least for function inputs.
  • Loading branch information
tung committed Apr 14, 2012
1 parent 2bd13c8 commit 2d6201c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libnitrohack/include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extern boolean is_db_wall(int,int);
extern boolean find_drawbridge(int *,int*);
extern boolean create_drawbridge(struct level *lev, int x, int y, int dir, boolean flag);
extern void open_drawbridge(int,int);
extern void close_drawbridge(int,int);
extern boolean close_drawbridge(int,int);
extern void destroy_drawbridge(int,int);

/* ### decl.c ### */
Expand Down
1 change: 1 addition & 0 deletions libnitrohack/include/mondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define verysmall(ptr) ((ptr)->msize < MZ_SMALL)
#define bigmonst(ptr) ((ptr)->msize >= MZ_LARGE)
#define hugemonst(ptr) ((ptr)->msize >= MZ_HUGE)

#define pm_resistance(ptr,typ) (((ptr)->mresists & (typ)) != 0)

Expand Down
18 changes: 14 additions & 4 deletions libnitrohack/src/dbridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,28 @@ static void do_entity(struct entity *etmp)
}

/*
* Close the drawbridge located at x,y
* Close the drawbridge located at x,y.
* Returns TRUE if the drawbridge was closed, FALSE otherwise.
*/
void close_drawbridge(int x, int y)
boolean close_drawbridge(int x, int y)
{
struct rm *loc1, *loc2;
struct monst *m;
struct trap *t;
int x2, y2;

loc1 = &level->locations[x][y];
if (loc1->typ != DRAWBRIDGE_DOWN) return;
if (loc1->typ != DRAWBRIDGE_DOWN) return FALSE;
/* A huge monster will block the drawbridge. */
if ((m = m_at(level, x, y)) && hugemonst(m->data)) {
pline("%s blocks the drawbridge with %s weight!",
canseemon(m) ? Amonnam(m) : "Something",
canseemon(m) ? mhis(m) : "its");
return FALSE;
}
if (rn2(5) == 0) {
pline("The mechanism seems to have something stuck in it and won't close.");
return;
return FALSE;
}
x2 = x; y2 = y;
get_wall_for_db(&x2,&y2);
Expand Down Expand Up @@ -639,6 +648,7 @@ void close_drawbridge(int x, int y)
newsym(x, y);
newsym(x2, y2);
block_point(x2,y2); /* vision */
return TRUE;
}

/*
Expand Down
7 changes: 6 additions & 1 deletion libnitrohack/src/zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,12 @@ struct monst *beam_hit(int ddx, int ddy, int range, /* direction and range */
if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y))
&& level->locations[x][y].typ == DRAWBRIDGE_DOWN)
makeknown(obj->otyp);
close_drawbridge(x,y);
if (!close_drawbridge(x, y)) {
/* Stop the ray to prevent a door being made
* in the drawbridge's doorway.
*/
return NULL;
}
break;
case WAN_STRIKING:
case SPE_FORCE_BOLT:
Expand Down

0 comments on commit 2d6201c

Please sign in to comment.