summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/items.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-08 01:15:23 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-08 01:15:23 +0000
commitb43697b1403a3063482e3b554b8df81aa9335de6 (patch)
treefa6a164410e8f37433062309205dbfdd9b5f1f77 /crawl-ref/source/items.cc
parentb13a963a72807e98426643a9cde533cab12704ae (diff)
downloadcrawl-ref-b43697b1403a3063482e3b554b8df81aa9335de6.tar.gz
crawl-ref-b43697b1403a3063482e3b554b8df81aa9335de6.zip
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
Diffstat (limited to 'crawl-ref/source/items.cc')
-rw-r--r--crawl-ref/source/items.cc20
1 files changed, 11 insertions, 9 deletions
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
}