refine PR #1135 - encumbrance messages

When picking up multiple items (or looting multiple items) in one
operation, only show encumbrance for the first item that causes that
to change instead of complaining about non-zero encumbrance on every
item.  The very first item is treated as if it caused a change, so
you get "you have a little trouble lifting <obj>" even if you were
already burdened, same as before.

Only lightly tested.
This commit is contained in:
PatR
2023-11-21 14:59:08 -08:00
parent 28a4afb3bb
commit c8c963afe6
3 changed files with 60 additions and 31 deletions
+2
View File
@@ -775,6 +775,8 @@ struct instance_globals_p {
/* pickup.c */ /* pickup.c */
boolean picked_filter; boolean picked_filter;
int pickup_encumbrance; /* when picking up multiple items in a single
* operation, encumbrance after previous item */
/* pline.c */ /* pline.c */
unsigned pline_flags; unsigned pline_flags;
+1
View File
@@ -675,6 +675,7 @@ const struct instance_globals_p g_init_p = {
0, /* perm_invent_toggling_direction */ 0, /* perm_invent_toggling_direction */
/* pickup.c */ /* pickup.c */
FALSE, /* picked_filter */ FALSE, /* picked_filter */
0, /* pickup_encumbrance */
/* pline.c */ /* pline.c */
0U, /* pline_flags */ 0U, /* pline_flags */
UNDEFINED_VALUES, /* prevmsg */ UNDEFINED_VALUES, /* prevmsg */
+57 -31
View File
@@ -28,6 +28,7 @@ static int delta_cwt(struct obj *, struct obj *);
static long carry_count(struct obj *, struct obj *, long, boolean, int *, static long carry_count(struct obj *, struct obj *, long, boolean, int *,
int *); int *);
static int lift_object(struct obj *, struct obj *, long *, boolean); static int lift_object(struct obj *, struct obj *, long *, boolean);
static void pickup_prinv(struct obj *, long, const char *);
static boolean mbag_explodes(struct obj *, int); static boolean mbag_explodes(struct obj *, int);
static boolean is_boh_item_gone(void); static boolean is_boh_item_gone(void);
static void do_boh_explosion(struct obj *, boolean); static void do_boh_explosion(struct obj *, boolean);
@@ -62,10 +63,10 @@ static void tipcontainer(struct obj *);
#define Icebox (gc.current_container->otyp == ICE_BOX) #define Icebox (gc.current_container->otyp == ICE_BOX)
static const char static const char
slightloadmsg[] = "You have a little trouble lifting", slightloadpfx[] = "You have a little trouble",
moderateloadmsg[] = "You have trouble lifting", moderateloadpfx[] = "You have trouble",
nearloadmsg[] = "You have much trouble lifting", nearloadpfx[] = "You have much trouble",
overloadmsg[] = "You have extreme difficulty lifting"; overloadpfx[] = "You have extreme difficulty";
/* BUG: this lets you look at cockatrice corpses while blind without /* BUG: this lets you look at cockatrice corpses while blind without
touching them */ touching them */
@@ -649,6 +650,9 @@ pickup(int what) /* should be a long */
return 0; return 0;
} }
/* used by pickup_object() for encumbrance feedback */
gp.pickup_encumbrance = 0;
if (what < 0) /* pick N of something */ if (what < 0) /* pick N of something */
count = -what; count = -what;
else /* pick anything */ else /* pick anything */
@@ -861,6 +865,7 @@ pickup(int what) /* should be a long */
check_here(n_picked > 0); check_here(n_picked > 0);
} }
pickupdone: pickupdone:
gp.pickup_encumbrance = 0;
add_valid_menu_class(0); /* reset */ add_valid_menu_class(0); /* reset */
return (n_tried > 0); return (n_tried > 0);
} }
@@ -1674,13 +1679,12 @@ lift_object(
long savequan = obj->quan; long savequan = obj->quan;
obj->quan = *cnt_p; obj->quan = *cnt_p;
Strcpy(qbuf, (next_encumbr >= EXT_ENCUMBER) ? overloadmsg Sprintf(qbuf, "%s %s ",
: (next_encumbr >= HVY_ENCUMBER) ? nearloadmsg (next_encumbr >= EXT_ENCUMBER) ? overloadpfx
: (next_encumbr >= MOD_ENCUMBER) ? moderateloadmsg : (next_encumbr >= HVY_ENCUMBER) ? nearloadpfx
: slightloadmsg); : (next_encumbr >= MOD_ENCUMBER) ? moderateloadpfx
if (container) : slightloadpfx,
(void) strsubst(qbuf, "lifting", "removing"); !container ? "lifting" : "removing");
Strcat(qbuf, " ");
(void) safe_qbuf(qbuf, qbuf, ". Continue?", obj, doname, (void) safe_qbuf(qbuf, qbuf, ". Continue?", obj, doname,
ansimpleoname, something); ansimpleoname, something);
obj->quan = savequan; obj->quan = savequan;
@@ -1712,11 +1716,10 @@ lift_object(
int int
pickup_object( pickup_object(
struct obj *obj, struct obj *obj,
long count, long count, /* if non-zero, pick up a subset of this amount */
boolean telekinesis) /* not picking it up directly by hand */ boolean telekinesis) /* not picking it up directly by hand */
{ {
int res, nearload; int res;
const char *prefix;
if (obj->quan < count) { if (obj->quan < count) {
impossible("pickup_object: count %ld > quan %ld?", count, obj->quan); impossible("pickup_object: count %ld > quan %ld?", count, obj->quan);
@@ -1785,13 +1788,7 @@ pickup_object(
if (uwep && uwep == obj) if (uwep && uwep == obj)
gm.mrg_to_wielded = TRUE; gm.mrg_to_wielded = TRUE;
nearload = near_capacity(); pickup_prinv(obj, count, "lifting");
prefix = (nearload >= EXT_ENCUMBER) ? overloadmsg
: (nearload >= HVY_ENCUMBER) ? nearloadmsg
: (nearload >= MOD_ENCUMBER) ? moderateloadmsg
: (nearload >= SLT_ENCUMBER) ? slightloadmsg
: (char *) 0;
prinv(prefix, obj, count);
gm.mrg_to_wielded = FALSE; gm.mrg_to_wielded = FALSE;
return 1; return 1;
} }
@@ -1844,6 +1841,36 @@ pick_obj(struct obj *otmp)
return result; return result;
} }
/* pickup_object()/out_container() helper;
print an added-to-invent message for current object, limiting feedback
about encumbrance to the first item which causes that to change */
static void
pickup_prinv(
struct obj *obj,
long count,
const char *verb)
{
char pbuf[QBUFSZ];
const char *prefix;
int nearload = near_capacity();
pbuf[0] = '\0';
if (nearload == gp.pickup_encumbrance) {
prefix = (char *) 0;
} else {
prefix = (nearload >= EXT_ENCUMBER) ? overloadpfx
: (nearload >= HVY_ENCUMBER) ? nearloadpfx
: (nearload >= MOD_ENCUMBER) ? moderateloadpfx
: (nearload >= SLT_ENCUMBER) ? slightloadpfx
: (char *) 0;
gp.pickup_encumbrance = nearload;
}
if (prefix)
Sprintf(pbuf, "%s %s", prefix, verb);
prinv(pbuf, obj, count);
}
/* /*
* prints a message if encumbrance changed since the last check and * prints a message if encumbrance changed since the last check and
* returns the new encumbrance value (from near_capacity()). * returns the new encumbrance value (from near_capacity()).
@@ -2595,10 +2622,10 @@ ck_bag(struct obj *obj)
static int static int
out_container(struct obj *obj) out_container(struct obj *obj)
{ {
register struct obj *otmp; struct obj *otmp;
boolean is_gold = (obj->oclass == COIN_CLASS); int res;
int res, loadlev;
long count; long count;
boolean is_gold = (obj->oclass == COIN_CLASS);
if (!gc.current_container) { if (!gc.current_container) {
impossible("<out> no gc.current_container?"); impossible("<out> no gc.current_container?");
@@ -2637,12 +2664,7 @@ out_container(struct obj *obj)
pick_pick(obj); /* shopkeeper feedback */ pick_pick(obj); /* shopkeeper feedback */
otmp = addinv(obj); otmp = addinv(obj);
loadlev = near_capacity(); pickup_prinv(otmp, count, "removing");
prinv(loadlev ? ((loadlev < MOD_ENCUMBER)
? "You have a little trouble removing"
: "You have much trouble removing")
: (char *) 0,
otmp, count);
if (is_gold) { if (is_gold) {
bot(); /* update character's gold piece count immediately */ bot(); /* update character's gold piece count immediately */
@@ -3104,6 +3126,7 @@ traditional_loot(boolean put_in)
objlist = &(gc.current_container->cobj); objlist = &(gc.current_container->cobj);
actionfunc = out_container; actionfunc = out_container;
checkfunc = (int (*)(OBJ_P)) 0; checkfunc = (int (*)(OBJ_P)) 0;
gp.pickup_encumbrance = 0; /* used to limit verbosity */
} }
if (query_classes(selection, &one_by_one, &allflag, action, *objlist, if (query_classes(selection, &one_by_one, &allflag, action, *objlist,
@@ -3131,6 +3154,8 @@ menu_loot(int retry, boolean put_in)
int mflags, res; int mflags, res;
long count = 0; long count = 0;
gp.pickup_encumbrance = 0; /* used by out_container(); no harm in
* zeroing it if about to use in_container() */
if (retry) { if (retry) {
all_categories = (retry == -2); all_categories = (retry == -2);
} else if (flags.menu_style == MENU_FULL) { } else if (flags.menu_style == MENU_FULL) {
@@ -3138,7 +3163,8 @@ menu_loot(int retry, boolean put_in)
Sprintf(buf, "%s what type of objects?", action); Sprintf(buf, "%s what type of objects?", action);
mflags = (ALL_TYPES | UNPAID_TYPES | BUCX_TYPES | CHOOSE_ALL mflags = (ALL_TYPES | UNPAID_TYPES | BUCX_TYPES | CHOOSE_ALL
| JUSTPICKED ); | JUSTPICKED );
n = query_category(buf, put_in ? gi.invent : gc.current_container->cobj, n = query_category(buf,
put_in ? gi.invent : gc.current_container->cobj,
mflags, &pick_list, PICK_ANY); mflags, &pick_list, PICK_ANY);
if (!n) if (!n)
return ECMD_OK; return ECMD_OK;