summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/xom.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/xom.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/xom.cc')
-rw-r--r--crawl-ref/source/xom.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index fc40cb3750..6af82176bb 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -227,17 +227,17 @@ static object_class_type _get_unrelated_wield_class(object_class_type ref)
object_class_type objtype = OBJ_WEAPONS;
if (ref == OBJ_WEAPONS)
{
- if (random2(10))
- objtype = OBJ_STAVES;
- else
+ if (one_chance_in(10))
objtype = OBJ_MISCELLANY;
+ else
+ objtype = OBJ_STAVES;
}
else if (ref == OBJ_STAVES)
{
- if (random2(10))
- objtype = OBJ_WEAPONS;
- else
+ if (one_chance_in(10))
objtype = OBJ_MISCELLANY;
+ else
+ objtype = OBJ_WEAPONS;
}
else
{
@@ -313,7 +313,7 @@ static bool _xom_annoyance_gift(int power)
const object_class_type objtype =
_get_unrelated_wield_class(weapon->base_type);
- if (power > random2(256))
+ if (x_chance_in_y(power, 256))
acquirement(objtype, GOD_XOM);
else
_xom_make_item(objtype, OBJ_RANDOM, power * 3);
@@ -336,9 +336,8 @@ static bool _xom_gives_item(int power)
// cloak or body armour. Ha ha!
god_speaks(GOD_XOM, _get_xom_speech("armour gift").c_str());
_xom_make_item(OBJ_ARMOUR,
- random2(10) ?
- get_random_body_armour_type(you.your_level * 2)
- : ARM_CLOAK,
+ one_chance_in(10) ? ARM_CLOAK :
+ get_random_body_armour_type(you.your_level * 2),
power * 3);
return (true);
}
@@ -350,7 +349,7 @@ static bool _xom_gives_item(int power)
// better than random object), and it is sometimes tuned to the
// player's skills and nature. Being tuned to the player's skills
// and nature is not very Xomlike...
- if (power > random2(256))
+ if (x_chance_in_y(power, 256))
{
// Random-type acquirement.
const int r = random2(7);
@@ -465,6 +464,7 @@ static bool _xom_is_good(int sever)
}
else if (random2(sever) <= 3)
{
+ // XXX: Can we clean up this ugliness, please?
const int numdemons =
std::min(random2(random2(random2(sever+1)+1)+1)+2, 16);
int numdifferent = 0;