OSDN Git Service

Merge branch 'For2.2.2-Refactoring' into For3.0.0-Monster-Adjustment
[hengband/hengband.git] / src / monster-floor / quantum-effect.c
1 #include "monster-floor/quantum-effect.h"
2 #include "floor/line-of-sight.h"
3 #include "monster-floor/monster-death.h"
4 #include "monster-floor/monster-remover.h"
5 #include "monster-race/monster-race.h"
6 #include "monster-race/race-flags1.h"
7 #include "monster-race/race-flags2.h"
8 #include "monster/monster-describer.h"
9 #include "monster/monster-description-types.h"
10 #include "monster/monster-info.h"
11 #include "monster/smart-learn-types.h"
12 #include "mspell/assign-monster-spell.h"
13 #include "spell-kind/spells-teleport.h"
14 #include "system/floor-type-definition.h"
15 #include "view/display-messages.h"
16
17 /*!
18  * @brief ユニークでない量子生物を消滅させる
19  * @param target_ptr プレーヤーへの参照ポインタ
20  * @param m_idx モンスターID
21  * @param see_m モンスターが視界内にいたらTRUE
22  * @return なし
23  */
24 static void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
25 {
26     monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
27     if (see_m) {
28         GAME_TEXT m_name[MAX_NLEN];
29         monster_desc(target_ptr, m_name, m_ptr, 0);
30         msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
31     }
32
33     monster_death(target_ptr, m_idx, FALSE);
34     delete_monster_idx(target_ptr, m_idx);
35     if (is_pet(m_ptr) && !(m_ptr->ml))
36         msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
37 }
38
39 /*!
40  * todo ユニークとプレーヤーとの間でしか効果が発生しない。ユニークとその他のモンスター間では何もしなくてよい?
41  * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
42  * @param target_ptr プレーヤーへの参照ポインタ
43  * @param m_idx モンスターID
44  * @param see_m モンスターが視界内にいたらTRUE
45  * @return なし
46  * @details
47  * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
48  * 波動関数の収縮はテレポートではないので反テレポート無効
49  * @notes
50  * パターンは収縮どころか拡散しているが、この際気にしてはいけない
51  */
52 static void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
53 {
54     monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
55     bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
56     if (!see_m && !coherent)
57         return;
58
59     if (see_m) {
60         GAME_TEXT m_name[MAX_NLEN];
61         monster_desc(target_ptr, m_name, m_ptr, MD_NONE);
62         msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
63     } else
64         msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
65
66     bool target = one_in_(2);
67     const int blink = 32 * 5 + 4;
68     if (target)
69         (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx, TRUE);
70     else
71         teleport_player_away(m_idx, target_ptr, 10, TRUE);
72 }
73
74 /*!
75  * @brief 量子生物の量子的効果を実行する
76  * @param target_ptr プレーヤーへの参照ポインタ
77  * @param m_idx モンスターID
78  * @param see_m モンスターが視界内にいたらTRUE
79  * @return モンスターが量子的効果により消滅したらTRUE
80  */
81 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
82 {
83     monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
84     monster_race *r_ptr = &r_info[m_ptr->r_idx];
85     if ((r_ptr->flags2 & RF2_QUANTUM) == 0)
86         return FALSE;
87     if (!randint0(2))
88         return FALSE;
89     if (randint0((m_idx % 100) + 10))
90         return FALSE;
91
92     bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
93     can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
94     if (can_disappear) {
95         vanish_nonunique(target_ptr, m_idx, see_m);
96         return TRUE;
97     }
98
99     produce_quantum_effect(target_ptr, m_idx, see_m);
100     return FALSE;
101 }