OSDN Git Service

2a756c82847b4b9fd210a04f81a21d47b3fc913c
[hengband/hengband.git] / src / player / eldritch-horror.c
1 /*!
2  * @brief エルドリッチホラー処理
3  * @date 2020/06/07
4  * @author Hourier
5  */
6
7 #include "player/eldritch-horror.h"
8 #include "core/player-update-types.h"
9 #include "core/stuff-handler.h"
10 #include "monster-race/monster-race-hook.h"
11 #include "monster-race/monster-race.h"
12 #include "monster-race/race-flags1.h"
13 #include "monster-race/race-flags2.h"
14 #include "monster-race/race-flags3.h"
15 #include "monster/horror-descriptions.h"
16 #include "monster/monster-describer.h"
17 #include "monster/monster-info.h"
18 #include "monster/monster-list.h"
19 #include "monster/monster-util.h"
20 #include "monster/smart-learn-types.h"
21 #include "mutation/mutation-flag-types.h"
22 #include "player/mimic-info-table.h"
23 #include "player/player-status-flags.h"
24 #include "player/player-status.h"
25 #include "status/bad-status-setter.h"
26 #include "status/base-status.h"
27 #include "system/floor-type-definition.h"
28 #include "view/display-messages.h"
29 #include "world/world.h"
30 #ifdef JP
31 #else
32 #include "locale/english.h"
33 #endif
34
35 /*!
36  * @brief エルドリッチホラーの形容詞種別を決める
37  * @param r_ptr モンスター情報への参照ポインタ
38  * @return
39  */
40 static concptr decide_horror_message(monster_race *r_ptr)
41 {
42     int horror_num = randint0(MAX_SAN_HORROR_SUM);
43     if (horror_num < MAX_SAN_HORROR_COMMON) {
44         return horror_desc_common[horror_num];
45     }
46
47     if ((r_ptr->flags3 & RF3_EVIL) != 0) {
48         return horror_desc_evil[horror_num - MAX_SAN_HORROR_COMMON];
49     }
50
51     return horror_desc_neutral[horror_num - MAX_SAN_HORROR_COMMON];
52 }
53
54 /*!
55  * todo m_nameとdescで何が違うのかは良く分からない
56  * @brief エルドリッチホラー持ちのモンスターを見た時の反応 (モンスター名版)
57  * @param m_name モンスター名
58  * @param r_ptr モンスター情報への参照ポインタ
59  * @return なし
60  */
61 static void see_eldritch_horror(GAME_TEXT *m_name, monster_race *r_ptr)
62 {
63     concptr horror_message = decide_horror_message(r_ptr);
64     msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"), horror_message, m_name);
65     r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
66 }
67
68 /*!
69  * @brief エルドリッチホラー持ちのモンスターを見た時の反応 (モンスター名版)
70  * @param desc モンスター名 (エルドリッチホラー持ちの全モンスターからランダム…のはず)
71  * @param r_ptr モンスターへの参照ポインタ
72  * @return なし
73  */
74 static void feel_eldritch_horror(concptr desc, monster_race *r_ptr)
75 {
76     concptr horror_message = decide_horror_message(r_ptr);
77     msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"), horror_message, desc);
78     r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
79 }
80
81 /*!
82  * @brief ELDRITCH_HORRORによるプレイヤーの精神破壊処理
83  * @param m_ptr ELDRITCH_HORRORを引き起こしたモンスターの参照ポインタ。薬・罠・魔法の影響ならNULL
84  * @param necro 暗黒領域魔法の詠唱失敗によるものならばTRUEを返す
85  * @return なし
86  */
87 void sanity_blast(player_type *creature_ptr, monster_type *m_ptr, bool necro)
88 {
89     if (creature_ptr->phase_out || !current_world_ptr->character_dungeon)
90         return;
91
92     int power = 100;
93     if (!necro && m_ptr) {
94         GAME_TEXT m_name[MAX_NLEN];
95         monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
96         power = r_ptr->level / 2;
97         monster_desc(creature_ptr, m_name, m_ptr, 0);
98         if (!(r_ptr->flags1 & RF1_UNIQUE)) {
99             if (r_ptr->flags1 & RF1_FRIENDS)
100                 power /= 2;
101         } else
102             power *= 2;
103
104         if (!current_world_ptr->is_loading_now)
105             return;
106
107         if (!m_ptr->ml)
108             return;
109
110         if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
111             return;
112
113         if (is_pet(m_ptr))
114             return;
115
116         if (randint1(100) > power)
117             return;
118
119         if (saving_throw(creature_ptr->skill_sav - power))
120             return;
121
122         if (creature_ptr->image) {
123             msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"), funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
124
125             if (one_in_(3)) {
126                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
127                 creature_ptr->image = creature_ptr->image + randint1(r_ptr->level);
128             }
129
130             return;
131         }
132
133         see_eldritch_horror(m_name, r_ptr);
134         if (is_specific_player_race(creature_ptr, RACE_IMP) || is_specific_player_race(creature_ptr, RACE_BALROG)
135             || (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON) || current_world_ptr->wizard)
136             return;
137
138         if (is_specific_player_race(creature_ptr, RACE_SKELETON) || is_specific_player_race(creature_ptr, RACE_ZOMBIE)
139             || is_specific_player_race(creature_ptr, RACE_VAMPIRE) || is_specific_player_race(creature_ptr, RACE_SPECTRE)
140             || (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)) {
141             if (saving_throw(25 + creature_ptr->lev))
142                 return;
143         }
144     } else if (!necro) {
145         monster_race *r_ptr;
146         GAME_TEXT m_name[MAX_NLEN];
147         concptr desc;
148         get_mon_num_prep(creature_ptr, get_nightmare, NULL);
149         r_ptr = &r_info[get_mon_num(creature_ptr, 0, MAX_DEPTH, 0)];
150         power = r_ptr->level + 10;
151         desc = r_name + r_ptr->name;
152         get_mon_num_prep(creature_ptr, NULL, NULL);
153 #ifdef JP
154 #else
155
156         if (!(r_ptr->flags1 & RF1_UNIQUE))
157             sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
158         else
159 #endif
160         sprintf(m_name, "%s", desc);
161
162         if (!(r_ptr->flags1 & RF1_UNIQUE)) {
163             if (r_ptr->flags1 & RF1_FRIENDS)
164                 power /= 2;
165         } else
166             power *= 2;
167
168         if (saving_throw(creature_ptr->skill_sav * 100 / power)) {
169             msg_format(_("夢の中で%sに追いかけられた。", "%^s chases you through your dreams."), m_name);
170             return;
171         }
172
173         if (creature_ptr->image) {
174             msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"), funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
175
176             if (one_in_(3)) {
177                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
178                 creature_ptr->image = creature_ptr->image + randint1(r_ptr->level);
179             }
180
181             return;
182         }
183
184         feel_eldritch_horror(desc, r_ptr);
185         if (!creature_ptr->mimic_form) {
186             switch (creature_ptr->prace) {
187             case RACE_IMP:
188             case RACE_BALROG:
189                 if (saving_throw(20 + creature_ptr->lev))
190                     return;
191                 break;
192             case RACE_SKELETON:
193             case RACE_ZOMBIE:
194             case RACE_SPECTRE:
195             case RACE_VAMPIRE:
196                 if (saving_throw(10 + creature_ptr->lev))
197                     return;
198                 break;
199             }
200         } else {
201             if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON) {
202                 if (saving_throw(20 + creature_ptr->lev))
203                     return;
204             } else if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD) {
205                 if (saving_throw(10 + creature_ptr->lev))
206                     return;
207             }
208         }
209     } else {
210         msg_print(_("ネクロノミコンを読んで正気を失った!", "Your sanity is shaken by reading the Necronomicon!"));
211     }
212
213     /* 過去の効果無効率再現のため5回saving_throw 実行 */
214     if (saving_throw(creature_ptr->skill_sav - power) && saving_throw(creature_ptr->skill_sav - power) && saving_throw(creature_ptr->skill_sav - power)
215         && saving_throw(creature_ptr->skill_sav - power) && saving_throw(creature_ptr->skill_sav - power)) {
216         return;
217     }
218
219     switch (randint1(22)) {
220     case 1: {
221         if (!(creature_ptr->muta3 & MUT3_MORONIC)) {
222             if ((creature_ptr->stat_use[A_INT] < 4) && (creature_ptr->stat_use[A_WIS] < 4)) {
223                 msg_print(_("あなたは完璧な馬鹿になったような気がした。しかしそれは元々だった。", "You turn into an utter moron!"));
224             } else {
225                 msg_print(_("あなたは完璧な馬鹿になった!", "You turn into an utter moron!"));
226             }
227
228             if (creature_ptr->muta3 & MUT3_HYPER_INT) {
229                 msg_print(_("あなたの脳は生体コンピュータではなくなった。", "Your brain is no longer a living computer."));
230                 creature_ptr->muta3 &= ~(MUT3_HYPER_INT);
231             }
232
233             creature_ptr->muta3 |= MUT3_MORONIC;
234         }
235
236         break;
237     }
238     case 2: {
239         if (!(creature_ptr->muta2 & MUT2_COWARDICE) && !has_resist_fear(creature_ptr)) {
240             msg_print(_("あなたはパラノイアになった!", "You become paranoid!"));
241             if (creature_ptr->muta3 & MUT3_FEARLESS) {
242                 msg_print(_("あなたはもう恐れ知らずではなくなった。", "You are no longer fearless."));
243                 creature_ptr->muta3 &= ~(MUT3_FEARLESS);
244             }
245
246             creature_ptr->muta2 |= MUT2_COWARDICE;
247         }
248
249         break;
250     }
251     case 3: {
252         if (!(creature_ptr->muta2 & MUT2_HALLU) && !has_resist_chaos(creature_ptr)) {
253             msg_print(_("幻覚をひき起こす精神錯乱に陥った!", "You are afflicted by a hallucinatory insanity!"));
254             creature_ptr->muta2 |= MUT2_HALLU;
255         }
256
257         break;
258     }
259     case 4: {
260         if (!(creature_ptr->muta2 & MUT2_BERS_RAGE) && !has_resist_conf(creature_ptr)) {
261             msg_print(_("激烈な感情の発作におそわれるようになった!", "You become subject to fits of berserk rage!"));
262             creature_ptr->muta2 |= MUT2_BERS_RAGE;
263         }
264
265         break;
266     }
267     case 5:
268     case 6:
269     case 7:
270     case 8:
271     case 9:
272     case 10:
273     case 11:
274     case 12: {
275         if (!has_resist_conf(creature_ptr)) {
276             (void)set_confused(creature_ptr, creature_ptr->confused + randint0(4) + 4);
277         }
278
279         if (!has_resist_chaos(creature_ptr) && one_in_(3)) {
280             (void)set_image(creature_ptr, creature_ptr->image + randint0(250) + 150);
281         }
282
283         /* todo いつからかは不明だがreturnとbreakが同時に存在している。どちらがデッドコードか不明瞭なので保留 */
284         return;
285         break;
286     }
287     case 13:
288     case 14:
289     case 15: {
290         if (!has_resist_conf(creature_ptr)) {
291             (void)set_confused(creature_ptr, creature_ptr->confused + randint0(4) + 4);
292         }
293         if (!creature_ptr->free_act) {
294             (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + randint0(4) + 4);
295         }
296         if (!has_resist_chaos(creature_ptr)) {
297             (void)set_image(creature_ptr, creature_ptr->image + randint0(250) + 150);
298         }
299
300         do {
301             (void)do_dec_stat(creature_ptr, A_INT);
302         } while (randint0(100) > creature_ptr->skill_sav && one_in_(2));
303
304         do {
305             (void)do_dec_stat(creature_ptr, A_WIS);
306         } while (randint0(100) > creature_ptr->skill_sav && one_in_(2));
307
308         break;
309     }
310     case 16:
311     case 17: {
312         if (lose_all_info(creature_ptr))
313             msg_print(_("あまりの恐怖に全てのことを忘れてしまった!", "You forget everything in your utmost terror!"));
314         break;
315     }
316     case 18:
317     case 19:
318     case 20:
319     case 21:
320     case 22: {
321         do_dec_stat(creature_ptr, A_INT);
322         do_dec_stat(creature_ptr, A_WIS);
323         break;
324     }
325     default:
326         break;
327     }
328
329     creature_ptr->update |= PU_BONUS;
330     handle_stuff(creature_ptr);
331 }