summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stuff.h
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-09 15:38:21 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-09 15:38:21 +0000
commit3fcc28592001fa644a08d88517d15380de417107 (patch)
treed4b19c1730d9c92fccff13f080386a508ba32a72 /crawl-ref/source/stuff.h
parenteb847d5f2f0331435f6bc081d1009bdf3982fd31 (diff)
downloadcrawl-ref-3fcc28592001fa644a08d88517d15380de417107.tar.gz
crawl-ref-3fcc28592001fa644a08d88517d15380de417107.zip
Nemelex now remembers what you've sacrificed and gifts decks accordingly.
High-value sacrifices can reduce the gift countdown. Nemelex is easier to please. Breaks savefiles. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1821 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.h')
-rw-r--r--crawl-ref/source/stuff.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 27c8ec519e..f936151b24 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -128,5 +128,20 @@ public:
~rng_save_excursion() { pop_rng_state(); }
};
-#endif
+template<typename Iterator>
+int choose_random_weighted(Iterator beg, const Iterator end)
+{
+ int totalweight = 0;
+ int count = 0, result = 0;
+ while ( beg != end )
+ {
+ totalweight += *beg;
+ if ( random2(totalweight) < *beg )
+ result = count;
+ ++count;
+ ++beg;
+ }
+ return result;
+}
+#endif