summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spells2.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/spells2.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/spells2.cc')
-rw-r--r--crawl-ref/source/spells2.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index 797e233c43..3955799d24 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -159,7 +159,7 @@ static bool _mark_detected_creature(int gridx, int gridy, const monsters *mon,
bool found_good = false;
- if (fuzz_radius && fuzz_chance > random2(100))
+ if (fuzz_radius && x_chance_in_y(fuzz_chance, 100))
{
const int fuzz_diam = 2 * fuzz_radius + 1;
@@ -1154,7 +1154,8 @@ bool cast_sticks_to_snakes(int pow, god_type god)
if (one_chance_in(5 - std::min(4, div_rand_round(pow * 2, 25)))
|| get_ammo_brand(you.inv[wpn]) == SPMSL_POISONED)
{
- mon = random2(100) < pow / 3 ? MONS_BROWN_SNAKE : MONS_SNAKE;
+ mon = x_chance_in_y(pow / 3, 100) ? MONS_BROWN_SNAKE
+ : MONS_SNAKE;
}
else
mon = MONS_SMALL_SNAKE;
@@ -1518,17 +1519,18 @@ bool cast_summon_elemental(int pow, god_type god,
// - Earth elementals are more static and easy to tame (as before).
// - Fire elementals fall in between the two (10 is still fairly easy).
const bool friendly = ((mon != MONS_FIRE_ELEMENTAL
- || random2(10) < you.skills[SK_FIRE_MAGIC])
+ || x_chance_in_y(you.skills[SK_FIRE_MAGIC], 10))
&& (mon != MONS_WATER_ELEMENTAL
- || random2((you.species == SP_MERFOLK) ? 5 : 15)
- < you.skills[SK_ICE_MAGIC])
+ || x_chance_in_y(you.skills[SK_ICE_MAGIC],
+ (you.species == SP_MERFOLK) ? 5
+ : 15))
&& (mon != MONS_AIR_ELEMENTAL
- || random2(15) < you.skills[SK_AIR_MAGIC])
+ || x_chance_in_y(you.skills[SK_AIR_MAGIC], 15))
&& (mon != MONS_EARTH_ELEMENTAL
- || random2(5) < you.skills[SK_EARTH_MAGIC])
+ || x_chance_in_y(you.skills[SK_EARTH_MAGIC], 5))
&& random2(100) >= unfriendly);