From 36d977f61f7cbd629bf71e5c12a12c3c68ca19be Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Fri, 27 Nov 2020 23:43:52 +0200 Subject: [PATCH] Unify HP loss and passing out from overexertion --- include/extern.h | 1 + src/allmain.c | 12 +----------- src/hack.c | 26 +++++++++++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/extern.h b/include/extern.h index 946550810..f2e2ba258 100644 --- a/include/extern.h +++ b/include/extern.h @@ -896,6 +896,7 @@ E int NDECL(wiz_debug_cmd_traveldisplay); #endif E boolean NDECL(u_rooted); E void NDECL(domove); +E void NDECL(overexert_hp); E boolean NDECL(overexertion); E void NDECL(invocation_message); E void NDECL(switch_terrain); diff --git a/src/allmain.c b/src/allmain.c index d015e7621..6cdf9bd4d 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -215,17 +215,7 @@ boolean resuming; if (wtcap > MOD_ENCUMBER && u.umoved) { if (!(wtcap < EXT_ENCUMBER ? g.moves % 30 : g.moves % 10)) { - if (Upolyd && u.mh > 1) { - u.mh--; - g.context.botl = TRUE; - } else if (!Upolyd && u.uhp > 1) { - u.uhp--; - g.context.botl = TRUE; - } else { - You("pass out from exertion!"); - exercise(A_CON, FALSE); - fall_asleep(-10, FALSE); - } + overexert_hp(); } } diff --git a/src/hack.c b/src/hack.c index f50538ada..3566831a2 100644 --- a/src/hack.c +++ b/src/hack.c @@ -2061,6 +2061,22 @@ int x1, y1, x2, y2; } } +/* HP loss or passing out from overexerting yourself */ +void +overexert_hp() +{ + int *hp = (!Upolyd ? &u.uhp : &u.mh); + + if (*hp > 1) { + *hp -= 1; + g.context.botl = TRUE; + } else { + You("pass out from exertion!"); + exercise(A_CON, FALSE); + fall_asleep(-10, FALSE); + } +} + /* combat increases metabolism */ boolean overexertion() @@ -2070,15 +2086,7 @@ overexertion() execute if you decline to attack a peaceful monster */ gethungry(); if ((g.moves % 3L) != 0L && near_capacity() >= HVY_ENCUMBER) { - int *hp = (!Upolyd ? &u.uhp : &u.mh); - - if (*hp > 1) { - *hp -= 1; - } else { - You("pass out from exertion!"); - exercise(A_CON, FALSE); - fall_asleep(-10, FALSE); - } + overexert_hp(); } return (boolean) (g.multi < 0); /* might have fainted (forced to sleep) */ }