From 2278434228e64874354867a35e87532bbed88aff Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 20 Dec 2021 08:30:48 -0800 Subject: [PATCH] simplify issuing urgent messages Change custompline(URGENT_MESSAGE, mesg, ...); calls to new urgent_pline(mesg, ...); --- include/extern.h | 1 + src/hack.c | 2 +- src/mhitu.c | 15 +++++++-------- src/pickup.c | 4 ++-- src/pline.c | 18 +++++++++++++++++- src/read.c | 4 ++-- src/steal.c | 37 +++++++++++++++++-------------------- src/zap.c | 6 ++++-- 8 files changed, 51 insertions(+), 36 deletions(-) diff --git a/include/extern.h b/include/extern.h index c4f7d9331..e302abaac 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1989,6 +1989,7 @@ extern void dumplogfreemessages(void); #endif extern void pline(const char *, ...) PRINTF_F(1, 2); extern void custompline(unsigned, const char *, ...) PRINTF_F(2, 3); +extern void urgent_pline(const char *, ...) PRINTF_F(1, 2); extern void Norep(const char *, ...) PRINTF_F(1, 2); extern void free_youbuf(void); extern void You(const char *, ...) PRINTF_F(1, 2); diff --git a/src/hack.c b/src/hack.c index 07c6d2c46..6ffe51c75 100644 --- a/src/hack.c +++ b/src/hack.c @@ -3281,7 +3281,7 @@ losehp(int n, const char *knam, boolean k_format) g.killer.format = k_format; if (g.killer.name != knam) /* the thing that killed you */ Strcpy(g.killer.name, knam ? knam : ""); - custompline(URGENT_MESSAGE, "You die..."); + urgent_pline("You die..."); done(DIED); } else if (n > 0 && u.uhp * 10 < u.uhpmax) { maybe_wail(); diff --git a/src/mhitu.c b/src/mhitu.c index d1de21099..938a4fa88 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1838,12 +1838,11 @@ doseduce(struct monst *mon) } naked = (!uarmc && !uarmf && !uarmg && !uarms && !uarmh && !uarmu); - custompline(URGENT_MESSAGE, - "%s %s%s.", Who, - Deaf ? "seems to murmur into your ear" - : naked ? "murmurs sweet nothings into your ear" - : "murmurs in your ear", - naked ? "" : ", while helping you undress"); + urgent_pline("%s %s%s.", Who, + Deaf ? "seems to murmur into your ear" + : naked ? "murmurs sweet nothings into your ear" + : "murmurs in your ear", + naked ? "" : ", while helping you undress"); mayberem(mon, Who, uarmc, cloak_simple_name(uarmc)); if (!uarmc) mayberem(mon, Who, uarm, suit_simple_name(uarm)); @@ -1894,9 +1893,9 @@ doseduce(struct monst *mon) adjalign(1); /* by this point you have discovered mon's identity, blind or not... */ - custompline(URGENT_MESSAGE, + urgent_pline( "Time stands still while you and %s lie in each other's arms...", - noit_mon_nam(mon)); + noit_mon_nam(mon)); /* 3.6.1: a combined total for charisma plus intelligence of 35-1 used to guarantee successful outcome; now total maxes out at 32 as far as deciding what will happen; chance for bad outcome when diff --git a/src/pickup.c b/src/pickup.c index d00ddcb5c..c0255f4cb 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -2392,9 +2392,9 @@ in_container(struct obj *obj) } } else if (Is_mbag(g.current_container) && mbag_explodes(obj, 0)) { /* explicitly mention what item is triggering the explosion */ - custompline(URGENT_MESSAGE, + urgent_pline( "As you put %s inside, you are blasted by a magical explosion!", - doname(obj)); + doname(obj)); /* did not actually insert obj yet */ if (was_unpaid) addtobill(obj, FALSE, FALSE, TRUE); diff --git a/src/pline.c b/src/pline.c index 300f44fd2..a8cdb7338 100644 --- a/src/pline.c +++ b/src/pline.c @@ -207,7 +207,7 @@ RESTORE_WARNING_FORMAT_NONLITERAL message history (tty interface uses pline() to issue prompts and they shouldn't be blockable via MSGTYPE=hide) */ void -custompline(unsigned pflags, const char * line, ...) +custompline(unsigned pflags, const char *line, ...) { va_list the_args; @@ -218,6 +218,22 @@ custompline(unsigned pflags, const char * line, ...) va_end(the_args); } +/* if player has dismissed --More-- with ESC to suppress further messages + until next input request, tell the interface that it should override that + and re-enable them; equivalent to custompline(URGENT_MESSAGE, line, ...) + but slightly simpler to use */ +void +urgent_pline(const char *line, ...) +{ + va_list the_args; + + va_start(the_args, line); + g.pline_flags = URGENT_MESSAGE; + vpline(line, the_args); + g.pline_flags = 0; + va_end(the_args); +} + void Norep(const char *line, ...) { diff --git a/src/read.c b/src/read.c index 9d14c444f..ac503d3d8 100644 --- a/src/read.c +++ b/src/read.c @@ -2467,7 +2467,7 @@ do_class_genocide(void) u.mh = -1; if (Unchanging) { if (!feel_dead++) - custompline(URGENT_MESSAGE, "You die."); + urgent_pline("You die."); /* finish genociding this class of monsters before ultimately dying */ gameover = TRUE; @@ -2484,7 +2484,7 @@ do_class_genocide(void) You_feel("%s inside.", udeadinside()); } else { if (!feel_dead++) - custompline(URGENT_MESSAGE, "You die."); + urgent_pline("You die."); gameover = TRUE; } } diff --git a/src/steal.c b/src/steal.c index 05003ace0..56922c7fe 100644 --- a/src/steal.c +++ b/src/steal.c @@ -428,23 +428,21 @@ steal(struct monst* mtmp, char* objnambuf) unmul((char *) 0); slowly = (armordelay >= 1 || g.multi < 0); if (flags.female) - custompline(URGENT_MESSAGE, - "%s charms you. You gladly %s your %s.", - !seen ? "She" : Monnam(mtmp), - curssv ? "let her take" - : !slowly ? "hand over" - : was_doffing ? "continue removing" - : "start removing", - equipname(otmp)); + urgent_pline("%s charms you. You gladly %s your %s.", + !seen ? "She" : Monnam(mtmp), + curssv ? "let her take" + : !slowly ? "hand over" + : was_doffing ? "continue removing" + : "start removing", + equipname(otmp)); else - custompline(URGENT_MESSAGE, - "%s seduces you and %s off your %s.", - !seen ? "She" : Adjmonnam(mtmp, "beautiful"), - curssv ? "helps you to take" - : !slowly ? "you take" - : was_doffing ? "you continue taking" - : "you start taking", - equipname(otmp)); + urgent_pline("%s seduces you and %s off your %s.", + !seen ? "She" : Adjmonnam(mtmp, "beautiful"), + curssv ? "helps you to take" + : !slowly ? "you take" + : was_doffing ? "you continue taking" + : "you start taking", + equipname(otmp)); named++; /* the following is to set multi for later on */ nomul(-armordelay); @@ -479,10 +477,9 @@ steal(struct monst* mtmp, char* objnambuf) subfrombill(otmp, shop_keeper(*u.ushops)); freeinv(otmp); /* if attached ball was taken, uball and uchain are now Null */ - custompline(URGENT_MESSAGE, - "%s%s stole %s.", named ? "She" : Monnam(mtmp), - (was_punished && !Punished) ? " removed your chain and" : "", - doname(otmp)); + urgent_pline("%s%s stole %s.", named ? "She" : Monnam(mtmp), + (was_punished && !Punished) ? " removed your chain and" : "", + doname(otmp)); could_petrify = (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])); (void) mpickobj(mtmp, otmp); /* may free otmp */ diff --git a/src/zap.c b/src/zap.c index 38ab80041..56fc9eaac 100644 --- a/src/zap.c +++ b/src/zap.c @@ -2634,8 +2634,10 @@ zapyourself(struct obj *obj, boolean ordinary) learn_it = TRUE; Sprintf(g.killer.name, "shot %sself with a death ray", uhim()); g.killer.format = NO_KILLER_PREFIX; - You("irradiate yourself with pure energy!"); - custompline(URGENT_MESSAGE, "You die."); + /* probably don't need these to be urgent; player just gave input + without subsequent opportunity to dismiss --More-- with ESC */ + urgent_pline("You irradiate yourself with pure energy!"); + urgent_pline("You die."); /* They might survive with an amulet of life saving */ done(DIED); break;