From b43697b1403a3063482e3b554b8df81aa9335de6 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Mon, 8 Oct 2007 01:15:23 +0000 Subject: Ran into a bug where searching backwards through inventory for a free slot which won't leave gaps (in find_free_slot()) would fail if the inventory was empty; fixed bug by making find_free_slot() retry with forwards search if backwards search failed. I can't reproduce the bug, but the fix doesn't seem to cause any problems when there isn't a bug. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2368 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/items.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'crawl-ref/source/items.cc') diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index ab702c249e..35e84a18d9 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -1376,15 +1376,7 @@ int find_free_slot(const item_def &i) if (slotisfree(slot)) return slot; - if (searchforward) - { - // Return first free slot - for (slot = 0; slot < ENDOFPACK; ++slot) { - if (!is_valid_item(you.inv[slot])) - return slot; - } - } - else + if (!searchforward) { // This is the new default free slot search. We look for the last // available slot that does not leave a gap in the inventory. @@ -1405,6 +1397,16 @@ int find_free_slot(const item_def &i) } } } + + // Either searchforward is true, or search backwards failed and + // we re-try searching the oposite direction. + + // Return first free slot + for (slot = 0; slot < ENDOFPACK; ++slot) { + if (!is_valid_item(you.inv[slot])) + return slot; + } + return (-1); #undef slotisfree } -- cgit v1.2.3-54-g00ecf