OSDN Git Service

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