OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-market-edits' into feature...
[hengband/hengband.git] / src / mspell / improper-mspell-remover.c
index 4c5c41b..3ea6b15 100644 (file)
 #include "mspell/improper-mspell-remover.h"
 #include "game-option/birth-options.h"
 #include "monster-race/monster-race.h"
-#include "monster-race/race-flags-ability1.h"
-#include "monster-race/race-flags-ability2.h"
 #include "monster-race/race-flags2.h"
-#include "monster-race/race-flags4.h"
 #include "monster/smart-learn-types.h"
-#include "player/player-race.h"
-#include "status/element-resistance.h"
+#include "mspell/element-resistance-checker.h"
+#include "mspell/high-resistance-checker.h"
+#include "mspell/smart-mspell-util.h"
 #include "system/floor-type-definition.h"
 #include "system/monster-type-definition.h"
 
-// Monster Spell Remover.
-typedef struct msr_type {
-    monster_race *r_ptr;
-    u32b f4;
-    u32b f5;
-    u32b f6;
-    u32b smart;
-} msr_type;
-
-static msr_type *initialize_msr_type(player_type *target_ptr, msr_type *msr_ptr, MONSTER_IDX m_idx, const u32b f4p, const u32b f5p, const u32b f6p)
-{
-    monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
-    msr_ptr->r_ptr = &r_info[m_ptr->r_idx];
-    msr_ptr->f4 = f4p;
-    msr_ptr->f5 = f5p;
-    msr_ptr->f6 = f6p;
-    msr_ptr->smart = 0L;
-    return msr_ptr;
-}
-
-/*!
- * @brief モンスターがプレイヤーの弱点をついた選択を取るかどうかの判定 /
- * Internal probability routine
- * @param r_ptr モンスター種族の構造体参照ポインタ
- * @param prob 基本確率(%)
- * @return 適した選択を取るならばTRUEを返す。
- */
-static bool int_outof(monster_race *r_ptr, PERCENTAGE prob)
-{
-    if (!(r_ptr->flags2 & RF2_SMART))
-        prob = prob / 2;
-
-    return (randint0(100) < prob);
-}
-
-static void add_cheat_remove_flags_element(player_type *target_ptr, msr_type *msr_ptr)
-{
-    if (target_ptr->resist_acid)
-        msr_ptr->smart |= SM_RES_ACID;
-
-    if (is_oppose_acid(target_ptr))
-        msr_ptr->smart |= SM_OPP_ACID;
-
-    if (target_ptr->immune_acid)
-        msr_ptr->smart |= SM_IMM_ACID;
-
-    if (target_ptr->resist_elec)
-        msr_ptr->smart |= SM_RES_ELEC;
-
-    if (is_oppose_elec(target_ptr))
-        msr_ptr->smart |= SM_OPP_ELEC;
-
-    if (target_ptr->immune_elec)
-        msr_ptr->smart |= SM_IMM_ELEC;
-
-    if (target_ptr->resist_fire)
-        msr_ptr->smart |= SM_RES_FIRE;
-
-    if (is_oppose_fire(target_ptr))
-        msr_ptr->smart |= SM_OPP_FIRE;
-
-    if (target_ptr->immune_fire)
-        msr_ptr->smart |= SM_IMM_FIRE;
-
-    if (target_ptr->resist_cold)
-        msr_ptr->smart |= SM_RES_COLD;
-
-    if (is_oppose_cold(target_ptr))
-        msr_ptr->smart |= SM_OPP_COLD;
-
-    if (target_ptr->immune_cold)
-        msr_ptr->smart |= SM_IMM_COLD;
-
-    if (target_ptr->resist_pois)
-        msr_ptr->smart |= SM_RES_POIS;
-
-    if (is_oppose_pois(target_ptr))
-        msr_ptr->smart |= SM_OPP_POIS;
-}
-
-static void add_cheat_remove_flags_others(player_type *target_ptr, msr_type *msr_ptr)
-{
-    if (target_ptr->resist_neth)
-        msr_ptr->smart |= SM_RES_NETH;
-
-    if (target_ptr->resist_lite)
-        msr_ptr->smart |= SM_RES_LITE;
-
-    if (target_ptr->resist_dark)
-        msr_ptr->smart |= SM_RES_DARK;
-
-    if (target_ptr->resist_fear)
-        msr_ptr->smart |= SM_RES_FEAR;
-
-    if (target_ptr->resist_conf)
-        msr_ptr->smart |= SM_RES_CONF;
-
-    if (target_ptr->resist_chaos)
-        msr_ptr->smart |= SM_RES_CHAOS;
-
-    if (target_ptr->resist_disen)
-        msr_ptr->smart |= SM_RES_DISEN;
-
-    if (target_ptr->resist_blind)
-        msr_ptr->smart |= SM_RES_BLIND;
-
-    if (target_ptr->resist_nexus)
-        msr_ptr->smart |= SM_RES_NEXUS;
-
-    if (target_ptr->resist_sound)
-        msr_ptr->smart |= SM_RES_SOUND;
-
-    if (target_ptr->resist_shard)
-        msr_ptr->smart |= SM_RES_SHARD;
-
-    if (target_ptr->reflect)
-        msr_ptr->smart |= SM_IMM_REFLECT;
-
-    if (target_ptr->free_act)
-        msr_ptr->smart |= SM_IMM_FREE;
-
-    if (!target_ptr->msp)
-        msr_ptr->smart |= SM_IMM_MANA;
-}
-
 static void add_cheat_remove_flags(player_type *target_ptr, msr_type *msr_ptr)
 {
     if (!smart_cheat)
@@ -145,339 +18,6 @@ static void add_cheat_remove_flags(player_type *target_ptr, msr_type *msr_ptr)
     add_cheat_remove_flags_others(target_ptr, msr_ptr);
 }
 
