OSDN Git Service

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