summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/beam.cc
diff options
context:
space:
mode:
authorStefan O'Rear <stefanor@cox.net>2009-11-08 00:34:50 -0800
committerStefan O'Rear <stefanor@cox.net>2009-11-08 00:47:40 -0800
commita103e213a8648c722555e49ad580c46116b13c93 (patch)
treedc2853defaca39d22d06511e8fb740108de239cf /crawl-ref/source/beam.cc
parent0e18c9cc6ebe782f5791b5ebcea10946e9f2c2d8 (diff)
downloadcrawl-ref-a103e213a8648c722555e49ad580c46116b13c93.tar.gz
crawl-ref-a103e213a8648c722555e49ad580c46116b13c93.zip
Remove some code duplication
Diffstat (limited to 'crawl-ref/source/beam.cc')
-rw-r--r--crawl-ref/source/beam.cc112
1 files changed, 53 insertions, 59 deletions
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);
}