diff options
author | drachereborn <kerwin.khu@gmail.com> | 2014-05-08 23:00:44 +0200 |
---|---|---|
committer | reaverb <reaverb.Crawl@gmail.com> | 2014-05-09 19:47:38 -0400 |
commit | 2821b36c4d7dd51232b9cfe24305f43647f3554d (patch) | |
tree | d2fcd2d584c45a7eef9259089bcc72aea38c35c1 /crawl-ref/source/spl-cast.cc | |
parent | a3c592f31c63efa212dabc083d2ac895e6074061 (diff) | |
download | crawl-ref-2821b36c4d7dd51232b9cfe24305f43647f3554d.tar.gz crawl-ref-2821b36c4d7dd51232b9cfe24305f43647f3554d.zip |
Use Sif miscast protection when coloring spell fail chances
(I have pretty severely edited this patch. #8301 on mantis) -reaverb
Diffstat (limited to 'crawl-ref/source/spl-cast.cc')
-rw-r--r-- | crawl-ref/source/spl-cast.cc | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 0d9c091820..4c18ce892d 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -1176,6 +1176,19 @@ static targetter* _spell_targetter(spell_type spell, int pow, int range) } } +double chance_miscast_prot() +{ + double miscast_prot = 0; + + if (you_worship(GOD_SIF_MUNA) + && !player_under_penance() + && you.piety >= piety_breakpoint(3)) + { + miscast_prot = (double) you.piety/piety_breakpoint(5); + } + return min(1.0, miscast_prot); +} + // Returns SPRET_SUCCESS if spell is successfully cast for purposes of // exercising, SPRET_FAIL otherwise, or SPRET_ABORT if the player cancelled // the casting. @@ -1389,10 +1402,9 @@ spret_type your_spells(spell_type spell, int powc, flush_input_buffer(FLUSH_ON_FAILURE); learned_something_new(HINT_SPELL_MISCAST); - if (you_worship(GOD_SIF_MUNA) - && !player_under_penance() - && you.piety >= piety_breakpoint(3) - && x_chance_in_y(you.piety, piety_breakpoint(5))) + if(random_real_inc() > chance_miscast_prot()) + // Using random_real_inc() is a bit hacky but it's + // better than duplcating the miscast protection code. { simple_god_message(" protects you from the effects of your miscast!"); return SPRET_FAIL; @@ -1980,11 +1992,21 @@ double get_miscast_chance(spell_type spell, int severity) return chance; } +double get_miscast_chance_with_miscast_prot(spell_type spell) +{ + double raw_chance = get_miscast_chance(spell); + double miscast_prot = chance_miscast_prot(); + double chance = raw_chance * (1 - miscast_prot); + + return chance; +} + // Chooses a colour for the failure rate display for a spell. The colour is // based on the chance of getting a severity >= 2 miscast. int failure_rate_colour(spell_type spell) { - double chance = get_miscast_chance(spell); + double chance = get_miscast_chance_with_miscast_prot(spell); + return (chance < 0.001) ? LIGHTGREY : (chance < 0.005) ? YELLOW : (chance < 0.025) ? LIGHTRED : |