summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/religion.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/religion.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/religion.cc')
-rw-r--r--crawl-ref/source/religion.cc19
1 files changed, 9 insertions, 10 deletions
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 28861f3f46..094dc87a02 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -2652,7 +2652,7 @@ bool did_god_conduct(conduct_type thing_done, int level, bool known,
// use up the deck, and 80% on a card which does use up the
// deck.
int chance = 0;
- switch(level)
+ switch (level)
{
case 0: chance = 0; break;
case 1: chance = 40; break;
@@ -2661,7 +2661,8 @@ bool did_god_conduct(conduct_type thing_done, int level, bool known,
case 3: chance = 100; break;
}
- if (random2(100) < chance && you.attribute[ATTR_CARD_COUNTDOWN])
+ if (x_chance_in_y(chance, 100)
+ && you.attribute[ATTR_CARD_COUNTDOWN])
{
you.attribute[ATTR_CARD_COUNTDOWN]--;
#if DEBUG_DIAGNOSTICS || DEBUG_CARDS || DEBUG_GIFTS
@@ -3446,10 +3447,11 @@ static bool _zin_retribution()
int punishment = random2(10);
// if little mutated or can't unmutate, do something else instead
- if (punishment < 2 && (how_mutated() <= random2(3)
- || player_mutation_level(MUT_MUTATION_RESISTANCE) == 3))
+ if (punishment < 2
+ && (how_mutated() <= random2(3)
+ || player_mutation_level(MUT_MUTATION_RESISTANCE) == 3))
{
- punishment = random2(8)+2;
+ punishment = random2(8) + 2;
}
switch (punishment)
@@ -3460,16 +3462,13 @@ static bool _zin_retribution()
simple_god_message(" draws some chaos from your body!", god);
bool success = false;
for (int i = 0; i < 7; ++i)
- if (random2(10) > i
- && delete_mutation(RANDOM_GOOD_MUTATION))
- {
+ if (x_chance_in_y(i, 10) && delete_mutation(RANDOM_GOOD_MUTATION))
success = true;
- }
if (success && !how_mutated())
{
simple_god_message(" rids your body of chaos!", god);
- // lower penance a bit more for being particularly successful
+ // Lower penance a bit more for being particularly successful.
dec_penance(god, 1);
}
break;