OSDN Git Service

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