OSDN Git Service

[Fix] GF_STAR_HEALの処理でclone monsterが実行される
[hengband/hengband.git] / src / effect / effect-monster-switcher.c
index 19711a6..f3dc68b 100644 (file)
@@ -1,38 +1,45 @@
 /*!
+ * todo どうしても「その他」に分類せざるを得ない魔法種別が残った
+ * 本ファイル内の行数はまともなレベルに落ち着いているので、一旦ここに留め置くこととする
  * @brief 魔法種別による各種処理切り替え
  * @date 2020/04/29
  * @author Hourier
  */
 
-#include "angband.h"
-#include "effect-monster-util.h"
 #include "effect/effect-monster-switcher.h"
-#include "player-damage.h"
-#include "avatar.h"
-#include "quest.h"
-#include "monster-status.h"
-#include "effect/spells-effect-util.h"
-#include "player-effects.h"
-#include "monsterrace-hook.h"
-#include "combat/melee.h"
-#include "cmd/cmd-pet.h" // 暫定、後で消すかも.
-#include "spell/spells-type.h"
-#include "effect/effect-monster-resist-hurt.h"
-#include "effect/effect-monster-psi.h"
-#include "effect/effect-monster-domination.h"
-#include "effect/effect-monster-oldies.h"
+#include "cmd-action/cmd-attack.h"
 #include "effect/effect-monster-charm.h"
-#include "effect/effect-monster-lite-dark.h"
+#include "effect/effect-monster-curse.h"
 #include "effect/effect-monster-evil.h"
+#include "effect/effect-monster-lite-dark.h"
+#include "effect/effect-monster-oldies.h"
+#include "effect/effect-monster-psi.h"
+#include "effect/effect-monster-resist-hurt.h"
 #include "effect/effect-monster-spirit.h"
-
-gf_switch_result effect_monster_hypodynamia(player_type *caster_ptr, effect_monster_type *em_ptr)
+#include "effect/effect-monster-util.h"
+#include "monster-race/monster-race.h"
+#include "monster-race/race-flags1.h"
+#include "monster-race/race-flags2.h"
+#include "monster-race/race-flags3.h"
+#include "monster-race/monster-race-hook.h"
+#include "monster-floor/monster-death.h"
+#include "monster/monster-status-setter.h"
+#include "monster/monster-status.h"
+#include "monster/monster-info.h"
+#include "player-info/avatar.h"
+#include "player/player-damage.h"
+#include "spell-kind/spells-genocide.h"
+#include "spell/spell-types.h"
+#include "view/display-messages.h"
+
+process_result effect_monster_hypodynamia(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        if (em_ptr->seen) em_ptr->obvious = TRUE;
+
        if (monster_living(em_ptr->m_ptr->r_idx))
        {
                em_ptr->do_time = (em_ptr->dam + 7) / 8;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
        if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr))
