From a103e213a8648c722555e49ad580c46116b13c93 Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Sun, 8 Nov 2009 00:34:50 -0800 Subject: Remove some code duplication --- crawl-ref/source/beam.cc | 112 ++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 59 deletions(-) (limited to 'crawl-ref/source/beam.cc') diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index 93f1a63bbf..cf98dc724c 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -3616,70 +3616,64 @@ bool bolt::misses_player() if (you.invisible() && !can_see_invis) real_tohit /= 2; - if (is_beam) - { - // Beams can be dodged. - if (player_light_armour(true) && !aimed_at_feet && coinflip()) - exercise(SK_DODGING, 1); - - if (you.duration[DUR_DEFLECT_MISSILES]) - real_tohit = random2(real_tohit * 2) / 3; - else if (you.duration[DUR_REPEL_MISSILES] - || player_mutation_level(MUT_REPULSION_FIELD) == 3) - { - real_tohit -= random2(real_tohit / 2); - } + // Wow, what a horrid test. These cannot be blocked or dodged + if (!is_beam && !is_blockable()) + return (false); - if (!test_beam_hit(real_tohit, dodge)) - { - mprf("The %s misses you.", name.c_str()); - return (true); - } - } - else if (is_blockable()) + if (is_blockable() + && you.shield() + && !aimed_at_feet + && player_shield_class() > 0) { - // Non-beams can be blocked or dodged. - if (you.shield() - && !aimed_at_feet - && player_shield_class() > 0) - { - // We use the original to-hit here. - const int testhit = random2(hit * 130 / 100 - + you.shield_block_penalty()); + // We use the original to-hit here. + const int testhit = random2(hit * 130 / 100 + + you.shield_block_penalty()); - const int block = you.shield_bonus(); + const int block = you.shield_bonus(); #ifdef DEBUG_DIAGNOSTICS - mprf(MSGCH_DIAGNOSTICS, "Beamshield: hit: %d, block %d", - testhit, block); + mprf(MSGCH_DIAGNOSTICS, "Beamshield: hit: %d, block %d", + testhit, block); #endif - if (testhit < block) + if (testhit < block) + { + if (is_reflectable(you.shield())) { - if (is_reflectable(you.shield())) - { - mprf( "Your %s reflects the %s!", - you.shield()->name(DESC_PLAIN).c_str(), - name.c_str() ); - _ident_reflector(you.shield()); - reflect(); - } - else - { - mprf( "You block the %s.", name.c_str() ); - finish_beam(); - } - you.shield_block_succeeded(); - return (true); + mprf( "Your %s reflects the %s!", + you.shield()->name(DESC_PLAIN).c_str(), + name.c_str() ); + _ident_reflector(you.shield()); + reflect(); } - - // Some training just for the "attempt". - if (coinflip()) - exercise(SK_SHIELDS, one_chance_in(3) ? 1 : 0); + else + { + mprf( "You block the %s.", name.c_str() ); + finish_beam(); + } + you.shield_block_succeeded(); + return (true); } - if (player_light_armour(true) && !aimed_at_feet && coinflip()) - exercise(SK_DODGING, 1); + // Some training just for the "attempt". + if (coinflip()) + exercise(SK_SHIELDS, one_chance_in(3) ? 1 : 0); + } + + if (player_light_armour(true) && !aimed_at_feet && coinflip()) + exercise(SK_DODGING, 1); + if (is_beam) + { + if (you.duration[DUR_DEFLECT_MISSILES]) + real_tohit = random2(real_tohit * 2) / 3; + else if (you.duration[DUR_REPEL_MISSILES] + || player_mutation_level(MUT_REPULSION_FIELD) == 3) + { + real_tohit -= random2(real_tohit / 2); + } + } + else + { if (you.duration[DUR_DEFLECT_MISSILES]) real_tohit = random2(real_tohit / 2); else if (you.duration[DUR_REPEL_MISSILES] @@ -3687,14 +3681,14 @@ bool bolt::misses_player() { real_tohit = random2(real_tohit); } + } - // miss message - if (!test_beam_hit(real_tohit, dodge)) - { - mprf("The %s misses you.", name.c_str()); - return (true); - } + if (!test_beam_hit(real_tohit, dodge)) + { + mprf("The %s misses you.", name.c_str()); + return (true); } + return (false); } -- cgit v1.2.3-54-g00ecf