diff options
author | Vsevolod Kozlov <zaba@thorium.homeunix.org> | 2009-12-27 16:50:24 +0300 |
---|---|---|
committer | Vsevolod Kozlov <zaba@thorium.homeunix.org> | 2009-12-27 16:50:24 +0300 |
commit | c0788ba0603604a5d998c0c30afd8e33b4c1c6ce (patch) | |
tree | 52448981b2a2de623d14c5719a9fa706d44f935d /crawl-ref | |
parent | 0fe55b6adbe990a2321dfc9b50e862da27186759 (diff) | |
download | crawl-ref-c0788ba0603604a5d998c0c30afd8e33b4c1c6ce.tar.gz crawl-ref-c0788ba0603604a5d998c0c30afd8e33b4c1c6ce.zip |
Reduce code duplication in trap_def::shot_damage.
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/traps.cc | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index e8b8d92bce..e2dcd625ea 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -679,36 +679,26 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) int trap_def::shot_damage(actor& act) { - if (act.atype() == ACT_PLAYER) - { - switch (this->type) - { - case TRAP_NEEDLE: return 0; - case TRAP_DART: return random2( 4 + you.your_level/2) + 1; - case TRAP_ARROW: return random2( 7 + you.your_level) + 1; - case TRAP_SPEAR: return random2(10 + you.your_level) + 1; - case TRAP_BOLT: return random2(13 + you.your_level) + 1; - case TRAP_AXE: return random2(15 + you.your_level) + 1; - default: return 0; - } - } - else if (act.atype() == ACT_MONSTER) + int level = you.your_level; + + // Trap damage to monsters is not a function of level, because + // they are fairly stupid and tend to have fewer hp than + // players -- this choice prevents traps from easily killing + // large monsters fairly deep within the dungeon. + if (act.atype() == ACT_MONSTER) + level = 0; + + switch (this->type) { - // Trap damage to monsters is not a function of level, because - // they are fairly stupid and tend to have fewer hp than - // players -- this choice prevents traps from easily killing - // large monsters fairly deep within the dungeon. - switch (this->type) - { case TRAP_NEEDLE: return 0; - case TRAP_DART: return random2( 4) + 1; - case TRAP_ARROW: return random2( 7) + 1; - case TRAP_SPEAR: return random2(10) + 1; - case TRAP_BOLT: return random2(13) + 1; - case TRAP_AXE: return random2(15) + 1; + case TRAP_DART: return random2( 4 + level/2) + 1; + case TRAP_ARROW: return random2( 7 + level) + 1; + case TRAP_SPEAR: return random2(10 + level) + 1; + case TRAP_BOLT: return random2(13 + level) + 1; + case TRAP_AXE: return random2(15 + level) + 1; default: return 0; - } } + return (0); } |