OSDN Git Service

Replaced "spelling" with "spell casting" in English name for high mage innate ability.
[hengbandforosx/hengbandosx.git] / src / cmd-eat.c
1 /*!
2  * @file cmd-eat.c
3  * @brief プレイヤーの食べるコマンド実装
4  * @date 2018/09/07
5  * @details
6  * cmd6.cより分離。
7  */
8
9
10 #include "angband.h"
11 #include "object-hook.h"
12 #include "avatar.h"
13 #include "spells-status.h"
14 #include "realm-hex.h"
15 #include "player-status.h"
16
17 /*!
18  * @brief 食料を食べるコマンドのサブルーチン
19  * @param item 食べるオブジェクトの所持品ID
20  * @return なし
21  */
22 void do_cmd_eat_food_aux(INVENTORY_IDX item)
23 {
24         int ident, lev;
25         BIT_FLAGS inventory_flags;
26         object_type *o_ptr;
27
28         if (music_singing_any()) stop_singing(p_ptr);
29         if (hex_spelling_any()) stop_hex_spell_all();
30
31         /* Get the item (in the pack) */
32         if (item >= 0)
33         {
34                 o_ptr = &inventory[item];
35         }
36
37         /* Get the item (on the floor) */
38         else
39         {
40                 o_ptr = &current_floor_ptr->o_list[0 - item];
41         }
42
43         sound(SOUND_EAT);
44
45         take_turn(p_ptr, 100);
46
47         /* Identity not known yet */
48         ident = FALSE;
49
50         /* Object level */
51         lev = k_info[o_ptr->k_idx].level;
52
53         if (o_ptr->tval == TV_FOOD)
54         {
55                 /* Analyze the food */
56                 switch (o_ptr->sval)
57                 {
58                 case SV_FOOD_POISON:
59                 {
60                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
61                         {
62                                 if (set_poisoned(p_ptr->poisoned + randint0(10) + 10))
63                                 {
64                                         ident = TRUE;
65                                 }
66                         }
67                         break;
68                 }
69
70                 case SV_FOOD_BLINDNESS:
71                 {
72                         if (!p_ptr->resist_blind)
73                         {
74                                 if (set_blind(p_ptr->blind + randint0(200) + 200))
75                                 {
76                                         ident = TRUE;
77                                 }
78                         }
79                         break;
80                 }
81
82                 case SV_FOOD_PARANOIA:
83                 {
84                         if (!p_ptr->resist_fear)
85                         {
86                                 if (set_afraid(p_ptr->afraid + randint0(10) + 10))
87                                 {
88                                         ident = TRUE;
89                                 }
90                         }
91                         break;
92                 }
93
94                 case SV_FOOD_CONFUSION:
95                 {
96                         if (!p_ptr->resist_conf)
97                         {
98                                 if (set_confused(p_ptr->confused + randint0(10) + 10))
99                                 {
100                                         ident = TRUE;
101                                 }
102                         }
103                         break;
104                 }
105
106                 case SV_FOOD_HALLUCINATION:
107                 {
108                         if (!p_ptr->resist_chaos)
109                         {
110                                 if (set_image(p_ptr->image + randint0(250) + 250))
111                                 {
112                                         ident = TRUE;
113                                 }
114                         }
115                         break;
116                 }
117
118                 case SV_FOOD_PARALYSIS:
119                 {
120                         if (!p_ptr->free_act)
121                         {
122                                 if (set_paralyzed(p_ptr->paralyzed + randint0(10) + 10))
123                                 {
124                                         ident = TRUE;
125                                 }
126                         }
127                         break;
128                 }
129
130                 case SV_FOOD_WEAKNESS:
131                 {
132                         take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
133                         (void)do_dec_stat(A_STR);
134                         ident = TRUE;
135                         break;
136                 }
137
138                 case SV_FOOD_SICKNESS:
139                 {
140                         take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
141                         (void)do_dec_stat(A_CON);
142                         ident = TRUE;
143                         break;
144                 }
145
146                 case SV_FOOD_STUPIDITY:
147                 {
148                         take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
149                         (void)do_dec_stat(A_INT);
150                         ident = TRUE;
151                         break;
152                 }
153
154                 case SV_FOOD_NAIVETY:
155                 {
156                         take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
157                         (void)do_dec_stat(A_WIS);
158                         ident = TRUE;
159                         break;
160                 }
161
162                 case SV_FOOD_UNHEALTH:
163                 {
164                         take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
165                         (void)do_dec_stat(A_CON);
166                         ident = TRUE;
167                         break;
168                 }
169
170                 case SV_FOOD_DISEASE:
171                 {
172                         take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
173                         (void)do_dec_stat(A_STR);
174                         ident = TRUE;
175                         break;
176                 }
177
178                 case SV_FOOD_CURE_POISON:
179                 {
180                         if (set_poisoned(0)) ident = TRUE;
181                         break;
182                 }
183
184                 case SV_FOOD_CURE_BLINDNESS:
185                 {
186                         if (set_blind(0)) ident = TRUE;
187                         break;
188                 }
189
190                 case SV_FOOD_CURE_PARANOIA:
191                 {
192                         if (set_afraid(0)) ident = TRUE;
193                         break;
194                 }
195
196                 case SV_FOOD_CURE_CONFUSION:
197                 {
198                         if (set_confused(0)) ident = TRUE;
199                         break;
200                 }
201
202                 case SV_FOOD_CURE_SERIOUS:
203                 {
204                         ident = cure_serious_wounds(4, 8);
205                         break;
206                 }
207
208                 case SV_FOOD_RESTORE_STR:
209                 {
210                         if (do_res_stat(A_STR)) ident = TRUE;
211                         break;
212                 }
213
214                 case SV_FOOD_RESTORE_CON:
215                 {
216                         if (do_res_stat(A_CON)) ident = TRUE;
217                         break;
218                 }
219
220                 case SV_FOOD_RESTORING:
221                 {
222                         ident = restore_all_status();
223                         break;
224                 }
225
226
227 #ifdef JP
228                 /* それぞれの食べ物の感想をオリジナルより細かく表現 */
229                 case SV_FOOD_BISCUIT:
230                 {
231                         msg_print("甘くてサクサクしてとてもおいしい。");
232                         ident = TRUE;
233                         break;
234                 }
235
236                 case SV_FOOD_JERKY:
237                 {
238                         msg_print("歯ごたえがあっておいしい。");
239                         ident = TRUE;
240                         break;
241                 }
242
243                 case SV_FOOD_SLIME_MOLD:
244                 {
245                         msg_print("これはなんとも形容しがたい味だ。");
246                         ident = TRUE;
247                         break;
248                 }
249
250                 case SV_FOOD_RATION:
251                 {
252                         msg_print("これはおいしい。");
253                         ident = TRUE;
254                         break;
255                 }
256 #else
257                 case SV_FOOD_RATION:
258                 case SV_FOOD_BISCUIT:
259                 case SV_FOOD_JERKY:
260                 case SV_FOOD_SLIME_MOLD:
261                 {
262                         msg_print("That tastes good.");
263                         ident = TRUE;
264                         break;
265                 }
266 #endif
267
268
269                 case SV_FOOD_WAYBREAD:
270                 {
271                         msg_print(_("これはひじょうに美味だ。", "That tastes good."));
272                         (void)set_poisoned(0);
273                         (void)hp_player(damroll(4, 8));
274                         ident = TRUE;
275                         break;
276                 }
277
278 #ifdef JP
279                 case SV_FOOD_PINT_OF_ALE:
280                 {
281                         msg_print("のどごし爽やかだ。");
282                         ident = TRUE;
283                         break;
284                 }
285
286                 case SV_FOOD_PINT_OF_WINE:
287                 {
288                         msg_print("That tastes good.");
289                         ident = TRUE;
290                         break;
291                 }
292 #else
293                 case SV_FOOD_PINT_OF_ALE:
294                 case SV_FOOD_PINT_OF_WINE:
295                 {
296                         msg_print("That tastes good.");
297                         ident = TRUE;
298                         break;
299                 }
300 #endif
301
302                 }
303         }
304         /*
305          * Store what may have to be updated for the inventory (including
306          * autodestroy if set by something else).  Then turn off those flags
307          * so that updates triggered by calling gain_exp() or set_food() below
308          * do not rearrange the inventory before the food item is destroyed in
309          * the pack.
310          */
311         inventory_flags = (PU_COMBINE | PU_REORDER |
312                            (p_ptr->update & PU_AUTODESTROY));
313         p_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
314
315         if (!(object_is_aware(o_ptr)))
316         {
317                 chg_virtue(V_KNOWLEDGE, -1);
318                 chg_virtue(V_PATIENCE, -1);
319                 chg_virtue(V_CHANCE, 1);
320         }
321
322         /* We have tried it */
323         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);
324
325         /* The player is now aware of the object */
326         if (ident && !object_is_aware(o_ptr))
327         {
328                 object_aware(o_ptr);
329                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
330         }
331
332         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
333
334         /* Food can feed the player */
335         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
336         {
337                 /* Reduced nutritional benefit */
338                 (void)set_food(p_ptr->food + (o_ptr->pval / 10));
339                 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。",
340                         "Mere victuals hold scant sustenance for a being such as yourself."));
341
342                 if (p_ptr->food < PY_FOOD_ALERT)   /* Hungry */
343                         msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!",
344                                 "Your hunger can only be satisfied with fresh blood!"));
345         }
346         else if ((prace_is_(RACE_SKELETON) ||
347                 prace_is_(RACE_GOLEM) ||
348                 prace_is_(RACE_ZOMBIE) ||
349                 prace_is_(RACE_SPECTRE)) &&
350                 (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))
351         {
352                 concptr staff;
353
354                 if (o_ptr->tval == TV_STAFF &&
355                         (item < 0) && (o_ptr->number > 1))
356                 {
357                         p_ptr->update |= inventory_flags;
358                         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
359                         return;
360                 }
361                 staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
362
363                 /* "Eat" charges */
364                 if (o_ptr->pval == 0)
365                 {
366                         msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
367                         o_ptr->ident |= (IDENT_EMPTY);
368                         p_ptr->update |= inventory_flags;
369                         p_ptr->window |= (PW_INVEN);
370
371                         return;
372                 }
373                 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
374
375                 /* Use a single charge */
376                 o_ptr->pval--;
377
378                 /* Eat a charge */
379                 set_food(p_ptr->food + 5000);
380
381                 /* XXX Hack -- unstack if necessary */
382                 if (o_ptr->tval == TV_STAFF &&
383                         (item >= 0) && (o_ptr->number > 1))
384                 {
385                         object_type forge;
386                         object_type *q_ptr;
387                         q_ptr = &forge;
388
389                         /* Obtain a local object */
390                         object_copy(q_ptr, o_ptr);
391
392                         /* Modify quantity */
393                         q_ptr->number = 1;
394
395                         /* Restore the charges */
396                         o_ptr->pval++;
397
398                         /* Unstack the used item */
399                         o_ptr->number--;
400                         p_ptr->total_weight -= q_ptr->weight;
401                         item = inven_carry(q_ptr);
402
403                         msg_format(_("杖をまとめなおした。", "You unstack your staff."));
404                 }
405
406                 /* Describe charges in the pack */
407                 if (item >= 0)
408                 {
409                         inven_item_charges(item);
410                 }
411
412                 /* Describe charges on the floor */
413                 else
414                 {
415                         floor_item_charges(0 - item);
416                 }
417
418                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
419                 p_ptr->update |= inventory_flags;
420
421                 /* Don't eat a staff/wand itself */
422                 return;
423         }
424         else if ((prace_is_(RACE_DEMON) ||
425                 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&
426                 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&
427                         my_strchr("pht", r_info[o_ptr->pval].d_char)))
428         {
429                 /* Drain vitality of humanoids */
430                 GAME_TEXT o_name[MAX_NLEN];
431                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
432                 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);
433                 (void)set_food(PY_FOOD_MAX - 1);
434         }
435         else if (prace_is_(RACE_SKELETON))
436         {
437 #if 0
438                 if (o_ptr->tval == TV_SKELETON ||
439                         (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
440                 {
441                         msg_print(_("あなたは骨で自分の体を補った。", "Your body absorbs the bone."));
442                         set_food(p_ptr->food + 5000);
443                 }
444                 else
445 #endif
446
447                         if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||
448                                 (o_ptr->sval < SV_FOOD_BISCUIT)))
449                         {
450                                 object_type forge;
451                                 object_type *q_ptr = &forge;
452
453                                 msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
454                                 object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));
455
456                                 /* Drop the object from heaven */
457                                 (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);
458                         }
459                         else
460                         {
461                                 msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
462                         }
463         }
464         else if (prace_is_(RACE_GOLEM) ||
465                 prace_is_(RACE_ZOMBIE) ||
466                 prace_is_(RACE_ENT) ||
467                 prace_is_(RACE_DEMON) ||
468                 prace_is_(RACE_ANDROID) ||
469                 prace_is_(RACE_SPECTRE) ||
470                 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))
471         {
472                 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
473                 set_food(p_ptr->food + ((o_ptr->pval) / 20));
474         }
475         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)
476         {
477                 /* Waybread is always fully satisfying. */
478                 set_food(MAX(p_ptr->food, PY_FOOD_MAX - 1));
479         }
480         else
481         {
482                 /* Food can feed the player */
483                 (void)set_food(p_ptr->food + o_ptr->pval);
484         }
485
486         p_ptr->update |= inventory_flags;
487
488         /* Destroy a food in the pack */
489         if (item >= 0)
490         {
491                 inven_item_increase(item, -1);
492                 inven_item_describe(item);
493                 inven_item_optimize(item);
494         }
495
496         /* Destroy a food on the floor */
497         else
498         {
499                 floor_item_increase(0 - item, -1);
500                 floor_item_describe(0 - item);
501                 floor_item_optimize(0 - item);
502         }
503 }
504
505
506 /*!
507  * @brief 食料を食べるコマンドのメインルーチン /
508  * Eat some food (from the pack or floor)
509  * @return なし
510  */
511 void do_cmd_eat_food(void)
512 {
513         OBJECT_IDX item;
514         concptr        q, s;
515
516         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
517         {
518                 set_action(ACTION_NONE);
519         }
520
521         /* Restrict choices to food */
522         item_tester_hook = item_tester_hook_eatable;
523
524         q = _("どれを食べますか? ", "Eat which item? ");
525         s = _("食べ物がない。", "You have nothing to eat.");
526
527         if (!choose_object(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
528
529         /* Eat the object */
530         do_cmd_eat_food_aux(item);
531 }
532