OSDN Git Service

d853aab0eb22a03241f99780fe9490db3ddd912a
[hengband/hengband.git] / src / cmd / 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 "main/sound-definitions-table.h"
12 #include "util.h"
13
14 #include "object-flavor.h"
15 #include "object-hook.h"
16 #include "avatar.h"
17 #include "spells-status.h"
18 #include "realm-hex.h"
19 #include "player-status.h"
20 #include "player-effects.h"
21 #include "player-damage.h"
22 #include "player/mimic-info-table.h"
23 #include "player-class.h"
24 #include "player-inventory.h"
25 #include "floor.h"
26 #include "object/object-kind.h"
27 #include "view/display-main-window.h"
28
29  /*!
30   * @brief 食料を食べるコマンドのサブルーチン
31   * @param item 食べるオブジェクトの所持品ID
32   * @return なし
33   */
34 void exe_eat_food(player_type *creature_ptr, INVENTORY_IDX item)
35 {
36         int ident, lev;
37         object_type *o_ptr;
38
39         if (music_singing_any(creature_ptr)) stop_singing(creature_ptr);
40         if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
41         o_ptr = REF_ITEM(creature_ptr, creature_ptr->current_floor_ptr, item);
42
43         sound(SOUND_EAT);
44
45         take_turn(creature_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 (!(creature_ptr->resist_pois || is_oppose_pois(creature_ptr)))
61                         {
62                                 if (set_poisoned(creature_ptr, creature_ptr->poisoned + randint0(10) + 10))
63                                 {
64                                         ident = TRUE;
65                                 }
66                         }
67                         break;
68                 }
69
70                 case SV_FOOD_BLINDNESS:
71                 {
72                         if (!creature_ptr->resist_blind)
73                         {
74                                 if (set_blind(creature_ptr, creature_ptr->blind + randint0(200) + 200))
75                                 {
76                                         ident = TRUE;
77                                 }
78                         }
79                         break;
80                 }
81
82                 case SV_FOOD_PARANOIA:
83                 {
84                         if (!creature_ptr->resist_fear)
85                         {
86                                 if (set_afraid(creature_ptr, creature_ptr->afraid + randint0(10) + 10))
87                                 {
88                                         ident = TRUE;
89                                 }
90                         }
91                         break;
92                 }
93
94                 case SV_FOOD_CONFUSION:
95                 {
96                         if (!creature_ptr->resist_conf)
97                         {
98                                 if (set_confused(creature_ptr, creature_ptr->confused + randint0(10) + 10))
99                                 {
100                                         ident = TRUE;
101                                 }
102                         }
103                         break;
104                 }
105
106                 case SV_FOOD_HALLUCINATION:
107                 {
108                         if (!creature_ptr->resist_chaos)
109                         {
110                                 if (set_image(creature_ptr, creature_ptr->image + randint0(250) + 250))
111                                 {
112                                         ident = TRUE;
113                                 }
114                         }
115                         break;
116                 }
117
118                 case SV_FOOD_PARALYSIS:
119                 {
120                         if (!creature_ptr->free_act)
121                         {
122                                 if (set_paralyzed(creature_ptr, creature_ptr->paralyzed + randint0(10) + 10))
123                                 {
124                                         ident = TRUE;
125                                 }
126                         }
127                         break;
128                 }
129
130                 case SV_FOOD_WEAKNESS:
131                 {
132                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
133                         (void)do_dec_stat(creature_ptr, A_STR);
134                         ident = TRUE;
135                         break;
136                 }
137
138                 case SV_FOOD_SICKNESS:
139                 {
140                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
141                         (void)do_dec_stat(creature_ptr, A_CON);
142                         ident = TRUE;
143                         break;
144                 }
145
146                 case SV_FOOD_STUPIDITY:
147                 {
148                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
149                         (void)do_dec_stat(creature_ptr, A_INT);
150                         ident = TRUE;
151                         break;
152                 }
153
154                 case SV_FOOD_NAIVETY:
155                 {
156                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
157                         (void)do_dec_stat(creature_ptr, A_WIS);
158                         ident = TRUE;
159                         break;
160                 }
161
162                 case SV_FOOD_UNHEALTH:
163                 {
164                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
165                         (void)do_dec_stat(creature_ptr, A_CON);
166                         ident = TRUE;
167                         break;
168                 }
169
170                 case SV_FOOD_DISEASE:
171                 {
172                         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
173                         (void)do_dec_stat(creature_ptr, A_STR);
174                         ident = TRUE;
175                         break;
176                 }
177
178                 case SV_FOOD_CURE_POISON:
179                 {
180                         if (set_poisoned(creature_ptr, 0)) ident = TRUE;
181                         break;
182                 }
183
184                 case SV_FOOD_CURE_BLINDNESS:
185                 {
186                         if (set_blind(creature_ptr, 0)) ident = TRUE;
187                         break;
188                 }
189
190                 case SV_FOOD_CURE_PARANOIA:
191                 {
192                         if (set_afraid(creature_ptr, 0)) ident = TRUE;
193                         break;
194                 }
195
196                 case SV_FOOD_CURE_CONFUSION:
197                 {
198                         if (set_confused(creature_ptr, 0)) ident = TRUE;
199                         break;
200                 }
201
202                 case SV_FOOD_CURE_SERIOUS:
203                 {
204                         ident = cure_serious_wounds(creature_ptr, 4, 8);
205                         break;
206                 }
207
208                 case SV_FOOD_RESTORE_STR:
209                 {
210                         if (do_res_stat(creature_ptr, A_STR)) ident = TRUE;
211                         break;
212                 }
213
214                 case SV_FOOD_RESTORE_CON:
215                 {
216                         if (do_res_stat(creature_ptr, A_CON)) ident = TRUE;
217                         break;
218                 }
219
220                 case SV_FOOD_RESTORING:
221                 {
222                         ident = restore_all_status(creature_ptr);
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(creature_ptr, 0);
273                         (void)hp_player(creature_ptr, damroll(4, 8));
274                         ident = TRUE;
275                         break;
276                 }
277
278                 case SV_FOOD_PINT_OF_ALE:
279                 {
280                         msg_print(_("のどごし爽やかだ。", "That tastes good."));
281                         ident = TRUE;
282                         break;
283                 }
284
285                 case SV_FOOD_PINT_OF_WINE:
286                 {
287                         msg_print(_("のどごし爽やかだ。", "That tastes good."));
288                         ident = TRUE;
289                         break;
290                 }
291
292                 }
293         }
294         
295         /*
296          * Store what may have to be updated for the inventory (including
297          * autodestroy if set by something else).  Then turn off those flags
298          * so that updates triggered by calling gain_exp() or set_food() below
299          * do not rearrange the inventory before the food item is destroyed in
300          * the pack.
301          */
302         BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (creature_ptr->update & PU_AUTODESTROY));
303         creature_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
304
305         if (!(object_is_aware(o_ptr)))
306         {
307                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
308                 chg_virtue(creature_ptr, V_PATIENCE, -1);
309                 chg_virtue(creature_ptr, V_CHANCE, 1);
310         }
311
312         /* We have tried it */
313         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);
314
315         /* The player is now aware of the object */
316         if (ident && !object_is_aware(o_ptr))
317         {
318                 object_aware(creature_ptr, o_ptr);
319                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
320         }
321
322         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
323
324         /* Food can feed the player */
325         if (PRACE_IS_(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE))
326         {
327                 /* Reduced nutritional benefit */
328                 (void)set_food(creature_ptr, creature_ptr->food + (o_ptr->pval / 10));
329                 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。",
330                         "Mere victuals hold scant sustenance for a being such as yourself."));
331
332                 if (creature_ptr->food < PY_FOOD_ALERT)   /* Hungry */
333                         msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!",
334                                 "Your hunger can only be satisfied with fresh blood!"));
335         }
336         else if ((PRACE_IS_(creature_ptr, RACE_SKELETON) ||
337                 PRACE_IS_(creature_ptr, RACE_GOLEM) ||
338                 PRACE_IS_(creature_ptr, RACE_ZOMBIE) ||
339                 PRACE_IS_(creature_ptr, RACE_SPECTRE)) &&
340                 (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))
341         {
342                 concptr staff;
343
344                 if (o_ptr->tval == TV_STAFF &&
345                         (item < 0) && (o_ptr->number > 1))
346                 {
347                         creature_ptr->update |= inventory_flags;
348                         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
349                         return;
350                 }
351                 staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
352
353                 /* "Eat" charges */
354                 if (o_ptr->pval == 0)
355                 {
356                         msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
357                         o_ptr->ident |= (IDENT_EMPTY);
358                         creature_ptr->update |= inventory_flags;
359                         creature_ptr->window |= (PW_INVEN);
360
361                         return;
362                 }
363                 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
364
365                 /* Use a single charge */
366                 o_ptr->pval--;
367
368                 /* Eat a charge */
369                 set_food(creature_ptr, creature_ptr->food + 5000);
370
371                 /* XXX Hack -- unstack if necessary */
372                 if (o_ptr->tval == TV_STAFF &&
373                         (item >= 0) && (o_ptr->number > 1))
374                 {
375                         object_type forge;
376                         object_type *q_ptr;
377                         q_ptr = &forge;
378                         object_copy(q_ptr, o_ptr);
379
380                         /* Modify quantity */
381                         q_ptr->number = 1;
382
383                         /* Restore the charges */
384                         o_ptr->pval++;
385
386                         /* Unstack the used item */
387                         o_ptr->number--;
388                         creature_ptr->total_weight -= q_ptr->weight;
389                         item = inven_carry(creature_ptr, q_ptr);
390
391                         msg_format(_("杖をまとめなおした。", "You unstack your staff."));
392                 }
393
394                 /* Describe charges in the pack */
395                 if (item >= 0)
396                 {
397                         inven_item_charges(creature_ptr, item);
398                 }
399
400                 /* Describe charges on the floor */
401                 else
402                 {
403                         floor_item_charges(creature_ptr->current_floor_ptr, 0 - item);
404                 }
405
406                 creature_ptr->window |= (PW_INVEN | PW_EQUIP);
407                 creature_ptr->update |= inventory_flags;
408
409                 /* Don't eat a staff/wand itself */
410                 return;
411         }
412
413         if ((PRACE_IS_(creature_ptr, RACE_DEMON) ||
414                 (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&
415                 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&
416                         my_strchr("pht", r_info[o_ptr->pval].d_char)))
417         {
418                 /* Drain vitality of humanoids */
419                 GAME_TEXT o_name[MAX_NLEN];
420                 object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
421                 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);
422                 (void)set_food(creature_ptr, PY_FOOD_MAX - 1);
423         }
424         else if (PRACE_IS_(creature_ptr, RACE_SKELETON))
425         {
426                 if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||
427                         (o_ptr->sval < SV_FOOD_BISCUIT)))
428                 {
429                         object_type forge;
430                         object_type *q_ptr = &forge;
431
432                         msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
433                         object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));
434
435                         /* Drop the object from heaven */
436                         (void)drop_near(creature_ptr, q_ptr, -1, creature_ptr->y, creature_ptr->x);
437                 }
438                 else
439                 {
440                         msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
441                 }
442         }
443         else if (PRACE_IS_(creature_ptr, RACE_GOLEM) ||
444                 PRACE_IS_(creature_ptr, RACE_ZOMBIE) ||
445                 PRACE_IS_(creature_ptr, RACE_ENT) ||
446                 PRACE_IS_(creature_ptr, RACE_DEMON) ||
447                 PRACE_IS_(creature_ptr, RACE_ANDROID) ||
448                 PRACE_IS_(creature_ptr, RACE_SPECTRE) ||
449                 (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))
450         {
451                 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
452                 set_food(creature_ptr, creature_ptr->food + ((o_ptr->pval) / 20));
453         }
454         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)
455         {
456                 /* Waybread is always fully satisfying. */
457                 set_food(creature_ptr, MAX(creature_ptr->food, PY_FOOD_MAX - 1));
458         }
459         else
460         {
461                 /* Food can feed the player */
462                 (void)set_food(creature_ptr, creature_ptr->food + o_ptr->pval);
463         }
464
465         creature_ptr->update |= inventory_flags;
466         vary_item(creature_ptr, item, -1);
467 }
468
469
470 /*!
471  * @brief 食料を食べるコマンドのメインルーチン /
472  * Eat some food (from the pack or floor)
473  * @return なし
474  */
475 void do_cmd_eat_food(player_type *creature_ptr)
476 {
477         OBJECT_IDX item;
478         concptr q, s;
479
480         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
481         {
482                 set_action(creature_ptr, ACTION_NONE);
483         }
484
485         item_tester_hook = item_tester_hook_eatable;
486
487         q = _("どれを食べますか? ", "Eat which item? ");
488         s = _("食べ物がない。", "You have nothing to eat.");
489
490         if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0)) return;
491
492         exe_eat_food(creature_ptr, item);
493 }
494