Author Topic: Item Sorting  (Read 3251 times)

Sega Chief

  • *
  • Posts: 4086
  • These guys is sick
    • View Profile
Item Sorting
« on: 2015-04-19 15:12:39 »
Hey all,

I had a question about how items are sorted through the inventory using the different categories. I've always used Type as it sorts by their actual item index, but a few people have been asking about the others like sorting for Battle (damage dealing items I imagine) and finding it to be a bit all over the place. Is there a way to change the way these sort categories behave? Or is there info on how they sort items anywhere?

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Item Sorting
« Reply #1 on: 2015-04-20 17:20:20 »
Each method uses its own comparator to determine if two items are in the right order. Then it reverse bubble sorts the entire list until there are no changes or 64 somethings? happened.

For the following pseudo-code, if the return value is positive then the items are swapped. Since it's reverse, it's starting with the last item. Item1 starts at 319 and item2 starts at 318.
Field -
Code: [Select]
If Item1 can be used in the field then
   If Item2 can be used in the field then
      return 0 //If both are usable then ignore them
   Else
      return 1 //Item2 can't be used in the field, Item1 should be higher than that.
   End If
Elseif Item2 can be used in the field then
   return -1 //Item1 can't be used in the field, but item2 is already higher
Else
   return 0 //Neither can be used in the field and it doesn't care what the order is now.
End If

Battle -
(Same as above, but replace "can be used in field" with "can be used in battle")

Throw -
(Same as above, but replace same condition with "can be thrown")

Type -
Code: [Select]
return Item2.index - Item1.index //If Item1's index is less than Item2's the result will be positive and trigger a swap
Name -
Code: [Select]
If ItemNameSortOrder[ Item1.index ] < ItemNameSortOrder [Item2.index] then //ItemNameSortOrder is a fixed array with ranked positions in a full item list.
   return 1
End If

Most -
Code: [Select]
return Item1.count - Item2.count
Least -
Code: [Select]
return Item2.count - Item1.count
« Last Edit: 2015-04-20 17:28:07 by NFITC1 »

Sega Chief

  • *
  • Posts: 4086
  • These guys is sick
    • View Profile
Re: Item Sorting
« Reply #2 on: 2015-04-20 19:02:10 »
Got it, are these lists static or does it actually check for the flag on each item? For instance, if one item was set to be used in-battle would this be taken into account by the sort or would it be treated as if the flag wasn't on?

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Item Sorting
« Reply #3 on: 2015-04-20 19:08:35 »
Only the name list is static. The others check the actual details of the item.

Sega Chief

  • *
  • Posts: 4086
  • These guys is sick
    • View Profile
Re: Item Sorting
« Reply #4 on: 2015-04-20 19:25:30 »
Alright then, I'll keep that in mind. Thanks for the info!