-static void check_acid_resistance(msr_type *msr_ptr)
-{
-    if (msr_ptr->smart & SM_IMM_ACID) {
-        msr_ptr->f4 &= ~(RF4_BR_ACID);
-        msr_ptr->f5 &= ~(RF5_BA_ACID);
-        msr_ptr->f5 &= ~(RF5_BO_ACID);
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_ACID) && (msr_ptr->smart & SM_RES_ACID)) {
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f4 &= ~(RF4_BR_ACID);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BA_ACID);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BO_ACID);
-
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_ACID) || (msr_ptr->smart & SM_RES_ACID)) {
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f4 &= ~(RF4_BR_ACID);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BA_ACID);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BO_ACID);
-    }
-}
-
-static void check_elec_resistance(msr_type *msr_ptr)
-{
-    if (msr_ptr->smart & SM_IMM_ELEC) {
-        msr_ptr->f4 &= ~(RF4_BR_ELEC);
-        msr_ptr->f5 &= ~(RF5_BA_ELEC);
-        msr_ptr->f5 &= ~(RF5_BO_ELEC);
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_ELEC) && (msr_ptr->smart & SM_RES_ELEC)) {
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f4 &= ~(RF4_BR_ELEC);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BA_ELEC);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BO_ELEC);
-
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_ELEC) || (msr_ptr->smart & SM_RES_ELEC)) {
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f4 &= ~(RF4_BR_ELEC);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BA_ELEC);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BO_ELEC);
-    }
-}
-
-static void check_fire_resistance(msr_type *msr_ptr)
-{
-    if (msr_ptr->smart & SM_IMM_FIRE) {
-        msr_ptr->f4 &= ~(RF4_BR_FIRE);
-        msr_ptr->f5 &= ~(RF5_BA_FIRE);
-        msr_ptr->f5 &= ~(RF5_BO_FIRE);
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_FIRE) && (msr_ptr->smart & SM_RES_FIRE)) {
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f4 &= ~(RF4_BR_FIRE);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BA_FIRE);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BO_FIRE);
-
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_FIRE) || (msr_ptr->smart & SM_RES_FIRE)) {
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f4 &= ~(RF4_BR_FIRE);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BA_FIRE);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BO_FIRE);
-    }
-}
-
-static void check_cold_resistance(msr_type *msr_ptr)
-{
-    if (msr_ptr->smart & (SM_IMM_COLD)) {
-        msr_ptr->f4 &= ~(RF4_BR_COLD);
-        msr_ptr->f5 &= ~(RF5_BA_COLD);
-        msr_ptr->f5 &= ~(RF5_BO_COLD);
-        msr_ptr->f5 &= ~(RF5_BO_ICEE);
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_COLD) && (msr_ptr->smart & SM_RES_COLD)) {
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f4 &= ~(RF4_BR_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BA_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BO_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BO_ICEE);
-
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_COLD) || (msr_ptr->smart & SM_RES_COLD)) {
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f4 &= ~(RF4_BR_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BA_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BO_COLD);
-
-        if (int_outof(msr_ptr->r_ptr, 20))
-            msr_ptr->f5 &= ~(RF5_BO_ICEE);
-    }
-}
-
-static void check_pois_resistance(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_OPP_POIS) && (msr_ptr->smart & SM_RES_POIS)) {
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f4 &= ~(RF4_BR_POIS);
-
-        if (int_outof(msr_ptr->r_ptr, 80))
-            msr_ptr->f5 &= ~(RF5_BA_POIS);
-
-        if (int_outof(msr_ptr->r_ptr, 60))
-            msr_ptr->f4 &= ~(RF4_BA_NUKE);
-
-        if (int_outof(msr_ptr->r_ptr, 60))
-            msr_ptr->f4 &= ~(RF4_BR_NUKE);
-
-        return;
-    }
-
-    if ((msr_ptr->smart & SM_OPP_POIS) || (msr_ptr->smart & SM_RES_POIS)) {
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f4 &= ~(RF4_BR_POIS);
-
-        if (int_outof(msr_ptr->r_ptr, 30))
-            msr_ptr->f5 &= ~(RF5_BA_POIS);
-    }
-}
-
-void check_element_resistance(msr_type *msr_ptr)
-{
-    check_acid_resistance(msr_ptr);
-    check_elec_resistance(msr_ptr);
-    check_fire_resistance(msr_ptr);
-    check_cold_resistance(msr_ptr);
-    check_pois_resistance(msr_ptr);
-}
-
-static void check_nether_resistance(player_type *target_ptr, msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_NETH) == 0)
-        return;
-
-    if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
-        msr_ptr->f4 &= ~(RF4_BR_NETH);
-        msr_ptr->f5 &= ~(RF5_BA_NETH);
-        msr_ptr->f5 &= ~(RF5_BO_NETH);
-        return;
-    }
-
-    if (int_outof(msr_ptr->r_ptr, 20))
-        msr_ptr->f4 &= ~(RF4_BR_NETH);
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f5 &= ~(RF5_BA_NETH);
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f5 &= ~(RF5_BO_NETH);
-}
-
-static void check_lite_resistance(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_LITE) == 0)
-        return;
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BR_LITE);
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f5 &= ~(RF5_BA_LITE);
-}
-
-static void check_dark_resistance(player_type *target_ptr, msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_DARK) == 0)
-        return;
-
-    if (is_specific_player_race(target_ptr, RACE_VAMPIRE)) {
-        msr_ptr->f4 &= ~(RF4_BR_DARK);
-        msr_ptr->f5 &= ~(RF5_BA_DARK);
-        return;
-    }
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BR_DARK);
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f5 &= ~(RF5_BA_DARK);
-}
-
-static void check_conf_resistance(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_CONF) == 0)
-        return;
-
-    msr_ptr->f5 &= ~(RF5_CONF);
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BR_CONF);
-}
-
-static void check_chaos_resistance(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_CHAOS) == 0)
-        return;
-
-    if (int_outof(msr_ptr->r_ptr, 20))
-        msr_ptr->f4 &= ~(RF4_BR_CHAO);
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BA_CHAO);
-}
-
-static void check_nexus_resistance(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_RES_NEXUS) == 0)
-        return;
-
-    if (int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BR_NEXU);
-
-    msr_ptr->f6 &= ~(RF6_TELE_LEVEL);
-}
-
-static void check_reflection(msr_type *msr_ptr)
-{
-    if ((msr_ptr->smart & SM_IMM_REFLECT) == 0)
-        return;
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_COLD);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_FIRE);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_ACID);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_ELEC);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_NETH);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_WATE);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_MANA);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_PLAS);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_BO_ICEE);
-
-    if (int_outof(msr_ptr->r_ptr, 150))
-        msr_ptr->f5 &= ~(RF5_MISSILE);
-}
-
-void check_high_resistances(player_type *target_ptr, msr_type *msr_ptr)
-{
-    check_nether_resistance(target_ptr, msr_ptr);
-    check_lite_resistance(msr_ptr);
-    check_dark_resistance(target_ptr, msr_ptr);
-    if (msr_ptr->smart & SM_RES_FEAR)
-        msr_ptr->f5 &= ~(RF5_SCARE);
-
-    check_conf_resistance(msr_ptr);
-    check_chaos_resistance(msr_ptr);
-    if (((msr_ptr->smart & SM_RES_DISEN) != 0) && int_outof(msr_ptr->r_ptr, 40))
-        msr_ptr->f4 &= ~(RF4_BR_DISE);
-
-    if (msr_ptr->smart & SM_RES_BLIND)
-        msr_ptr->f5 &= ~(RF5_BLIND);
-
-    check_nexus_resistance(msr_ptr);
-    if (((msr_ptr->smart & SM_RES_SOUND) != 0) && int_outof(msr_ptr->r_ptr, 50))
-        msr_ptr->f4 &= ~(RF4_BR_SOUN);
-
-    if (((msr_ptr->smart & SM_RES_SHARD) != 0) && int_outof(msr_ptr->r_ptr, 40))
-        msr_ptr->f4 &= ~(RF4_BR_SHAR);
-
-    check_reflection(msr_ptr);
-    if (msr_ptr->smart & SM_IMM_FREE) {
-        msr_ptr->f5 &= ~(RF5_HOLD);
-        msr_ptr->f5 &= ~(RF5_SLOW);
-    }
-
-    if (msr_ptr->smart & SM_IMM_MANA)
-        msr_ptr->f5 &= ~(RF5_DRAIN_MANA);
-}
-
 /*!
  * @brief モンスターの魔法一覧から戦術的に適さない魔法を除外する /
  * Remove the "bad" spells from a spell list