summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mutation.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-06 16:47:06 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-06 16:47:06 +0000
commit200b4c0e08504a7c8df898d77a9d72b3fa573c04 (patch)
treeb6cf73c902a55861ab60656e0225f0385c2c3a59 /crawl-ref/source/mutation.cc
parent7f2ded93231941b48fba24bcc9a55602295f72bd (diff)
downloadcrawl-ref-200b4c0e08504a7c8df898d77a9d72b3fa573c04.tar.gz
crawl-ref-200b4c0e08504a7c8df898d77a9d72b3fa573c04.zip
Add a function x_chance_in_y(x,y) to replace the various
random2(y) < x checks, e.g. x_chance_in_y(weight, totalweight). This should make things a bit more readable. Apply it to a number of files. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6428 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/mutation.cc')
-rw-r--r--crawl-ref/source/mutation.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/crawl-ref/source/mutation.cc b/crawl-ref/source/mutation.cc
index af0d204581..ff05e986dd 100644
--- a/crawl-ref/source/mutation.cc
+++ b/crawl-ref/source/mutation.cc
@@ -1633,8 +1633,9 @@ static bool accept_mutation(mutation_type mutat, bool ignore_rarity = false)
return (true);
const int rarity = mutation_defs[mutat].rarity + you.demon_pow[mutat];
+
// Low rarity means unlikely to choose it.
- return (rarity > random2(10));
+ return (x_chance_in_y(rarity, 10));
}
static mutation_type get_random_xom_mutation()
@@ -1687,7 +1688,7 @@ static mutation_type get_random_mutation(bool prefer_good,
cweight += weight;
- if (random2(cweight) < weight)
+ if (x_chance_in_y(weight, cweight))
chosen = curr;
}
return (chosen);
@@ -1718,7 +1719,7 @@ bool mutate(mutation_type which_mutation, bool failMsg,
}
// Zin's protection.
- if (you.religion == GOD_ZIN && you.piety > random2(MAX_PIETY))
+ if (you.religion == GOD_ZIN && x_chance_in_y(you.piety, MAX_PIETY))
{
simple_god_message(" protects your body from chaos!");
return (false);
@@ -1781,7 +1782,8 @@ bool mutate(mutation_type which_mutation, bool failMsg,
if (which_mutation == RANDOM_MUTATION
|| which_mutation == RANDOM_XOM_MUTATION)
{
- if (random2(15) < how_mutated(false, true))
+ // If already heavily mutated, remove a mutation instead.
+ if (x_chance_in_y(how_mutated(false, true), 15))
{
// God gifts override mutation loss due to being heavily
// mutated.