OSDN Git Service

Merge remote-tracking branch 'remotes/origin/For2.2.X-Add-Monster' into For2.2.2...
[hengband/hengband.git] / src / cmd / cmd-quaff.c
1 /*!
2  * @file cmd-quaff.c
3  * @brief プレイヤーの飲むコマンド実装
4  * @date 2018/09/07
5  * @details
6  * cmd6.cより分離。
7  */
8
9 #include "angband.h"
10 #include "util.h"
11
12 #include "birth.h"
13 #include "selfinfo.h"
14 #include "object-hook.h"
15 #include "mutation.h"
16 #include "avatar.h"
17 #include "spells.h"
18 #include "spells-status.h"
19 #include "player-effects.h"
20 #include "player-status.h"
21 #include "player-damage.h"
22 #include "player-race.h"
23 #include "player-inventory.h"
24 #include "realm-hex.h"
25 #include "spells-floor.h"
26 #include "object-broken.h"
27 #include "cmd-basic.h"
28 #include "floor.h"
29 #include "objectkind.h"
30 #include "view-mainwindow.h"
31 #include "player-class.h"
32
33 /*!
34  * @brief 薬を飲むコマンドのサブルーチン /
35  * Quaff a potion (from the pack or the floor)
36  * @param creature_ptr プレーヤーへの参照ポインタ
37  * @param item 飲む薬オブジェクトの所持品ID
38  * @return なし
39  */
40 void exe_quaff_potion(player_type *creature_ptr, INVENTORY_IDX item)
41 {
42         bool ident;
43         DEPTH lev;
44         object_type *o_ptr;
45         object_type forge;
46         object_type *q_ptr;
47
48         take_turn(creature_ptr, 100);
49
50         if (creature_ptr->timewalk)
51         {
52                 if (flush_failure) flush();
53                 msg_print(_("瓶から水が流れ出てこない!", "The potion doesn't flow out from the bottle."));
54
55                 sound(SOUND_FAIL);
56                 return;
57         }
58
59         if (music_singing_any(creature_ptr)) stop_singing(creature_ptr);
60         if (hex_spelling_any(creature_ptr))
61         {
62                 if (!hex_spelling(creature_ptr, HEX_INHAIL)) stop_hex_spell_all(creature_ptr);
63         }
64
65         o_ptr = REF_ITEM(creature_ptr, creature_ptr->current_floor_ptr, item);
66         q_ptr = &forge;
67         object_copy(q_ptr, o_ptr);
68
69         /* Single object */
70         q_ptr->number = 1;
71
72         vary_item(creature_ptr, item, -1);
73         sound(SOUND_QUAFF);
74
75
76         /* Not identified yet */
77         ident = FALSE;
78
79         /* Object level */
80         lev = k_info[q_ptr->k_idx].level;
81
82         /* Analyze the potion */
83         if (q_ptr->tval == TV_POTION)
84         {
85                 switch (q_ptr->sval)
86                 {
87                         /* 飲みごたえをオリジナルより細かく表現 */
88                 case SV_POTION_WATER:
89                         msg_print(_("口の中がさっぱりした。", ""));
90                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
91                         ident = TRUE;
92                         break;
93
94                 case SV_POTION_APPLE_JUICE:
95                         msg_print(_("甘くてサッパリとしていて、とてもおいしい。", ""));
96                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
97                         ident = TRUE;
98                         break;
99
100                 case SV_POTION_SLIME_MOLD:
101                         msg_print(_("なんとも不気味な味だ。", ""));
102                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
103                         ident = TRUE;
104                         break;
105
106                 case SV_POTION_SLOWNESS:
107                         if (set_slow(creature_ptr, randint1(25) + 15, FALSE)) ident = TRUE;
108                         break;
109
110                 case SV_POTION_SALT_WATER:
111                         msg_print(_("うぇ!思わず吐いてしまった。", "The potion makes you vomit!"));
112
113                         if (!(PRACE_IS_(creature_ptr, RACE_GOLEM) ||
114                               PRACE_IS_(creature_ptr, RACE_ZOMBIE) ||
115                               PRACE_IS_(creature_ptr, RACE_DEMON) ||
116                               PRACE_IS_(creature_ptr, RACE_ANDROID) ||
117                               PRACE_IS_(creature_ptr, RACE_SPECTRE) ||
118                               (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)))
119                         {
120                                 /* Only living creatures get thirsty */
121                                 (void)set_food(creature_ptr, PY_FOOD_STARVE - 1);
122                         }
123
124                         (void)set_poisoned(creature_ptr, 0);
125                         (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 4);
126                         ident = TRUE;
127                         break;
128
129                 case SV_POTION_POISON:
130                         if (!(creature_ptr->resist_pois || is_oppose_pois(creature_ptr)))
131                         {
132                                 if (set_poisoned(creature_ptr, creature_ptr->poisoned + randint0(15) + 10))
133                                 {
134                                         ident = TRUE;
135                                 }
136                         }
137                         break;
138
139                 case SV_POTION_BLINDNESS:
140                         if (!creature_ptr->resist_blind)
141                         {
142                                 if (set_blind(creature_ptr, creature_ptr->blind + randint0(100) + 100))
143                                 {
144                                         ident = TRUE;
145                                 }
146                         }
147                         break;
148
149                 case SV_POTION_BOOZE:
150                         ident = booze(creature_ptr);
151                         break;
152
153                 case SV_POTION_SLEEP:
154                         if (!creature_ptr->free_act)
155                         {
156                                 msg_print(_("あなたは眠ってしまった。", "You fall asleep."));
157
158                                 if (ironman_nightmare)
159                                 {
160                                         msg_print(_("恐ろしい光景が頭に浮かんできた。", "A horrible vision enters your mind."));
161
162                                         /* Have some nightmares */
163                                         sanity_blast(creature_ptr, NULL, FALSE);
164                                 }
165                                 if (set_paralyzed(creature_ptr, creature_ptr->paralyzed + randint0(4) + 4))
166                                 {
167                                         ident = TRUE;
168                                 }
169                         }
170                         break;
171
172                 case SV_POTION_LOSE_MEMORIES:
173                         if (!creature_ptr->hold_exp && (creature_ptr->exp > 0))
174                         {
175                                 msg_print(_("過去の記憶が薄れていく気がする。", "You feel your memories fade."));
176                                 chg_virtue(creature_ptr, V_KNOWLEDGE, -5);
177
178                                 lose_exp(creature_ptr, creature_ptr->exp / 4);
179                                 ident = TRUE;
180                         }
181                         break;
182
183                 case SV_POTION_RUINATION:
184                         msg_print(_("身も心も弱ってきて、精気が抜けていくようだ。", "Your nerves and muscles feel weak and lifeless!"));
185                         take_hit(creature_ptr, DAMAGE_LOSELIFE, damroll(10, 10), _("破滅の薬", "a potion of Ruination"), -1);
186
187                         (void)dec_stat(creature_ptr, A_DEX, 25, TRUE);
188                         (void)dec_stat(creature_ptr, A_WIS, 25, TRUE);
189                         (void)dec_stat(creature_ptr, A_CON, 25, TRUE);
190                         (void)dec_stat(creature_ptr, A_STR, 25, TRUE);
191                         (void)dec_stat(creature_ptr, A_CHR, 25, TRUE);
192                         (void)dec_stat(creature_ptr, A_INT, 25, TRUE);
193                         ident = TRUE;
194                         break;
195
196                 case SV_POTION_DEC_STR:
197                         if (do_dec_stat(creature_ptr, A_STR)) ident = TRUE;
198                         break;
199
200                 case SV_POTION_DEC_INT:
201                         if (do_dec_stat(creature_ptr, A_INT)) ident = TRUE;
202                         break;
203
204                 case SV_POTION_DEC_WIS:
205                         if (do_dec_stat(creature_ptr, A_WIS)) ident = TRUE;
206                         break;
207
208                 case SV_POTION_DEC_DEX:
209                         if (do_dec_stat(creature_ptr, A_DEX)) ident = TRUE;
210                         break;
211
212                 case SV_POTION_DEC_CON:
213                         if (do_dec_stat(creature_ptr, A_CON)) ident = TRUE;
214                         break;
215
216                 case SV_POTION_DEC_CHR:
217                         if (do_dec_stat(creature_ptr, A_CHR)) ident = TRUE;
218                         break;
219
220                 case SV_POTION_DETONATIONS:
221                         ident = detonation(creature_ptr);
222                         break;
223
224                 case SV_POTION_DEATH:
225                         chg_virtue(creature_ptr, V_VITALITY, -1);
226                         chg_virtue(creature_ptr, V_UNLIFE, 5);
227                         msg_print(_("死の予感が体中を駆けめぐった。", "A feeling of Death flows through your body."));
228                         take_hit(creature_ptr, DAMAGE_LOSELIFE, 5000, _("死の薬", "a potion of Death"), -1);
229                         ident = TRUE;
230                         break;
231
232                 case SV_POTION_INFRAVISION:
233                         if (set_tim_infra(creature_ptr, creature_ptr->tim_infra + 100 + randint1(100), FALSE))
234                         {
235                                 ident = TRUE;
236                         }
237                         break;
238
239                 case SV_POTION_DETECT_INVIS:
240                         if (set_tim_invis(creature_ptr, creature_ptr->tim_invis + 12 + randint1(12), FALSE))
241                         {
242                                 ident = TRUE;
243                         }
244                         break;
245
246                 case SV_POTION_SLOW_POISON:
247                         if (set_poisoned(creature_ptr, creature_ptr->poisoned / 2)) ident = TRUE;
248                         break;
249
250                 case SV_POTION_CURE_POISON:
251                         if (set_poisoned(creature_ptr, 0)) ident = TRUE;
252                         break;
253
254                 case SV_POTION_BOLDNESS:
255                         if (set_afraid(creature_ptr, 0)) ident = TRUE;
256                         break;
257
258                 case SV_POTION_SPEED:
259                         if (!creature_ptr->fast)
260                         {
261                                 if (set_fast(creature_ptr, randint1(25) + 15, FALSE)) ident = TRUE;
262                         }
263                         else
264                         {
265                                 (void)set_fast(creature_ptr, creature_ptr->fast + 5, FALSE);
266                         }
267                         break;
268
269                 case SV_POTION_RESIST_HEAT:
270                         if (set_oppose_fire(creature_ptr, creature_ptr->oppose_fire + randint1(10) + 10, FALSE))
271                         {
272                                 ident = TRUE;
273                         }
274                         break;
275
276                 case SV_POTION_RESIST_COLD:
277                         if (set_oppose_cold(creature_ptr, creature_ptr->oppose_cold + randint1(10) + 10, FALSE))
278                         {
279                                 ident = TRUE;
280                         }
281                         break;
282
283                 case SV_POTION_HEROISM:
284                         ident = heroism(creature_ptr, 25);
285                         break;
286
287                 case SV_POTION_BESERK_STRENGTH:
288                         ident = berserk(creature_ptr, randint1(25) + 25);
289                         break;
290
291                 case SV_POTION_CURE_LIGHT:
292                         ident = cure_light_wounds(creature_ptr, 2, 8);
293                         break;
294
295                 case SV_POTION_CURE_SERIOUS:
296                         ident = cure_serious_wounds(creature_ptr, 4, 8);
297                         break;
298
299                 case SV_POTION_CURE_CRITICAL:
300                         ident = cure_critical_wounds(creature_ptr, damroll(6, 8));
301                         break;
302
303                 case SV_POTION_HEALING:
304                         ident = cure_critical_wounds(creature_ptr, 300);
305                         break;
306
307                 case SV_POTION_STAR_HEALING:
308                         ident = cure_critical_wounds(creature_ptr, 1200);
309                         break;
310
311                 case SV_POTION_LIFE:
312                         ident = life_stream(creature_ptr, TRUE, TRUE);
313                         break;
314
315                 case SV_POTION_RESTORE_MANA:
316                         ident = restore_mana(creature_ptr, TRUE);
317                         break;
318
319                 case SV_POTION_RESTORE_EXP:
320                         if (restore_level(creature_ptr)) ident = TRUE;
321                         break;
322
323                 case SV_POTION_RES_STR:
324                         if (do_res_stat(creature_ptr, A_STR)) ident = TRUE;
325                         break;
326
327                 case SV_POTION_RES_INT:
328                         if (do_res_stat(creature_ptr, A_INT)) ident = TRUE;
329                         break;
330
331                 case SV_POTION_RES_WIS:
332                         if (do_res_stat(creature_ptr, A_WIS)) ident = TRUE;
333                         break;
334
335                 case SV_POTION_RES_DEX:
336                         if (do_res_stat(creature_ptr, A_DEX)) ident = TRUE;
337                         break;
338
339                 case SV_POTION_RES_CON:
340                         if (do_res_stat(creature_ptr, A_CON)) ident = TRUE;
341                         break;
342
343                 case SV_POTION_RES_CHR:
344                         if (do_res_stat(creature_ptr, A_CHR)) ident = TRUE;
345                         break;
346
347                 case SV_POTION_INC_STR:
348                         if (do_inc_stat(creature_ptr, A_STR)) ident = TRUE;
349                         break;
350
351                 case SV_POTION_INC_INT:
352                         if (do_inc_stat(creature_ptr, A_INT)) ident = TRUE;
353                         break;
354
355                 case SV_POTION_INC_WIS:
356                         if (do_inc_stat(creature_ptr, A_WIS)) ident = TRUE;
357                         break;
358
359                 case SV_POTION_INC_DEX:
360                         if (do_inc_stat(creature_ptr, A_DEX)) ident = TRUE;
361                         break;
362
363                 case SV_POTION_INC_CON:
364                         if (do_inc_stat(creature_ptr, A_CON)) ident = TRUE;
365                         break;
366
367                 case SV_POTION_INC_CHR:
368                         if (do_inc_stat(creature_ptr, A_CHR)) ident = TRUE;
369                         break;
370
371                 case SV_POTION_AUGMENTATION:
372                         if (do_inc_stat(creature_ptr, A_STR)) ident = TRUE;
373                         if (do_inc_stat(creature_ptr, A_INT)) ident = TRUE;
374                         if (do_inc_stat(creature_ptr, A_WIS)) ident = TRUE;
375                         if (do_inc_stat(creature_ptr, A_DEX)) ident = TRUE;
376                         if (do_inc_stat(creature_ptr, A_CON)) ident = TRUE;
377                         if (do_inc_stat(creature_ptr, A_CHR)) ident = TRUE;
378                         break;
379
380                 case SV_POTION_ENLIGHTENMENT:
381                         msg_print(_("自分の置かれている状況が脳裏に浮かんできた...", "An image of your surroundings forms in your mind..."));
382                         chg_virtue(creature_ptr, V_KNOWLEDGE, 1);
383                         chg_virtue(creature_ptr, V_ENLIGHTEN, 1);
384                         wiz_lite(creature_ptr, FALSE);
385                         ident = TRUE;
386                         break;
387
388                 case SV_POTION_STAR_ENLIGHTENMENT:
389                         msg_print(_("更なる啓蒙を感じた...", "You begin to feel more enlightened..."));
390                         chg_virtue(creature_ptr, V_KNOWLEDGE, 1);
391                         chg_virtue(creature_ptr, V_ENLIGHTEN, 2);
392                         msg_print(NULL);
393                         wiz_lite(creature_ptr, FALSE);
394                         (void)do_inc_stat(creature_ptr, A_INT);
395                         (void)do_inc_stat(creature_ptr, A_WIS);
396                         (void)detect_traps(creature_ptr, DETECT_RAD_DEFAULT, TRUE);
397                         (void)detect_doors(creature_ptr, DETECT_RAD_DEFAULT);
398                         (void)detect_stairs(creature_ptr, DETECT_RAD_DEFAULT);
399                         (void)detect_treasure(creature_ptr, DETECT_RAD_DEFAULT);
400                         (void)detect_objects_gold(creature_ptr, DETECT_RAD_DEFAULT);
401                         (void)detect_objects_normal(creature_ptr, DETECT_RAD_DEFAULT);
402                         identify_pack(creature_ptr);
403                         self_knowledge(creature_ptr);
404                         ident = TRUE;
405                         break;
406
407                 case SV_POTION_SELF_KNOWLEDGE:
408                         msg_print(_("自分自身のことが少しは分かった気がする...", "You begin to know yourself a little better..."));
409                         msg_print(NULL);
410                         self_knowledge(creature_ptr);
411                         ident = TRUE;
412                         break;
413
414                 case SV_POTION_EXPERIENCE:
415                         if (creature_ptr->prace == RACE_ANDROID) break;
416                         chg_virtue(creature_ptr, V_ENLIGHTEN, 1);
417                         if (creature_ptr->exp < PY_MAX_EXP)
418                         {
419                                 EXP ee = (creature_ptr->exp / 2) + 10;
420                                 if (ee > 100000L) ee = 100000L;
421                                 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
422                                 gain_exp(creature_ptr, ee);
423                                 ident = TRUE;
424                         }
425                         break;
426
427                 case SV_POTION_RESISTANCE:
428                         (void)set_oppose_acid(creature_ptr, creature_ptr->oppose_acid + randint1(20) + 20, FALSE);
429                         (void)set_oppose_elec(creature_ptr, creature_ptr->oppose_elec + randint1(20) + 20, FALSE);
430                         (void)set_oppose_fire(creature_ptr, creature_ptr->oppose_fire + randint1(20) + 20, FALSE);
431                         (void)set_oppose_cold(creature_ptr, creature_ptr->oppose_cold + randint1(20) + 20, FALSE);
432                         (void)set_oppose_pois(creature_ptr, creature_ptr->oppose_pois + randint1(20) + 20, FALSE);
433                         ident = TRUE;
434                         break;
435
436                 case SV_POTION_CURING:
437                         if (true_healing(creature_ptr, 50)) ident = TRUE;
438                         break;
439
440                 case SV_POTION_INVULNERABILITY:
441                         (void)set_invuln(creature_ptr, creature_ptr->invuln + randint1(4) + 4, FALSE);
442                         ident = TRUE;
443                         break;
444
445                 case SV_POTION_NEW_LIFE:
446                         roll_hitdice(creature_ptr, 0L);
447                         get_max_stats(creature_ptr);
448                         creature_ptr->update |= PU_BONUS;
449                         lose_all_mutations(creature_ptr);
450                         ident = TRUE;
451                         break;
452
453                 case SV_POTION_NEO_TSUYOSHI:
454                         (void)set_image(creature_ptr, 0);
455                         (void)set_tsuyoshi(creature_ptr, creature_ptr->tsuyoshi + randint1(100) + 100, FALSE);
456                         ident = TRUE;
457                         break;
458
459                 case SV_POTION_TSUYOSHI:
460                         msg_print(_("「オクレ兄さん!」", "Brother OKURE!"));
461                         msg_print(NULL);
462                         creature_ptr->tsuyoshi = 1;
463                         (void)set_tsuyoshi(creature_ptr, 0, TRUE);
464                         if (!creature_ptr->resist_chaos)
465                         {
466                                 (void)set_image(creature_ptr, 50 + randint1(50));
467                         }
468                         ident = TRUE;
469                         break;
470                 
471                 case SV_POTION_POLYMORPH:
472                         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && one_in_(23))
473                         {
474                                 lose_all_mutations(creature_ptr);
475                         }
476                         else
477                         {
478                                 do
479                                 {
480                                         if (one_in_(2))
481                                         {
482                                                 if(gain_mutation(creature_ptr, 0)) ident = TRUE;
483                                         }
484                                         else if (lose_mutation(creature_ptr, 0)) ident = TRUE;
485                                 } while(!ident || one_in_(2));
486                         }
487                         break;
488                 }
489         }
490
491         if (PRACE_IS_(creature_ptr, RACE_SKELETON))
492         {
493                 msg_print(_("液体の一部はあなたのアゴを素通りして落ちた!", "Some of the fluid falls through your jaws!"));
494                 (void)potion_smash_effect(creature_ptr, 0, creature_ptr->y, creature_ptr->x, q_ptr->k_idx);
495         }
496         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
497
498         if (!(object_is_aware(q_ptr)))
499         {
500                 chg_virtue(creature_ptr, V_PATIENCE, -1);
501                 chg_virtue(creature_ptr, V_CHANCE, 1);
502                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
503         }
504
505         /* The item has been tried */
506         object_tried(q_ptr);
507
508         /* An identification was made */
509         if (ident && !object_is_aware(q_ptr))
510         {
511                 object_aware(creature_ptr, q_ptr);
512                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
513         }
514
515         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
516
517         /* Potions can feed the player */
518         switch (creature_ptr->mimic_form)
519         {
520         case MIMIC_NONE:
521                 switch (creature_ptr->prace)
522                 {
523                         case RACE_VAMPIRE:
524                                 (void)set_food(creature_ptr, creature_ptr->food + (q_ptr->pval / 10));
525                                 break;
526                         case RACE_SKELETON:
527                                 /* Do nothing */
528                                 break;
529                         case RACE_GOLEM:
530                         case RACE_ZOMBIE:
531                         case RACE_DEMON:
532                         case RACE_SPECTRE:
533                                 set_food(creature_ptr, creature_ptr->food + ((q_ptr->pval) / 20));
534                                 break;
535                         case RACE_ANDROID:
536                                 if (q_ptr->tval == TV_FLASK)
537                                 {
538                                         msg_print(_("オイルを補給した。", "You replenish yourself with the oil."));
539                                         set_food(creature_ptr, creature_ptr->food + 5000);
540                                 }
541                                 else
542                                 {
543                                         set_food(creature_ptr, creature_ptr->food + ((q_ptr->pval) / 20));
544                                 }
545                                 break;
546                         case RACE_ENT:
547                                 msg_print(_("水分を取り込んだ。", "You are moistened."));
548                                 set_food(creature_ptr, MIN(creature_ptr->food + q_ptr->pval + MAX(0, q_ptr->pval * 10) + 2000, PY_FOOD_MAX - 1));
549                                 break;
550                         default:
551                                 (void)set_food(creature_ptr, creature_ptr->food + q_ptr->pval);
552                                 break;
553                 }
554                 break;
555         case MIMIC_DEMON:
556         case MIMIC_DEMON_LORD:
557                 set_food(creature_ptr, creature_ptr->food + ((q_ptr->pval) / 20));
558                 break;
559         case MIMIC_VAMPIRE:
560                 (void)set_food(creature_ptr, creature_ptr->food + (q_ptr->pval / 10));
561                 break;
562         default:
563                 (void)set_food(creature_ptr, creature_ptr->food + q_ptr->pval);
564                 break;
565         }
566 }
567
568
569
570 /*!
571  * @brief 薬を飲むコマンドのメインルーチン /
572  * Quaff some potion (from the pack or floor)
573  * @return なし
574  */
575 void do_cmd_quaff_potion(player_type *creature_ptr)
576 {
577         OBJECT_IDX item;
578         concptr q, s;
579
580         if (creature_ptr->wild_mode)
581         {
582                 return;
583         }
584
585         if (cmd_limit_arena(creature_ptr)) return;
586
587         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
588         {
589                 set_action(creature_ptr, ACTION_NONE);
590         }
591
592         /* Restrict choices to potions */
593         item_tester_hook = item_tester_hook_quaff;
594
595         q = _("どの薬を飲みますか? ", "Quaff which potion? ");
596         s = _("飲める薬がない。", "You have no potions to quaff.");
597
598         if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0)) return;
599
600         /* Quaff the potion */
601         exe_quaff_potion(creature_ptr, item);
602 }