paranoid_confirm:Trap vs vapor+gas cloud regions

Extend paranoid_confirm:trap to also ask for confirmation when
attempting to enter a gas cloud region (scroll of stinking cloud,
breath from green dragons or iron golems, steam clouds from boiling
water, vapor left by fog cloud movement, no doubt several others).

Like with traps, can be overridden for a given move by using the
'm' prefix.  Unlike traps, doesn't try to guess whether moving into
a region will be harmless.

Doesn't affect movement into cloud terrain (Plane of Air).

Update the Guidebook to describe the revised behavior of
paranoid_confirm:trap and to mention how #terrain deals with regions.

'any_visible_region()' got mixed in with this but isn't used yet.
Affects extern.h and region.c.
This commit is contained in:
PatR
2024-08-11 14:59:57 -07:00
parent 37ad527512
commit 0eb8896301
6 changed files with 86 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 hack.c $NHDT-Date: 1720128165 2024/07/04 21:22:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.449 $ */
/* NetHack 3.7 hack.c $NHDT-Date: 1723410639 2024/08/11 21:10:39 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.452 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2517,11 +2517,12 @@ domove_core(void)
{
struct monst *mtmp;
struct rm *tmpr;
NhRegion *newreg, *oldreg;
coordxy x, y;
struct trap *trap = NULL;
int glyph;
coordxy chainx = 0, chainy = 0,
ballx = 0, bally = 0; /* ball&chain new positions */
ballx = 0, bally = 0; /* ball&chain new positions */
int bc_control = 0; /* control for ball&chain */
boolean cause_delay = FALSE, /* dragging ball will skip a move */
displaceu = FALSE; /* involuntary swap */
@@ -2624,10 +2625,14 @@ domove_core(void)
return;
/* maybe ask player for confirmation before walking into known traps */
if (ParanoidTrap && (trap = t_at(x, y)) != 0 && trap->tseen
if (ParanoidTrap && !Stunned && !Confusion
/* skip if player used 'm' prefix or is moving recklessly */
&& (!svc.context.nopick || svc.context.run)
&& !Stunned && !Confusion
/* check for discovered trap */
&& (trap = t_at(x, y)) != 0 && trap->tseen
/* check whether attempted move will be viable */
&& test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)
/* override confirmation if the trap is harmless to the hero */
&& (immune_to_trap(&gy.youmonst, trap->ttyp) != TRAP_CLEARLY_IMMUNE
/* Hallucination: all traps still show as ^, but the
hero can't tell what they are, so treat as dangerous */
@@ -2662,6 +2667,33 @@ domove_core(void)
return;
}
}
/* treat entering a visible region like entering a trap */
if (ParanoidTrap && !Blind && !Stunned && !Confusion && !Hallucination
/* skip if player used 'm' prefix or is moving recklessly */
&& (!svc.context.nopick || svc.context.run)
/* check for region(s) */
&& (newreg = visible_region_at(x, y)) != 0
&& ((oldreg = visible_region_at(u.ux, u.uy)) == 0
/* if moving from one region into another, only ask for
confirmation if the one potentially being entered inflicts
damage (poison gas) and the one being exited doesn't (vapor) */
|| (reg_damg(newreg) > 0 && reg_damg(oldreg) == 0))
/* check whether attempted move will be viable */
&& test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)
/* we don't override confirmation for poison resistance since the
region also hinders hero's vision even if/when no damage is done */
) {
char qbuf[QBUFSZ];
Snprintf(qbuf, sizeof qbuf, "%s into that %s cloud?",
locomotion(gy.youmonst.data, "step"),
(reg_damg(newreg) > 0) ? "poison gas" : "vapor");
if (!paranoid_query(ParanoidConfirm, upstart(qbuf))) {
nomul(0);
svc.context.move = 0;
return;
}
}
if (u.utrap) {
boolean moved = trapmove(x, y, trap);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 region.c $NHDT-Date: 1707462965 2024/02/09 07:16:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.89 $ */
/* NetHack 3.7 region.c $NHDT-Date: 1723410640 2024/08/11 21:10:40 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.97 $ */
/* Copyright (c) 1996 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */
@@ -628,6 +628,29 @@ remove_mon_from_regions(struct monst *mon)
#endif /*0*/
/* per-turn damaeg inflicted by visible region; hides details from caller */
int
reg_damg(NhRegion *reg)
{
int damg = (!reg->visible || reg->ttl == -2L) ? 0 : reg->arg.a_int;
return damg;
}
/* check whether current level has any visible regions */
boolean
any_visible_region(void)
{
int i;
for (i = 0; i < svn.n_regions; i++) {
if (!gr.regions[i]->visible || gr.regions[i]->ttl == -2L)
continue;
return TRUE;
}
return FALSE;
}
/*
* Check if a spot is under a visible region (eg: gas cloud).
* Returns NULL if not, otherwise returns region.
@@ -666,8 +689,8 @@ save_regions(NHFILE *nhfp)
goto skip_lots;
if (nhfp->structlevel) {
/* timestamp */
bwrite(nhfp->fd, (genericptr_t) &svm.moves, sizeof (svm.moves));
bwrite(nhfp->fd, (genericptr_t) &svn.n_regions, sizeof (svn.n_regions));
bwrite(nhfp->fd, (genericptr_t) &svm.moves, sizeof svm.moves);
bwrite(nhfp->fd, (genericptr_t) &svn.n_regions, sizeof svn.n_regions);
}
for (i = 0; i < svn.n_regions; i++) {
r = gr.regions[i];
@@ -747,11 +770,11 @@ rest_regions(NHFILE *nhfp)
tmstamp = (svm.moves - tmstamp);
if (nhfp->structlevel)
mread(nhfp->fd, (genericptr_t) &svn.n_regions, sizeof (svn.n_regions));
mread(nhfp->fd, (genericptr_t) &svn.n_regions, sizeof svn.n_regions);
gm.max_regions = svn.n_regions;
if (svn.n_regions > 0)
gr.regions = (NhRegion **) alloc(sizeof (NhRegion *) * svn.n_regions);
gr.regions = (NhRegion **) alloc(svn.n_regions * sizeof (NhRegion *));
for (i = 0; i < svn.n_regions; i++) {
r = gr.regions[i] = (NhRegion *) alloc(sizeof (NhRegion));
if (nhfp->structlevel) {