From a1b1f3b250beaac9395158794dc06d76ed174b3b Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Mon, 6 Nov 2023 17:50:25 -0500 Subject: [PATCH] Try to unify "back on solid ground" messaging Put everything through a single function that can handle all the complicated parts of using the correct proposition for different terrain types, and will not just call things "solid ground" indiscriminately. This got complicated but I'm not sure if it's possible to do it much simpler while still using the distinct names for each type of terrain (unless you are OK with the sentences sounding sort of wonky). --- include/extern.h | 3 ++- src/hack.c | 6 +----- src/pickup.c | 16 +--------------- src/pray.c | 4 ++-- src/trap.c | 43 +++++++++++++++++++++++++++++++++++++++---- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/include/extern.h b/include/extern.h index 604b341c9..65c4ba256 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2949,7 +2949,8 @@ extern void acid_damage(struct obj *); extern int water_damage(struct obj *, const char *, boolean); extern void water_damage_chain(struct obj *, boolean); extern boolean rnd_nextto_goodpos(coordxy *, coordxy *, struct monst *); -extern void back_on_ground(int); +extern void back_on_ground(boolean); +extern void rescued_from_terrain(int); extern boolean drown(void); extern void drain_en(int, boolean); extern int dountrap(void); diff --git a/src/hack.c b/src/hack.c index 47dc27afb..5e44d2867 100644 --- a/src/hack.c +++ b/src/hack.c @@ -2826,11 +2826,7 @@ pooleffects( } else if (is_lava(u.ux, u.uy)) { You("leave the %s...", hliquid("water")); /* oops! */ } else { - char icebuf[BUFSZ]; - You("are %s %s again.", - (Levitation || Flying) ? "over" : "on", - is_ice(u.ux, u.uy) ? ice_descr(u.ux, u.uy, icebuf) - : "solid land"); + back_on_ground(FALSE); iflags.last_msg = PLNMSG_BACK_ON_GROUND; } } else if (Is_waterlevel(&u.uz)) { diff --git a/src/pickup.c b/src/pickup.c index f258d437c..a145b8fe0 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -384,21 +384,7 @@ describe_decor(void) || IS_LAVA(iflags.prev_decor) || iflags.prev_decor == ICE) { if (iflags.last_msg != PLNMSG_BACK_ON_GROUND) { - const char *preposit = (Levitation || Flying) ? "over" : "on", - *surf = surface(u.ux, u.uy); - - if (is_ice(u.ux, u.uy)) { - surf = ice_descr(u.ux, u.uy, fbuf); - } else if (!strcmpi(surf, "floor") - || !strcmpi(surf, "ground")) { - surf = "solid ground"; - } else { /* "cloud", "air", "air bubble", "wall" */ - surf = !strcmp(surf, "air") ? the(surf) : an(surf); - preposit = "in"; - } - pline("%s %s %s.", - flags.verbose ? "You are back" : "Back", - preposit, surf); + back_on_ground(FALSE); } } } diff --git a/src/pray.c b/src/pray.c index 8e9f6efa6..5e3d9ed17 100644 --- a/src/pray.c +++ b/src/pray.c @@ -389,8 +389,8 @@ fix_worst_trouble(int trouble) /* teleport should always succeed, but if not, just untrap them */ if (!safe_teleds(TELEDS_NO_FLAGS)) reset_utrap(TRUE); - back_on_ground(DISSOLVED); /* DISSOLVED: pending cause of death - * if trouble didn't get cured */ + rescued_from_terrain(DISSOLVED); /* DISSOLVED: pending cause of death + * if trouble didn't get cured */ break; case TROUBLE_STARVING: /* temporarily lost strength recovery now handled by init_uhunger() */ diff --git a/src/trap.c b/src/trap.c index 7a3ae7ee2..dfaea88c8 100644 --- a/src/trap.c +++ b/src/trap.c @@ -4699,11 +4699,46 @@ rnd_nextto_goodpos(coordxy *x, coordxy *y, struct monst *mtmp) return FALSE; } +/* print a message about being back on the ground after leaving a pool */ +void +back_on_ground(boolean rescued) +{ + const char *preposit = (Levitation || Flying) ? "over" : "on", + *surf = surface(u.ux, u.uy), *you_are_back; + char icebuf[QBUFSZ]; + + if (is_ice(u.ux, u.uy)) { + /* "on ice" */ + surf = ice_descr(u.ux, u.uy, icebuf); + } else if (!strcmpi(surf, "floor") || !strcmpi(surf, "ground")) { + /* "on solid ground" */ + surf = "solid ground"; + } else if (!strcmpi(surf, "bridge") || !strcmpi(surf, "altar") + || !strcmpi(surf, "headstone")) { + /* "on a bridge" */ + surf = an(surf); + } else if (!strcmpi(surf, "stairs") || !strcmpi(surf, "lava") + || !strcmpi(surf, "bottom")) { + /* "on the stairs" */ + surf = the(surf); + } else { /* "cloud", "air", "air bubble", "wall", "fountain", "doorway" */ + /* "in a cloud", "in the air" */ + surf = !strcmp(surf, "air") ? the(surf) : an(surf); + preposit = "in"; + } + if (rescued) { + you_are_back = "You find yourself"; + } else { + you_are_back = flags.verbose ? "You are back" : "Back"; + } + pline("%s %s %s.", you_are_back, preposit, surf); +} + /* life-saving or divine rescue has attempted to get the hero out of hostile terrain and put hero in an unexpected spot or failed due to overfull level and just prevented death so "back on solid ground" may be inappropriate */ void -back_on_ground(int how) +rescued_from_terrain(int how) { static const char find_yourself[] = "find yourself"; struct rm *lev = &levl[u.ux][u.uy]; @@ -4738,7 +4773,7 @@ back_on_ground(int how) break; } if (!mesggiven) - You("%s back on solid %s.", find_yourself, surface(u.ux, u.uy)); + back_on_ground(TRUE); iflags.last_msg = PLNMSG_BACK_ON_GROUND; /* for describe_decor() */ /* feedback just disclosed this */ @@ -4882,7 +4917,7 @@ drown(void) if (u.uinwater) set_uinwater(0); /* u.uinwater = 0 */ - back_on_ground(DROWNING); + rescued_from_terrain(DROWNING); return TRUE; } @@ -6505,7 +6540,7 @@ lava_effects(void) set_itimeout(&HWwalking, 5L); goto burn_stuff; } - back_on_ground(BURNING); + rescued_from_terrain(BURNING); /* normally done via safe_teleds() -> teleds() -> spoteffects() but spoteffects() was no-op when called with nonzero in_lava_effects */