trap.c reformatting

Monstly changing '<type>* <var>' to '<type> *<var>'.  Wrap or shorten
a few wide lines.

One of the rolling boulder routines accessed gb.bhitpos.x,y many times;
change that to use local x,y instead.
This commit is contained in:
PatR
2024-02-19 11:11:23 -08:00
parent 5ef51a88d4
commit c84dc79610
+127 -145
View File
@@ -67,7 +67,8 @@ static void untrap_box(struct obj *, boolean, boolean);
#if 0 #if 0
static void join_adjacent_pits(struct trap *); static void join_adjacent_pits(struct trap *);
#endif #endif
static boolean thitm(int, struct monst *, struct obj *, int, boolean) NONNULLARG2; static boolean thitm(int, struct monst *, struct obj *, int,
boolean) NONNULLARG2;
static void maybe_finish_sokoban(void); static void maybe_finish_sokoban(void);
static const char *const a_your[2] = { "a", "your" }; static const char *const a_your[2] = { "a", "your" };
@@ -81,7 +82,7 @@ static const char *const blindgas[6] = { "humid", "odorless",
/* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode); /* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode);
returns TRUE if hit on torso */ returns TRUE if hit on torso */
boolean boolean
burnarmor(struct monst* victim) burnarmor(struct monst *victim)
{ {
struct obj *item; struct obj *item;
char buf[BUFSZ]; char buf[BUFSZ];
@@ -971,7 +972,7 @@ mu_maybe_destroy_web(
/* make a single arrow/dart/rock for a trap to shoot or drop */ /* make a single arrow/dart/rock for a trap to shoot or drop */
static struct obj * static struct obj *
t_missile(int otyp, struct trap* trap) t_missile(int otyp, struct trap *trap)
{ {
struct obj *otmp = mksobj(otyp, TRUE, FALSE); struct obj *otmp = mksobj(otyp, TRUE, FALSE);
@@ -1012,7 +1013,7 @@ reset_utrap(boolean msg)
} }
} }
/* is trap type ttyp triggered by touching the floor? */ /* is trap type ttyp triggered by touching the floor? */
static boolean static boolean
floor_trigger(int ttyp) floor_trigger(int ttyp)
{ {
@@ -1191,8 +1192,8 @@ trapeffect_arrow_trap(
static int static int
trapeffect_dart_trap( trapeffect_dart_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags UNUSED) unsigned int trflags UNUSED)
{ {
struct obj *otmp; struct obj *otmp;
@@ -1920,8 +1921,8 @@ trapeffect_pit(
static int static int
trapeffect_hole( trapeffect_hole(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -1979,8 +1980,8 @@ trapeffect_hole(
static int static int
trapeffect_telep_trap( trapeffect_telep_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags UNUSED) unsigned int trflags UNUSED)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -1997,8 +1998,8 @@ trapeffect_telep_trap(
static int static int
trapeffect_level_telep( trapeffect_level_telep(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2015,8 +2016,8 @@ trapeffect_level_telep(
static int static int
trapeffect_web( trapeffect_web(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2184,8 +2185,8 @@ trapeffect_web(
static int static int
trapeffect_statue_trap( trapeffect_statue_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags UNUSED) unsigned int trflags UNUSED)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2198,8 +2199,8 @@ trapeffect_statue_trap(
static int static int
trapeffect_magic_trap( trapeffect_magic_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2339,8 +2340,8 @@ trapeffect_anti_magic(
static int static int
trapeffect_poly_trap( trapeffect_poly_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2390,8 +2391,8 @@ trapeffect_poly_trap(
static int static int
trapeffect_landmine( trapeffect_landmine(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2440,7 +2441,7 @@ trapeffect_landmine(
exercise(A_DEX, FALSE); exercise(A_DEX, FALSE);
} }
/* add a pit before calling losehp so bones won't keep the landmine; /* add a pit before calling losehp so bones won't keep the landmine;
* blow_up_landmine will remove the pit afterwards if inappropriate */ blow_up_landmine() will remove pit afterwards if inappropriate */
trap->ttyp = PIT; trap->ttyp = PIT;
trap->madeby_u = FALSE; trap->madeby_u = FALSE;
losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN); losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN);
@@ -2515,8 +2516,8 @@ trapeffect_landmine(
static int static int
trapeffect_rolling_boulder_trap( trapeffect_rolling_boulder_trap(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags UNUSED) unsigned int trflags UNUSED)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2565,8 +2566,8 @@ trapeffect_rolling_boulder_trap(
static int static int
trapeffect_magic_portal( trapeffect_magic_portal(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
@@ -2580,14 +2581,14 @@ trapeffect_magic_portal(
static int static int
trapeffect_vibrating_square( trapeffect_vibrating_square(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags UNUSED) unsigned int trflags UNUSED)
{ {
if (mtmp == &gy.youmonst) { if (mtmp == &gy.youmonst) {
feeltrap(trap); feeltrap(trap);
/* messages handled elsewhere; the trap symbol is merely to mark the /* messages handled elsewhere; the trap symbol is merely to mark the
* square for future reference */ square for future reference */
} else { } else {
boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed);
boolean see_it = cansee(mtmp->mx, mtmp->my); boolean see_it = cansee(mtmp->mx, mtmp->my);
@@ -2789,8 +2790,8 @@ immune_to_trap(struct monst *mon, unsigned ttype)
static int static int
trapeffect_selector( trapeffect_selector(
struct monst* mtmp, struct monst *mtmp,
struct trap* trap, struct trap *trap,
unsigned int trflags) unsigned int trflags)
{ {
switch (trap->ttyp) { switch (trap->ttyp) {
@@ -2909,7 +2910,7 @@ dotrap(struct trap *trap, unsigned trflags)
} }
static char * static char *
trapnote(struct trap* trap, boolean noprefix) trapnote(struct trap *trap, boolean noprefix)
{ {
static const char *const tnnames[] = { static const char *const tnnames[] = {
"C note", "D flat", "D note", "E flat", "C note", "D flat", "D note", "E flat",
@@ -3018,7 +3019,7 @@ steedintrap(struct trap *trap, struct obj *otmp)
/* some actions common to both player and monsters for triggered landmine */ /* some actions common to both player and monsters for triggered landmine */
void void
blow_up_landmine(struct trap* trap) blow_up_landmine(struct trap *trap)
{ {
coordxy x = trap->tx, y = trap->ty, dbx, dby; coordxy x = trap->tx, y = trap->ty, dbx, dby;
struct rm *lev = &levl[x][y]; struct rm *lev = &levl[x][y];
@@ -3064,7 +3065,7 @@ blow_up_landmine(struct trap* trap)
} }
static void static void
launch_drop_spot(struct obj* obj, coordxy x, coordxy y) launch_drop_spot(struct obj *obj, coordxy x, coordxy y)
{ {
if (!obj) { if (!obj) {
gl.launchplace.obj = (struct obj *) 0; gl.launchplace.obj = (struct obj *) 0;
@@ -3111,12 +3112,10 @@ launch_obj(
struct monst *mtmp; struct monst *mtmp;
struct obj *otmp, *otmp2; struct obj *otmp, *otmp2;
int dx, dy; int dx, dy;
coordxy x, y;
struct obj *singleobj; struct obj *singleobj;
boolean used_up = FALSE; boolean used_up = FALSE, otherside = FALSE;
boolean otherside = FALSE; int dist, tmp, delaycnt = 0;
int dist;
int tmp;
int delaycnt = 0;
otmp = sobj_at(otyp, x1, y1); otmp = sobj_at(otyp, x1, y1);
/* Try the other side too, for rolling boulder traps */ /* Try the other side too, for rolling boulder traps */
@@ -3157,8 +3156,8 @@ launch_obj(
sizeof(struct dig_info)); sizeof(struct dig_info));
dist = distmin(x1, y1, x2, y2); dist = distmin(x1, y1, x2, y2);
gb.bhitpos.x = x1; x = gb.bhitpos.x = x1;
gb.bhitpos.y = y1; y = gb.bhitpos.y = y1;
dx = sgn(x2 - x1); dx = sgn(x2 - x1);
dy = sgn(y2 - y1); dy = sgn(y2 - y1);
switch (style) { switch (style) {
@@ -3189,10 +3188,10 @@ launch_obj(
default: default:
if (!delaycnt) if (!delaycnt)
delaycnt = 1; delaycnt = 1;
if (!cansee(gb.bhitpos.x, gb.bhitpos.y)) if (!cansee(x, y))
curs_on_u(); curs_on_u();
tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng)); tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng));
tmp_at(gb.bhitpos.x, gb.bhitpos.y); tmp_at(x, y);
} }
/* Mark a spot to place object in bones files to prevent /* Mark a spot to place object in bones files to prevent
* loss of object. Use the starting spot to ensure that * loss of object. Use the starting spot to ensure that
@@ -3202,27 +3201,27 @@ launch_obj(
* that would prevent it from ever getting there (bars), and we * that would prevent it from ever getting there (bars), and we
* can't tell that yet. * can't tell that yet.
*/ */
launch_drop_spot(singleobj, gb.bhitpos.x, gb.bhitpos.y); launch_drop_spot(singleobj, x, y);
/* Set the object in motion */ /* Set the object in motion */
while (dist-- > 0 && !used_up) { while (dist-- > 0 && !used_up) {
struct trap *t; struct trap *t;
tmp_at(gb.bhitpos.x, gb.bhitpos.y); tmp_at(x, y);
tmp = delaycnt; tmp = delaycnt;
/* dstage@u.washington.edu -- Delay only if hero sees it */ /* dstage@u.washington.edu -- Delay only if hero sees it */
if (cansee(gb.bhitpos.x, gb.bhitpos.y)) if (cansee(x, y))
while (tmp-- > 0) while (tmp-- > 0)
nh_delay_output(); nh_delay_output();
gb.bhitpos.x += dx; x = (gb.bhitpos.x += dx);
gb.bhitpos.y += dy; y = (gb.bhitpos.y += dy);
if ((mtmp = m_at(gb.bhitpos.x, gb.bhitpos.y)) != 0) { if ((mtmp = m_at(x, y)) != 0) {
if (otyp == BOULDER && throws_rocks(mtmp->data)) { if (otyp == BOULDER && throws_rocks(mtmp->data)) {
if (rn2(3)) { if (rn2(3)) {
if (cansee(gb.bhitpos.x, gb.bhitpos.y)) if (cansee(x, y))
pline("%s snatches the boulder.", Monnam(mtmp)); pline("%s snatches the boulder.", Monnam(mtmp));
singleobj->otrapped = 0; singleobj->otrapped = 0;
(void) mpickobj(mtmp, singleobj); (void) mpickobj(mtmp, singleobj);
@@ -3237,7 +3236,7 @@ launch_obj(
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
break; break;
} }
} else if (u_at(gb.bhitpos.x, gb.bhitpos.y)) { } else if (u_at(x, y)) {
if (gm.multi) if (gm.multi)
nomul(0); nomul(0);
if (thitu(9 + singleobj->spe, dmgval(singleobj, &gy.youmonst), if (thitu(9 + singleobj->spe, dmgval(singleobj, &gy.youmonst),
@@ -3245,14 +3244,15 @@ launch_obj(
stop_occupation(); stop_occupation();
} }
if (style == ROLL) { if (style == ROLL) {
if (down_gate(gb.bhitpos.x, gb.bhitpos.y) != -1) { if (down_gate(x, y) != -1) {
if (ship_object(singleobj, gb.bhitpos.x, gb.bhitpos.y, FALSE)) { if (ship_object(singleobj, x, y, FALSE)) {
used_up = TRUE; used_up = TRUE;
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
break; break;
} }
} }
if ((t = t_at(gb.bhitpos.x, gb.bhitpos.y)) != 0 && otyp == BOULDER) { if ((t = t_at(x, y)) != 0
&& otyp == BOULDER) {
int newlev = 0; int newlev = 0;
d_level dest; d_level dest;
@@ -3260,20 +3260,20 @@ launch_obj(
case LANDMINE: case LANDMINE:
if (rn2(10) > 2) { if (rn2(10) > 2) {
pline("KAABLAMM!!!%s", pline("KAABLAMM!!!%s",
cansee(gb.bhitpos.x, gb.bhitpos.y) cansee(x, y)
? " The rolling boulder triggers a land mine." ? " The rolling boulder triggers a land mine."
: ""); : "");
deltrap(t); deltrap(t);
del_engr_at(gb.bhitpos.x, gb.bhitpos.y); del_engr_at(x, y);
place_object(singleobj, gb.bhitpos.x, gb.bhitpos.y); place_object(singleobj, x, y);
singleobj->otrapped = 0; singleobj->otrapped = 0;
fracture_rock(singleobj); fracture_rock(singleobj);
(void) scatter(gb.bhitpos.x, gb.bhitpos.y, 4, (void) scatter(x, y, 4,
MAY_DESTROY | MAY_HIT | MAY_FRACTURE MAY_DESTROY | MAY_HIT | MAY_FRACTURE
| VIS_EFFECTS, | VIS_EFFECTS,
(struct obj *) 0); (struct obj *) 0);
if (cansee(gb.bhitpos.x, gb.bhitpos.y)) if (cansee(x, y))
newsym(gb.bhitpos.x, gb.bhitpos.y); newsym(x, y);
used_up = TRUE; used_up = TRUE;
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
} }
@@ -3287,7 +3287,7 @@ launch_obj(
break; break;
/*FALLTHRU*/ /*FALLTHRU*/
case TELEP_TRAP: case TELEP_TRAP:
if (cansee(gb.bhitpos.x, gb.bhitpos.y)) if (cansee(x, y))
pline("Suddenly the rolling boulder disappears!"); pline("Suddenly the rolling boulder disappears!");
else if (!Deaf) else if (!Deaf)
You_hear("a rumbling stop abruptly."); You_hear("a rumbling stop abruptly.");
@@ -3311,7 +3311,7 @@ launch_obj(
case TRAPDOOR: case TRAPDOOR:
/* the boulder won't be used up if there is a /* the boulder won't be used up if there is a
monster in the trap; stop rolling anyway */ monster in the trap; stop rolling anyway */
x2 = gb.bhitpos.x, y2 = gb.bhitpos.y; /* stops here */ x2 = x, y2 = y; /* stops here */
if (flooreffects(singleobj, x2, y2, "fall")) { if (flooreffects(singleobj, x2, y2, "fall")) {
used_up = TRUE; used_up = TRUE;
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
@@ -3325,47 +3325,45 @@ launch_obj(
if (used_up || dist == -1) if (used_up || dist == -1)
break; /* from 'while' loop */ break; /* from 'while' loop */
} }
if (flooreffects(singleobj, gb.bhitpos.x, gb.bhitpos.y, "fall")) { if (flooreffects(singleobj, x, y, "fall")) {
used_up = TRUE; used_up = TRUE;
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
break; break;
} }
if (otyp == BOULDER if (otyp == BOULDER && (otmp2 = sobj_at(BOULDER, x, y)) != 0) {
&& (otmp2 = sobj_at(BOULDER, gb.bhitpos.x, gb.bhitpos.y)) != 0) {
const char *bmsg = " as one boulder sets another in motion"; const char *bmsg = " as one boulder sets another in motion";
coordxy fx = x + dx, fy = y + dy;
if (!isok(gb.bhitpos.x + dx, gb.bhitpos.y + dy) || !dist if (!isok(fx, fy) || !dist || IS_ROCK(levl[fx][fy].typ))
|| IS_ROCK(levl[gb.bhitpos.x + dx][gb.bhitpos.y + dy].typ))
bmsg = " as one boulder hits another"; bmsg = " as one boulder hits another";
Soundeffect(se_loud_crash, 80); Soundeffect(se_loud_crash, 80);
You_hear("a loud crash%s!", You_hear("a loud crash%s!", cansee(fx, fy) ? bmsg : "");
cansee(gb.bhitpos.x, gb.bhitpos.y) ? bmsg : "");
obj_extract_self(otmp2); obj_extract_self(otmp2);
/* pass off the otrapped flag to the next boulder */ /* pass off the otrapped flag to the next boulder */
otmp2->otrapped = singleobj->otrapped; otmp2->otrapped = singleobj->otrapped;
singleobj->otrapped = 0; singleobj->otrapped = 0;
place_object(singleobj, gb.bhitpos.x, gb.bhitpos.y); place_object(singleobj, fx, fy);
singleobj = otmp2; singleobj = otmp2;
otmp2 = (struct obj *) 0; otmp2 = (struct obj *) 0;
wake_nearto(gb.bhitpos.x, gb.bhitpos.y, 10 * 10); wake_nearto(fx, fy, 10 * 10);
} }
} }
if (otyp == BOULDER && closed_door(gb.bhitpos.x, gb.bhitpos.y)) { if (otyp == BOULDER && closed_door(x, y)) {
if (cansee(gb.bhitpos.x, gb.bhitpos.y)) if (cansee(x, y))
pline_The("boulder crashes through a door."); pline_The("boulder crashes through a door.");
levl[gb.bhitpos.x][gb.bhitpos.y].doormask = D_BROKEN; levl[x][y].doormask = D_BROKEN;
if (dist) if (dist)
unblock_point(gb.bhitpos.x, gb.bhitpos.y); unblock_point(x, y);
} }
/* if about to hit something, do so now */ /* if about to hit something, do so now */
if (dist > 0 && isok(gb.bhitpos.x + dx, gb.bhitpos.y + dy)) { if (dist > 0 && isok(x + dx, y + dy)) {
coordxy fx = gb.bhitpos.x + dx, fy = gb.bhitpos.y + dy; coordxy fx = x + dx, fy = y + dy;
uchar typ = levl[fx][fy].typ; uchar typ = levl[fx][fy].typ;
if (typ == IRONBARS) { if (typ == IRONBARS) {
x2 = gb.bhitpos.x, y2 = gb.bhitpos.y; /* object stops here */ x2 = x, y2 = y; /* object stops here */
if (hits_bars(&singleobj, x2, y2, fx, fy, !rn2(20), 0)) { if (hits_bars(&singleobj, x2, y2, fx, fy, !rn2(20), 0)) {
if (!singleobj) { if (!singleobj) {
used_up = TRUE; used_up = TRUE;
@@ -3374,13 +3372,13 @@ launch_obj(
break; break;
} }
} else if (IS_STWALL(typ) || IS_TREE(typ)) { } else if (IS_STWALL(typ) || IS_TREE(typ)) {
x2 = gb.bhitpos.x, y2 = gb.bhitpos.y; /* object stops here */ x2 = x, y2 = y; /* object stops here */
if (!Deaf) if (!Deaf)
pline("Thump!"); pline("Thump!");
wake_nearto(x2, y2, 16); wake_nearto(x2, y2, 16);
} }
} }
} } /* while dist > 0 */
tmp_at(DISP_END, 0); tmp_at(DISP_END, 0);
launch_drop_spot((struct obj *) 0, 0, 0); launch_drop_spot((struct obj *) 0, 0, 0);
if (!used_up) { if (!used_up) {
@@ -3388,12 +3386,12 @@ launch_obj(
place_object(singleobj, x2, y2); place_object(singleobj, x2, y2);
newsym(x2, y2); newsym(x2, y2);
return 1; return 1;
} else }
return 2; return 2;
} }
void void
seetrap(struct trap* trap) seetrap(struct trap *trap)
{ {
if (!trap->tseen) { if (!trap->tseen) {
trap->tseen = 1; trap->tseen = 1;
@@ -3403,7 +3401,7 @@ seetrap(struct trap* trap)
/* like seetrap() but overrides vision */ /* like seetrap() but overrides vision */
void void
feeltrap(struct trap* trap) feeltrap(struct trap *trap)
{ {
trap->tseen = 1; trap->tseen = 1;
map_trap(trap, 1); map_trap(trap, 1);
@@ -3442,7 +3440,7 @@ find_random_launch_coord(struct trap *ttmp, coord *cc)
if (ttmp->ttyp == ROLLING_BOULDER_TRAP) if (ttmp->ttyp == ROLLING_BOULDER_TRAP)
mindist = 2; mindist = 2;
distance = rn1(5, 4); /* 4..8 away */ distance = rn1(5, 4); /* 4..8 away */
tmp = rn2(N_DIRS); /* randomly pick a direction to try first */ tmp = rn2(N_DIRS); /* randomly pick a direction to try first */
while (distance >= mindist) { while (distance >= mindist) {
dx = xdir[tmp]; dx = xdir[tmp];
dy = ydir[tmp]; dy = ydir[tmp];
@@ -3554,8 +3552,7 @@ mintrap(struct monst *mtmp, unsigned mintrapflags)
|| trap->ttyp == HOLE || trap->ttyp == HOLE
|| trap->ttyp == WEB)) { || trap->ttyp == WEB)) {
/* If you come upon an obviously trapped monster, then /* If you come upon an obviously trapped monster, then
* you must be able to see the trap it's in too. you must be able to see the trap it's in too. */
*/
seetrap(trap); seetrap(trap);
} }
@@ -4248,20 +4245,12 @@ domagictrap(void)
} }
} }
/* Set an item on fire. /* Set an item on fire. Return whether the object was destroyed. */
* "force" means not to roll a luck-based protection check for the
* item.
* "x" and "y" are the coordinates to dump the contents of a
* container, if it burns up.
*
* Return whether the object was destroyed.
*/
boolean boolean
fire_damage( fire_damage(
struct obj *obj, struct obj *obj,
boolean force, boolean force, /* if True, skip luck-based protection check */
coordxy x, coordxy x, coordxy y) /* where to place contents of burned up container */
coordxy y)
{ {
int chance; int chance;
struct obj *otmp, *ncobj; struct obj *otmp, *ncobj;
@@ -4352,8 +4341,7 @@ fire_damage_chain(
struct obj *chain, struct obj *chain,
boolean force, boolean force,
boolean here, boolean here,
coordxy x, coordxy x, coordxy y)
coordxy y)
{ {
struct obj *obj, *nobj; struct obj *obj, *nobj;
int num = 0; int num = 0;
@@ -4375,7 +4363,7 @@ fire_damage_chain(
/* obj has been thrown or dropped into lava; damage is worse than mere fire */ /* obj has been thrown or dropped into lava; damage is worse than mere fire */
boolean boolean
lava_damage(struct obj* obj, coordxy x, coordxy y) lava_damage(struct obj *obj, coordxy x, coordxy y)
{ {
int otyp = obj->otyp, ocls = obj->oclass; int otyp = obj->otyp, ocls = obj->oclass;
@@ -4417,7 +4405,7 @@ lava_damage(struct obj* obj, coordxy x, coordxy y)
} }
void void
acid_damage(struct obj* obj) acid_damage(struct obj *obj)
{ {
/* Scrolls but not spellbooks can be erased by acid. */ /* Scrolls but not spellbooks can be erased by acid. */
struct monst *victim; struct monst *victim;
@@ -4456,16 +4444,12 @@ acid_damage(struct obj* obj)
} }
/* Get an object wet and damage it appropriately. /* Get an object wet and damage it appropriately.
* "obj": if null, returns ER_NOTHING Returns an erosion return value (ER_*). */
* "ostr", if present, is used instead of the object name in some messages.
* "force" means not to roll luck to protect some objects.
* Returns an erosion return value (ER_*)
*/
int int
water_damage( water_damage(
struct obj *obj, struct obj *obj, /* might be Null; return ER_NOTHING if so */
const char *ostr, const char *ostr, /* if non-Null, use instead of cxname() in messages */
boolean force) boolean force) /* if True, skip luck-based protection check */
{ {
boolean in_invent = obj && carried(obj), described = FALSE; boolean in_invent = obj && carried(obj), described = FALSE;
@@ -5209,10 +5193,7 @@ move_into_trap(struct trap *ttmp)
} }
} }
/* 0: doesn't even try /* 0: doesn't even try; 1: tries and fails; 2: succeeds */
* 1: tries and fails
* 2: succeeds
*/
static int static int
try_disarm( try_disarm(
struct trap *ttmp, struct trap *ttmp,
@@ -5303,7 +5284,7 @@ try_disarm(
} }
static void static void
reward_untrap(struct trap* ttmp, struct monst* mtmp) reward_untrap(struct trap *ttmp, struct monst *mtmp)
{ {
if (!ttmp->madeby_u) { if (!ttmp->madeby_u) {
if (rnl(10) < 8 && !mtmp->mpeaceful && !helpless(mtmp) if (rnl(10) < 8 && !mtmp->mpeaceful && !helpless(mtmp)
@@ -5314,8 +5295,8 @@ reward_untrap(struct trap* ttmp, struct monst* mtmp)
set_malign(mtmp); /* reset alignment */ set_malign(mtmp); /* reset alignment */
pline("%s is grateful.", Monnam(mtmp)); pline("%s is grateful.", Monnam(mtmp));
} }
/* Helping someone out of a trap is a nice thing to do, /* Helping someone out of a trap is a nice thing to do.
* A lawful may be rewarded, but not too often. */ A lawful may be rewarded, but not too often. */
if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) { if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) {
adjalign(1); adjalign(1);
You_feel("that you did the right thing."); You_feel("that you did the right thing.");
@@ -5367,7 +5348,7 @@ disarm_holdingtrap(struct trap *ttmp)
} }
static int static int
disarm_landmine(struct trap* ttmp) /* Helge Hafting */ disarm_landmine(struct trap *ttmp) /* Helge Hafting */
{ {
int fails = try_disarm(ttmp, FALSE); int fails = try_disarm(ttmp, FALSE);
@@ -5380,7 +5361,7 @@ disarm_landmine(struct trap* ttmp) /* Helge Hafting */
/* getobj callback for object to disarm a squeaky board with */ /* getobj callback for object to disarm a squeaky board with */
static int static int
unsqueak_ok(struct obj* obj) unsqueak_ok(struct obj *obj)
{ {
if (!obj) if (!obj)
return GETOBJ_EXCLUDE; return GETOBJ_EXCLUDE;
@@ -5403,7 +5384,7 @@ unsqueak_ok(struct obj* obj)
/* it may not make much sense to use grease on floor boards, but so what? */ /* it may not make much sense to use grease on floor boards, but so what? */
static int static int
disarm_squeaky_board(struct trap* ttmp) disarm_squeaky_board(struct trap *ttmp)
{ {
struct obj *obj; struct obj *obj;
boolean bad_tool; boolean bad_tool;
@@ -5437,7 +5418,7 @@ disarm_squeaky_board(struct trap* ttmp)
/* removes traps that shoot arrows, darts, etc. */ /* removes traps that shoot arrows, darts, etc. */
static int static int
disarm_shooting_trap(struct trap* ttmp, int otyp) disarm_shooting_trap(struct trap *ttmp, int otyp)
{ {
int fails = try_disarm(ttmp, FALSE); int fails = try_disarm(ttmp, FALSE);
@@ -5851,8 +5832,9 @@ untrap(
boolean boolean
openholdingtrap( openholdingtrap(
struct monst *mon, struct monst *mon,
boolean *noticed) /* set to true iff hero notices the effect; */ boolean *noticed) /* set to true iff hero notices the effect;
{ /* otherwise left with its previous value intact */ * otherwise left with its previous value intact */
{
struct trap *t; struct trap *t;
char buf[BUFSZ], whichbuf[20]; char buf[BUFSZ], whichbuf[20];
const char *trapdescr = 0, *which = 0; const char *trapdescr = 0, *which = 0;
@@ -5950,8 +5932,9 @@ openholdingtrap(
boolean boolean
closeholdingtrap( closeholdingtrap(
struct monst *mon, struct monst *mon,
boolean *noticed) /* set to true iff hero notices the effect; */ boolean *noticed) /* set to true iff hero notices the effect;
{ /* otherwise left with its previous value intact */ * otherwise left with its previous value intact */
{
struct trap *t; struct trap *t;
unsigned dotrapflags; unsigned dotrapflags;
boolean ishero = (mon == &gy.youmonst), result; boolean ishero = (mon == &gy.youmonst), result;
@@ -6259,9 +6242,9 @@ count_traps(int ttyp)
} }
void void
deltrap(register struct trap* trap) deltrap(struct trap *trap)
{ {
register struct trap *ttmp; struct trap *ttmp;
clear_conjoined_pits(trap); clear_conjoined_pits(trap);
if (trap == gf.ftrap) { if (trap == gf.ftrap) {
@@ -6307,7 +6290,7 @@ conjoined_pits(
} }
static void static void
clear_conjoined_pits(struct trap* trap) clear_conjoined_pits(struct trap *trap)
{ {
int diridx, adjidx; int diridx, adjidx;
coordxy x, y; coordxy x, y;
@@ -6331,7 +6314,7 @@ clear_conjoined_pits(struct trap* trap)
} }
static boolean static boolean
adj_nonconjoined_pit(struct trap* adjtrap) adj_nonconjoined_pit(struct trap *adjtrap)
{ {
struct trap *trap_with_u = t_at(u.ux0, u.uy0); struct trap *trap_with_u = t_at(u.ux0, u.uy0);
@@ -6349,7 +6332,7 @@ adj_nonconjoined_pit(struct trap* adjtrap)
* (currently not called from anywhere) * (currently not called from anywhere)
*/ */
static void static void
join_adjacent_pits(struct trap* trap) join_adjacent_pits(struct trap *trap)
{ {
struct trap *t; struct trap *t;
int diridx; int diridx;
@@ -6375,7 +6358,7 @@ join_adjacent_pits(struct trap* trap)
* Returns TRUE if you escaped a pit and are standing on the precipice. * Returns TRUE if you escaped a pit and are standing on the precipice.
*/ */
boolean boolean
uteetering_at_seen_pit(struct trap* trap) uteetering_at_seen_pit(struct trap *trap)
{ {
return (trap && is_pit(trap->ttyp) && trap->tseen return (trap && is_pit(trap->ttyp) && trap->tseen
&& u_at(trap->tx, trap->ty) && u_at(trap->tx, trap->ty)
@@ -6387,7 +6370,7 @@ uteetering_at_seen_pit(struct trap* trap)
* release a trap door * release a trap door
*/ */
boolean boolean
uescaped_shaft(struct trap* trap) uescaped_shaft(struct trap *trap)
{ {
return (trap && is_hole(trap->ttyp) && trap->tseen return (trap && is_hole(trap->ttyp) && trap->tseen
&& u_at(trap->tx, trap->ty)); && u_at(trap->tx, trap->ty));
@@ -6395,7 +6378,7 @@ uescaped_shaft(struct trap* trap)
/* Destroy a trap that emanates from the floor. */ /* Destroy a trap that emanates from the floor. */
boolean boolean
delfloortrap(struct trap* ttmp) delfloortrap(struct trap *ttmp)
{ {
/* some of these are arbitrary -dlc */ /* some of these are arbitrary -dlc */
if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || (ttmp->ttyp == BEAR_TRAP) if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || (ttmp->ttyp == BEAR_TRAP)
@@ -6421,7 +6404,7 @@ delfloortrap(struct trap* ttmp)
/* used for doors (also tins). can be used for anything else that opens. */ /* used for doors (also tins). can be used for anything else that opens. */
void void
b_trapped(const char* item, int bodypart) b_trapped(const char *item, int bodypart)
{ {
int lvl = level_difficulty(), int lvl = level_difficulty(),
dmg = rnd(5 + (lvl < 5 ? lvl : 2 + lvl / 2)); dmg = rnd(5 + (lvl < 5 ? lvl : 2 + lvl / 2));
@@ -6463,7 +6446,8 @@ thitm(
pline("%s is almost hit by %s!", Monnam(mon), doname(obj)); pline("%s is almost hit by %s!", Monnam(mon), doname(obj));
} else { } else {
int dam = 1; int dam = 1;
boolean harmless = (obj && stone_missile(obj) && passes_rocks(mon->data)); boolean harmless = (obj && stone_missile(obj)
&& passes_rocks(mon->data));
if (obj && cansee(mon->mx, mon->my)) if (obj && cansee(mon->mx, mon->my))
pline("%s is hit by %s%s", Monnam(mon), doname(obj), pline("%s is hit by %s%s", Monnam(mon), doname(obj),
@@ -6550,7 +6534,7 @@ lava_effects(void)
for (obj = gi.invent; obj; obj = obj->nobj) { for (obj = gi.invent; obj; obj = obj->nobj) {
if (obj->in_use) { /* remove_worn_item() sets in_use */ if (obj->in_use) { /* remove_worn_item() sets in_use */
/* one item can be protected from burning up [accommodates /* one item can be protected from burning up [accommodates
steal(AMULET_OF_FLYING) -> remove_worn_item() -> drop steal(AMULET_OF_FLYING) -> remove_worn_item() -> fall
into lava (which happens before item is transferred into lava (which happens before item is transferred
from invent to thief->minvent)]; item will still be in from invent to thief->minvent)]; item will still be in
inventory when we return to caller or save bones (or inventory when we return to caller or save bones (or
@@ -6820,13 +6804,11 @@ maybe_finish_sokoban(void)
} }
/* Return the string name of the trap type passed in, unless the player is /* Return the string name of the trap type passed in, unless the player is
* hallucinating, in which case return a random or hallucinatory trap name. hallucinating, in which case return a random or hallucinatory trap name. */
* If the second argument is true, return the correct trap name even when
* hallucinating (for things like wizard mode wishing for traps and impossible
* calls).
*/
const char * const char *
trapname(int ttyp, boolean override) trapname(
int ttyp,
boolean override) /* if True, ignore Hallucination */
{ {
static const char *const halu_trapnames[] = { static const char *const halu_trapnames[] = {
/* riffs on actual nethack traps */ /* riffs on actual nethack traps */
@@ -6863,7 +6845,7 @@ trapname(int ttyp, boolean override)
/* inspired by "tourist trap" */ /* inspired by "tourist trap" */
copynchars(roletrap, copynchars(roletrap,
rn2(3) ? ((fem && gu.urole.name.f) ? gu.urole.name.f rn2(3) ? ((fem && gu.urole.name.f) ? gu.urole.name.f
: gu.urole.name.m) : gu.urole.name.m)
: rank_of(u.ulevel, Role_switch, fem), : rank_of(u.ulevel, Role_switch, fem),
(int) (sizeof roletrap - sizeof " trap")); (int) (sizeof roletrap - sizeof " trap"));
Strcat(roletrap, " trap"); Strcat(roletrap, " trap");
@@ -6882,7 +6864,7 @@ trapname(int ttyp, boolean override)
chain, due to some external source of fire. The object chain should chain, due to some external source of fire. The object chain should
be somewhere exposed, like someone's open inventory or the floor. */ be somewhere exposed, like someone's open inventory or the floor. */
void void
ignite_items(struct obj* objchn) ignite_items(struct obj *objchn)
{ {
struct obj *obj; struct obj *obj;
boolean bynexthere = (objchn && objchn->where == OBJ_FLOOR); boolean bynexthere = (objchn && objchn->where == OBJ_FLOOR);