OSDN Git Service

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