updating 'time' status

Handling botl updates for 'time' was inconsistent.  Set the flag to
do that when moves is incremented (where the update is suppressed if
running) or when running stops short.

losehp() would cancel running/traveling if called when in normal form
but not if called when polymorphed, so theoretically you could take
damage and keep on running.  I don't have a test case to verify that.
This commit is contained in:
PatR
2020-03-16 17:32:12 -07:00
parent 8ccc9773aa
commit 40d19525c3
5 changed files with 55 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 extern.h $NHDT-Date: 1583073988 2020/03/01 14:46:28 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.809 $ */
/* NetHack 3.6 extern.h $NHDT-Date: 1584405113 2020/03/17 00:31:53 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.814 $ */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */
@@ -906,6 +906,7 @@ E int NDECL(dopickup);
E void NDECL(lookaround);
E boolean FDECL(crawl_destination, (int, int));
E int NDECL(monster_nearby);
E void FDECL(end_running, (BOOLEAN_P));
E void FDECL(nomul, (int));
E void FDECL(unmul, (const char *));
E void FDECL(losehp, (int, const char *, BOOLEAN_P));

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 allmain.c $NHDT-Date: 1580044340 2020/01/26 13:12:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.138 $ */
/* NetHack 3.6 allmain.c $NHDT-Date: 1584405115 2020/03/17 00:31:55 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.143 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -178,6 +178,9 @@ boolean resuming;
g.monstermoves++; /* [obsolete (for a long time...)] */
g.moves++;
if (flags.time && !g.context.run)
iflags.time_botl = TRUE; /* 'moves' just changed */
/********************************/
/* once-per-turn things go here */
/********************************/
@@ -189,8 +192,6 @@ boolean resuming;
if (u.ublesscnt)
u.ublesscnt--;
if (flags.time && !g.context.run)
iflags.time_botl = TRUE;
/* One possible result of prayer is healing. Whether or
* not you get healed depends on your current hit points.
@@ -436,8 +437,6 @@ boolean resuming;
if (!g.multi) {
/* lookaround may clear multi */
g.context.move = 0;
if (flags.time)
g.context.botl = TRUE;
continue;
}
if (g.context.mv) {
@@ -457,9 +456,6 @@ boolean resuming;
}
if (u.utotype) /* change dungeon level */
deferred_goto(); /* after rhack() */
/* !g.context.move here: multiple movement command stopped */
else if (flags.time && (!g.context.move || !g.context.mv))
g.context.botl = TRUE;
if (g.vision_full_recalc)
vision_recalc(0); /* vision! */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 eat.c $NHDT-Date: 1577190688 2019/12/24 12:31:28 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.222 $ */
/* NetHack 3.6 eat.c $NHDT-Date: 1584405116 2020/03/17 00:31:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.223 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -3056,17 +3056,16 @@ boolean incr;
switch (newhs) {
case HUNGRY:
if (Hallucination) {
You((!incr) ? "now have a lesser case of the munchies."
: "are getting the munchies.");
You(!incr ? "now have a lesser case of the munchies."
: "are getting the munchies.");
} else
You((!incr) ? "only feel hungry now."
: (u.uhunger < 145)
? "feel hungry."
: "are beginning to feel hungry.");
You(!incr ? "only feel hungry now."
: (u.uhunger < 145) ? "feel hungry."
: "are beginning to feel hungry.");
if (incr && g.occupation
&& (g.occupation != eatfood && g.occupation != opentin))
stop_occupation();
g.context.travel = g.context.travel1 = g.context.mv = g.context.run = 0;
end_running(TRUE);
break;
case WEAK:
if (Hallucination)
@@ -3079,14 +3078,13 @@ boolean incr;
? g.urole.name.m
: "Elf");
else
You((!incr)
? "feel weak now."
: (u.uhunger < 45) ? "feel weak."
: "are beginning to feel weak.");
You(!incr ? "feel weak now."
: (u.uhunger < 45) ? "feel weak."
: "are beginning to feel weak.");
if (incr && g.occupation
&& (g.occupation != eatfood && g.occupation != opentin))
stop_occupation();
g.context.travel = g.context.travel1 = g.context.mv = g.context.run = 0;
end_running(TRUE);
break;
}
u.uhs = newhs;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 hack.c $NHDT-Date: 1582799171 2020/02/27 10:26:11 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.249 $ */
/* NetHack 3.6 hack.c $NHDT-Date: 1584405116 2020/03/17 00:31:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.250 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -954,7 +954,7 @@ int mode;
if ((mode == TRAVP_TRAVEL || mode == TRAVP_VALID) && g.context.travel1
&& distmin(u.ux, u.uy, u.tx, u.ty) == 1
&& !(u.ux != u.tx && u.uy != u.ty && NODIAG(u.umonnum))) {
g.context.run = 0;
end_running(FALSE);
if (test_move(u.ux, u.uy, u.tx - u.ux, u.ty - u.uy, TEST_MOVE)) {
if (mode == TRAVP_TRAVEL) {
u.dx = u.tx - u.ux;
@@ -1964,10 +1964,14 @@ domove_core()
}
if (g.context.run && flags.runmode != RUN_TPORT) {
/* display every step or every 7th step depending upon mode */
/* for tport mode, don't display anything until we've stopped;
for normal (leap) mode, update display every 7th step
(relative to turn counter; ought to be to start of running);
for walk and crawl (visual debugging) modes, update the
display after every step */
if (flags.runmode != RUN_LEAP || !(g.moves % 7L)) {
if (flags.time)
iflags.time_botl = 1;
/* moveloop() suppresses time_botl when running */
iflags.time_botl = flags.time;
curs_on_u();
delay_output();
if (flags.runmode == RUN_CRAWL) {
@@ -2927,6 +2931,21 @@ monster_nearby()
return 0;
}
void
end_running(and_travel)
boolean and_travel;
{
/* moveloop() suppresses time_botl when context.run is non-zero; when
running stops, update 'time' even if other botl status is unchanged */
if (flags.time && g.context.run)
iflags.time_botl = TRUE;
g.context.run = 0;
/* 'context.mv' isn't travel but callers who want to end travel
all clear it too */
if (and_travel)
g.context.travel = g.context.travel1 = g.context.mv = 0;
}
void
nomul(nval)
int nval;
@@ -2939,7 +2958,7 @@ int nval;
g.multi = nval;
if (nval == 0)
g.multi_reason = NULL;
g.context.travel = g.context.travel1 = g.context.mv = g.context.run = 0;
end_running(TRUE);
}
/* called when a non-movement, multi-turn action has completed */
@@ -2947,7 +2966,7 @@ void
unmul(msg_override)
const char *msg_override;
{
g.context.botl = 1;
g.context.botl = TRUE;
g.multi = 0; /* caller will usually have done this already */
if (msg_override)
g.nomovemsg = msg_override;
@@ -3018,11 +3037,19 @@ register int n;
register const char *knam;
boolean k_format;
{
#if 0 /* code below is prepared to handle negative 'loss' so don't add this
* until we've verified that no callers intentionally rely on that */
if (n <= 0) {
impossible("hero losing %d hit points due to \"%s\"?", n, knam);
return;
}
#endif
g.context.botl = TRUE; /* u.uhp or u.mh is changing */
end_running(TRUE);
if (Upolyd) {
u.mh -= n;
if (u.mhmax < u.mh)
u.mhmax = u.mh;
g.context.botl = 1;
if (u.mh < 1)
rehumanize();
else if (n > 0 && u.mh * 10 < u.mhmax && Unchanging)
@@ -3033,9 +3060,6 @@ boolean k_format;
u.uhp -= n;
if (u.uhp > u.uhpmax)
u.uhpmax = u.uhp; /* perhaps n was negative */
else
g.context.travel = g.context.travel1 = g.context.mv = g.context.run = 0;
g.context.botl = 1;
if (u.uhp < 1) {
g.killer.format = k_format;
if (g.killer.name != knam) /* the thing that killed you */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 uhitm.c $NHDT-Date: 1581886869 2020/02/16 21:01:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.227 $ */
/* NetHack 3.6 uhitm.c $NHDT-Date: 1584405117 2020/03/17 00:31:57 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.228 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -366,14 +366,12 @@ register struct monst *mtmp;
Strcpy(buf, y_monnam(mtmp));
buf[0] = highc(buf[0]);
You("stop. %s is in the way!", buf);
g.context.travel = g.context.travel1 = g.context.mv = g.context.run
= 0;
end_running(TRUE);
return TRUE;
} else if ((mtmp->mfrozen || (!mtmp->mcanmove)
|| (mtmp->data->mmove == 0)) && rn2(6)) {
pline("%s doesn't seem to move!", Monnam(mtmp));
g.context.travel = g.context.travel1 = g.context.mv = g.context.run
= 0;
end_running(TRUE);
return TRUE;
} else
return FALSE;