misbehavior by #adjust

Reported directly to devteam:  using '#adjust a a' to collect
invent stacks compatible with the one in slot 'a' all into 'a' gave
feedback of "Merging: a - ..." even though "Collecting: a - ..."
was intended.  Also, if there weren't any such compatible stacks,
so that the whole operation didn't accomplish anything, it reported
"Collecting a - ..." without the intended colon between the action
and the inventory letter.

Test case was trivial:  start with a stack of 2 of something in 'a'
and use '#adjust 1a b' to split into two stacks, then '#adjust a a'
to collect them back again.

While fixing this, I noticed that '#adjust a b' and '#adjust b a'
(from same starting situation) just swapped a and b instead of the
intended behavior of merging them back together.
This commit is contained in:
PatR
2024-03-21 22:32:31 -07:00
parent 9ba0cf2ff0
commit f801863e5c
2 changed files with 23 additions and 4 deletions

View File

@@ -1373,6 +1373,16 @@ when a spellbook was polymorphed into a novel and then incrementing spestudied
walking on ice can make you slide in a random direction
if an adjacent statue was a in a pit, you could break it with a pick-axe even
though you're conceptually at the wrong elevation to reach it
using '#adjust c c' to collect all invent items compatible with the one in
slot c prefixed the inventory update message with "Merging:" rather
than "Collecting:" if there was at least one compatible stack; when
there weren't any compatible stacks and it was effectively a no-op,
the prefix used was "Collecting", lacking its intended colon
using '#adjust c d' or '#adjust d c' after splitting slot c via '#adjust Nc d'
for N less than c's stack size swapped c and d instead of re-merging
them even though merging was the intended behavior (the 3.6 change
that caused this was intended to avoid collecting other compatible
stacks while still merging the two specified ones)
Fixes to 3.7.0-x General Problems Exposed Via git Repository

View File

@@ -5595,7 +5595,7 @@ doorganize_core(struct obj *obj)
collect = (let == obj->invlet);
/* change the inventory and print the resulting item */
adj_type = collect ? "Collecting" : !splitting ? "Moving:" : "Splitting:";
adj_type = collect ? "Collecting:" : !splitting ? "Moving:" : "Splitting:";
/*
* don't use freeinv/addinv to avoid double-touching artifacts,
@@ -5603,7 +5603,8 @@ doorganize_core(struct obj *obj)
*/
extract_nobj(obj, &gi.invent);
for (otmp = gi.invent; otmp;) {
for (otmp = gi.invent; otmp; ) {
otmpname = has_oname(otmp) ? ONAME(otmp) : (char *) 0;
/* it's tempting to pull this outside the loop, but merged() could
free ONAME(obj) [via obfree()] and replace it with ONAME(otmp) */
objname = has_oname(obj) ? ONAME(obj) : (char *) 0;
@@ -5615,16 +5616,24 @@ doorganize_core(struct obj *obj)
with compatible named ones; we only want that if it is
the 'from' stack (obj) with a name and candidate (otmp)
without one, not unnamed 'from' with named candidate. */
otmpname = has_oname(otmp) ? ONAME(otmp) : (char *) 0;
if ((!otmpname || (objname && !strcmp(objname, otmpname)))
&& merged(&otmp, &obj)) {
adj_type = "Merging:";
/*adj_type = "Collecting:"; //already set to this*/
obj = otmp;
otmp = otmp->nobj;
extract_nobj(obj, &gi.invent);
continue; /* otmp has already been updated */
}
} else if (otmp->invlet == let) {
/* Merging: when from and to are compatible */
if ((!otmpname || (objname && !strcmp(objname, otmpname)))
&& merged(&otmp, &obj)) {
adj_type = "Merging:";
obj = otmp;
otmp = otmp->nobj;
extract_nobj(obj, &gi.invent);
break; /* otmp has been updated and we're done merging */
}
/* Moving or splitting: don't merge extra compatible stacks.
Found 'otmp' in destination slot; merge if compatible,
otherwise bump whatever is there to an open slot. */