partial fix for #H5216 - sortloot inconsistency
The tie-breaker for the qsort comparison routine used for 'sortloot' had its logic backwards. Instead of retaining the original relative order for tied items, it inadvertently reversed them. So a chest containing club dagger named A dagger named B dagger named C long sword would alternate between that order and club dagger named C dagger named B dagger named A long sword each time the chest's contents were examined. This fixes that, and also simplifies the unnecessarily convoluted bless/curse state handling. The other half of the report was a request that 'sortloot:n' not do any sorting. Right now, if the player has 'sortpack' set then 'sortloot:n' results in grouping into object classes within pack order rather than not sorting at all. (Also, armor and weapons are further ordered within their groups: armor by slot [helms, gloves, shields, &c] and weapons by function [ammo, launchers, missiles, 'ordinary', pole- arms].) I think the proper fix is to add a new setting for 'sortpack' which yields the current behavior before changing 'n' to leave things in their unsorted order.
This commit is contained in:
15
src/invent.c
15
src/invent.c
@@ -166,16 +166,9 @@ const genericptr vptr2;
|
||||
if ((namcmp = strcmpi(nam1, nam2)) != 0)
|
||||
return namcmp;
|
||||
|
||||
/* Sort by BUCX. Map blessed to 4, uncursed to 2, cursed to 1, and
|
||||
unknown to 0. */
|
||||
val1 = obj1->bknown
|
||||
? (obj1->blessed << 2)
|
||||
+ ((!obj1->blessed && !obj1->cursed) << 1) + obj1->cursed
|
||||
: 0;
|
||||
val2 = obj2->bknown
|
||||
? (obj2->blessed << 2)
|
||||
+ ((!obj2->blessed && !obj2->cursed) << 1) + obj2->cursed
|
||||
: 0;
|
||||
/* Sort by BUCX. */
|
||||
val1 = obj1->bknown ? (obj1->blessed ? 3 : !obj1->cursed ? 2 : 1) : 0;
|
||||
val2 = obj2->bknown ? (obj2->blessed ? 3 : !obj2->cursed ? 2 : 1) : 0;
|
||||
if (val1 != val2)
|
||||
return val2 - val1; /* bigger is better */
|
||||
|
||||
@@ -216,7 +209,7 @@ tiebreak:
|
||||
/* They're identical, as far as we're concerned. We want
|
||||
to force a deterministic order, and do so by producing a
|
||||
stable sort: maintain the original order of equal items. */
|
||||
return (sli2->indx - sli1->indx);
|
||||
return (sli1->indx - sli2->indx);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user