summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stuff.h
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-07 07:53:33 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-07 07:53:33 +0000
commit0f4b659dddc446658c1cb6387dfdd03bcb758db5 (patch)
treecc9b007258e1b62f34cc2caffeca20d865387d7d /crawl-ref/source/stuff.h
parentfea3c8df37716c2bb4c033d463b9a796098e0a83 (diff)
downloadcrawl-ref-0f4b659dddc446658c1cb6387dfdd03bcb758db5.tar.gz
crawl-ref-0f4b659dddc446658c1cb6387dfdd03bcb758db5.zip
Breaks savefile compatibility.
Re-arranged book_type so that books you might find on the floor come first, then books only given out by certain gods, and so on. Added book types BOOK_RANDART_LEVEL, BOOK_RANDART_THEME and BOOK_CARD_EFFECT. Can now get randart books both from acquirement and shops/floor. Acquirement books have a chance of being a manual with a spell discipline skill. Randart books have their own appearances now, and fixed level books their own naming scheme. Needs more entries. Randart books aren't hilited in the menu like other randarts are; don't know why. Added some assertions to choose_random_weighted(). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7761 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.h')
-rw-r--r--crawl-ref/source/stuff.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 7682bd2fe5..996809b4ab 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -212,16 +212,22 @@ public:
template<typename Iterator>
int choose_random_weighted(Iterator beg, const Iterator end)
{
+ ASSERT(beg < end);
+
int totalweight = 0;
- int count = 0, result = 0;
+ int count = 0, result = 0, times_set = 0;
while ( beg != end )
{
totalweight += *beg;
if ( random2(totalweight) < *beg )
+ {
result = count;
+ times_set++;
+ }
++count;
++beg;
}
+ ASSERT(times_set > 0);
return result;
}