Skip to content

Commit 51489c0

Browse files
committed
Fix: misbehavior by #adjust.
From NetHack 3.7 git commit f801863: '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.'
1 parent 68087a2 commit 51489c0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

doc/evilhack-changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3368,4 +3368,5 @@ The following changes to date are:
33683368
- Fix: same-race monsters could still spawn peaceful for Convicts and Infidels
33693369
- Fix: unique monsters are not bound by maximum hit point value in grow_up()
33703370
- Fix: Infidels couldn't drop cursed loadstones
3371+
- Fix: misbehavior by #adjust
33713372

src/invent.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -4346,15 +4346,16 @@ doorganize() /* inventory organizer by Del Lamb */
43464346

43474347
collect = (let == obj->invlet);
43484348
/* change the inventory and print the resulting item */
4349-
adj_type = collect ? "Collecting" : !splitting ? "Moving:" : "Splitting:";
4349+
adj_type = collect ? "Collecting:" : !splitting ? "Moving:" : "Splitting:";
43504350

43514351
/*
43524352
* don't use freeinv/addinv to avoid double-touching artifacts,
43534353
* dousing lamps, losing luck, cursing loadstone, etc.
43544354
*/
43554355
extract_nobj(obj, &invent);
43564356

4357-
for (otmp = invent; otmp;) {
4357+
for (otmp = invent; otmp; ) {
4358+
otmpname = has_oname(otmp) ? ONAME(otmp) : (char *) 0;
43584359
/* it's tempting to pull this outside the loop, but merged() could
43594360
free ONAME(obj) [via obfree()] and replace it with ONAME(otmp) */
43604361
objname = has_oname(obj) ? ONAME(obj) : (char *) 0;
@@ -4366,16 +4367,24 @@ doorganize() /* inventory organizer by Del Lamb */
43664367
with compatible named ones; we only want that if it is
43674368
the 'from' stack (obj) with a name and candidate (otmp)
43684369
without one, not unnamed 'from' with named candidate. */
4369-
otmpname = has_oname(otmp) ? ONAME(otmp) : (char *) 0;
43704370
if ((!otmpname || (objname && !strcmp(objname, otmpname)))
43714371
&& merged(&otmp, &obj)) {
4372-
adj_type = "Merging:";
4372+
/*adj_type = "Collecting:"; //already set to this*/
43734373
obj = otmp;
43744374
otmp = otmp->nobj;
43754375
extract_nobj(obj, &invent);
43764376
continue; /* otmp has already been updated */
43774377
}
43784378
} else if (otmp->invlet == let) {
4379+
/* Merging: when from and to are compatible */
4380+
if ((!otmpname || (objname && !strcmp(objname, otmpname)))
4381+
&& merged(&otmp, &obj)) {
4382+
adj_type = "Merging:";
4383+
obj = otmp;
4384+
otmp = otmp->nobj;
4385+
extract_nobj(obj, &invent);
4386+
break; /* otmp has been updated and we're done merging */
4387+
}
43794388
/* Moving or splitting: don't merge extra compatible stacks.
43804389
Found 'otmp' in destination slot; merge if compatible,
43814390
otherwise bump whatever is there to an open slot. */

0 commit comments

Comments
 (0)