OSDN Git Service

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