OSDN Git Service

f860f17377e1f6b5351e4660b3060c0b66dd06e4
[hengband/hengband.git] / src / mutation / mutation-processor.c
1 #include "mutation/mutation-processor.h"
2 #include "core/disturbance.h"
3 #include "core/hp-mp-processor.h"
4 #include "core/player-redraw-types.h"
5 #include "grid/grid.h"
6 #include "inventory/inventory-object.h"
7 #include "inventory/inventory-slot-types.h"
8 #include "io/targeting.h"
9 #include "monster-floor/monster-summon.h"
10 #include "monster-floor/place-monster-types.h"
11 #include "monster-race/monster-race.h"
12 #include "monster/monster-status.h"
13 #include "mutation/mutation-flag-types.h"
14 #include "mutation/mutation.h"
15 #include "object-hook/hook-checker.h"
16 #include "object-hook/hook-enchant.h"
17 #include "object/lite-processor.h"
18 #include "player/digestion-processor.h"
19 #include "player/player-damage.h"
20 #include "spell-kind/spells-floor.h"
21 #include "spell-kind/spells-launcher.h"
22 #include "spell-kind/spells-lite.h"
23 #include "spell-kind/spells-sight.h"
24 #include "spell-kind/spells-teleport.h"
25 #include "spell-kind/spells-world.h"
26 #include "spell-realm/spells-hex.h"
27 #include "spell/spell-types.h"
28 #include "spell/spells-summon.h"
29 #include "status/bad-status-setter.h"
30 #include "status/base-status.h"
31 #include "status/body-improvement.h"
32 #include "status/buff-setter.h"
33 #include "status/shape-changer.h"
34 #include "status/sight-setter.h"
35 #include "store/store-owners.h"
36 #include "store/store-util.h"
37 #include "store/store.h"
38 #include "system/floor-type-definition.h"
39 #include "term/screen-processor.h"
40 #include "view/display-messages.h"
41
42 /*!
43  * @brief 10ゲームターンが進行するごとに突然変異の発動判定を行う処理
44  * / Handle mutation effects once every 10 game turns
45  * @return なし
46  */
47 void process_world_aux_mutation(player_type *creature_ptr)
48 {
49     if (!creature_ptr->muta2 || creature_ptr->phase_out || creature_ptr->wild_mode)
50         return;
51
52     if ((creature_ptr->muta2 & MUT2_BERS_RAGE) && one_in_(3000)) {
53         disturb(creature_ptr, FALSE, TRUE);
54         msg_print(_("ウガァァア!", "RAAAAGHH!"));
55         msg_print(_("激怒の発作に襲われた!", "You feel a fit of rage coming over you!"));
56         (void)set_shero(creature_ptr, 10 + randint1(creature_ptr->lev), FALSE);
57         (void)set_afraid(creature_ptr, 0);
58     }
59
60     if ((creature_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13)) {
61         if (!creature_ptr->resist_fear) {
62             disturb(creature_ptr, FALSE, TRUE);
63             msg_print(_("とても暗い... とても恐い!", "It's so dark... so scary!"));
64             set_afraid(creature_ptr, creature_ptr->afraid + 13 + randint1(26));
65         }
66     }
67
68     if ((creature_ptr->muta2 & MUT2_RTELEPORT) && (randint1(5000) == 88)) {
69         if (!creature_ptr->resist_nexus && !(creature_ptr->muta1 & MUT1_VTELEPORT) && !creature_ptr->anti_tele) {
70             disturb(creature_ptr, FALSE, TRUE);
71             msg_print(_("あなたの位置は突然ひじょうに不確定になった...", "Your position suddenly seems very uncertain..."));
72             msg_print(NULL);
73             teleport_player(creature_ptr, 40, TELEPORT_PASSIVE);
74         }
75     }
76
77     if ((creature_ptr->muta2 & MUT2_ALCOHOL) && (randint1(6400) == 321)) {
78         if (!creature_ptr->resist_conf && !creature_ptr->resist_chaos) {
79             disturb(creature_ptr, FALSE, TRUE);
80             creature_ptr->redraw |= PR_EXTRA;
81             msg_print(_("いひきがもーろーとひてきたきがふる...ヒック!", "You feel a SSSCHtupor cOmINg over yOu... *HIC*!"));
82         }
83
84         if (!creature_ptr->resist_conf) {
85             (void)set_confused(creature_ptr, creature_ptr->confused + randint0(20) + 15);
86         }
87
88         if (!creature_ptr->resist_chaos) {
89             if (one_in_(20)) {
90                 msg_print(NULL);
91                 if (one_in_(3))
92                     lose_all_info(creature_ptr);
93                 else
94                     wiz_dark(creature_ptr);
95                 (void)teleport_player_aux(creature_ptr, 100, FALSE, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
96                 wiz_dark(creature_ptr);
97                 msg_print(_("あなたは見知らぬ場所で目が醒めた...頭が痛い。", "You wake up somewhere with a sore head..."));
98                 msg_print(_("何も覚えていない。どうやってここに来たかも分からない!", "You can't remember a thing or how you got here!"));
99             } else {
100                 if (one_in_(3)) {
101                     msg_print(_("き~れいなちょおちょらとんれいる~", "Thishcischs GooDSChtuff!"));
102                     (void)set_image(creature_ptr, creature_ptr->image + randint0(150) + 150);
103                 }
104             }
105         }
106     }
107
108     if ((creature_ptr->muta2 & MUT2_HALLU) && (randint1(6400) == 42)) {
109         if (!creature_ptr->resist_chaos) {
110             disturb(creature_ptr, FALSE, TRUE);
111             creature_ptr->redraw |= PR_EXTRA;
112             (void)set_image(creature_ptr, creature_ptr->image + randint0(50) + 20);
113         }
114     }
115
116     if ((creature_ptr->muta2 & MUT2_FLATULENT) && (randint1(3000) == 13)) {
117         disturb(creature_ptr, FALSE, TRUE);
118         msg_print(_("ブゥーーッ!おっと。", "BRRAAAP! Oops."));
119         msg_print(NULL);
120         fire_ball(creature_ptr, GF_POIS, 0, creature_ptr->lev, 3);
121     }
122
123     if ((creature_ptr->muta2 & MUT2_PROD_MANA) && !creature_ptr->anti_magic && one_in_(9000)) {
124         int dire = 0;
125         disturb(creature_ptr, FALSE, TRUE);
126         msg_print(_("魔法のエネルギーが突然あなたの中に流れ込んできた!エネルギーを解放しなければならない!",
127             "Magical energy flows through you! You must release it!"));
128
129         flush();
130         msg_print(NULL);
131         (void)get_hack_dir(creature_ptr, &dire);
132         fire_ball(creature_ptr, GF_MANA, dire, creature_ptr->lev * 2, 3);
133     }
134
135     if ((creature_ptr->muta2 & MUT2_ATT_DEMON) && !creature_ptr->anti_magic && (randint1(6666) == 666)) {
136         bool pet = one_in_(6);
137         BIT_FLAGS mode = PM_ALLOW_GROUP;
138
139         if (pet)
140             mode |= PM_FORCE_PET;
141         else
142             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
143
144         if (summon_specific(creature_ptr, (pet ? -1 : 0), creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_DEMON, mode)) {
145             msg_print(_("あなたはデーモンを引き寄せた!", "You have attracted a demon!"));
146             disturb(creature_ptr, FALSE, TRUE);
147         }
148     }
149
150     if ((creature_ptr->muta2 & MUT2_SPEED_FLUX) && one_in_(6000)) {
151         disturb(creature_ptr, FALSE, TRUE);
152         if (one_in_(2)) {
153             msg_print(_("精力的でなくなった気がする。", "You feel less energetic."));
154
155             if (creature_ptr->fast > 0) {
156                 set_fast(creature_ptr, 0, TRUE);
157             } else {
158                 set_slow(creature_ptr, randint1(30) + 10, FALSE);
159             }
160         } else {
161             msg_print(_("精力的になった気がする。", "You feel more energetic."));
162
163             if (creature_ptr->slow > 0) {
164                 set_slow(creature_ptr, 0, TRUE);
165             } else {
166                 set_fast(creature_ptr, randint1(30) + 10, FALSE);
167             }
168         }
169         msg_print(NULL);
170     }
171     if ((creature_ptr->muta2 & MUT2_BANISH_ALL) && one_in_(9000)) {
172         disturb(creature_ptr, FALSE, TRUE);
173         msg_print(_("突然ほとんど孤独になった気がする。", "You suddenly feel almost lonely."));
174
175         banish_monsters(creature_ptr, 100);
176         if (!creature_ptr->current_floor_ptr->dun_level && creature_ptr->town_num) {
177             int n;
178             do {
179                 n = randint0(MAX_STORES);
180             } while ((n == STORE_HOME) || (n == STORE_MUSEUM));
181
182             msg_print(_("店の主人が丘に向かって走っている!", "You see one of the shopkeepers running for the hills!"));
183             store_shuffle(creature_ptr, n);
184         }
185         msg_print(NULL);
186     }
187
188     if ((creature_ptr->muta2 & MUT2_EAT_LIGHT) && one_in_(3000)) {
189         object_type *o_ptr;
190
191         msg_print(_("影につつまれた。", "A shadow passes over you."));
192         msg_print(NULL);
193
194         if ((creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) {
195             hp_player(creature_ptr, 10);
196         }
197
198         o_ptr = &creature_ptr->inventory_list[INVEN_LITE];
199
200         if (o_ptr->tval == TV_LITE) {
201             if (!object_is_fixed_artifact(o_ptr) && (o_ptr->xtra4 > 0)) {
202                 hp_player(creature_ptr, o_ptr->xtra4 / 20);
203                 o_ptr->xtra4 /= 2;
204                 msg_print(_("光源からエネルギーを吸収した!", "You absorb energy from your light!"));
205                 notice_lite_change(creature_ptr, o_ptr);
206             }
207         }
208
209         /*
210          * Unlite the area (radius 10) around player and
211          * do 50 points damage to every affected monster
212          */
213         unlite_area(creature_ptr, 50, 10);
214     }
215
216     if ((creature_ptr->muta2 & MUT2_ATT_ANIMAL) && !creature_ptr->anti_magic && one_in_(7000)) {
217         bool pet = one_in_(3);
218         BIT_FLAGS mode = PM_ALLOW_GROUP;
219
220         if (pet)
221             mode |= PM_FORCE_PET;
222         else
223             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
224
225         if (summon_specific(creature_ptr, (pet ? -1 : 0), creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_ANIMAL, mode)) {
226             msg_print(_("動物を引き寄せた!", "You have attracted an animal!"));
227             disturb(creature_ptr, FALSE, TRUE);
228         }
229     }
230
231     if ((creature_ptr->muta2 & MUT2_RAW_CHAOS) && !creature_ptr->anti_magic && one_in_(8000)) {
232         disturb(creature_ptr, FALSE, TRUE);
233         msg_print(_("周りの空間が歪んでいる気がする!", "You feel the world warping around you!"));
234
235         msg_print(NULL);
236         fire_ball(creature_ptr, GF_CHAOS, 0, creature_ptr->lev, 8);
237     }
238
239     if ((creature_ptr->muta2 & MUT2_NORMALITY) && one_in_(5000)) {
240         if (!lose_mutation(creature_ptr, 0))
241             msg_print(_("奇妙なくらい普通になった気がする。", "You feel oddly normal."));
242     }
243
244     if ((creature_ptr->muta2 & MUT2_WRAITH) && !creature_ptr->anti_magic && one_in_(3000)) {
245         disturb(creature_ptr, FALSE, TRUE);
246         msg_print(_("非物質化した!", "You feel insubstantial!"));
247
248         msg_print(NULL);
249         set_wraith_form(creature_ptr, randint1(creature_ptr->lev / 2) + (creature_ptr->lev / 2), FALSE);
250     }
251
252     if ((creature_ptr->muta2 & MUT2_POLY_WOUND) && one_in_(3000)) {
253         do_poly_wounds(creature_ptr);
254     }
255
256     if ((creature_ptr->muta2 & MUT2_WASTING) && one_in_(3000)) {
257         int which_stat = randint0(A_MAX);
258         int sustained = FALSE;
259
260         switch (which_stat) {
261         case A_STR:
262             if (creature_ptr->sustain_str)
263                 sustained = TRUE;
264             break;
265         case A_INT:
266             if (creature_ptr->sustain_int)
267                 sustained = TRUE;
268             break;
269         case A_WIS:
270             if (creature_ptr->sustain_wis)
271                 sustained = TRUE;
272             break;
273         case A_DEX:
274             if (creature_ptr->sustain_dex)
275                 sustained = TRUE;
276             break;
277         case A_CON:
278             if (creature_ptr->sustain_con)
279                 sustained = TRUE;
280             break;
281         case A_CHR:
282             if (creature_ptr->sustain_chr)
283                 sustained = TRUE;
284             break;
285         default:
286             msg_print(_("不正な状態!", "Invalid stat chosen!"));
287             sustained = TRUE;
288         }
289
290         if (!sustained) {
291             disturb(creature_ptr, FALSE, TRUE);
292             msg_print(_("自分が衰弱していくのが分かる!", "You can feel yourself wasting away!"));
293             msg_print(NULL);
294             (void)dec_stat(creature_ptr, which_stat, randint1(6) + 6, one_in_(3));
295         }
296     }
297
298     if ((creature_ptr->muta2 & MUT2_ATT_DRAGON) && !creature_ptr->anti_magic && one_in_(3000)) {
299         bool pet = one_in_(5);
300         BIT_FLAGS mode = PM_ALLOW_GROUP;
301
302         if (pet)
303             mode |= PM_FORCE_PET;
304         else
305             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
306
307         if (summon_specific(creature_ptr, (pet ? -1 : 0), creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_DRAGON, mode)) {
308             msg_print(_("ドラゴンを引き寄せた!", "You have attracted a dragon!"));
309             disturb(creature_ptr, FALSE, TRUE);
310         }
311     }
312
313     if ((creature_ptr->muta2 & MUT2_WEIRD_MIND) && !creature_ptr->anti_magic && one_in_(3000)) {
314         if (creature_ptr->tim_esp > 0) {
315             msg_print(_("精神にもやがかかった!", "Your mind feels cloudy!"));
316             set_tim_esp(creature_ptr, 0, TRUE);
317         } else {
318             msg_print(_("精神が広がった!", "Your mind expands!"));
319             set_tim_esp(creature_ptr, creature_ptr->lev, FALSE);
320         }
321     }
322
323     if ((creature_ptr->muta2 & MUT2_NAUSEA) && !creature_ptr->slow_digest && one_in_(9000)) {
324         disturb(creature_ptr, FALSE, TRUE);
325         msg_print(_("胃が痙攣し、食事を失った!", "Your stomach roils, and you lose your lunch!"));
326         msg_print(NULL);
327         set_food(creature_ptr, PY_FOOD_WEAK);
328         if (music_singing_any(creature_ptr))
329             stop_singing(creature_ptr);
330         if (hex_spelling_any(creature_ptr))
331             stop_hex_spell_all(creature_ptr);
332     }
333
334     if ((creature_ptr->muta2 & MUT2_WALK_SHAD) && !creature_ptr->anti_magic && one_in_(12000) && !creature_ptr->current_floor_ptr->inside_arena) {
335         reserve_alter_reality(creature_ptr);
336     }
337
338     if ((creature_ptr->muta2 & MUT2_WARNING) && one_in_(1000)) {
339         int danger_amount = 0;
340         for (MONSTER_IDX monster = 0; monster < creature_ptr->current_floor_ptr->m_max; monster++) {
341             monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[monster];
342             monster_race *r_ptr = &r_info[m_ptr->r_idx];
343             if (!monster_is_valid(m_ptr))
344                 continue;
345
346             if (r_ptr->level >= creature_ptr->lev) {
347                 danger_amount += r_ptr->level - creature_ptr->lev + 1;
348             }
349         }
350
351         if (danger_amount > 100)
352             msg_print(_("非常に恐ろしい気がする!", "You feel utterly terrified!"));
353         else if (danger_amount > 50)
354             msg_print(_("恐ろしい気がする!", "You feel terrified!"));
355         else if (danger_amount > 20)
356             msg_print(_("非常に心配な気がする!", "You feel very worried!"));
357         else if (danger_amount > 10)
358             msg_print(_("心配な気がする!", "You feel paranoid!"));
359         else if (danger_amount > 5)
360             msg_print(_("ほとんど安全な気がする。", "You feel almost safe."));
361         else
362             msg_print(_("寂しい気がする。", "You feel lonely."));
363     }
364
365     if ((creature_ptr->muta2 & MUT2_INVULN) && !creature_ptr->anti_magic && one_in_(5000)) {
366         disturb(creature_ptr, FALSE, TRUE);
367         msg_print(_("無敵な気がする!", "You feel invincible!"));
368         msg_print(NULL);
369         (void)set_invuln(creature_ptr, randint1(8) + 8, FALSE);
370     }
371
372     if ((creature_ptr->muta2 & MUT2_SP_TO_HP) && one_in_(2000)) {
373         MANA_POINT wounds = (MANA_POINT)(creature_ptr->mhp - creature_ptr->chp);
374
375         if (wounds > 0) {
376             HIT_POINT healing = creature_ptr->csp;
377             if (healing > wounds)
378                 healing = wounds;
379
380             hp_player(creature_ptr, healing);
381             creature_ptr->csp -= healing;
382             creature_ptr->redraw |= (PR_HP | PR_MANA);
383         }
384     }
385
386     if ((creature_ptr->muta2 & MUT2_HP_TO_SP) && !creature_ptr->anti_magic && one_in_(4000)) {
387         HIT_POINT wounds = (HIT_POINT)(creature_ptr->msp - creature_ptr->csp);
388
389         if (wounds > 0) {
390             HIT_POINT healing = creature_ptr->chp;
391             if (healing > wounds)
392                 healing = wounds;
393
394             creature_ptr->csp += healing;
395             creature_ptr->redraw |= (PR_HP | PR_MANA);
396             take_hit(creature_ptr, DAMAGE_LOSELIFE, healing, _("頭に昇った血", "blood rushing to the head"), -1);
397         }
398     }
399
400     if ((creature_ptr->muta2 & MUT2_DISARM) && one_in_(10000)) {
401         disturb(creature_ptr, FALSE, TRUE);
402         msg_print(_("足がもつれて転んだ!", "You trip over your own feet!"));
403         take_hit(creature_ptr, DAMAGE_NOESCAPE, randint1(creature_ptr->wt / 6), _("転倒", "tripping"), -1);
404         drop_weapons(creature_ptr);
405     }
406 }
407
408 bool drop_weapons(player_type *creature_ptr)
409 {
410     INVENTORY_IDX slot = 0;
411     object_type *o_ptr = NULL;
412
413     if (creature_ptr->wild_mode)
414         return FALSE;
415
416     msg_print(NULL);
417     if (has_melee_weapon(creature_ptr, INVEN_RARM)) {
418         slot = INVEN_RARM;
419         o_ptr = &creature_ptr->inventory_list[INVEN_RARM];
420
421         if (has_melee_weapon(creature_ptr, INVEN_LARM) && one_in_(2)) {
422             o_ptr = &creature_ptr->inventory_list[INVEN_LARM];
423             slot = INVEN_LARM;
424         }
425     } else if (has_melee_weapon(creature_ptr, INVEN_LARM)) {
426         o_ptr = &creature_ptr->inventory_list[INVEN_LARM];
427         slot = INVEN_LARM;
428     }
429
430     if (slot && !object_is_cursed(o_ptr)) {
431         msg_print(_("武器を落としてしまった!", "You drop your weapon!"));
432         drop_from_inventory(creature_ptr, slot, 1);
433         return TRUE;
434     }
435
436     return FALSE;
437 }