OSDN Git Service

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