diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-07-06 16:47:06 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-07-06 16:47:06 +0000 |
commit | 200b4c0e08504a7c8df898d77a9d72b3fa573c04 (patch) | |
tree | b6cf73c902a55861ab60656e0225f0385c2c3a59 /crawl-ref/source/effects.cc | |
parent | 7f2ded93231941b48fba24bcc9a55602295f72bd (diff) | |
download | crawl-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/effects.cc')
-rw-r--r-- | crawl-ref/source/effects.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index 3b0c21128e..26d2847bef 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -888,7 +888,7 @@ static int _find_acquirement_subtype(object_class_type class_wanted, const int weight = you.skills[i] + 1; count += weight; - if (random2(count) < weight) + if (x_chance_in_y(weight, count)) skill = i; } @@ -909,7 +909,7 @@ static int _find_acquirement_subtype(object_class_type class_wanted, if (wskill == SK_THROWING) wskill = weapon_skill(OBJ_WEAPONS, i); - if (wskill == skill && random2(count += acqweight) < acqweight) + if (wskill == skill && x_chance_in_y(acqweight, count += acqweight)) type_wanted = i; } } @@ -923,7 +923,7 @@ static int _find_acquirement_subtype(object_class_type class_wanted, if (you.skills[i]) { count += you.skills[i]; - if (random2(count) < you.skills[i]) + if (x_chance_in_y(you.skills[i], count)) skill = i; } } @@ -1309,10 +1309,10 @@ static int _find_acquirement_subtype(object_class_type class_wanted, while (you.had_book[type_wanted]); } - // if the book is invalid find any valid one. + // If the book is invalid find any valid one. while (book_rarity(type_wanted) == 100 - || type_wanted == BOOK_DESTRUCTION - || type_wanted == BOOK_MANUAL) + || type_wanted == BOOK_DESTRUCTION + || type_wanted == BOOK_MANUAL) { type_wanted = random2(NUM_BOOKS); } @@ -1436,11 +1436,13 @@ static int _find_acquirement_subtype(object_class_type class_wanted, case OBJ_MISCELLANY: do + { type_wanted = random2(NUM_MISCELLANY); + } while (type_wanted == MISC_HORN_OF_GERYON - || type_wanted == MISC_RUNE_OF_ZOT - || type_wanted == MISC_CRYSTAL_BALL_OF_FIXATION - || type_wanted == MISC_EMPTY_EBONY_CASKET); + || type_wanted == MISC_RUNE_OF_ZOT + || type_wanted == MISC_CRYSTAL_BALL_OF_FIXATION + || type_wanted == MISC_EMPTY_EBONY_CASKET); break; default: break; @@ -2210,7 +2212,7 @@ static void _hell_effects() else if (temp_rand > 7) // 10 in 27 odds {dlb} { // 60:40 miscast:summon split {dlb} - summon_instead = (random2(5) > 2); + summon_instead = x_chance_in_y(2, 5); switch (you.where_are_you) { @@ -2486,11 +2488,11 @@ void handle_time(long time_delta) // about 1.5 points on average, so they can corrupt the player // quite quickly. Wielding one for a short battle is OK, which is // as things should be. -- GDL - if (you.duration[DUR_INVIS] && random2(10) < 6) + if (you.duration[DUR_INVIS] && x_chance_in_y(6, 10)) added_contamination++; if (you.duration[DUR_HASTE] && !you.duration[DUR_BERSERKER] - && random2(10) < 6) + && x_chance_in_y(6, 10)) { added_contamination++; } @@ -2637,7 +2639,7 @@ void handle_time(long time_delta) break; } - if (random2(100) < total_skill) + if (x_chance_in_y(total_skill, 100)) { item_def& item = you.inv[you.equip[EQ_WEAPON]]; @@ -3016,7 +3018,7 @@ void update_corpses(double elapsedTime) } int fountain_checks = static_cast<int>(elapsedTime / 1000.0); - if (random2(1000) < static_cast<int>(elapsedTime) % 1000) + if (x_chance_in_y(static_cast<int>(elapsedTime) % 1000, 1000)) fountain_checks += 1; // dry fountains may start flowing again |