diff options
author | Vsevolod Kozlov <zaba@thorium.homeunix.org> | 2009-11-05 19:58:50 +1000 |
---|---|---|
committer | Jude Brown <bookofjude@users.sourceforge.net> | 2009-11-05 19:58:50 +1000 |
commit | b9def0122143459c4d1fd0721384028f3974dc69 (patch) | |
tree | f7b26f422d93b6f6769a45cb757c9075279a7c6a /crawl-ref/source/monster.cc | |
parent | 313465bf23382559f7c26c63849b64266c8d939f (diff) | |
download | crawl-ref-b9def0122143459c4d1fd0721384028f3974dc69.tar.gz crawl-ref-b9def0122143459c4d1fd0721384028f3974dc69.zip |
Move *_res(ist)_magic to relevant classes, provide actor interface.
Signed-off-by: Jude Brown <bookofjude@users.sourceforge.net>
Diffstat (limited to 'crawl-ref/source/monster.cc')
-rw-r--r-- | crawl-ref/source/monster.cc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc index 64c71a0486..705e689ce8 100644 --- a/crawl-ref/source/monster.cc +++ b/crawl-ref/source/monster.cc @@ -3154,6 +3154,78 @@ int monsters::res_acid() const return (get_mons_resists(this).acid); } +int monsters::res_magic() const +{ + if (mons_immune_magic(this)) + return MAG_IMMUNE; + + int u = (get_monster_data(this->type))->resist_magic; + + // Negative values get multiplied with monster hit dice. + if (u < 0) + u = this->hit_dice * -u * 4 / 3; + + // Randarts have a multiplicative effect. + u *= (scan_mon_inv_randarts(this, ARTP_MAGIC) + 100); + u /= 100; + + // ego armour resistance + const int armour = this->inv[MSLOT_ARMOUR]; + const int _shield = this->inv[MSLOT_SHIELD]; + + if (armour != NON_ITEM + && get_armour_ego_type( mitm[armour] ) == SPARM_MAGIC_RESISTANCE ) + { + u += 30; + } + + if (_shield != NON_ITEM + && get_armour_ego_type( mitm[_shield] ) == SPARM_MAGIC_RESISTANCE ) + { + u += 30; + } + + if (this->has_ench(ENCH_LOWERED_MR)) + u /= 2; + + return (u); +} + +bool monsters::check_res_magic(int pow) +{ + int mrs = this->res_magic(); + + if (mrs == MAG_IMMUNE) + return (true); + + // Evil, evil hack to make weak one hd monsters easier for first + // level characters who have resistable 1st level spells. Six is + // a very special value because mrs = hd * 2 * 3 for most monsters, + // and the weak, low level monsters have been adjusted so that the + // "3" is typically a 1. There are some notable one hd monsters + // that shouldn't fall under this, so we do < 6, instead of <= 6... + // or checking monster->hit_dice. The goal here is to make the + // first level easier for these classes and give them a better + // shot at getting to level two or three and spells that can help + // them out (or building a level or two of their base skill so they + // aren't resisted as often). -- bwr + if (mrs < 6 && coinflip()) + return (false); + + pow = stepdown_value( pow, 30, 40, 100, 120 ); + + const int mrchance = (100 + mrs) - pow; + const int mrch2 = random2(100) + random2(101); + +#if DEBUG_DIAGNOSTICS + mprf(MSGCH_DIAGNOSTICS, + "Power: %d, monster's MR: %d, target: %d, roll: %d", + pow, mrs, mrchance, mrch2 ); +#endif + + return (mrch2 < mrchance); +} + flight_type monsters::flight_mode() const { return (mons_flies(this)); |