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

@@ -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. */