git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@556 c06c8d41-db1a-0410-9941-cceddc491573
JUNF2JNFSVAITA6XQU3CEOMP5PG4PVSHKIGFTSUCYCN4ICPEXEKAC
// Arrange items that have been selected for multidrop so that
// equipped items are dropped after other items, and equipped items
// are dropped in the same order as their EQ_ slots are numbered.
static bool drop_item_order(const SelItem &first, const SelItem &second)
{
const item_def &i1 = you.inv[first.slot];
const item_def &i2 = you.inv[second.slot];
const int slot1 = get_equip_slot(&i1),
slot2 = get_equip_slot(&i2);
if (slot1 != -1 && slot2 != -1)
return (slot1 < slot2);
else if (slot1 != -1 && slot2 == -1)
return (false);
else if (slot2 != -1 && slot1 == -1)
return (true);
return (first.slot < second.slot);
}
// Sort the dropped items so we don't see weird behaviour when
// dropping a worn robe before a cloak (old behaviour: remove
// cloak, remove robe, wear cloak, drop robe, remove cloak, drop
// cloak).
std::sort( items_for_multidrop.begin(), items_for_multidrop.end(),
drop_item_order );
// delay.duration-- *must* be done before multidrop, because
// multidrop is now a parent delay, which means other delays
// can be pushed to the front of the queue, invalidating the
// "delay" reference here, and resulting in tons of debugging
// fun with valgrind.
delay.duration--;