OSDN Git Service

[Refactor] #37353 REF_ITEM マクロを各所に適用.
[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-damage.h"
21 #include "player-race.h"
22 #include "player-class.h"
23 #include "floor.h"
24 #include "objectkind.h"
25 #include "realm.h"
26 #include "realm-song.h"
27 #include "view-mainwindow.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();
41         o_ptr = REF_ITEM(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()))
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(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();
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         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
295
296         if (!(object_is_aware(o_ptr)))
297         {
298                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
299                 chg_virtue(creature_ptr, V_PATIENCE, -1);
300                 chg_virtue(creature_ptr, V_CHANCE, 1);
301         }
302
303         /* We have tried it */
304         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);
305
306         /* The player is now aware of the object */
307         if (ident && !object_is_aware(o_ptr))
308         {
309                 object_aware(o_ptr);
310                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
311         }
312
313         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
314
315
316         /* Food can feed the player */
317         if (PRACE_IS_(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE))
318         {
319                 /* Reduced nutritional benefit */
320                 (void)set_food(creature_ptr, creature_ptr->food + (o_ptr->pval / 10));
321                 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。",
322                         "Mere victuals hold scant sustenance for a being such as yourself."));
323
324                 if (creature_ptr->food < PY_FOOD_ALERT)   /* Hungry */
325                         msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!",
326                                 "Your hunger can only be satisfied with fresh blood!"));
327         }
328         else if ((PRACE_IS_(creature_ptr, RACE_SKELETON) ||
329                 PRACE_IS_(creature_ptr, RACE_GOLEM) ||
330                 PRACE_IS_(creature_ptr, RACE_ZOMBIE) ||
331                 PRACE_IS_(creature_ptr, RACE_SPECTRE)) &&
332                 (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))
333         {
334                 concptr staff;
335
336                 if (o_ptr->tval == TV_STAFF &&
337                         (item < 0) && (o_ptr->number > 1))
338                 {
339                         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
340                         return;
341                 }
342                 staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
343
344                 /* "Eat" charges */
345                 if (o_ptr->pval == 0)
346                 {
347                         msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
348                         o_ptr->ident |= (IDENT_EMPTY);
349                         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
350                         creature_ptr->window |= (PW_INVEN);
351
352                         return;
353                 }
354                 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
355
356                 /* Use a single charge */
357                 o_ptr->pval--;
358
359                 /* Eat a charge */
360                 set_food(creature_ptr, creature_ptr->food + 5000);
361
362                 /* XXX Hack -- unstack if necessary */
363                 if (o_ptr->tval == TV_STAFF &&
364                         (item >= 0) && (o_ptr->number > 1))
365                 {
366                         object_type forge;
367                         object_type *q_ptr;
368                         q_ptr = &forge;
369                         object_copy(q_ptr, o_ptr);
370
371                         /* Modify quantity */
372                         q_ptr->number = 1;
373
374                         /* Restore the charges */
375                         o_ptr->pval++;
376
377                         /* Unstack the used item */
378                         o_ptr->number--;
379                         creature_ptr->total_weight -= q_ptr->weight;
380                         item = inven_carry(q_ptr);
381
382                         msg_format(_("杖をまとめなおした。", "You unstack your staff."));
383                 }
384
385                 /* Describe charges in the pack */
386                 if (item >= 0)
387                 {
388                         inven_item_charges(item);
389                 }
390
391                 /* Describe charges on the floor */
392                 else
393                 {
394                         floor_item_charges(0 - item);
395                 }
396
397                 creature_ptr->window |= (PW_INVEN | PW_EQUIP);
398
399                 /* Don't eat a staff/wand itself */
400                 return;
401         }
402         else if ((PRACE_IS_(creature_ptr, RACE_DEMON) ||
403                 (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&
404                 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&
405                         my_strchr("pht", r_info[o_ptr->pval].d_char)))
406         {
407                 /* Drain vitality of humanoids */
408                 GAME_TEXT o_name[MAX_NLEN];
409                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
410                 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);
411                 (void)set_food(creature_ptr, PY_FOOD_MAX - 1);
412         }
413         else if (PRACE_IS_(creature_ptr, RACE_SKELETON))
414         {
415 #if 0
416                 if (o_ptr->tval == TV_SKELETON ||
417                         (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
418                 {
419                         msg_print(_("あなたは骨で自分の体を補った。", "Your body absorbs the bone."));
420                         set_food(creature_ptr, creature_ptr->food + 5000);
421                 }
422                 else
423 #endif
424
425                         if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||
426                                 (o_ptr->sval < SV_FOOD_BISCUIT)))
427                         {
428                                 object_type forge;
429                                 object_type *q_ptr = &forge;
430
431                                 msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
432                                 object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));
433
434                                 /* Drop the object from heaven */
435                                 (void)drop_near(q_ptr, -1, creature_ptr->y, creature_ptr->x);
436                         }
437                         else
438                         {
439                                 msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
440                         }
441         }
442         else if (PRACE_IS_(creature_ptr, RACE_GOLEM) ||
443                 PRACE_IS_(creature_ptr, RACE_ZOMBIE) ||
444                 PRACE_IS_(creature_ptr, RACE_ENT) ||
445                 PRACE_IS_(creature_ptr, RACE_DEMON) ||
446                 PRACE_IS_(creature_ptr, RACE_ANDROID) ||
447                 PRACE_IS_(creature_ptr, RACE_SPECTRE) ||
448                 (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))
449         {
450                 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
451                 set_food(creature_ptr, creature_ptr->food + ((o_ptr->pval) / 20));
452         }
453         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)
454         {
455                 /* Waybread is always fully satisfying. */
456                 set_food(creature_ptr, MAX(creature_ptr->food, PY_FOOD_MAX - 1));
457         }
458         else
459         {
460                 /* Food can feed the player */
461                 (void)set_food(creature_ptr, creature_ptr->food + o_ptr->pval);
462         }
463
464         if (item >= 0)
465         {
466                 inven_item_increase(item, -1);
467                 inven_item_describe(item);
468                 inven_item_optimize(item);
469         }
470         else
471         {
472                 floor_item_increase(0 - item, -1);
473                 floor_item_describe(0 - item);
474                 floor_item_optimize(0 - item);
475         }
476 }
477
478
479 /*!
480  * @brief 食料を食べるコマンドのメインルーチン /
481  * Eat some food (from the pack or floor)
482  * @return なし
483  */
484 void do_cmd_eat_food(player_type *creature_ptr)
485 {
486         OBJECT_IDX item;
487         concptr q, s;
488
489         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
490         {
491                 set_action(creature_ptr, ACTION_NONE);
492         }
493
494         item_tester_hook = item_tester_hook_eatable;
495
496         q = _("どれを食べますか? ", "Eat which item? ");
497         s = _("食べ物がない。", "You have nothing to eat.");
498
499         if (!choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), 0)) return;
500
501         exe_eat_food(creature_ptr, item);
502 }
503