@@ -45,12 +52,12 @@ gf_switch_result effect_monster_hypodynamia(player_type *caster_ptr, effect_mons
        em_ptr->note = _("には効果がなかった。", " is unaffected.");
        em_ptr->obvious = FALSE;
        em_ptr->dam = 0;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
 // todo リファクタリング前のコード時点で、単に耐性があるだけでもダメージ0だった.
-gf_switch_result effect_monster_death_ray(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result effect_monster_death_ray(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        if (em_ptr->seen) em_ptr->obvious = TRUE;
 
@@ -66,7 +73,7 @@ gf_switch_result effect_monster_death_ray(player_type *caster_ptr, effect_monste
                em_ptr->note = _("には完全な耐性がある!", " is immune.");
                em_ptr->obvious = FALSE;
                em_ptr->dam = 0;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
        if (((em_ptr->r_ptr->flags1 & RF1_UNIQUE) &&
@@ -79,59 +86,16 @@ gf_switch_result effect_monster_death_ray(player_type *caster_ptr, effect_monste
                em_ptr->dam = 0;
        }
 
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_stasis(effect_monster_type *em_ptr, bool to_evil)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-
-       int stasis_damage = (em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10);
-       bool has_resistance = (em_ptr->r_ptr->flags1 & RF1_UNIQUE) != 0;
-       has_resistance |= em_ptr->r_ptr->level > randint1(stasis_damage) + 10;
-       if (to_evil) has_resistance |= (em_ptr->r_ptr->flags3 & RF3_EVIL) == 0;
-
-       if (has_resistance)
-       {
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->obvious = FALSE;
-       }
-       else
-       {
-               em_ptr->note = _("は動けなくなった!", " is suspended!");
-               em_ptr->do_sleep = 500;
-       }
-
-       em_ptr->dam = 0;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_stun(effect_monster_type *em_ptr)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-
-       em_ptr->do_stun = damroll((em_ptr->caster_lev / 20) + 3, (em_ptr->dam)) + 1;
-       if ((em_ptr->r_ptr->flags1 & (RF1_UNIQUE)) ||
-               (em_ptr->r_ptr->level > randint1((em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10)) + 10))
-       {
-               em_ptr->do_stun = 0;
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->obvious = FALSE;
-       }
-
-       em_ptr->dam = 0;
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_kill_wall(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result effect_monster_kill_wall(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        if ((em_ptr->r_ptr->flags3 & (RF3_HURT_ROCK)) == 0)
        {
                em_ptr->dam = 0;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
        if (em_ptr->seen) em_ptr->obvious = TRUE;
@@ -140,72 +104,11 @@ gf_switch_result effect_monster_kill_wall(player_type *caster_ptr, effect_monste
 
        em_ptr->note = _("の皮膚がただれた!", " loses some skin!");
        em_ptr->note_dies = _("はドロドロに溶けた!", " dissolves!");
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_curse_1(effect_monster_type *em_ptr)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-       if (!em_ptr->who) msg_format(_("%sを指差して呪いをかけた。", "You point at %s and curse."), em_ptr->m_name);
-       if (randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35))
-       {
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->dam = 0;
-       }
-
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_curse_2(effect_monster_type *em_ptr)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-       if (!em_ptr->who) msg_format(_("%sを指差して恐ろしげに呪いをかけた。", "You point at %s and curse horribly."), em_ptr->m_name);
-
-       if (randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35))
-       {
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->dam = 0;
-       }
-
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_curse_3(effect_monster_type *em_ptr)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-       if (!em_ptr->who) msg_format(_("%sを指差し、恐ろしげに呪文を唱えた!", "You point at %s, incanting terribly!"), em_ptr->m_name);
-
-       if (randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35))
-       {
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->dam = 0;
-       }
-
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_curse_4(effect_monster_type *em_ptr)
-{
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-       if (!em_ptr->who)
-               msg_format(_("%sの秘孔を突いて、「お前は既に死んでいる」と叫んだ。",
-                       "You point at %s, screaming the word, 'DIE!'."), em_ptr->m_name);
-
-       if ((randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35)) && ((em_ptr->who <= 0) || (em_ptr->m_caster_ptr->r_idx != MON_KENSHIROU)))
-       {
-               em_ptr->note = _("には効果がなかった。", " is unaffected.");
-               em_ptr->dam = 0;
-       }
-
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_hand_doom(effect_monster_type *em_ptr)
+process_result effect_monster_hand_doom(effect_monster_type *em_ptr)
 {
        if (em_ptr->seen) em_ptr->obvious = TRUE;
 
@@ -213,7 +116,7 @@ gf_switch_result effect_monster_hand_doom(effect_monster_type *em_ptr)
        {
                em_ptr->note = _("には効果がなかった。", " is unaffected.");
                em_ptr->dam = 0;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
        if ((em_ptr->who > 0) ? ((em_ptr->caster_lev + randint1(em_ptr->dam)) > (em_ptr->r_ptr->level + 10 + randint1(20))) :
@@ -229,66 +132,11 @@ gf_switch_result effect_monster_hand_doom(effect_monster_type *em_ptr)
                em_ptr->dam = 0;
        }
 
-       return GF_SWITCH_CONTINUE;
-}
-
-
-static bool effect_monster_check_capturability(player_type *caster_ptr, effect_monster_type *em_ptr, int capturable_hp)
-{
-       if (em_ptr->m_ptr->hp >= randint0(capturable_hp)) return FALSE;
-
-       if (em_ptr->m_ptr->mflag2 & MFLAG2_CHAMELEON)
-               choose_new_monster(caster_ptr, em_ptr->g_ptr->m_idx, FALSE, MON_CHAMELEON);
-
-       msg_format(_("%sを捕えた!", "You capture %^s!"), em_ptr->m_name);
-       cap_mon = em_ptr->m_ptr->r_idx;
-       cap_mspeed = em_ptr->m_ptr->mspeed;
-       cap_hp = em_ptr->m_ptr->hp;
-       cap_maxhp = em_ptr->m_ptr->max_maxhp;
-       cap_nickname = em_ptr->m_ptr->nickname;
-       if ((em_ptr->g_ptr->m_idx == caster_ptr->riding) && rakuba(caster_ptr, -1, FALSE))
-               msg_format(_("地面に落とされた。", "You have fallen from %s."), em_ptr->m_name);
-
-       delete_monster_idx(caster_ptr, em_ptr->g_ptr->m_idx);
-       return TRUE;
-}
-
-
-gf_switch_result effect_monster_capture(player_type *caster_ptr, effect_monster_type *em_ptr)
-{
-       floor_type *floor_ptr = caster_ptr->current_floor_ptr;
-       int capturable_hp;
-       if ((floor_ptr->inside_quest && (quest[floor_ptr->inside_quest].type == QUEST_TYPE_KILL_ALL) && !is_pet(em_ptr->m_ptr)) ||
-               (em_ptr->r_ptr->flags1 & (RF1_UNIQUE)) || (em_ptr->r_ptr->flags7 & (RF7_NAZGUL)) || (em_ptr->r_ptr->flags7 & (RF7_UNIQUE2)) || (em_ptr->r_ptr->flags1 & RF1_QUESTOR) || em_ptr->m_ptr->parent_m_idx)
-       {
-               msg_format(_("%sには効果がなかった。", "%s is unaffected."), em_ptr->m_name);
-               em_ptr->skipped = TRUE;
-               return GF_SWITCH_CONTINUE;
-       }
-
-       if (is_pet(em_ptr->m_ptr)) capturable_hp = em_ptr->m_ptr->maxhp * 4L;
-       else if ((caster_ptr->pclass == CLASS_BEASTMASTER) && monster_living(em_ptr->m_ptr->r_idx))
-               capturable_hp = em_ptr->m_ptr->maxhp * 3 / 10;
-       else
-               capturable_hp = em_ptr->m_ptr->maxhp * 3 / 20;
-
-       if (em_ptr->m_ptr->hp >= capturable_hp)
-       {
-               msg_format(_("もっと弱らせないと。", "You need to weaken %s more."), em_ptr->m_name);
-               em_ptr->skipped = TRUE;
-               return GF_SWITCH_CONTINUE;
-       }
-       
-       if (effect_monster_check_capturability(caster_ptr, em_ptr, capturable_hp))
-               return GF_SWITCH_TRUE;
-
-       msg_format(_("うまく捕まえられなかった。", "You failed to capture %s."), em_ptr->m_name);
-       em_ptr->skipped = TRUE;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_engetsu(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result effect_monster_engetsu(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        int effect = 0;
        bool done = TRUE;
@@ -300,15 +148,15 @@ gf_switch_result effect_monster_engetsu(player_type *caster_ptr, effect_monster_
                em_ptr->dam = 0;
                em_ptr->skipped = TRUE;
                if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr)) em_ptr->r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
-       if (MON_CSLEEP(em_ptr->m_ptr))
+       if (monster_csleep_remaining(em_ptr->m_ptr))
        {
                em_ptr->note = _("には効果がなかった。", " is unaffected.");
                em_ptr->dam = 0;
                em_ptr->skipped = TRUE;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
 
        if (one_in_(5)) effect = 1;
@@ -326,7 +174,7 @@ gf_switch_result effect_monster_engetsu(player_type *caster_ptr, effect_monster_
                }
                else
                {
-                       if (set_monster_slow(caster_ptr, em_ptr->g_ptr->m_idx, MON_SLOW(em_ptr->m_ptr) + 50))
+                       if (set_monster_slow(caster_ptr, em_ptr->g_ptr->m_idx, monster_slow_remaining(em_ptr->m_ptr) + 50))
                        {
                                em_ptr->note = _("の動きが遅くなった。", " starts moving slower.");
                        }
@@ -371,26 +219,26 @@ gf_switch_result effect_monster_engetsu(player_type *caster_ptr, effect_monster_
        }
 
        em_ptr->dam = 0;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_genocide(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result effect_monster_genocide(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        if (em_ptr->seen) em_ptr->obvious = TRUE;
        if (genocide_aux(caster_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, !em_ptr->who, (em_ptr->r_ptr->level + 1) / 2, _("モンスター消滅", "Genocide One")))
        {
                if (em_ptr->seen_msg) msg_format(_("%sは消滅した!", "%^s disappeared!"), em_ptr->m_name);
                chg_virtue(caster_ptr, V_VITALITY, -1);
-               return GF_SWITCH_TRUE;
+               return PROCESS_TRUE;
        }
 
        em_ptr->skipped = TRUE;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_photo(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result effect_monster_photo(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        if (!em_ptr->who)
                msg_format(_("%sを写真に撮った。", "You take a photograph of %s."), em_ptr->m_name);
@@ -410,61 +258,11 @@ gf_switch_result effect_monster_photo(player_type *caster_ptr, effect_monster_ty
        }
 
        em_ptr->photo = em_ptr->m_ptr->r_idx;
-       return GF_SWITCH_CONTINUE;
-}
-
-
-gf_switch_result effect_monster_crusade(player_type *caster_ptr, effect_monster_type *em_ptr)
-{
-       bool success = FALSE;
-       if (em_ptr->seen) em_ptr->obvious = TRUE;
-
-       if ((em_ptr->r_ptr->flags3 & (RF3_GOOD)) && !caster_ptr->current_floor_ptr->inside_arena)
-       {
-               if (em_ptr->r_ptr->flags3 & (RF3_NO_CONF)) em_ptr->dam -= 50;
-               if (em_ptr->dam < 1) em_ptr->dam = 1;
-
-               if (is_pet(em_ptr->m_ptr))
-               {
-                       em_ptr->note = _("の動きが速くなった。", " starts moving faster.");
-                       (void)set_monster_fast(caster_ptr, em_ptr->g_ptr->m_idx, MON_FAST(em_ptr->m_ptr) + 100);
-                       success = TRUE;
-               }
-               else if ((em_ptr->r_ptr->flags1 & (RF1_QUESTOR)) ||
-                       (em_ptr->r_ptr->flags1 & (RF1_UNIQUE)) ||
-                       (em_ptr->m_ptr->mflag2 & MFLAG2_NOPET) ||
-                       (caster_ptr->cursed & TRC_AGGRAVATE) ||
-                       ((em_ptr->r_ptr->level + 10) > randint1(em_ptr->dam)))
-               {
-                       if (one_in_(4)) em_ptr->m_ptr->mflag2 |= MFLAG2_NOPET;
-               }
-               else
-               {
-                       em_ptr->note = _("を支配した。", " is tamed!");
-                       set_pet(caster_ptr, em_ptr->m_ptr);
-                       (void)set_monster_fast(caster_ptr, em_ptr->g_ptr->m_idx, MON_FAST(em_ptr->m_ptr) + 100);
-
-                       if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr)) em_ptr->r_ptr->r_flags3 |= (RF3_GOOD);
-                       success = TRUE;
-               }
-       }
-
-       if (!success)
-       {
-               if (!(em_ptr->r_ptr->flags3 & RF3_NO_FEAR))
-               {
-                       em_ptr->do_fear = randint1(90) + 10;
-               }
-               else if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr))
-                       em_ptr->r_ptr->r_flags3 |= (RF3_NO_FEAR);
-       }
-
-       em_ptr->dam = 0;
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
-gf_switch_result effect_monster_wounds(effect_monster_type *em_ptr)
+process_result effect_monster_wounds(effect_monster_type *em_ptr)
 {
        if (em_ptr->seen) em_ptr->obvious = TRUE;
 
@@ -474,7 +272,7 @@ gf_switch_result effect_monster_wounds(effect_monster_type *em_ptr)
                em_ptr->dam = 0;
        }
 
-       return GF_SWITCH_CONTINUE;
+       return PROCESS_CONTINUE;
 }
 
 
@@ -483,7 +281,7 @@ gf_switch_result effect_monster_wounds(effect_monster_type *em_ptr)
  * @param em_ptr モンスター効果構造体への参照ポインタ
  * @return ここのスイッチングで終るならTRUEかFALSE、後続処理を実行するならCONTINUE
  */
-gf_switch_result switch_effects_monster(player_type *caster_ptr, effect_monster_type *em_ptr)
+process_result switch_effects_monster(player_type *caster_ptr, effect_monster_type *em_ptr)
 {
        switch (em_ptr->effect_type)
        {
@@ -561,9 +359,7 @@ gf_switch_result switch_effects_monster(player_type *caster_ptr, effect_monster_
        case GF_OLD_CLONE:
                return effect_monster_old_clone(caster_ptr, em_ptr);
        case GF_STAR_HEAL:
-               if (effect_monster_old_clone(caster_ptr, em_ptr) == GF_SWITCH_TRUE)
-                       return GF_SWITCH_CONTINUE;
-       /* Fall through */
+               return effect_monster_star_heal(caster_ptr, em_ptr);
        case GF_OLD_HEAL:
                return effect_monster_old_heal(caster_ptr, em_ptr);
        case GF_OLD_SPEED:
@@ -641,7 +437,7 @@ gf_switch_result switch_effects_monster(player_type *caster_ptr, effect_monster_
        case GF_CAPTURE:
                return effect_monster_capture(caster_ptr, em_ptr);
        case GF_ATTACK:
-               return (gf_switch_result)py_attack(caster_ptr, em_ptr->y, em_ptr->x, em_ptr->dam);
+               return (process_result)do_cmd_attack(caster_ptr, em_ptr->y, em_ptr->x, em_ptr->dam);
        case GF_ENGETSU:
                return effect_monster_engetsu(caster_ptr, em_ptr);
        case GF_GENOCIDE:
@@ -656,7 +452,7 @@ gf_switch_result switch_effects_monster(player_type *caster_ptr, effect_monster_
        {
                em_ptr->skipped = TRUE;
                em_ptr->dam = 0;
-               return GF_SWITCH_CONTINUE;
+               return PROCESS_CONTINUE;
        }
        }
 }