OSDN Git Service

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